Project

General

Profile

Download (8.62 KB) Statistics
| Branch: | Tag: | Revision:
1 9573d170 Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * status_graph.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8 191cb31d Stephen Beaver
 *
9 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12 191cb31d Stephen Beaver
 *
13 0f3f6cc9 Jared Dillard
 * 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 191cb31d Stephen Beaver
 *
17 0f3f6cc9 Jared Dillard
 * http://www.apache.org/licenses/LICENSE-2.0
18 191cb31d Stephen Beaver
 *
19 0f3f6cc9 Jared Dillard
 * 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 191cb31d Stephen Beaver
 */
25 5b237745 Scott Ullrich
26 6b07c15a Matthew Grooms
##|+PRIV
27
##|*IDENT=page-status-trafficgraph
28 5230f468 jim-p
##|*NAME=Status: Traffic Graph
29 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
30
##|*MATCH=status_graph.php*
31 8e95a671 jim-p
##|*MATCH=bandwidth_by_ip.php*
32 8a2f80b2 jim-p
##|*MATCH=graph.php*
33
##|*MATCH=ifstats.php*
34 6b07c15a Matthew Grooms
##|-PRIV
35
36 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
37 179ab6b3 Luiz Otavio O Souza
require_once("ipsec.inc");
38 5b237745 Scott Ullrich
39 94556105 Scott Ullrich
// Get configured interface list
40 61ab4cd3 Scott Ullrich
$ifdescrs = get_configured_interface_with_descr();
41 abe98adb Phil Davis
if (ipsec_enabled()) {
42 98128ad6 Phil Davis
	$ifdescrs['enc0'] = gettext("IPsec");
43 abe98adb Phil Davis
}
44
45 9f5d14ce jim-p
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 98128ad6 Phil Davis
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " " . $mode . ": ".htmlspecialchars($setting['description']);
50 9f5d14ce jim-p
			}
51
		}
52
	}
53
}
54 43a0ac8a Scott Ullrich
55 1a8b6554 Steve Beaver
if ($_REQUEST['if']) {
56
	$curif = $_REQUEST['if'];
57 50b2f6ab Scott Ullrich
	$found = false;
58 6c07db48 Phil Davis
	foreach ($ifdescrs as $descr => $ifdescr) {
59 b406c78a Ermal
		if ($descr == $curif) {
60
			$found = true;
61
			break;
62
		}
63
	}
64
	if ($found === false) {
65 6f3d2063 Renato Botelho
		header("Location: status_graph.php");
66 50b2f6ab Scott Ullrich
		exit;
67
	}
68
} else {
69 76165eac Phil Davis
	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 42b0c921 Phil Davis
	} else {
74 76165eac Phil Davis
		$curif = "wan";
75
	}
76 50b2f6ab Scott Ullrich
}
77 1a8b6554 Steve Beaver
if ($_REQUEST['sort']) {
78
	$cursort = $_REQUEST['sort'];
79 893fb622 Michele Di Maria
} else {
80
	$cursort = "";
81
}
82 1a8b6554 Steve Beaver
if ($_REQUEST['filter']) {
83
	$curfilter = $_REQUEST['filter'];
84 da11e022 Phil Davis
} else {
85
	$curfilter = "";
86
}
87 1a8b6554 Steve Beaver
if ($_REQUEST['hostipformat']) {
88
	$curhostipformat = $_REQUEST['hostipformat'];
89 4006a437 Phil Davis
} else {
90
	$curhostipformat = "";
91
}
92 1a8b6554 Steve Beaver
if ($_REQUEST['backgroundupdate']) {
93
	$curbackgroundupdate = $_REQUEST['backgroundupdate'];
94 fe5c31bb PiBa-NL
} else {
95
	$curbackgroundupdate = "";
96
}
97 769cdf3b Bill Marquette
98 e31aa678 sbeaver
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 abe98adb Phil Davis
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
111 f0a3b883 Scott Ullrich
112 4df96eff Scott Ullrich
include("head.inc");
113
114 e31aa678 sbeaver
$form = new Form(false);
115 a4af095c Renato Botelho
$form->addClass('auto-submit');
116 e31aa678 sbeaver
117 5f88f964 k-paulius
$section = new Form_Section('Graph Settings');
118 5b237745 Scott Ullrich
119 a4af095c Renato Botelho
$group = new Form_Group('');
120
121
$group->add(new Form_Select(
122 e31aa678 sbeaver
	'if',
123 a4af095c Renato Botelho
	null,
124 e31aa678 sbeaver
	$curif,
125
	iflist()
126 a4af095c Renato Botelho
))->setHelp('Interface');
127 e31aa678 sbeaver
128 a4af095c Renato Botelho
$group->add(new Form_Select(
129 e31aa678 sbeaver
	'sort',
130 a4af095c Renato Botelho
	null,
131 e31aa678 sbeaver
	$cursort,
132
	array (
133 b50d30c3 Stephen Beaver
		'in'	=> gettext('Bandwidth In'),
134
		'out'	=> gettext('Bandwidth Out')
135 e31aa678 sbeaver
	)
136 a4af095c Renato Botelho
))->setHelp('Sort by');
137 e31aa678 sbeaver
138 a4af095c Renato Botelho
$group->add(new Form_Select(
139 e31aa678 sbeaver
	'filter',
140 a4af095c Renato Botelho
	null,
141 e31aa678 sbeaver
	$curfilter,
142
	array (
143 b50d30c3 Stephen Beaver
		'local'	=> gettext('Local'),
144
		'remote'=> gettext('Remote'),
145
		'all'	=> gettext('All')
146 e31aa678 sbeaver
	)
147 a4af095c Renato Botelho
))->setHelp('Filter');
148 e31aa678 sbeaver
149 a4af095c Renato Botelho
$group->add(new Form_Select(
150 e31aa678 sbeaver
	'hostipformat',
151 a4af095c Renato Botelho
	null,
152 e31aa678 sbeaver
	$curhostipformat,
153
	array (
154 b50d30c3 Stephen Beaver
		''			=> gettext('IP Address'),
155
		'hostname'	=> gettext('Host Name'),
156
		'descr'		=> gettext('Description'),
157
		'fqdn'		=> gettext('FQDN')
158 e31aa678 sbeaver
	)
159 a4af095c Renato Botelho
))->setHelp('Display');
160
161 fe5c31bb PiBa-NL
$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 a4af095c Renato Botelho
$section->add($group);
172 e31aa678 sbeaver
173
$form->add($section);
174
print $form;
175
176
?>
177 849d3a37 Jared Dillard
178 d8837d57 PiBa-NL
<script src="/vendor/d3/d3.min.js?v=<?=filemtime('/usr/local/www/vendor/d3/d3.min.js')?>"></script>
179
<script src="/vendor/nvd3/nv.d3.js?v=<?=filemtime('/usr/local/www/vendor/nvd3/nv.d3.js')?>"></script>
180
<script src="/vendor/visibility/visibility-1.2.3.min.js?v=<?=filemtime('/usr/local/www/vendor/visibility/visibility-1.2.3.min.js')?>"></script>
181 849d3a37 Jared Dillard
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 fe5c31bb PiBa-NL
	window.interfaces = InterfaceString.split("|");
197 849d3a37 Jared Dillard
	window.charts = {};
198
    window.myData = {};
199
    window.updateIds = 0;
200 fe5c31bb PiBa-NL
    window.updateTimerIds = 0;
201 849d3a37 Jared Dillard
    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 fe5c31bb PiBa-NL
	$.each( window.interfaces, function( key, value ) {
210 849d3a37 Jared Dillard
211
		myData[value] = [];
212
		updateIds = 0;
213 fe5c31bb PiBa-NL
		updateTimerIds = 0;
214 849d3a37 Jared Dillard
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 fe5c31bb PiBa-NL
    var backgroundupdate = $('#backgroundupdate').val() === "true";
233
	draw_graph(refreshInterval, then, backgroundupdate);
234 849d3a37 Jared Dillard
235
	//re-draw graph when the page goes from inactive (in it's window) to active
236
	Visibility.change(function (e, state) {
237 fe5c31bb PiBa-NL
		if($('#backgroundupdate').val() === "true"){
238
			return;
239
		}
240 849d3a37 Jared Dillard
		if(state === "visible") {
241
242
			now = then = new Date(Date.now());
243
244
			var nowTime = now.getTime();
245
246 fe5c31bb PiBa-NL
			$.each( window.interfaces, function( key, value ) {
247 849d3a37 Jared Dillard
248
				Visibility.stop(updateIds);
249 fe5c31bb PiBa-NL
				clearInterval(updateTimerIds);
250 849d3a37 Jared Dillard
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 fe5c31bb PiBa-NL
			draw_graph(refreshInterval, then, false);
271 849d3a37 Jared Dillard
272
		}
273
	});
274
275
});
276
//]]>
277
</script>
278
279 d8837d57 PiBa-NL
<script src="/js/traffic-graphs.js?v=<?=filemtime('/usr/local/www/js/traffic-graphs.js')?>"></script>
280 849d3a37 Jared Dillard
281 8fd9052f Colin Fleming
<script type="text/javascript">
282
//<![CDATA[
283 f0a3b883 Scott Ullrich
284 fe5c31bb PiBa-NL
var graph_interfacenames = <?php
285
	foreach ($ifdescrs as $ifname => $ifdescr) {
286
		$iflist[$ifname] = $ifdescr;
287
	}
288
	echo json_encode($iflist);
289
?>;
290 abe98adb Phil Davis
function updateBandwidth() {
291 607b1c39 Sjon Hortensius
	$.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 abe98adb Phil Davis
				for (var y=0; y<10; y++) {
303 607b1c39 Sjon Hortensius
					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 3bd74348 bruno
							'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
309
							'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
310 607b1c39 Sjon Hortensius
						'</tr>');
311
					}
312
				}
313
			},
314
	});
315 f0a3b883 Scott Ullrich
}
316
317 abe98adb Phil Davis
events.push(function() {
318
	$('form.auto-submit').on('change', function() {
319 607b1c39 Sjon Hortensius
		$(this).submit();
320
	});
321 f0a3b883 Scott Ullrich
322 889f9ee0 heper
	setInterval('updateBandwidth()', 3000);
323 e31aa678 sbeaver
324 607b1c39 Sjon Hortensius
	updateBandwidth();
325
});
326 8fd9052f Colin Fleming
//]]>
327 f0a3b883 Scott Ullrich
</script>
328 5b237745 Scott Ullrich
<?php
329 9573d170 Scott Ullrich
330 872ce0dd Ermal Luçi
/* link the ipsec interface magically */
331 abe98adb Phil Davis
if (ipsec_enabled()) {
332 98128ad6 Phil Davis
	$ifdescrs['enc0'] = gettext("IPsec");
333 abe98adb Phil Davis
}
334 c1abd446 Seth Mos
335 5b237745 Scott Ullrich
?>
336 607b1c39 Sjon Hortensius
<div class="panel panel-default">
337
	<div class="panel-heading">
338 3d7a8696 k-paulius
		<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
339 e31aa678 sbeaver
	</div>
340 607b1c39 Sjon Hortensius
	<div class="panel-body">
341
		<div class="col-sm-6">
342 849d3a37 Jared Dillard
			<div id="traffic-chart-<?=$curif?>" class="d3-chart traffic-widget-chart">
343
				<svg></svg>
344
			</div>
345 607b1c39 Sjon Hortensius
		</div>
346
		<div class="col-sm-6">
347
			<table class="table table-striped table-condensed">
348
				<thead>
349
					<tr>
350 abe98adb Phil Davis
						<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
351 607b1c39 Sjon Hortensius
						<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 e57c91a2 Renato Botelho
	</div>
361 8ab3e9ed Erik Kristensen
</div>
362 c10cb196 Stephen Beaver
<?php include("foot.inc");