Project

General

Profile

Download (7.81 KB) Statistics
| Branch: | Tag: | Revision:
1 9573d170 Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 aaec5634 Renato Botelho
 * status_graph.php
4 191cb31d Stephen Beaver
 *
5 aaec5634 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * All rights reserved.
8 191cb31d Stephen Beaver
 *
9 aaec5634 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 aaec5634 Renato Botelho
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15 191cb31d Stephen Beaver
 *
16 aaec5634 Renato Botelho
 * 1. Redistributions of source code must retain the above copyright notice,
17
 *    this list of conditions and the following disclaimer.
18 191cb31d Stephen Beaver
 *
19 aaec5634 Renato Botelho
 * 2. Redistributions in binary form must reproduce the above copyright
20
 *    notice, this list of conditions and the following disclaimer in
21
 *    the documentation and/or other materials provided with the
22
 *    distribution.
23 191cb31d Stephen Beaver
 *
24 aaec5634 Renato Botelho
 * 3. All advertising materials mentioning features or use of this software
25
 *    must display the following acknowledgment:
26
 *    "This product includes software developed by the pfSense Project
27
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28 191cb31d Stephen Beaver
 *
29 aaec5634 Renato Botelho
 * 4. The names "pfSense" and "pfSense Project" must not be used to
30
 *    endorse or promote products derived from this software without
31
 *    prior written permission. For written permission, please contact
32
 *    coreteam@pfsense.org.
33 191cb31d Stephen Beaver
 *
34 aaec5634 Renato Botelho
 * 5. Products derived from this software may not be called "pfSense"
35
 *    nor may "pfSense" appear in their names without prior written
36
 *    permission of the Electric Sheep Fencing, LLC.
37 191cb31d Stephen Beaver
 *
38 aaec5634 Renato Botelho
 * 6. Redistributions of any form whatsoever must retain the following
39
 *    acknowledgment:
40 191cb31d Stephen Beaver
 *
41 aaec5634 Renato Botelho
 * "This product includes software developed by the pfSense Project
42
 * for use in the pfSense software distribution (http://www.pfsense.org/).
43 191cb31d Stephen Beaver
 *
44 aaec5634 Renato Botelho
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 191cb31d Stephen Beaver
 */
57 5b237745 Scott Ullrich
58 6b07c15a Matthew Grooms
##|+PRIV
59
##|*IDENT=page-status-trafficgraph
60 5230f468 jim-p
##|*NAME=Status: Traffic Graph
61 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
62
##|*MATCH=status_graph.php*
63 8e95a671 jim-p
##|*MATCH=bandwidth_by_ip.php*
64 8a2f80b2 jim-p
##|*MATCH=graph.php*
65
##|*MATCH=ifstats.php*
66 6b07c15a Matthew Grooms
##|-PRIV
67
68 aceaf18c Phil Davis
require_once("guiconfig.inc");
69 179ab6b3 Luiz Otavio O Souza
require_once("ipsec.inc");
70 5b237745 Scott Ullrich
71 42b0c921 Phil Davis
if ($_POST['width']) {
72 9573d170 Scott Ullrich
	$width = $_POST['width'];
73 42b0c921 Phil Davis
} else {
74 f0a3b883 Scott Ullrich
	$width = "100%";
75 42b0c921 Phil Davis
}
76 9573d170 Scott Ullrich
77 42b0c921 Phil Davis
if ($_POST['height']) {
78 9573d170 Scott Ullrich
	$height = $_POST['height'];
79 42b0c921 Phil Davis
} else {
80 f0a3b883 Scott Ullrich
	$height = "200";
81 42b0c921 Phil Davis
}
82 9573d170 Scott Ullrich
83 94556105 Scott Ullrich
// Get configured interface list
84 61ab4cd3 Scott Ullrich
$ifdescrs = get_configured_interface_with_descr();
85 abe98adb Phil Davis
if (ipsec_enabled()) {
86 98128ad6 Phil Davis
	$ifdescrs['enc0'] = gettext("IPsec");
87 abe98adb Phil Davis
}
88
89 9f5d14ce jim-p
foreach (array('server', 'client') as $mode) {
90
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
91
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
92
			if (!isset($setting['disable'])) {
93 98128ad6 Phil Davis
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " " . $mode . ": ".htmlspecialchars($setting['description']);
94 9f5d14ce jim-p
			}
95
		}
96
	}
97
}
98 43a0ac8a Scott Ullrich
99 8d967cb2 Luca Zorzi
// Compatiblity to restore GET parameters used pre-2.3
100
// Useful to save a URL for a given graph configuration
101
if (isset($_GET['if']) && !isset($_POST['if'])) {
102
	$_POST['if'] = $_GET['if'];
103
}
104
if (isset($_GET['sort']) && !isset($_POST['sort'])) {
105
	$_POST['sort'] = $_GET['sort'];
106
}
107
if (isset($_GET['filter']) && !isset($_POST['filter'])) {
108
	$_POST['filter'] = $_GET['filter'];
109
}
110
if (isset($_GET['hostipformat']) && !isset($_POST['hostipformat'])) {
111
	$_POST['hostipformat'] = $_GET['hostipformat'];
112
}
113
114 e31aa678 sbeaver
if ($_POST['if']) {
115
	$curif = $_POST['if'];
116 50b2f6ab Scott Ullrich
	$found = false;
117 6c07db48 Phil Davis
	foreach ($ifdescrs as $descr => $ifdescr) {
118 b406c78a Ermal
		if ($descr == $curif) {
119
			$found = true;
120
			break;
121
		}
122
	}
123
	if ($found === false) {
124 6f3d2063 Renato Botelho
		header("Location: status_graph.php");
125 50b2f6ab Scott Ullrich
		exit;
126
	}
127
} else {
128 76165eac Phil Davis
	if (empty($ifdescrs["wan"])) {
129
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
130
		reset($ifdescrs);
131
		$curif = key($ifdescrs);
132 42b0c921 Phil Davis
	} else {
133 76165eac Phil Davis
		$curif = "wan";
134
	}
135 50b2f6ab Scott Ullrich
}
136 e31aa678 sbeaver
if ($_POST['sort']) {
137
	$cursort = $_POST['sort'];
138 893fb622 Michele Di Maria
} else {
139
	$cursort = "";
140
}
141 e31aa678 sbeaver
if ($_POST['filter']) {
142
	$curfilter = $_POST['filter'];
143 da11e022 Phil Davis
} else {
144
	$curfilter = "";
145
}
146 e31aa678 sbeaver
if ($_POST['hostipformat']) {
147
	$curhostipformat = $_POST['hostipformat'];
148 4006a437 Phil Davis
} else {
149
	$curhostipformat = "";
150
}
151 769cdf3b Bill Marquette
152 e31aa678 sbeaver
function iflist() {
153
	global $ifdescrs;
154
155
	$iflist = array();
156
157
	foreach ($ifdescrs as $ifn => $ifd) {
158
		$iflist[$ifn] = $ifd;
159
	}
160
161
	return($iflist);
162
}
163
164 abe98adb Phil Davis
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
165 f0a3b883 Scott Ullrich
166 4df96eff Scott Ullrich
include("head.inc");
167
168 e31aa678 sbeaver
$form = new Form(false);
169 a4af095c Renato Botelho
$form->addClass('auto-submit');
170 e31aa678 sbeaver
171 5f88f964 k-paulius
$section = new Form_Section('Graph Settings');
172 5b237745 Scott Ullrich
173 a4af095c Renato Botelho
$group = new Form_Group('');
174
175
$group->add(new Form_Select(
176 e31aa678 sbeaver
	'if',
177 a4af095c Renato Botelho
	null,
178 e31aa678 sbeaver
	$curif,
179
	iflist()
180 a4af095c Renato Botelho
))->setHelp('Interface');
181 e31aa678 sbeaver
182 a4af095c Renato Botelho
$group->add(new Form_Select(
183 e31aa678 sbeaver
	'sort',
184 a4af095c Renato Botelho
	null,
185 e31aa678 sbeaver
	$cursort,
186
	array (
187 b50d30c3 Stephen Beaver
		'in'	=> gettext('Bandwidth In'),
188
		'out'	=> gettext('Bandwidth Out')
189 e31aa678 sbeaver
	)
190 a4af095c Renato Botelho
))->setHelp('Sort by');
191 e31aa678 sbeaver
192 a4af095c Renato Botelho
$group->add(new Form_Select(
193 e31aa678 sbeaver
	'filter',
194 a4af095c Renato Botelho
	null,
195 e31aa678 sbeaver
	$curfilter,
196
	array (
197 b50d30c3 Stephen Beaver
		'local'	=> gettext('Local'),
198
		'remote'=> gettext('Remote'),
199
		'all'	=> gettext('All')
200 e31aa678 sbeaver
	)
201 a4af095c Renato Botelho
))->setHelp('Filter');
202 e31aa678 sbeaver
203 a4af095c Renato Botelho
$group->add(new Form_Select(
204 e31aa678 sbeaver
	'hostipformat',
205 a4af095c Renato Botelho
	null,
206 e31aa678 sbeaver
	$curhostipformat,
207
	array (
208 b50d30c3 Stephen Beaver
		''			=> gettext('IP Address'),
209
		'hostname'	=> gettext('Host Name'),
210
		'descr'		=> gettext('Description'),
211
		'fqdn'		=> gettext('FQDN')
212 e31aa678 sbeaver
	)
213 a4af095c Renato Botelho
))->setHelp('Display');
214
215
$section->add($group);
216 e31aa678 sbeaver
217
$form->add($section);
218
print $form;
219
220
?>
221 8fd9052f Colin Fleming
<script type="text/javascript">
222
//<![CDATA[
223 f0a3b883 Scott Ullrich
224 abe98adb Phil Davis
function updateBandwidth() {
225 607b1c39 Sjon Hortensius
	$.ajax(
226
		'/bandwidth_by_ip.php',
227
		{
228
			type: 'get',
229
			data: $(document.forms[0]).serialize(),
230
			success: function (data) {
231
				var hosts_split = data.split("|");
232
233
				$('#top10-hosts').empty();
234
235
				//parse top ten bandwidth abuser hosts
236 abe98adb Phil Davis
				for (var y=0; y<10; y++) {
237 607b1c39 Sjon Hortensius
					if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
238
						hostinfo = hosts_split[y].split(";");
239
240
						$('#top10-hosts').append('<tr>'+
241
							'<td>'+ hostinfo[0] +'</td>'+
242 3bd74348 bruno
							'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
243
							'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
244 607b1c39 Sjon Hortensius
						'</tr>');
245
					}
246
				}
247
			},
248
	});
249 f0a3b883 Scott Ullrich
}
250
251 abe98adb Phil Davis
events.push(function() {
252
	$('form.auto-submit').on('change', function() {
253 607b1c39 Sjon Hortensius
		$(this).submit();
254
	});
255 f0a3b883 Scott Ullrich
256 889f9ee0 heper
	setInterval('updateBandwidth()', 3000);
257 e31aa678 sbeaver
258 607b1c39 Sjon Hortensius
	updateBandwidth();
259
});
260 8fd9052f Colin Fleming
//]]>
261 f0a3b883 Scott Ullrich
</script>
262 5b237745 Scott Ullrich
<?php
263 9573d170 Scott Ullrich
264 872ce0dd Ermal Luçi
/* link the ipsec interface magically */
265 abe98adb Phil Davis
if (ipsec_enabled()) {
266 98128ad6 Phil Davis
	$ifdescrs['enc0'] = gettext("IPsec");
267 abe98adb Phil Davis
}
268 c1abd446 Seth Mos
269 5b237745 Scott Ullrich
?>
270 607b1c39 Sjon Hortensius
<div class="panel panel-default">
271
	<div class="panel-heading">
272 3d7a8696 k-paulius
		<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
273 e31aa678 sbeaver
	</div>
274 607b1c39 Sjon Hortensius
	<div class="panel-body">
275
		<div class="col-sm-6">
276
			<object data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&amp;ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>">
277
				<param name="id" value="graph" />
278
				<param name="type" value="image/svg+xml" />
279 5c0ab3cd NewEraCracker
				<param name="width" value="<?=$width;?>" />
280
				<param name="height" value="<?=$height;?>" />
281 607b1c39 Sjon Hortensius
				<param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
282
			</object>
283
		</div>
284
		<div class="col-sm-6">
285
			<table class="table table-striped table-condensed">
286
				<thead>
287
					<tr>
288 abe98adb Phil Davis
						<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
289 607b1c39 Sjon Hortensius
						<th><?=gettext("Bandwidth In"); ?></th>
290
						<th><?=gettext("Bandwidth Out"); ?></th>
291
					</tr>
292
				</thead>
293
				<tbody id="top10-hosts">
294
					<!-- to be added by javascript -->
295
				</tbody>
296
			</table>
297
		</div>
298 e57c91a2 Renato Botelho
	</div>
299 8ab3e9ed Erik Kristensen
</div>
300 c10cb196 Stephen Beaver
<?php include("foot.inc");