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