Project

General

Profile

Download (11.6 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 8a2f80b2 jim-p
##|*MATCH=graph.php*
45
##|*MATCH=ifstats.php*
46 6b07c15a Matthew Grooms
##|-PRIV
47
48 5b237745 Scott Ullrich
require("guiconfig.inc");
49
50 9573d170 Scott Ullrich
if ($_POST['width'])
51
	$width = $_POST['width'];
52
else
53 f0a3b883 Scott Ullrich
	$width = "100%";
54 9573d170 Scott Ullrich
55 dd521ae8 Scott Ullrich
if ($_POST['height'])
56 9573d170 Scott Ullrich
	$height = $_POST['height'];
57
else
58 f0a3b883 Scott Ullrich
	$height = "200";
59 9573d170 Scott Ullrich
60 94556105 Scott Ullrich
// Get configured interface list
61 61ab4cd3 Scott Ullrich
$ifdescrs = get_configured_interface_with_descr();
62 9f5d14ce jim-p
if (isset($config['ipsec']['enable']))
63
	$ifdescrs['enc0'] = "IPsec";
64
foreach (array('server', 'client') as $mode) {
65
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
66
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
67
			if (!isset($setting['disable'])) {
68
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
69
			}
70
		}
71
	}
72
}
73 43a0ac8a Scott Ullrich
74 50b2f6ab Scott Ullrich
if ($_GET['if']) {
75 5b237745 Scott Ullrich
	$curif = $_GET['if'];
76 50b2f6ab Scott Ullrich
	$found = false;
77 b406c78a Ermal
	foreach($ifdescrs as $descr => $ifdescr) {
78
		if ($descr == $curif) {
79
			$found = true;
80
			break;
81
		}
82
	}
83
	if ($found === false) {
84 6f3d2063 Renato Botelho
		header("Location: status_graph.php");
85 50b2f6ab Scott Ullrich
		exit;
86
	}
87
} else {
88 76165eac Phil Davis
	if (empty($ifdescrs["wan"])) {
89
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
90
		reset($ifdescrs);
91
		$curif = key($ifdescrs);
92
	}
93
	else {
94
		$curif = "wan";
95
	}
96 50b2f6ab Scott Ullrich
}
97 893fb622 Michele Di Maria
if ($_GET['sort']) {
98
	$cursort = $_GET['sort'];
99
} else {
100
	$cursort = "";
101
}
102 da11e022 Phil Davis
if ($_GET['filter']) {
103
	$curfilter = $_GET['filter'];
104
} else {
105
	$curfilter = "";
106
}
107 4006a437 Phil Davis
if ($_GET['hostipformat']) {
108
	$curhostipformat = $_GET['hostipformat'];
109
} else {
110
	$curhostipformat = "";
111
}
112 769cdf3b Bill Marquette
113 d0033721 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
114 f0a3b883 Scott Ullrich
115 4df96eff Scott Ullrich
include("head.inc");
116
117 5b237745 Scott Ullrich
?>
118
119
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
120 286996b4 Colin Fleming
<?php include("fbegin.inc"); ?>
121 f0a3b883 Scott Ullrich
122 07130afe ayvis
<script type="text/javascript">
123 286996b4 Colin Fleming
//<![CDATA[
124 f0a3b883 Scott Ullrich
function updateBandwidth(){
125 ffac939e Ermal
    var hostinterface = jQuery("#if").val();
126 2675f511 Renato Botelho
	var sorting = jQuery("#sort").val();
127 da11e022 Phil Davis
	var filter = jQuery("#filter").val();
128 4006a437 Phil Davis
	var hostipformat = jQuery("#hostipformat").val();
129 da11e022 Phil Davis
    bandwidthAjax(hostinterface, sorting, filter, hostipformat);
130 f0a3b883 Scott Ullrich
}
131
132 da11e022 Phil Davis
function bandwidthAjax(hostinterface, sorting, filter, hostipformat) {
133
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting + "&filter=" + filter + "&hostipformat=" + hostipformat;
134 f0a3b883 Scott Ullrich
	var opt = {
135
	    // Use GET
136 e03ef9a0 Vinicius Coque
	    type: 'get',
137
	    error: function(req) {
138 1cf47c49 Ermal
	        /* XXX: Leave this for debugging purposes: Handle 404
139 e03ef9a0 Vinicius Coque
	        if(req.status == 404)
140
	            alert('Error 404: location "' + uri + '" was not found.');
141 1cf47c49 Ermal
		*/
142
	        /* Handle other errors
143 e03ef9a0 Vinicius Coque
	        else
144 b1b930dd Ermal
	            alert('Error ' + req.status + ' -- ' + req.statusText + ' -- ' + uri);
145 1cf47c49 Ermal
		*/
146 f0a3b883 Scott Ullrich
	    },
147 e03ef9a0 Vinicius Coque
		success: function(data) {
148
			updateBandwidthHosts(data);
149 f0a3b883 Scott Ullrich
	    }
150
	}
151 e03ef9a0 Vinicius Coque
	jQuery.ajax(uri, opt);
152 f0a3b883 Scott Ullrich
}
153
154
function updateBandwidthHosts(data){
155
    var hosts_split = data.split("|");
156
    d = document;
157
    //parse top ten bandwidth abuser hosts
158
    for (var y=0; y<10; y++){
159 5356362c Phil Davis
        if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
160
			hostinfo = hosts_split[y].split(";");
161
162
			//update host ip info
163
			var HostIpID = "hostip" + y;
164
			var hostip = d.getElementById(HostIpID);
165
			hostip.innerHTML = hostinfo[0];
166
167
			//update bandwidth inbound to host
168
			var hostbandwidthInID = "bandwidthin" + y;
169
			var hostbandwidthin = d.getElementById(hostbandwidthInID);
170
			hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
171
172
			//update bandwidth outbound from host
173
			var hostbandwidthOutID = "bandwidthout" + y;
174
			var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
175
			hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
176
177
			//make the row appear if hidden
178
			var rowid = "#host" + y;
179
			if (jQuery(rowid).css('display') == "none"){
180
				//hide rows that contain no data
181
				jQuery(rowid).show(1000);
182
			}
183 f0a3b883 Scott Ullrich
        }
184
        else
185
        {
186 e03ef9a0 Vinicius Coque
            var rowid = "#host" + y;
187 7f8f5d01 Phil Davis
            if (jQuery(rowid).css('display') != "none"){
188 f0a3b883 Scott Ullrich
                //hide rows that contain no data
189 e03ef9a0 Vinicius Coque
                jQuery(rowid).fadeOut(2000);
190 f0a3b883 Scott Ullrich
            }
191
        }
192
    }
193
    
194 e6dd418d sullrich
    setTimeout('updateBandwidth()', 1000);
195 f0a3b883 Scott Ullrich
}
196 286996b4 Colin Fleming
//]]>
197 f0a3b883 Scott Ullrich
</script>
198
199 5b237745 Scott Ullrich
<?php
200 9573d170 Scott Ullrich
201 872ce0dd Ermal Luçi
/* link the ipsec interface magically */
202 c6dfd289 jim-p
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
203 872ce0dd Ermal Luçi
	$ifdescrs['enc0'] = "IPsec";
204 c1abd446 Seth Mos
205 5b237745 Scott Ullrich
?>
206 60f9e276 Bill Marquette
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
207 59bb015e Carlos Eduardo Ramos
<?=gettext("Interface"); ?>:
208 b1b930dd Ermal
<select id="if" name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
209 5b237745 Scott Ullrich
<?php
210
foreach ($ifdescrs as $ifn => $ifd) {
211
	echo "<option value=\"$ifn\"";
212 286996b4 Colin Fleming
	if ($ifn == $curif) echo " selected=\"selected\"";
213 82bf9411 Scott Ullrich
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
214 5b237745 Scott Ullrich
}
215
?>
216
</select>
217 893fb622 Michele Di Maria
, Sort by: 
218 b1b930dd Ermal
<select id="sort" name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
219 da11e022 Phil Davis
	<option value="">Bw In</option>
220 286996b4 Colin Fleming
	<option value="out"<?php if ($cursort == "out") echo " selected=\"selected\"";?>>Bw Out</option>
221 da11e022 Phil Davis
</select>
222
, Filter: 
223
<select id="filter" name="filter" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
224 286996b4 Colin Fleming
	<option value="local"<?php if ($curfilter == "local") echo " selected=\"selected\"";?>>Local</option>
225
	<option value="remote"<?php if ($curfilter == "remote") echo " selected=\"selected\"";?>>Remote</option>
226
	<option value="all"<?php if ($curfilter == "all") echo " selected=\"selected\"";?>>All</option>
227 893fb622 Michele Di Maria
</select>
228 4006a437 Phil Davis
, Display: 
229
<select id="hostipformat" name="hostipformat" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
230
	<option value="">IP Address</option>
231
	<option value="hostname"<?php if ($curhostipformat == "hostname") echo " selected";?>>Host Name</option>
232 286996b4 Colin Fleming
	<option value="fqdn"<?php if ($curhostipformat == "fqdn") echo " selected=\"selected\"";?>>FQDN</option>
233 4006a437 Phil Davis
</select>
234 5b237745 Scott Ullrich
</form>
235 286996b4 Colin Fleming
<p>&nbsp;</p>
236 e57c91a2 Renato Botelho
<div id="niftyOutter">
237
    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
238 286996b4 Colin Fleming
        <object	data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&amp;ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>">
239
          <param name="id" value="graph" />
240
          <param name="type" value="image/svg+xml" />
241
          <param name="width" value="<? echo $width; ?>" />
242
          <param name="height" value="<? echo $height; ?>" />
243
          <param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
244
        </object>
245 f0a3b883 Scott Ullrich
    </div>
246 e57c91a2 Renato Botelho
    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
247 286996b4 Colin Fleming
        <table width="100%" border="0" cellspacing="0" cellpadding="0" summary="status">
248 f0a3b883 Scott Ullrich
            <tr>
249 8389a461 Phil Davis
                <td class="listtopic" valign="top"><?=(($curhostipformat=="") ? gettext("Host IP") : gettext("Host Name or IP")); ?></td>
250 d0033721 Carlos Eduardo Ramos
                <td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
251
                <td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
252 f0a3b883 Scott Ullrich
           </tr>
253
           <tr id="host0" style="display:none">
254
                <td id="hostip0" class="vncell">
255
                </td>
256
                <td id="bandwidthin0" class="listr">
257
                </td>
258
                <td id="bandwidthout0" class="listr">
259
                </td>
260
           </tr>
261
           <tr id="host1" style="display:none">
262
                <td id="hostip1" class="vncell">
263
                </td>
264
                <td id="bandwidthin1" class="listr">
265
                </td>
266
                <td id="bandwidthout1" class="listr">
267
                </td>
268
           </tr>
269
           <tr id="host2" style="display:none">
270
                <td id="hostip2" class="vncell">
271
                </td>
272
                <td id="bandwidthin2" class="listr">
273
                </td>
274
                <td id="bandwidthout2" class="listr">
275
                </td>
276
           </tr>
277
           <tr id="host3" style="display:none">
278
                <td id="hostip3" class="vncell">
279
                </td>
280
                <td id="bandwidthin3" class="listr">
281
                </td>
282
                <td id="bandwidthout3" class="listr">
283
                </td>
284
           </tr>
285
           <tr id="host4" style="display:none">
286
                <td id="hostip4" class="vncell">
287
                </td>
288
                <td id="bandwidthin4" class="listr">
289
                </td>
290
                <td id="bandwidthout4" class="listr">
291
                </td>
292
           </tr>
293
           <tr id="host5" style="display:none">
294
                <td id="hostip5" class="vncell">
295
                </td>
296
                <td id="bandwidthin5" class="listr">
297
                </td>
298
                <td id="bandwidthout5" class="listr">
299
                </td>
300
           </tr>
301
           <tr id="host6" style="display:none">
302
                <td id="hostip6" class="vncell">
303
                </td>
304
                <td id="bandwidthin6" class="listr">
305
                </td>
306
                <td id="bandwidthout6" class="listr">
307
                </td>
308
           </tr>
309
           <tr id="host7" style="display:none">
310
                <td id="hostip7" class="vncell">
311
                </td>
312
                <td id="bandwidthin7" class="listr">
313
                </td>
314
                <td id="bandwidthout7" class="listr">
315
                </td>
316
           </tr>
317
           <tr id="host8" style="display:none">
318
                <td id="hostip8" class="vncell">
319
                </td>
320
                <td id="bandwidthin8" class="listr">
321
                </td>
322
                <td id="bandwidthout8" class="listr">
323
                </td>
324
           </tr>
325
           <tr id="host9" style="display:none">
326
                <td id="hostip9" class="vncell">
327
                </td>
328
                <td id="bandwidthin9" class="listr">
329
                </td>
330
                <td id="bandwidthout9" class="listr">
331
                </td>
332
           </tr>
333
        </table>
334 e57c91a2 Renato Botelho
	</div>
335
	<div style="clear: both;"></div>
336 8ab3e9ed Erik Kristensen
</div>
337 286996b4 Colin Fleming
<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"); ?>.</p>
338 8ab3e9ed Erik Kristensen
339 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
340 f0a3b883 Scott Ullrich
341
<script type="text/javascript">
342 286996b4 Colin Fleming
//<![CDATA[
343 647df2d4 Ermal
jQuery(document).ready(updateBandwidth);
344 286996b4 Colin Fleming
//]]>
345 f0a3b883 Scott Ullrich
</script>
346 5b237745 Scott Ullrich
</body>
347
</html>