Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1 9573d170 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	status_graph.php
5 6ad24605 Scott Ullrich
	Part of pfSense
6
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8 9573d170 Scott Ullrich
9 6ad24605 Scott Ullrich
	Originally part of m0n0wall (http://m0n0.ch/wall)
10 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12 9573d170 Scott Ullrich
13 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 9573d170 Scott Ullrich
16 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 9573d170 Scott Ullrich
19 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 9573d170 Scott Ullrich
23 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34 1d333258 Scott Ullrich
/*	
35
	pfSense_MODULE:	routing
36
*/
37 5b237745 Scott Ullrich
38 6b07c15a Matthew Grooms
##|+PRIV
39
##|*IDENT=page-status-trafficgraph
40
##|*NAME=Status: Traffic Graph page
41
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
42
##|*MATCH=status_graph.php*
43 8e95a671 jim-p
##|*MATCH=bandwidth_by_ip.php*
44 6b07c15a Matthew Grooms
##|-PRIV
45
46 5b237745 Scott Ullrich
require("guiconfig.inc");
47
48 9573d170 Scott Ullrich
if ($_POST['width'])
49
	$width = $_POST['width'];
50
else
51 f0a3b883 Scott Ullrich
	$width = "100%";
52 9573d170 Scott Ullrich
53 dd521ae8 Scott Ullrich
if ($_POST['height'])
54 9573d170 Scott Ullrich
	$height = $_POST['height'];
55
else
56 f0a3b883 Scott Ullrich
	$height = "200";
57 9573d170 Scott Ullrich
58 94556105 Scott Ullrich
// Get configured interface list
59 61ab4cd3 Scott Ullrich
$ifdescrs = get_configured_interface_with_descr();
60 9f5d14ce jim-p
if (isset($config['ipsec']['enable']))
61
	$ifdescrs['enc0'] = "IPsec";
62
foreach (array('server', 'client') as $mode) {
63
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
64
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
65
			if (!isset($setting['disable'])) {
66
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
67
			}
68
		}
69
	}
70
}
71 43a0ac8a Scott Ullrich
72 50b2f6ab Scott Ullrich
if ($_GET['if']) {
73 5b237745 Scott Ullrich
	$curif = $_GET['if'];
74 50b2f6ab Scott Ullrich
	$found = false;
75
	foreach($ifdescrs as $descr => $ifdescr) 
76
		if($descr == $curif) $found = true;
77
	if(!$found) {
78
		Header("Location: status_graph.php");
79
		exit;
80
	}
81
} else {
82 029c5888 Scott Ullrich
	$curif = "wan";
83 50b2f6ab Scott Ullrich
}
84 893fb622 Michele Di Maria
if ($_GET['sort']) {
85
	$cursort = $_GET['sort'];
86
} else {
87
	$cursort = "";
88
}
89 769cdf3b Bill Marquette
90 d0033721 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
91 f0a3b883 Scott Ullrich
92 4df96eff Scott Ullrich
include("head.inc");
93
94 5b237745 Scott Ullrich
?>
95
96
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
97 f0a3b883 Scott Ullrich
98
<script language="javascript" type="text/javascript">
99
100
function updateBandwidth(){
101 50b2f6ab Scott Ullrich
    var hostinterface = "<?php echo htmlspecialchars($curif); ?>";
102 893fb622 Michele Di Maria
	var sorting = "<?php echo htmlspecialchars($cursort); ?>";
103
    bandwidthAjax(hostinterface, sorting);
104 f0a3b883 Scott Ullrich
}
105
106 893fb622 Michele Di Maria
function bandwidthAjax(hostinterface, sorting) {
107
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting;
108 f0a3b883 Scott Ullrich
	var opt = {
109
	    // Use GET
110 e03ef9a0 Vinicius Coque
	    type: 'get',
111
	    error: function(req) {
112
	        // Handle 404
113
	        if(req.status == 404)
114
	            alert('Error 404: location "' + uri + '" was not found.');
115
	        // Handle other errors
116
	        else
117
	            alert('Error ' + req.status + ' -- ' + req.statusText);
118 f0a3b883 Scott Ullrich
	    },
119 e03ef9a0 Vinicius Coque
		success: function(data) {
120
			updateBandwidthHosts(data);
121 f0a3b883 Scott Ullrich
	    }
122
	}
123 e03ef9a0 Vinicius Coque
	jQuery.ajax(uri, opt);
124 f0a3b883 Scott Ullrich
}
125
126
function updateBandwidthHosts(data){
127
    var hosts_split = data.split("|");
128
    d = document;
129
    //parse top ten bandwidth abuser hosts
130
    for (var y=0; y<10; y++){
131
        if (hosts_split[y] != "" && hosts_split[y] != "no info"){
132
            if (hosts_split[y]) {
133
                hostinfo = hosts_split[y].split(";");
134
135
                //update host ip info
136
                var HostIpID = "hostip" + y;
137
                var hostip = d.getElementById(HostIpID);
138
                hostip.innerHTML = hostinfo[0];
139
140
                //update bandwidth inbound to host
141
                var hostbandwidthInID = "bandwidthin" + y;
142
                var hostbandwidthin = d.getElementById(hostbandwidthInID);
143 e774e3b3 Ermal
                hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
144 f0a3b883 Scott Ullrich
145
                //update bandwidth outbound from host
146
                var hostbandwidthOutID = "bandwidthout" + y;
147
                var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
148 e774e3b3 Ermal
                hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
149 f0a3b883 Scott Ullrich
150
                //make the row appear if hidden
151 e03ef9a0 Vinicius Coque
                var rowid = "#host" + y;
152 7f8f5d01 Phil Davis
                if (jQuery(rowid).css('display') == "none"){
153 f0a3b883 Scott Ullrich
                     //hide rows that contain no data
154 e03ef9a0 Vinicius Coque
                     jQuery(rowid).show(1000);
155 f0a3b883 Scott Ullrich
                }
156
            }
157
        }
158
        else
159
        {
160 e03ef9a0 Vinicius Coque
            var rowid = "#host" + y;
161 7f8f5d01 Phil Davis
            if (jQuery(rowid).css('display') != "none"){
162 f0a3b883 Scott Ullrich
                //hide rows that contain no data
163 e03ef9a0 Vinicius Coque
                jQuery(rowid).fadeOut(2000);
164 f0a3b883 Scott Ullrich
            }
165
        }
166
    }
167
    
168 e6dd418d sullrich
    setTimeout('updateBandwidth()', 1000);
169 f0a3b883 Scott Ullrich
}
170
171
172
</script>
173
174 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
175
<?php
176 9573d170 Scott Ullrich
177 872ce0dd Ermal Luçi
/* link the ipsec interface magically */
178 c6dfd289 jim-p
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
179 872ce0dd Ermal Luçi
	$ifdescrs['enc0'] = "IPsec";
180 c1abd446 Seth Mos
181 5b237745 Scott Ullrich
?>
182 60f9e276 Bill Marquette
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
183 59bb015e Carlos Eduardo Ramos
<?=gettext("Interface"); ?>:
184 b5c78501 Seth Mos
<select name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
185 5b237745 Scott Ullrich
<?php
186
foreach ($ifdescrs as $ifn => $ifd) {
187
	echo "<option value=\"$ifn\"";
188
	if ($ifn == $curif) echo " selected";
189 82bf9411 Scott Ullrich
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
190 5b237745 Scott Ullrich
}
191
?>
192
</select>
193 893fb622 Michele Di Maria
, Sort by: 
194
<select name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
195
	<option value="">Bandwidth In</option>
196
	<option value="out"<?php if ($cursort == "out") echo " selected";?>>Bandwidth Out</option>
197
</select>
198 5b237745 Scott Ullrich
</form>
199 570cdbcf Bill Marquette
<p><form method="post" action="status_graph.php">
200 8ab3e9ed Erik Kristensen
</form>
201 da07227e Scott Ullrich
<p>
202 e57c91a2 Renato Botelho
<div id="niftyOutter">
203
    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
204 c58715af Erik Fonnesbeck
        <embed src="graph.php?ifnum=<?=htmlspecialchars($curif);?>&ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>" type="image/svg+xml" width="<?=$width;?>" height="<?=$height;?>" pluginspage="http://www.adobe.com/svg/viewer/install/auto" />
205 f0a3b883 Scott Ullrich
    </div>
206 e57c91a2 Renato Botelho
    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
207 f0a3b883 Scott Ullrich
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
208
            <tr>
209 d0033721 Carlos Eduardo Ramos
                <td class="listtopic" valign="top"><?=gettext("Host IP"); ?></td>
210
                <td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
211
                <td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
212 f0a3b883 Scott Ullrich
           </tr>
213
           <tr id="host0" style="display:none">
214
                <td id="hostip0" class="vncell">
215
                </td>
216
                <td id="bandwidthin0" class="listr">
217
                </td>
218
                <td id="bandwidthout0" class="listr">
219
                </td>
220
           </tr>
221
           <tr id="host1" style="display:none">
222
                <td id="hostip1" class="vncell">
223
                </td>
224
                <td id="bandwidthin1" class="listr">
225
                </td>
226
                <td id="bandwidthout1" class="listr">
227
                </td>
228
           </tr>
229
           <tr id="host2" style="display:none">
230
                <td id="hostip2" class="vncell">
231
                </td>
232
                <td id="bandwidthin2" class="listr">
233
                </td>
234
                <td id="bandwidthout2" class="listr">
235
                </td>
236
           </tr>
237
           <tr id="host3" style="display:none">
238
                <td id="hostip3" class="vncell">
239
                </td>
240
                <td id="bandwidthin3" class="listr">
241
                </td>
242
                <td id="bandwidthout3" class="listr">
243
                </td>
244
           </tr>
245
           <tr id="host4" style="display:none">
246
                <td id="hostip4" class="vncell">
247
                </td>
248
                <td id="bandwidthin4" class="listr">
249
                </td>
250
                <td id="bandwidthout4" class="listr">
251
                </td>
252
           </tr>
253
           <tr id="host5" style="display:none">
254
                <td id="hostip5" class="vncell">
255
                </td>
256
                <td id="bandwidthin5" class="listr">
257
                </td>
258
                <td id="bandwidthout5" class="listr">
259
                </td>
260
           </tr>
261
           <tr id="host6" style="display:none">
262
                <td id="hostip6" class="vncell">
263
                </td>
264
                <td id="bandwidthin6" class="listr">
265
                </td>
266
                <td id="bandwidthout6" class="listr">
267
                </td>
268
           </tr>
269
           <tr id="host7" style="display:none">
270
                <td id="hostip7" class="vncell">
271
                </td>
272
                <td id="bandwidthin7" class="listr">
273
                </td>
274
                <td id="bandwidthout7" class="listr">
275
                </td>
276
           </tr>
277
           <tr id="host8" style="display:none">
278
                <td id="hostip8" class="vncell">
279
                </td>
280
                <td id="bandwidthin8" class="listr">
281
                </td>
282
                <td id="bandwidthout8" class="listr">
283
                </td>
284
           </tr>
285
           <tr id="host9" style="display:none">
286
                <td id="hostip9" class="vncell">
287
                </td>
288
                <td id="bandwidthin9" class="listr">
289
                </td>
290
                <td id="bandwidthout9" class="listr">
291
                </td>
292
           </tr>
293
        </table>
294 e57c91a2 Renato Botelho
	</div>
295
	<div style="clear: both;"></div>
296 8ab3e9ed Erik Kristensen
</div>
297 e5fee340 Scott Ullrich
<p><span class="red"><strong><?=gettext("Note"); ?>:</strong></span> <?=gettext("the"); ?> <a href="http://www.adobe.com/svg/viewer/install/" target="_blank"><?=gettext("Adobe SVG Viewer"); ?></a>, <?=gettext("Firefox 1.5 or later or other browser supporting SVG is required to view the graph"); ?>.
298 8ab3e9ed Erik Kristensen
299 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
300 f0a3b883 Scott Ullrich
301
<script type="text/javascript">
302
window.onload = function(in_event)
303
	{
304
        updateBandwidth();
305
    }
306
307
</script>
308 5b237745 Scott Ullrich
</body>
309
</html>