Project

General

Profile

Download (7.62 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
$ifdescrs = array_merge($ifdescrs, interface_ipsec_vti_list_all());
56

    
57
if ($_REQUEST['if']) {
58
	$curif = $_REQUEST['if'];
59
	$found = false;
60
	foreach ($ifdescrs as $descr => $ifdescr) {
61
		if ($descr == $curif) {
62
			$found = true;
63
			break;
64
		}
65
	}
66
	if ($found === false) {
67
		header("Location: status_graph.php");
68
		exit;
69
	}
70
} else {
71
	if (empty($ifdescrs["wan"])) {
72
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
73
		reset($ifdescrs);
74
		$curif = key($ifdescrs);
75
	} else {
76
		$curif = "wan";
77
	}
78
}
79
if ($_REQUEST['sort']) {
80
	$cursort = $_REQUEST['sort'];
81
} else {
82
	$cursort = "";
83
}
84
if ($_REQUEST['filter']) {
85
	$curfilter = $_REQUEST['filter'];
86
} else {
87
	$curfilter = "";
88
}
89
if ($_REQUEST['hostipformat']) {
90
	$curhostipformat = $_REQUEST['hostipformat'];
91
} else {
92
	$curhostipformat = "";
93
}
94
if ($_REQUEST['backgroundupdate']) {
95
	$curbackgroundupdate = $_REQUEST['backgroundupdate'];
96
} else {
97
	$curbackgroundupdate = "";
98
}
99
if (isset($_REQUEST['smoothfactor'])){
100
	$cursmoothing = $_REQUEST['smoothfactor'];
101
} else {
102
	$cursmothing = 0;
103
}
104
if ($_REQUEST['invert']){
105
	$curinvert = $_REQUEST['invert'];
106
} else {
107
	$curinvert = "";
108
}
109

    
110
function iflist() {
111
	global $ifdescrs;
112

    
113
	$iflist = array();
114

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

    
119
	return($iflist);
120
}
121

    
122
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
123

    
124
include("head.inc");
125

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

    
129
$section = new Form_Section('Graph Settings');
130

    
131
$group = new Form_Group('Traffic Graph');
132

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

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

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

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

    
173
$section->add($group);
174

    
175
$group2 = new Form_Group('Controls');
176

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

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

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

    
208
))->setHelp('Graph Smoothing');
209

    
210
$section->add($group2);
211

    
212
$form->add($section);
213
print $form;
214

    
215
$realif = get_real_interface($curif);
216
?>
217

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

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

    
224
<script type="text/javascript">
225

    
226

    
227
//<![CDATA[
228
events.push(function() {
229

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

    
240
	graph_init();
241
	graph_visibilitycheck();
242

    
243
});
244
//]]>
245
</script>
246

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

    
249
<script type="text/javascript">
250
//<![CDATA[
251

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

    
267
				$('#top10-hosts').empty();
268

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

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

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

    
290
	setInterval('updateBandwidth()', 3000);
291

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

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

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