Project

General

Profile

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