Project

General

Profile

Download (7.55 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * status_graph.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 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
if (isset($_REQUEST['smoothfactor'])){
98
	$cursmoothing = $_REQUEST['smoothfactor'];
99
} else {
100
	$cursmothing = 0;
101
}
102
if ($_REQUEST['invert']){
103
	$curinvert = $_REQUEST['invert'];
104
} else {
105
	$curinvert = "";
106
}
107

    
108
function iflist() {
109
	global $ifdescrs;
110

    
111
	$iflist = array();
112

    
113
	foreach ($ifdescrs as $ifn => $ifd) {
114
		$iflist[$ifn] = $ifd;
115
	}
116

    
117
	return($iflist);
118
}
119

    
120
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
121

    
122
include("head.inc");
123

    
124
$form = new Form(false);
125
$form->addClass('auto-submit');
126

    
127
$section = new Form_Section('Graph Settings');
128

    
129
$group = new Form_Group('Traffic Graph');
130

    
131
$group->add(new Form_Select(
132
	'if',
133
	null,
134
	$curif,
135
	iflist()
136
))->setHelp('Interface');
137

    
138
$group->add(new Form_Select(
139
	'sort',
140
	null,
141
	$cursort,
142
	array (
143
		'in'	=> gettext('Bandwidth In'),
144
		'out'	=> gettext('Bandwidth Out')
145
	)
146
))->setHelp('Sort by');
147

    
148
$group->add(new Form_Select(
149
	'filter',
150
	null,
151
	$curfilter,
152
	array (
153
		'local'	=> gettext('Local'),
154
		'remote'=> gettext('Remote'),
155
		'all'	=> gettext('All')
156
	)
157
))->setHelp('Filter');
158

    
159
$group->add(new Form_Select(
160
	'hostipformat',
161
	null,
162
	$curhostipformat,
163
	array (
164
		''			=> gettext('IP Address'),
165
		'hostname'	=> gettext('Host Name'),
166
		'descr'		=> gettext('Description'),
167
		'fqdn'		=> gettext('FQDN')
168
	)
169
))->setHelp('Display');
170

    
171
$section->add($group);
172

    
173
$group2 = new Form_Group('Controls');
174

    
175
$group2->add(new Form_Select(
176
	'backgroundupdate',
177
	null,
178
	$curbackgroundupdate,
179
	array (
180
		'false'	=> gettext('Clear graphs when not visible.'),
181
		'true'	=> gettext('Keep graphs updated on inactive tab. (increases cpu usage)'),
182
	)
183
))->setHelp('Background updates');
184

    
185
$group2->add(new Form_Select(
186
	'invert',
187
	null,
188
	$curinvert,
189
	array (
190
		'true'	=> gettext('On'),
191
		'false'	=> gettext('Off'),
192
	)
193
))->setHelp('Invert in/out');
194

    
195
$group2->add(new Form_Input(
196
	'smoothfactor',
197
	null,
198
	'range',
199
	$cursmoothing,
200
	array (
201
		'min' => 0,
202
		'max' => 5,
203
		'step' => 1
204
		)
205

    
206
))->setHelp('Graph Smoothing');
207

    
208
$section->add($group2);
209

    
210
$form->add($section);
211
print $form;
212

    
213
$realif = get_real_interface($curif);
214
?>
215

    
216
<script src="/vendor/d3/d3.min.js?v=<?=filemtime('/usr/local/www/vendor/d3/d3.min.js')?>"></script>
217
<script src="/vendor/nvd3/nv.d3.js?v=<?=filemtime('/usr/local/www/vendor/nvd3/nv.d3.js')?>"></script>
218
<script src="/vendor/visibility/visibility-1.2.3.min.js?v=<?=filemtime('/usr/local/www/vendor/visibility/visibility-1.2.3.min.js')?>"></script>
219

    
220
<link href="/vendor/nvd3/nv.d3.css" media="screen, projection" rel="stylesheet" type="text/css">
221

    
222
<script type="text/javascript">
223

    
224

    
225
//<![CDATA[
226
events.push(function() {
227

    
228
	var InterfaceString = "<?=$curif?>";
229
	var RealInterfaceString = "<?=$realif?>";
230
    window.graph_backgroundupdate = $('#backgroundupdate').val() === "true";
231
	window.smoothing = $('#smoothfactor').val();
232
	window.interval = 1;
233
	window.invert = $('#invert').val() === "true";
234
	window.size = 8;
235
	window.interfaces = InterfaceString.split("|").filter(function(entry) { return entry.trim() != ''; });
236
	window.realinterfaces = RealInterfaceString.split("|").filter(function(entry) { return entry.trim() != ''; });
237

    
238
	graph_init();
239
	graph_visibilitycheck();
240

    
241
});
242
//]]>
243
</script>
244

    
245
<script src="/js/traffic-graphs.js?v=<?=filemtime('/usr/local/www/js/traffic-graphs.js')?>"></script>
246

    
247
<script type="text/javascript">
248
//<![CDATA[
249

    
250
var graph_interfacenames = <?php
251
	foreach ($ifdescrs as $ifname => $ifdescr) {
252
		$iflist[$ifname] = $ifdescr;
253
	}
254
	echo json_encode($iflist);
255
?>;
256
function updateBandwidth() {
257
	$.ajax(
258
		'/bandwidth_by_ip.php',
259
		{
260
			type: 'get',
261
			data: $(document.forms[0]).serialize(),
262
			success: function (data) {
263
				var hosts_split = data.split("|");
264

    
265
				$('#top10-hosts').empty();
266

    
267
				//parse top ten bandwidth abuser hosts
268
				for (var y=0; y<10; y++) {
269
					if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
270
						hostinfo = hosts_split[y].split(";");
271

    
272
						$('#top10-hosts').append('<tr>'+
273
							'<td>'+ hostinfo[0] +'</td>'+
274
							'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
275
							'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
276
						'</tr>');
277
					}
278
				}
279
			},
280
	});
281
}
282

    
283
events.push(function() {
284
	$('form.auto-submit').on('change', function() {
285
		$(this).submit();
286
	});
287

    
288
	setInterval('updateBandwidth()', 3000);
289

    
290
	updateBandwidth();
291
});
292
//]]>
293
</script>
294
<?php
295

    
296
/* link the ipsec interface magically */
297
if (ipsec_enabled()) {
298
	$ifdescrs['enc0'] = gettext("IPsec");
299
}
300

    
301
?>
302
<div class="panel panel-default">
303
	<div class="panel-heading">
304
		<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
305
	</div>
306
	<div class="panel-body">
307
		<div class="col-sm-6">
308
			<div id="traffic-chart-<?=$curif?>" class="d3-chart traffic-widget-chart">
309
				<svg></svg>
310
			</div>
311
		</div>
312
		<div class="col-sm-6">
313
			<table class="table table-striped table-condensed">
314
				<thead>
315
					<tr>
316
						<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
317
						<th><?=gettext("Bandwidth In"); ?></th>
318
						<th><?=gettext("Bandwidth Out"); ?></th>
319
					</tr>
320
				</thead>
321
				<tbody id="top10-hosts">
322
					<!-- to be added by javascript -->
323
				</tbody>
324
			</table>
325
		</div>
326
	</div>
327
</div>
328
<?php include("foot.inc");
(167-167/232)