Project

General

Profile

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