1
|
<?php
|
2
|
/*
|
3
|
* status_graph.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7
|
* All rights reserved.
|
8
|
*
|
9
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
10
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
* All rights reserved.
|
12
|
*
|
13
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
14
|
* you may not use this file except in compliance with the License.
|
15
|
* You may obtain a copy of the License at
|
16
|
*
|
17
|
* http://www.apache.org/licenses/LICENSE-2.0
|
18
|
*
|
19
|
* Unless required by applicable law or agreed to in writing, software
|
20
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
21
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
22
|
* See the License for the specific language governing permissions and
|
23
|
* limitations under the License.
|
24
|
*/
|
25
|
|
26
|
##|+PRIV
|
27
|
##|*IDENT=page-status-trafficgraph
|
28
|
##|*NAME=Status: Traffic Graph
|
29
|
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
|
30
|
##|*MATCH=status_graph.php*
|
31
|
##|*MATCH=bandwidth_by_ip.php*
|
32
|
##|*MATCH=graph.php*
|
33
|
##|*MATCH=ifstats.php*
|
34
|
##|-PRIV
|
35
|
|
36
|
require_once("guiconfig.inc");
|
37
|
require_once("ipsec.inc");
|
38
|
|
39
|
// Get configured interface list
|
40
|
$ifdescrs = get_configured_interface_with_descr();
|
41
|
if (ipsec_enabled()) {
|
42
|
$ifdescrs['enc0'] = gettext("IPsec");
|
43
|
}
|
44
|
|
45
|
foreach (array('server', 'client') as $mode) {
|
46
|
if (is_array($config['openvpn']["openvpn-{$mode}"])) {
|
47
|
foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
|
48
|
if (!isset($setting['disable'])) {
|
49
|
$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " " . $mode . ": ".htmlspecialchars($setting['description']);
|
50
|
}
|
51
|
}
|
52
|
}
|
53
|
}
|
54
|
|
55
|
if ($_REQUEST['if']) {
|
56
|
$curif = $_REQUEST['if'];
|
57
|
$found = false;
|
58
|
foreach ($ifdescrs as $descr => $ifdescr) {
|
59
|
if ($descr == $curif) {
|
60
|
$found = true;
|
61
|
break;
|
62
|
}
|
63
|
}
|
64
|
if ($found === false) {
|
65
|
header("Location: status_graph.php");
|
66
|
exit;
|
67
|
}
|
68
|
} else {
|
69
|
if (empty($ifdescrs["wan"])) {
|
70
|
/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
|
71
|
reset($ifdescrs);
|
72
|
$curif = key($ifdescrs);
|
73
|
} else {
|
74
|
$curif = "wan";
|
75
|
}
|
76
|
}
|
77
|
if ($_REQUEST['sort']) {
|
78
|
$cursort = $_REQUEST['sort'];
|
79
|
} else {
|
80
|
$cursort = "";
|
81
|
}
|
82
|
if ($_REQUEST['filter']) {
|
83
|
$curfilter = $_REQUEST['filter'];
|
84
|
} else {
|
85
|
$curfilter = "";
|
86
|
}
|
87
|
if ($_REQUEST['hostipformat']) {
|
88
|
$curhostipformat = $_REQUEST['hostipformat'];
|
89
|
} else {
|
90
|
$curhostipformat = "";
|
91
|
}
|
92
|
if ($_REQUEST['backgroundupdate']) {
|
93
|
$curbackgroundupdate = $_REQUEST['backgroundupdate'];
|
94
|
} else {
|
95
|
$curbackgroundupdate = "";
|
96
|
}
|
97
|
|
98
|
function iflist() {
|
99
|
global $ifdescrs;
|
100
|
|
101
|
$iflist = array();
|
102
|
|
103
|
foreach ($ifdescrs as $ifn => $ifd) {
|
104
|
$iflist[$ifn] = $ifd;
|
105
|
}
|
106
|
|
107
|
return($iflist);
|
108
|
}
|
109
|
|
110
|
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
|
111
|
|
112
|
include("head.inc");
|
113
|
|
114
|
$form = new Form(false);
|
115
|
$form->addClass('auto-submit');
|
116
|
|
117
|
$section = new Form_Section('Graph Settings');
|
118
|
|
119
|
$group = new Form_Group('');
|
120
|
|
121
|
$group->add(new Form_Select(
|
122
|
'if',
|
123
|
null,
|
124
|
$curif,
|
125
|
iflist()
|
126
|
))->setHelp('Interface');
|
127
|
|
128
|
$group->add(new Form_Select(
|
129
|
'sort',
|
130
|
null,
|
131
|
$cursort,
|
132
|
array (
|
133
|
'in' => gettext('Bandwidth In'),
|
134
|
'out' => gettext('Bandwidth Out')
|
135
|
)
|
136
|
))->setHelp('Sort by');
|
137
|
|
138
|
$group->add(new Form_Select(
|
139
|
'filter',
|
140
|
null,
|
141
|
$curfilter,
|
142
|
array (
|
143
|
'local' => gettext('Local'),
|
144
|
'remote'=> gettext('Remote'),
|
145
|
'all' => gettext('All')
|
146
|
)
|
147
|
))->setHelp('Filter');
|
148
|
|
149
|
$group->add(new Form_Select(
|
150
|
'hostipformat',
|
151
|
null,
|
152
|
$curhostipformat,
|
153
|
array (
|
154
|
'' => gettext('IP Address'),
|
155
|
'hostname' => gettext('Host Name'),
|
156
|
'descr' => gettext('Description'),
|
157
|
'fqdn' => gettext('FQDN')
|
158
|
)
|
159
|
))->setHelp('Display');
|
160
|
|
161
|
$group->add(new Form_Select(
|
162
|
'backgroundupdate',
|
163
|
null,
|
164
|
$curbackgroundupdate,
|
165
|
array (
|
166
|
'false' => gettext('Clear graphs when not visible.'),
|
167
|
'true' => gettext('Keep graphs updated on inactive tab. (increases cpu usage)'),
|
168
|
)
|
169
|
))->setHelp('Background updates');
|
170
|
|
171
|
$section->add($group);
|
172
|
|
173
|
$form->add($section);
|
174
|
print $form;
|
175
|
|
176
|
?>
|
177
|
|
178
|
<script src="/vendor/d3/d3.min.js"></script>
|
179
|
<script src="/vendor/nvd3/nv.d3.js"></script>
|
180
|
<script src="/vendor/visibility/visibility-1.2.3.min.js"></script>
|
181
|
|
182
|
<link href="/vendor/nvd3/nv.d3.css" media="screen, projection" rel="stylesheet" type="text/css">
|
183
|
|
184
|
<script type="text/javascript">
|
185
|
|
186
|
//<![CDATA[
|
187
|
events.push(function() {
|
188
|
|
189
|
var InterfaceString = "<?=$curif?>";
|
190
|
|
191
|
//store saved settings in a fresh localstorage
|
192
|
localStorage.clear();
|
193
|
localStorage.setItem('interval', 1);
|
194
|
localStorage.setItem('invert', "true");
|
195
|
localStorage.setItem('size', 1);
|
196
|
window.interfaces = InterfaceString.split("|");
|
197
|
window.charts = {};
|
198
|
window.myData = {};
|
199
|
window.updateIds = 0;
|
200
|
window.updateTimerIds = 0;
|
201
|
window.latest = [];
|
202
|
var refreshInterval = localStorage.getItem('interval');
|
203
|
|
204
|
//TODO make it fall on a second value so it increments better
|
205
|
var now = then = new Date(Date.now());
|
206
|
|
207
|
var nowTime = now.getTime();
|
208
|
|
209
|
$.each( window.interfaces, function( key, value ) {
|
210
|
|
211
|
myData[value] = [];
|
212
|
updateIds = 0;
|
213
|
updateTimerIds = 0;
|
214
|
|
215
|
var itemIn = new Object();
|
216
|
var itemOut = new Object();
|
217
|
|
218
|
itemIn.key = value + " (in)";
|
219
|
if(localStorage.getItem('invert') === "true") { itemIn.area = true; }
|
220
|
itemIn.first = true;
|
221
|
itemIn.values = [{x: nowTime, y: 0}];
|
222
|
myData[value].push(itemIn);
|
223
|
|
224
|
itemOut.key = value + " (out)";
|
225
|
if(localStorage.getItem('invert') === "true") { itemOut.area = true; }
|
226
|
itemOut.first = true;
|
227
|
itemOut.values = [{x: nowTime, y: 0}];
|
228
|
myData[value].push(itemOut);
|
229
|
|
230
|
});
|
231
|
|
232
|
var backgroundupdate = $('#backgroundupdate').val() === "true";
|
233
|
draw_graph(refreshInterval, then, backgroundupdate);
|
234
|
|
235
|
//re-draw graph when the page goes from inactive (in it's window) to active
|
236
|
Visibility.change(function (e, state) {
|
237
|
if($('#backgroundupdate').val() === "true"){
|
238
|
return;
|
239
|
}
|
240
|
if(state === "visible") {
|
241
|
|
242
|
now = then = new Date(Date.now());
|
243
|
|
244
|
var nowTime = now.getTime();
|
245
|
|
246
|
$.each( window.interfaces, function( key, value ) {
|
247
|
|
248
|
Visibility.stop(updateIds);
|
249
|
clearInterval(updateTimerIds);
|
250
|
|
251
|
myData[value] = [];
|
252
|
|
253
|
var itemIn = new Object();
|
254
|
var itemOut = new Object();
|
255
|
|
256
|
itemIn.key = value + " (in)";
|
257
|
if(localStorage.getItem('invert') === "true") { itemIn.area = true; }
|
258
|
itemIn.first = true;
|
259
|
itemIn.values = [{x: nowTime, y: 0}];
|
260
|
myData[value].push(itemIn);
|
261
|
|
262
|
itemOut.key = value + " (out)";
|
263
|
if(localStorage.getItem('invert') === "true") { itemOut.area = true; }
|
264
|
itemOut.first = true;
|
265
|
itemOut.values = [{x: nowTime, y: 0}];
|
266
|
myData[value].push(itemOut);
|
267
|
|
268
|
});
|
269
|
|
270
|
draw_graph(refreshInterval, then, false);
|
271
|
|
272
|
}
|
273
|
});
|
274
|
|
275
|
});
|
276
|
//]]>
|
277
|
</script>
|
278
|
|
279
|
<script src="/js/traffic-graphs.js"></script>
|
280
|
|
281
|
<script type="text/javascript">
|
282
|
//<![CDATA[
|
283
|
|
284
|
var graph_interfacenames = <?php
|
285
|
foreach ($ifdescrs as $ifname => $ifdescr) {
|
286
|
$iflist[$ifname] = $ifdescr;
|
287
|
}
|
288
|
echo json_encode($iflist);
|
289
|
?>;
|
290
|
function updateBandwidth() {
|
291
|
$.ajax(
|
292
|
'/bandwidth_by_ip.php',
|
293
|
{
|
294
|
type: 'get',
|
295
|
data: $(document.forms[0]).serialize(),
|
296
|
success: function (data) {
|
297
|
var hosts_split = data.split("|");
|
298
|
|
299
|
$('#top10-hosts').empty();
|
300
|
|
301
|
//parse top ten bandwidth abuser hosts
|
302
|
for (var y=0; y<10; y++) {
|
303
|
if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
|
304
|
hostinfo = hosts_split[y].split(";");
|
305
|
|
306
|
$('#top10-hosts').append('<tr>'+
|
307
|
'<td>'+ hostinfo[0] +'</td>'+
|
308
|
'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
|
309
|
'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
|
310
|
'</tr>');
|
311
|
}
|
312
|
}
|
313
|
},
|
314
|
});
|
315
|
}
|
316
|
|
317
|
events.push(function() {
|
318
|
$('form.auto-submit').on('change', function() {
|
319
|
$(this).submit();
|
320
|
});
|
321
|
|
322
|
setInterval('updateBandwidth()', 3000);
|
323
|
|
324
|
updateBandwidth();
|
325
|
});
|
326
|
//]]>
|
327
|
</script>
|
328
|
<?php
|
329
|
|
330
|
/* link the ipsec interface magically */
|
331
|
if (ipsec_enabled()) {
|
332
|
$ifdescrs['enc0'] = gettext("IPsec");
|
333
|
}
|
334
|
|
335
|
?>
|
336
|
<div class="panel panel-default">
|
337
|
<div class="panel-heading">
|
338
|
<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
|
339
|
</div>
|
340
|
<div class="panel-body">
|
341
|
<div class="col-sm-6">
|
342
|
<div id="traffic-chart-<?=$curif?>" class="d3-chart traffic-widget-chart">
|
343
|
<svg></svg>
|
344
|
</div>
|
345
|
</div>
|
346
|
<div class="col-sm-6">
|
347
|
<table class="table table-striped table-condensed">
|
348
|
<thead>
|
349
|
<tr>
|
350
|
<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
|
351
|
<th><?=gettext("Bandwidth In"); ?></th>
|
352
|
<th><?=gettext("Bandwidth Out"); ?></th>
|
353
|
</tr>
|
354
|
</thead>
|
355
|
<tbody id="top10-hosts">
|
356
|
<!-- to be added by javascript -->
|
357
|
</tbody>
|
358
|
</table>
|
359
|
</div>
|
360
|
</div>
|
361
|
</div>
|
362
|
<?php include("foot.inc");
|