Project

General

Profile

Download (11.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_graph.php
5
	Part of pfSense
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7
	Copyright (C) 2004 Scott Ullrich
8
	All rights reserved.
9

    
10
	Originally part of m0n0wall (http://m0n0.ch/wall)
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	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

    
24
	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
/*	
36
	pfSense_MODULE:	routing
37
*/
38

    
39
##|+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
##|*MATCH=bandwidth_by_ip.php*
45
##|*MATCH=graph.php*
46
##|*MATCH=ifstats.php*
47
##|-PRIV
48

    
49
require("guiconfig.inc");
50

    
51
if ($_POST['width'])
52
	$width = $_POST['width'];
53
else
54
	$width = "100%";
55

    
56
if ($_POST['height'])
57
	$height = $_POST['height'];
58
else
59
	$height = "200";
60

    
61
// Get configured interface list
62
$ifdescrs = get_configured_interface_with_descr();
63
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

    
75
if ($_GET['if']) {
76
	$curif = $_GET['if'];
77
	$found = false;
78
	foreach($ifdescrs as $descr => $ifdescr) {
79
		if ($descr == $curif) {
80
			$found = true;
81
			break;
82
		}
83
	}
84
	if ($found === false) {
85
		header("Location: status_graph.php");
86
		exit;
87
	}
88
} else {
89
	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
}
98
if ($_GET['sort']) {
99
	$cursort = $_GET['sort'];
100
} else {
101
	$cursort = "";
102
}
103
if ($_GET['filter']) {
104
	$curfilter = $_GET['filter'];
105
} else {
106
	$curfilter = "";
107
}
108
if ($_GET['hostipformat']) {
109
	$curhostipformat = $_GET['hostipformat'];
110
} else {
111
	$curhostipformat = "";
112
}
113

    
114
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
115

    
116
include("head.inc");
117

    
118
?>
119

    
120
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
121
<?php include("fbegin.inc"); ?>
122

    
123
<script type="text/javascript">
124
//<![CDATA[
125
function updateBandwidth(){
126
    var hostinterface = jQuery("#if").val();
127
	var sorting = jQuery("#sort").val();
128
	var filter = jQuery("#filter").val();
129
	var hostipformat = jQuery("#hostipformat").val();
130
    bandwidthAjax(hostinterface, sorting, filter, hostipformat);
131
}
132

    
133
function bandwidthAjax(hostinterface, sorting, filter, hostipformat) {
134
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting + "&filter=" + filter + "&hostipformat=" + hostipformat;
135
	var opt = {
136
	    // Use GET
137
	    type: 'get',
138
	    error: function(req) {
139
	        /* XXX: Leave this for debugging purposes: Handle 404
140
	        if(req.status == 404)
141
	            alert('Error 404: location "' + uri + '" was not found.');
142
		*/
143
	        /* Handle other errors
144
	        else
145
	            alert('Error ' + req.status + ' -- ' + req.statusText + ' -- ' + uri);
146
		*/
147
	    },
148
		success: function(data) {
149
			updateBandwidthHosts(data);
150
	    }
151
	}
152
	jQuery.ajax(uri, opt);
153
}
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
        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
        }
185
        else
186
        {
187
            var rowid = "#host" + y;
188
            if (jQuery(rowid).css('display') != "none"){
189
                //hide rows that contain no data
190
                jQuery(rowid).fadeOut(2000);
191
            }
192
        }
193
    }
194
    
195
    setTimeout('updateBandwidth()', 1000);
196
}
197
//]]>
198
</script>
199

    
200
<?php
201

    
202
/* link the ipsec interface magically */
203
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) 
204
	$ifdescrs['enc0'] = "IPsec";
205

    
206
?>
207
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
208
<?=gettext("Interface"); ?>:
209
<select id="if" name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
210
<?php
211
foreach ($ifdescrs as $ifn => $ifd) {
212
	echo "<option value=\"$ifn\"";
213
	if ($ifn == $curif) echo " selected=\"selected\"";
214
	echo ">" . htmlspecialchars($ifd) . "</option>\n";
215
}
216
?>
217
</select>
218
, Sort by: 
219
<select id="sort" name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
220
	<option value="">Bw In</option>
221
	<option value="out"<?php if ($cursort == "out") echo " selected=\"selected\"";?>>Bw Out</option>
222
</select>
223
, Filter: 
224
<select id="filter" name="filter" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
225
	<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
</select>
229
, 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
	<option value="fqdn"<?php if ($curhostipformat == "fqdn") echo " selected=\"selected\"";?>>FQDN</option>
234
</select>
235
</form>
236
<p>&nbsp;</p>
237
<div id="niftyOutter">
238
    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
239
        <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
    </div>
247
    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
248
        <table width="100%" border="0" cellspacing="0" cellpadding="0" summary="status">
249
            <tr>
250
                <td class="listtopic" valign="top"><?=(($curhostipformat=="") ? gettext("Host IP") : gettext("Host Name or IP")); ?></td>
251
                <td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
252
                <td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
253
           </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
	</div>
336
	<div style="clear: both;"></div>
337
</div>
338
<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

    
340
<?php include("fend.inc"); ?>
341

    
342
<script type="text/javascript">
343
//<![CDATA[
344
jQuery(document).ready(updateBandwidth);
345
//]]>
346
</script>
347
</body>
348
</html>
(190-190/256)