1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
status_graph.php
|
5
|
Part of pfSense
|
6
|
Copyright (C) 2004 Scott Ullrich
|
7
|
All rights reserved.
|
8
|
|
9
|
Originally part of m0n0wall (http://m0n0.ch/wall)
|
10
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
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
|
|
23
|
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
|
/*
|
35
|
pfSense_MODULE: routing
|
36
|
*/
|
37
|
|
38
|
##|+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
|
##|*MATCH=bandwidth_by_ip.php*
|
44
|
##|*MATCH=graph.php*
|
45
|
##|*MATCH=ifstats.php*
|
46
|
##|-PRIV
|
47
|
|
48
|
require("guiconfig.inc");
|
49
|
|
50
|
if ($_POST['width'])
|
51
|
$width = $_POST['width'];
|
52
|
else
|
53
|
$width = "100%";
|
54
|
|
55
|
if ($_POST['height'])
|
56
|
$height = $_POST['height'];
|
57
|
else
|
58
|
$height = "200";
|
59
|
|
60
|
// Get configured interface list
|
61
|
$ifdescrs = get_configured_interface_with_descr();
|
62
|
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
|
|
74
|
if ($_GET['if']) {
|
75
|
$curif = $_GET['if'];
|
76
|
$found = false;
|
77
|
foreach($ifdescrs as $descr => $ifdescr) {
|
78
|
if ($descr == $curif) {
|
79
|
$found = true;
|
80
|
break;
|
81
|
}
|
82
|
}
|
83
|
if ($found === false) {
|
84
|
header("Location: status_graph.php");
|
85
|
exit;
|
86
|
}
|
87
|
} else {
|
88
|
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
|
}
|
97
|
if ($_GET['sort']) {
|
98
|
$cursort = $_GET['sort'];
|
99
|
} else {
|
100
|
$cursort = "";
|
101
|
}
|
102
|
if ($_GET['filter']) {
|
103
|
$curfilter = $_GET['filter'];
|
104
|
} else {
|
105
|
$curfilter = "";
|
106
|
}
|
107
|
if ($_GET['hostipformat']) {
|
108
|
$curhostipformat = $_GET['hostipformat'];
|
109
|
} else {
|
110
|
$curhostipformat = "";
|
111
|
}
|
112
|
|
113
|
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
|
114
|
|
115
|
include("head.inc");
|
116
|
|
117
|
?>
|
118
|
|
119
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
120
|
<?php include("fbegin.inc"); ?>
|
121
|
|
122
|
<script type="text/javascript">
|
123
|
//<![CDATA[
|
124
|
function updateBandwidth(){
|
125
|
var hostinterface = jQuery("#if").val();
|
126
|
var sorting = jQuery("#sort").val();
|
127
|
var filter = jQuery("#filter").val();
|
128
|
var hostipformat = jQuery("#hostipformat").val();
|
129
|
bandwidthAjax(hostinterface, sorting, filter, hostipformat);
|
130
|
}
|
131
|
|
132
|
function bandwidthAjax(hostinterface, sorting, filter, hostipformat) {
|
133
|
uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting + "&filter=" + filter + "&hostipformat=" + hostipformat;
|
134
|
var opt = {
|
135
|
// Use GET
|
136
|
type: 'get',
|
137
|
error: function(req) {
|
138
|
/* XXX: Leave this for debugging purposes: Handle 404
|
139
|
if(req.status == 404)
|
140
|
alert('Error 404: location "' + uri + '" was not found.');
|
141
|
*/
|
142
|
/* Handle other errors
|
143
|
else
|
144
|
alert('Error ' + req.status + ' -- ' + req.statusText + ' -- ' + uri);
|
145
|
*/
|
146
|
},
|
147
|
success: function(data) {
|
148
|
updateBandwidthHosts(data);
|
149
|
}
|
150
|
}
|
151
|
jQuery.ajax(uri, opt);
|
152
|
}
|
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
|
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
|
}
|
184
|
else
|
185
|
{
|
186
|
var rowid = "#host" + y;
|
187
|
if (jQuery(rowid).css('display') != "none"){
|
188
|
//hide rows that contain no data
|
189
|
jQuery(rowid).fadeOut(2000);
|
190
|
}
|
191
|
}
|
192
|
}
|
193
|
|
194
|
setTimeout('updateBandwidth()', 1000);
|
195
|
}
|
196
|
//]]>
|
197
|
</script>
|
198
|
|
199
|
<?php
|
200
|
|
201
|
/* link the ipsec interface magically */
|
202
|
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
|
203
|
$ifdescrs['enc0'] = "IPsec";
|
204
|
|
205
|
?>
|
206
|
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
|
207
|
<?=gettext("Interface"); ?>:
|
208
|
<select id="if" name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
|
209
|
<?php
|
210
|
foreach ($ifdescrs as $ifn => $ifd) {
|
211
|
echo "<option value=\"$ifn\"";
|
212
|
if ($ifn == $curif) echo " selected=\"selected\"";
|
213
|
echo ">" . htmlspecialchars($ifd) . "</option>\n";
|
214
|
}
|
215
|
?>
|
216
|
</select>
|
217
|
, Sort by:
|
218
|
<select id="sort" name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
|
219
|
<option value="">Bw In</option>
|
220
|
<option value="out"<?php if ($cursort == "out") echo " selected=\"selected\"";?>>Bw Out</option>
|
221
|
</select>
|
222
|
, Filter:
|
223
|
<select id="filter" name="filter" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
|
224
|
<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
|
</select>
|
228
|
, 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
|
<option value="fqdn"<?php if ($curhostipformat == "fqdn") echo " selected=\"selected\"";?>>FQDN</option>
|
233
|
</select>
|
234
|
</form>
|
235
|
<p> </p>
|
236
|
<div id="niftyOutter">
|
237
|
<div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
|
238
|
<object data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&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
|
</div>
|
246
|
<div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
|
247
|
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="status">
|
248
|
<tr>
|
249
|
<td class="listtopic" valign="top"><?=(($curhostipformat=="") ? gettext("Host IP") : gettext("Host Name or IP")); ?></td>
|
250
|
<td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
|
251
|
<td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
|
252
|
</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
|
</div>
|
335
|
<div style="clear: both;"></div>
|
336
|
</div>
|
337
|
<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
|
|
339
|
<?php include("fend.inc"); ?>
|
340
|
|
341
|
<script type="text/javascript">
|
342
|
//<![CDATA[
|
343
|
jQuery(document).ready(updateBandwidth);
|
344
|
//]]>
|
345
|
</script>
|
346
|
</body>
|
347
|
</html>
|