Project

General

Profile

Download (6.89 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-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
$realif = get_real_interface($curif);
177
?>
178

    
179
<script src="/vendor/d3/d3.min.js?v=<?=filemtime('/usr/local/www/vendor/d3/d3.min.js')?>"></script>
180
<script src="/vendor/nvd3/nv.d3.js?v=<?=filemtime('/usr/local/www/vendor/nvd3/nv.d3.js')?>"></script>
181
<script src="/vendor/visibility/visibility-1.2.3.min.js?v=<?=filemtime('/usr/local/www/vendor/visibility/visibility-1.2.3.min.js')?>"></script>
182

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

    
185
<script type="text/javascript">
186

    
187

    
188
//<![CDATA[
189
events.push(function() {
190

    
191
	var InterfaceString = "<?=$curif?>";
192
	var RealInterfaceString = "<?=$realif?>";
193
    window.graph_backgroundupdate = $('#backgroundupdate').val() === "true";
194

    
195
	window.interval = 1;
196
	window.invert = "true";
197
	window.size = 8;
198
	window.interfaces = InterfaceString.split("|").filter(function(entry) { return entry.trim() != ''; });
199
	window.realinterfaces = RealInterfaceString.split("|").filter(function(entry) { return entry.trim() != ''; });
200

    
201
	graph_init();
202
	graph_visibilitycheck();
203

    
204
});
205
//]]>
206
</script>
207

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

    
210
<script type="text/javascript">
211
//<![CDATA[
212

    
213
var graph_interfacenames = <?php
214
	foreach ($ifdescrs as $ifname => $ifdescr) {
215
		$iflist[$ifname] = $ifdescr;
216
	}
217
	echo json_encode($iflist);
218
?>;
219
function updateBandwidth() {
220
	$.ajax(
221
		'/bandwidth_by_ip.php',
222
		{
223
			type: 'get',
224
			data: $(document.forms[0]).serialize(),
225
			success: function (data) {
226
				var hosts_split = data.split("|");
227

    
228
				$('#top10-hosts').empty();
229

    
230
				//parse top ten bandwidth abuser hosts
231
				for (var y=0; y<10; y++) {
232
					if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
233
						hostinfo = hosts_split[y].split(";");
234

    
235
						$('#top10-hosts').append('<tr>'+
236
							'<td>'+ hostinfo[0] +'</td>'+
237
							'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
238
							'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
239
						'</tr>');
240
					}
241
				}
242
			},
243
	});
244
}
245

    
246
events.push(function() {
247
	$('form.auto-submit').on('change', function() {
248
		$(this).submit();
249
	});
250

    
251
	setInterval('updateBandwidth()', 3000);
252

    
253
	updateBandwidth();
254
});
255
//]]>
256
</script>
257
<?php
258

    
259
/* link the ipsec interface magically */
260
if (ipsec_enabled()) {
261
	$ifdescrs['enc0'] = gettext("IPsec");
262
}
263

    
264
?>
265
<div class="panel panel-default">
266
	<div class="panel-heading">
267
		<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
268
	</div>
269
	<div class="panel-body">
270
		<div class="col-sm-6">
271
			<div id="traffic-chart-<?=$curif?>" class="d3-chart traffic-widget-chart">
272
				<svg></svg>
273
			</div>
274
		</div>
275
		<div class="col-sm-6">
276
			<table class="table table-striped table-condensed">
277
				<thead>
278
					<tr>
279
						<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
280
						<th><?=gettext("Bandwidth In"); ?></th>
281
						<th><?=gettext("Bandwidth Out"); ?></th>
282
					</tr>
283
				</thead>
284
				<tbody id="top10-hosts">
285
					<!-- to be added by javascript -->
286
				</tbody>
287
			</table>
288
		</div>
289
	</div>
290
</div>
291
<?php include("foot.inc");
(164-164/228)