Project

General

Profile

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