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