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
|
##|-PRIV
|
44
|
|
45
|
require("guiconfig.inc");
|
46
|
|
47
|
if ($_POST['width'])
|
48
|
$width = $_POST['width'];
|
49
|
else
|
50
|
$width = "100%";
|
51
|
|
52
|
if ($_POST['height'])
|
53
|
$height = $_POST['height'];
|
54
|
else
|
55
|
$height = "200";
|
56
|
|
57
|
// Get configured interface list
|
58
|
$ifdescrs = get_configured_interface_with_descr();
|
59
|
if (isset($config['ipsec']['enable']))
|
60
|
$ifdescrs['enc0'] = "IPsec";
|
61
|
foreach (array('server', 'client') as $mode) {
|
62
|
if (is_array($config['openvpn']["openvpn-{$mode}"])) {
|
63
|
foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
|
64
|
if (!isset($setting['disable'])) {
|
65
|
$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
}
|
70
|
|
71
|
if ($_GET['if']) {
|
72
|
$curif = $_GET['if'];
|
73
|
$found = false;
|
74
|
foreach($ifdescrs as $descr => $ifdescr)
|
75
|
if($descr == $curif) $found = true;
|
76
|
if(!$found) {
|
77
|
Header("Location: status_graph.php");
|
78
|
exit;
|
79
|
}
|
80
|
} else {
|
81
|
$curif = "wan";
|
82
|
}
|
83
|
|
84
|
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
|
85
|
|
86
|
include("head.inc");
|
87
|
|
88
|
?>
|
89
|
|
90
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
91
|
|
92
|
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
|
93
|
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
|
94
|
<script language="javascript" type="text/javascript">
|
95
|
|
96
|
function updateBandwidth(){
|
97
|
var hostinterface = "<?php echo htmlspecialchars($curif); ?>";
|
98
|
bandwidthAjax(hostinterface);
|
99
|
}
|
100
|
|
101
|
function bandwidthAjax(hostinterface) {
|
102
|
uri = "bandwidth_by_ip.php?if=" + hostinterface;
|
103
|
var opt = {
|
104
|
// Use GET
|
105
|
method: 'get',
|
106
|
asynchronous: true,
|
107
|
// Handle 404
|
108
|
on404: function(t) {
|
109
|
alert('Error 404: location "' + t.statusText + '" was not found.');
|
110
|
},
|
111
|
// Handle other errors
|
112
|
onFailure: function(t) {
|
113
|
alert('Error ' + t.status + ' -- ' + t.statusText);
|
114
|
},
|
115
|
onSuccess: function(t) {
|
116
|
updateBandwidthHosts(t.responseText);
|
117
|
}
|
118
|
}
|
119
|
new Ajax.Request(uri, opt);
|
120
|
}
|
121
|
|
122
|
function updateBandwidthHosts(data){
|
123
|
var hosts_split = data.split("|");
|
124
|
d = document;
|
125
|
//parse top ten bandwidth abuser hosts
|
126
|
for (var y=0; y<10; y++){
|
127
|
if (hosts_split[y] != "" && hosts_split[y] != "no info"){
|
128
|
if (hosts_split[y]) {
|
129
|
hostinfo = hosts_split[y].split(";");
|
130
|
|
131
|
//update host ip info
|
132
|
var HostIpID = "hostip" + y;
|
133
|
var hostip = d.getElementById(HostIpID);
|
134
|
hostip.innerHTML = hostinfo[0];
|
135
|
|
136
|
//update bandwidth inbound to host
|
137
|
var hostbandwidthInID = "bandwidthin" + y;
|
138
|
var hostbandwidthin = d.getElementById(hostbandwidthInID);
|
139
|
hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";
|
140
|
|
141
|
//update bandwidth outbound from host
|
142
|
var hostbandwidthOutID = "bandwidthout" + y;
|
143
|
var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
|
144
|
hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";
|
145
|
|
146
|
//make the row appear if hidden
|
147
|
var rowid = "host" + y;
|
148
|
textlink = d.getElementById(rowid);
|
149
|
if (textlink.style.display == "none"){
|
150
|
//hide rows that contain no data
|
151
|
Effect.Appear(rowid, {duration:1});
|
152
|
}
|
153
|
}
|
154
|
}
|
155
|
else
|
156
|
{
|
157
|
var rowid = "host" + y;
|
158
|
textlink = d.getElementById(rowid);
|
159
|
if (textlink.style.display != "none"){
|
160
|
//hide rows that contain no data
|
161
|
Effect.Fade(rowid, {duration:2});
|
162
|
}
|
163
|
}
|
164
|
}
|
165
|
|
166
|
setTimeout('updateBandwidth()', 1000);
|
167
|
}
|
168
|
|
169
|
|
170
|
</script>
|
171
|
|
172
|
<?php include("fbegin.inc"); ?>
|
173
|
<?php
|
174
|
|
175
|
/* link the ipsec interface magically */
|
176
|
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
|
177
|
$ifdescrs['enc0'] = "IPsec";
|
178
|
|
179
|
?>
|
180
|
<form name="form1" action="status_graph.php" method="get" style="padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid #999999">
|
181
|
<?=gettext("Interface"); ?>:
|
182
|
<select name="if" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
|
183
|
<?php
|
184
|
foreach ($ifdescrs as $ifn => $ifd) {
|
185
|
echo "<option value=\"$ifn\"";
|
186
|
if ($ifn == $curif) echo " selected";
|
187
|
echo ">" . htmlspecialchars($ifd) . "</option>\n";
|
188
|
}
|
189
|
?>
|
190
|
</select>
|
191
|
</form>
|
192
|
<p><form method="post" action="status_graph.php">
|
193
|
</form>
|
194
|
<p>
|
195
|
<div id="niftyOutter">
|
196
|
<div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
|
197
|
<object data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>" type="image/svg+xml" width="<?=$width;?>" height="<?=$height;?>">
|
198
|
<param name="src" value="graph.php?ifnum=<?=htmlspecialchars($curif);?>&ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>" />
|
199
|
<?=gettext("Your browser does not support the type SVG! You need to either use Firefox or download the Adobe SVG plugin"); ?>.
|
200
|
</object>
|
201
|
</div>
|
202
|
<div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
|
203
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
204
|
<tr>
|
205
|
<td class="listtopic" valign="top"><?=gettext("Host IP"); ?></td>
|
206
|
<td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
|
207
|
<td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
|
208
|
</tr>
|
209
|
<tr id="host0" style="display:none">
|
210
|
<td id="hostip0" class="vncell">
|
211
|
</td>
|
212
|
<td id="bandwidthin0" class="listr">
|
213
|
</td>
|
214
|
<td id="bandwidthout0" class="listr">
|
215
|
</td>
|
216
|
</tr>
|
217
|
<tr id="host1" style="display:none">
|
218
|
<td id="hostip1" class="vncell">
|
219
|
</td>
|
220
|
<td id="bandwidthin1" class="listr">
|
221
|
</td>
|
222
|
<td id="bandwidthout1" class="listr">
|
223
|
</td>
|
224
|
</tr>
|
225
|
<tr id="host2" style="display:none">
|
226
|
<td id="hostip2" class="vncell">
|
227
|
</td>
|
228
|
<td id="bandwidthin2" class="listr">
|
229
|
</td>
|
230
|
<td id="bandwidthout2" class="listr">
|
231
|
</td>
|
232
|
</tr>
|
233
|
<tr id="host3" style="display:none">
|
234
|
<td id="hostip3" class="vncell">
|
235
|
</td>
|
236
|
<td id="bandwidthin3" class="listr">
|
237
|
</td>
|
238
|
<td id="bandwidthout3" class="listr">
|
239
|
</td>
|
240
|
</tr>
|
241
|
<tr id="host4" style="display:none">
|
242
|
<td id="hostip4" class="vncell">
|
243
|
</td>
|
244
|
<td id="bandwidthin4" class="listr">
|
245
|
</td>
|
246
|
<td id="bandwidthout4" class="listr">
|
247
|
</td>
|
248
|
</tr>
|
249
|
<tr id="host5" style="display:none">
|
250
|
<td id="hostip5" class="vncell">
|
251
|
</td>
|
252
|
<td id="bandwidthin5" class="listr">
|
253
|
</td>
|
254
|
<td id="bandwidthout5" class="listr">
|
255
|
</td>
|
256
|
</tr>
|
257
|
<tr id="host6" style="display:none">
|
258
|
<td id="hostip6" class="vncell">
|
259
|
</td>
|
260
|
<td id="bandwidthin6" class="listr">
|
261
|
</td>
|
262
|
<td id="bandwidthout6" class="listr">
|
263
|
</td>
|
264
|
</tr>
|
265
|
<tr id="host7" style="display:none">
|
266
|
<td id="hostip7" class="vncell">
|
267
|
</td>
|
268
|
<td id="bandwidthin7" class="listr">
|
269
|
</td>
|
270
|
<td id="bandwidthout7" class="listr">
|
271
|
</td>
|
272
|
</tr>
|
273
|
<tr id="host8" style="display:none">
|
274
|
<td id="hostip8" class="vncell">
|
275
|
</td>
|
276
|
<td id="bandwidthin8" class="listr">
|
277
|
</td>
|
278
|
<td id="bandwidthout8" class="listr">
|
279
|
</td>
|
280
|
</tr>
|
281
|
<tr id="host9" style="display:none">
|
282
|
<td id="hostip9" class="vncell">
|
283
|
</td>
|
284
|
<td id="bandwidthin9" class="listr">
|
285
|
</td>
|
286
|
<td id="bandwidthout9" class="listr">
|
287
|
</td>
|
288
|
</tr>
|
289
|
</table>
|
290
|
</div>
|
291
|
<div style="clear: both;"></div>
|
292
|
</div>
|
293
|
<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"); ?>.
|
294
|
|
295
|
<?php include("fend.inc"); ?>
|
296
|
|
297
|
<script type="text/javascript">
|
298
|
window.onload = function(in_event)
|
299
|
{
|
300
|
updateBandwidth();
|
301
|
}
|
302
|
|
303
|
</script>
|
304
|
</body>
|
305
|
</html>
|