Project

General

Profile

Download (8.69 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 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 191cb31d Stephen Beaver
 *
11 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14 191cb31d Stephen Beaver
 *
15 0f3f6cc9 Jared Dillard
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18 191cb31d Stephen Beaver
 *
19 0f3f6cc9 Jared Dillard
 * http://www.apache.org/licenses/LICENSE-2.0
20 191cb31d Stephen Beaver
 *
21 0f3f6cc9 Jared Dillard
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26 191cb31d Stephen Beaver
 */
27 5b237745 Scott Ullrich
28 6b07c15a Matthew Grooms
##|+PRIV
29
##|*IDENT=page-status-trafficgraph
30 5230f468 jim-p
##|*NAME=Status: Traffic Graph
31 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
32
##|*MATCH=status_graph.php*
33 8e95a671 jim-p
##|*MATCH=bandwidth_by_ip.php*
34 8a2f80b2 jim-p
##|*MATCH=graph.php*
35
##|*MATCH=ifstats.php*
36 6b07c15a Matthew Grooms
##|-PRIV
37
38 d0ca7530 Reid Linnemann
require_once('config.inc');
39
require_once('config.lib.inc');
40
require_once('guiconfig.inc');
41
require_once('ipsec.inc');
42
43
44
$pconfig = config_get_path('traffic_graphs');
45 5b237745 Scott Ullrich
46 94556105 Scott Ullrich
// Get configured interface list
47 61ab4cd3 Scott Ullrich
$ifdescrs = get_configured_interface_with_descr();
48 abe98adb Phil Davis
if (ipsec_enabled()) {
49 98128ad6 Phil Davis
	$ifdescrs['enc0'] = gettext("IPsec");
50 abe98adb Phil Davis
}
51
52 9f5d14ce jim-p
foreach (array('server', 'client') as $mode) {
53 d35a18fc Christian McDonald
	foreach (config_get_path("openvpn/openvpn-{$mode}", []) as $setting) {
54 120f3169 Renato Botelho do Couto
		if (isset($setting['disable'])) {
55
			continue;
56 9f5d14ce jim-p
		}
57 120f3169 Renato Botelho do Couto
		$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] =
58
		    gettext("OpenVPN") . " " . $mode . ": " .
59
		    htmlspecialchars($setting['description']);
60 9f5d14ce jim-p
	}
61
}
62 235c051f jim-p
63
$ifdescrs = array_merge($ifdescrs, interface_ipsec_vti_list_all());
64 43a0ac8a Scott Ullrich
65 dd8a6d75 Stephen Jones
if (!empty($_POST)) {
66
	// update view if settings are changed or saved
67
	$curif = $_POST['if'];
68 50b2f6ab Scott Ullrich
	$found = false;
69 6c07db48 Phil Davis
	foreach ($ifdescrs as $descr => $ifdescr) {
70 b406c78a Ermal
		if ($descr == $curif) {
71
			$found = true;
72
			break;
73
		}
74
	}
75
	if ($found === false) {
76 6f3d2063 Renato Botelho
		header("Location: status_graph.php");
77 50b2f6ab Scott Ullrich
		exit;
78
	}
79 dd8a6d75 Stephen Jones
	$cursort = $_POST['sort'];
80
	$curfilter = $_POST['filter'];
81
	$curhostipformat = $_POST['hostipformat'];
82
	$curbackgroundupdate = $_POST['backgroundupdate'];
83
	$curinvert = $_POST['invert'];
84
	$cursmoothing = $_POST['smoothfactor'];
85 15c2e494 joshuasign
	$curmode = $_POST['mode'];
86 120f3169 Renato Botelho do Couto
87 dd8a6d75 Stephen Jones
	// Save data to config
88
	if (isset($_POST['save'])) {
89
		$pconfig = array();
90
		$pconfig["if"] = $curif;
91
		$pconfig["sort"] = $cursort;
92
		$pconfig["filter"] = $curfilter;
93
		$pconfig["hostipformat"] = $curhostipformat;
94
		$pconfig["backgroundupdate"] = $curbackgroundupdate;
95
		$pconfig["smoothfactor"] = $cursmoothing;
96
		$pconfig["invert"] = $curinvert;
97 15c2e494 joshuasign
		$pconfig["mode"] = $curmode;
98 d0ca7530 Reid Linnemann
		config_set_path("traffic_graphs", $pconfig);
99 dd8a6d75 Stephen Jones
		write_config("Traffic Graphs settings updated");
100
	}
101 50b2f6ab Scott Ullrich
} else {
102 dd8a6d75 Stephen Jones
	// default settings from config
103
	if (is_array($pconfig)) {
104
		$curif = $pconfig['if'];
105
		$cursort = $pconfig['sort'];
106
		$curfilter = $pconfig['filter'];
107
		$curhostipformat = $pconfig['hostipformat'];
108
		$curbackgroundupdate = $pconfig['backgroundupdate'];
109
		$cursmoothing = $pconfig['smoothfactor'];
110
		$curinvert = $pconfig['invert'];
111 15c2e494 joshuasign
		$curmode = $pconfig['mode'];;
112 42b0c921 Phil Davis
	} else {
113 dd8a6d75 Stephen Jones
		// initialize when no config details are present
114
		if (empty($ifdescrs["wan"])) {
115 120f3169 Renato Botelho do Couto
			/*
116
			 * Handle the case when WAN has been disabled. Use the
117
			 * first key in ifdescrs.
118
			 */
119 dd8a6d75 Stephen Jones
			reset($ifdescrs);
120
			$curif = key($ifdescrs);
121
		} else {
122
			$curif = "wan";
123
		}
124
		$cursort = "";
125
		$curfilter = "";
126
		$curhostipformat = "";
127
		$curbackgroundupdate = "";
128
		$cursmoothing = 0;
129
		$curinvert = "";
130 15c2e494 joshuasign
		$curmode = "";
131 76165eac Phil Davis
	}
132 50b2f6ab Scott Ullrich
}
133 769cdf3b Bill Marquette
134 e31aa678 sbeaver
function iflist() {
135
	global $ifdescrs;
136
137
	$iflist = array();
138
139
	foreach ($ifdescrs as $ifn => $ifd) {
140
		$iflist[$ifn] = $ifd;
141
	}
142
143
	return($iflist);
144
}
145
146 abe98adb Phil Davis
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
147 f0a3b883 Scott Ullrich
148 4df96eff Scott Ullrich
include("head.inc");
149
150 dd8a6d75 Stephen Jones
$form = new Form();
151 a4af095c Renato Botelho
$form->addClass('auto-submit');
152 e31aa678 sbeaver
153 5f88f964 k-paulius
$section = new Form_Section('Graph Settings');
154 5b237745 Scott Ullrich
155 e00f69c8 Stephen Jones
$group = new Form_Group('Traffic Graph');
156 a4af095c Renato Botelho
157
$group->add(new Form_Select(
158 e31aa678 sbeaver
	'if',
159 a4af095c Renato Botelho
	null,
160 e31aa678 sbeaver
	$curif,
161
	iflist()
162 a4af095c Renato Botelho
))->setHelp('Interface');
163 e31aa678 sbeaver
164 a4af095c Renato Botelho
$group->add(new Form_Select(
165 e31aa678 sbeaver
	'sort',
166 a4af095c Renato Botelho
	null,
167 e31aa678 sbeaver
	$cursort,
168
	array (
169 b50d30c3 Stephen Beaver
		'in'	=> gettext('Bandwidth In'),
170
		'out'	=> gettext('Bandwidth Out')
171 e31aa678 sbeaver
	)
172 a4af095c Renato Botelho
))->setHelp('Sort by');
173 e31aa678 sbeaver
174 a4af095c Renato Botelho
$group->add(new Form_Select(
175 e31aa678 sbeaver
	'filter',
176 a4af095c Renato Botelho
	null,
177 e31aa678 sbeaver
	$curfilter,
178
	array (
179 b50d30c3 Stephen Beaver
		'local'	=> gettext('Local'),
180
		'remote'=> gettext('Remote'),
181
		'all'	=> gettext('All')
182 e31aa678 sbeaver
	)
183 a4af095c Renato Botelho
))->setHelp('Filter');
184 e31aa678 sbeaver
185 a4af095c Renato Botelho
$group->add(new Form_Select(
186 e31aa678 sbeaver
	'hostipformat',
187 a4af095c Renato Botelho
	null,
188 e31aa678 sbeaver
	$curhostipformat,
189
	array (
190 120f3169 Renato Botelho do Couto
		''		=> gettext('IP Address'),
191 b50d30c3 Stephen Beaver
		'hostname'	=> gettext('Host Name'),
192
		'descr'		=> gettext('Description'),
193
		'fqdn'		=> gettext('FQDN')
194 e31aa678 sbeaver
	)
195 a4af095c Renato Botelho
))->setHelp('Display');
196
197 15c2e494 joshuasign
$group->add(new Form_Select(
198 120f3169 Renato Botelho do Couto
	'mode',
199
	null,
200
	$curmode,
201
	array (
202
		'rate'	=> gettext('rate (standard)'),
203
		'iftop'	=> gettext('iftop (experimental)')
204
	)
205 15c2e494 joshuasign
))->setHelp('Mode');
206 120f3169 Renato Botelho do Couto
207 e00f69c8 Stephen Jones
$section->add($group);
208
209
$group2 = new Form_Group('Controls');
210
211
$group2->add(new Form_Select(
212 fe5c31bb PiBa-NL
	'backgroundupdate',
213
	null,
214
	$curbackgroundupdate,
215
	array (
216
		'false'	=> gettext('Clear graphs when not visible.'),
217 120f3169 Renato Botelho do Couto
		'true'	=> gettext('Keep graphs updated on inactive tab. ' .
218
		    '(increases cpu usage)'),
219 fe5c31bb PiBa-NL
	)
220
))->setHelp('Background updates');
221
222 e00f69c8 Stephen Jones
$group2->add(new Form_Select(
223
	'invert',
224
	null,
225
	$curinvert,
226
	array (
227
		'true'	=> gettext('On'),
228
		'false'	=> gettext('Off'),
229
	)
230
))->setHelp('Invert in/out');
231
232
$group2->add(new Form_Input(
233
	'smoothfactor',
234
	null,
235
	'range',
236
	$cursmoothing,
237
	array (
238
		'min' => 0,
239
		'max' => 5,
240
		'step' => 1
241
		)
242
243
))->setHelp('Graph Smoothing');
244
245
$section->add($group2);
246 e31aa678 sbeaver
247
$form->add($section);
248
print $form;
249
250 d3fd2bbe PiBa-NL
$realif = get_real_interface($curif);
251 e31aa678 sbeaver
?>
252 849d3a37 Jared Dillard
253 d8837d57 PiBa-NL
<script src="/vendor/d3/d3.min.js?v=<?=filemtime('/usr/local/www/vendor/d3/d3.min.js')?>"></script>
254
<script src="/vendor/nvd3/nv.d3.js?v=<?=filemtime('/usr/local/www/vendor/nvd3/nv.d3.js')?>"></script>
255
<script src="/vendor/visibility/visibility-1.2.3.min.js?v=<?=filemtime('/usr/local/www/vendor/visibility/visibility-1.2.3.min.js')?>"></script>
256 849d3a37 Jared Dillard
257
<link href="/vendor/nvd3/nv.d3.css" media="screen, projection" rel="stylesheet" type="text/css">
258
259
<script type="text/javascript">
260
261 52229047 PiBa-NL
262 849d3a37 Jared Dillard
//<![CDATA[
263
events.push(function() {
264
265
	var InterfaceString = "<?=$curif?>";
266 d3fd2bbe PiBa-NL
	var RealInterfaceString = "<?=$realif?>";
267 120f3169 Renato Botelho do Couto
	window.graph_backgroundupdate = $('#backgroundupdate').val() === "true";
268 e00f69c8 Stephen Jones
	window.smoothing = $('#smoothfactor').val();
269 52229047 PiBa-NL
	window.interval = 1;
270 e00f69c8 Stephen Jones
	window.invert = $('#invert').val() === "true";
271 52229047 PiBa-NL
	window.size = 8;
272
	window.interfaces = InterfaceString.split("|").filter(function(entry) { return entry.trim() != ''; });
273
	window.realinterfaces = RealInterfaceString.split("|").filter(function(entry) { return entry.trim() != ''; });
274 849d3a37 Jared Dillard
275 52229047 PiBa-NL
	graph_init();
276
	graph_visibilitycheck();
277 849d3a37 Jared Dillard
278
});
279
//]]>
280
</script>
281
282 d8837d57 PiBa-NL
<script src="/js/traffic-graphs.js?v=<?=filemtime('/usr/local/www/js/traffic-graphs.js')?>"></script>
283 849d3a37 Jared Dillard
284 8fd9052f Colin Fleming
<script type="text/javascript">
285
//<![CDATA[
286 f0a3b883 Scott Ullrich
287 fe5c31bb PiBa-NL
var graph_interfacenames = <?php
288
	foreach ($ifdescrs as $ifname => $ifdescr) {
289
		$iflist[$ifname] = $ifdescr;
290
	}
291
	echo json_encode($iflist);
292
?>;
293 abe98adb Phil Davis
function updateBandwidth() {
294 607b1c39 Sjon Hortensius
	$.ajax(
295
		'/bandwidth_by_ip.php',
296
		{
297
			type: 'get',
298
			data: $(document.forms[0]).serialize(),
299
			success: function (data) {
300
				var hosts_split = data.split("|");
301
302
				$('#top10-hosts').empty();
303
304
				//parse top ten bandwidth abuser hosts
305 abe98adb Phil Davis
				for (var y=0; y<10; y++) {
306 607b1c39 Sjon Hortensius
					if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
307
						hostinfo = hosts_split[y].split(";");
308
309
						$('#top10-hosts').append('<tr>'+
310
							'<td>'+ hostinfo[0] +'</td>'+
311 3bd74348 bruno
							'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
312
							'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
313 607b1c39 Sjon Hortensius
						'</tr>');
314
					}
315
				}
316
			},
317
	});
318 f0a3b883 Scott Ullrich
}
319
320 abe98adb Phil Davis
events.push(function() {
321
	$('form.auto-submit').on('change', function() {
322 607b1c39 Sjon Hortensius
		$(this).submit();
323
	});
324 f0a3b883 Scott Ullrich
325 889f9ee0 heper
	setInterval('updateBandwidth()', 3000);
326 e31aa678 sbeaver
327 607b1c39 Sjon Hortensius
	updateBandwidth();
328
});
329 8fd9052f Colin Fleming
//]]>
330 f0a3b883 Scott Ullrich
</script>
331 5b237745 Scott Ullrich
<?php
332 9573d170 Scott Ullrich
333 872ce0dd Ermal Luçi
/* link the ipsec interface magically */
334 abe98adb Phil Davis
if (ipsec_enabled()) {
335 98128ad6 Phil Davis
	$ifdescrs['enc0'] = gettext("IPsec");
336 abe98adb Phil Davis
}
337 c1abd446 Seth Mos
338 5b237745 Scott Ullrich
?>
339 607b1c39 Sjon Hortensius
<div class="panel panel-default">
340
	<div class="panel-heading">
341 3d7a8696 k-paulius
		<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
342 e31aa678 sbeaver
	</div>
343 607b1c39 Sjon Hortensius
	<div class="panel-body">
344
		<div class="col-sm-6">
345 849d3a37 Jared Dillard
			<div id="traffic-chart-<?=$curif?>" class="d3-chart traffic-widget-chart">
346
				<svg></svg>
347
			</div>
348 607b1c39 Sjon Hortensius
		</div>
349
		<div class="col-sm-6">
350
			<table class="table table-striped table-condensed">
351
				<thead>
352
					<tr>
353 abe98adb Phil Davis
						<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
354 607b1c39 Sjon Hortensius
						<th><?=gettext("Bandwidth In"); ?></th>
355
						<th><?=gettext("Bandwidth Out"); ?></th>
356
					</tr>
357
				</thead>
358
				<tbody id="top10-hosts">
359
					<!-- to be added by javascript -->
360
				</tbody>
361
			</table>
362
		</div>
363 e57c91a2 Renato Botelho
	</div>
364 8ab3e9ed Erik Kristensen
</div>
365 c10cb196 Stephen Beaver
<?php include("foot.inc");