Project

General

Profile

Download (7.31 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_graph.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *
9
 *  Some or all of this file is based on the m0n0wall project which is
10
 *  Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
11
 *
12
 *	Redistribution and use in source and binary forms, with or without modification,
13
 *	are permitted provided that the following conditions are met:
14
 *
15
 *	1. Redistributions of source code must retain the above copyright notice,
16
 *		this list of conditions and the following disclaimer.
17
 *
18
 *	2. Redistributions in binary form must reproduce the above copyright
19
 *		notice, this list of conditions and the following disclaimer in
20
 *		the documentation and/or other materials provided with the
21
 *		distribution.
22
 *
23
 *	3. All advertising materials mentioning features or use of this software
24
 *		must display the following acknowledgment:
25
 *		"This product includes software developed by the pfSense Project
26
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
27
 *
28
 *	4. The names "pfSense" and "pfSense Project" must not be used to
29
 *		 endorse or promote products derived from this software without
30
 *		 prior written permission. For written permission, please contact
31
 *		 coreteam@pfsense.org.
32
 *
33
 *	5. Products derived from this software may not be called "pfSense"
34
 *		nor may "pfSense" appear in their names without prior written
35
 *		permission of the Electric Sheep Fencing, LLC.
36
 *
37
 *	6. Redistributions of any form whatsoever must retain the following
38
 *		acknowledgment:
39
 *
40
 *	"This product includes software developed by the pfSense Project
41
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
42
 *
43
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
55
 *
56
 *	====================================================================
57
 *
58
 */
59
/*
60
	pfSense_MODULE:	routing
61
*/
62

    
63
##|+PRIV
64
##|*IDENT=page-status-trafficgraph
65
##|*NAME=Status: Traffic Graph page
66
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
67
##|*MATCH=status_graph.php*
68
##|*MATCH=bandwidth_by_ip.php*
69
##|*MATCH=graph.php*
70
##|*MATCH=ifstats.php*
71
##|-PRIV
72

    
73
require("guiconfig.inc");
74

    
75
if ($_POST['width']) {
76
	$width = $_POST['width'];
77
} else {
78
	$width = "100%";
79
}
80

    
81
if ($_POST['height']) {
82
	$height = $_POST['height'];
83
} else {
84
	$height = "200";
85
}
86

    
87
// Get configured interface list
88
$ifdescrs = get_configured_interface_with_descr();
89
if (isset($config['ipsec']['enable'])) {
90
	$ifdescrs['enc0'] = "IPsec";
91
}
92
foreach (array('server', 'client') as $mode) {
93
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
94
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
95
			if (!isset($setting['disable'])) {
96
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
97
			}
98
		}
99
	}
100
}
101

    
102
if ($_POST['if']) {
103
	$curif = $_POST['if'];
104
	$found = false;
105
	foreach ($ifdescrs as $descr => $ifdescr) {
106
		if ($descr == $curif) {
107
			$found = true;
108
			break;
109
		}
110
	}
111
	if ($found === false) {
112
		header("Location: status_graph.php");
113
		exit;
114
	}
115
} else {
116
	if (empty($ifdescrs["wan"])) {
117
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
118
		reset($ifdescrs);
119
		$curif = key($ifdescrs);
120
	} else {
121
		$curif = "wan";
122
	}
123
}
124
if ($_POST['sort']) {
125
	$cursort = $_POST['sort'];
126
} else {
127
	$cursort = "";
128
}
129
if ($_POST['filter']) {
130
	$curfilter = $_POST['filter'];
131
} else {
132
	$curfilter = "";
133
}
134
if ($_POST['hostipformat']) {
135
	$curhostipformat = $_POST['hostipformat'];
136
} else {
137
	$curhostipformat = "";
138
}
139

    
140
function iflist() {
141
	global $ifdescrs;
142

    
143
	$iflist = array();
144

    
145
	foreach ($ifdescrs as $ifn => $ifd) {
146
		$iflist[$ifn] = $ifd;
147
	}
148

    
149
	return($iflist);
150
}
151

    
152
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
153

    
154
include("head.inc");
155

    
156
require_once('classes/Form.class.php');
157

    
158
$form = new Form(false);
159
$form->addClass('auto-submit');
160

    
161
$section = new Form_Section('Graph settings');
162

    
163
$group = new Form_Group('');
164

    
165
$group->add(new Form_Select(
166
	'if',
167
	null,
168
	$curif,
169
	iflist()
170
))->setHelp('Interface');
171

    
172
$group->add(new Form_Select(
173
	'sort',
174
	null,
175
	$cursort,
176
	array (
177
		'in'	=> 'Bandwidth In',
178
		'out'	=> 'Bandwidth Out'
179
	)
180
))->setHelp('Sort by');
181

    
182
$group->add(new Form_Select(
183
	'filter',
184
	null,
185
	$curfilter,
186
	array (
187
		'local'	=> 'Local',
188
		'remote'=> 'Remote',
189
		'all'	=> 'All'
190
	)
191
))->setHelp('Filter');
192

    
193
$group->add(new Form_Select(
194
	'hostipformat',
195
	null,
196
	$curhostipformat,
197
	array (
198
		''			=> 'IP Address',
199
		'hostname'	=> 'Host Name',
200
		'fqdn'		=> 'FQDN'
201
	)
202
))->setHelp('Display');
203

    
204
$section->add($group);
205

    
206
$form->add($section);
207
print $form;
208

    
209
?>
210
<script>
211

    
212
function updateBandwidth(){
213
	$.ajax(
214
		'/bandwidth_by_ip.php',
215
		{
216
			type: 'get',
217
			data: $(document.forms[0]).serialize(),
218
			success: function (data) {
219
				var hosts_split = data.split("|");
220

    
221
				$('#top10-hosts').empty();
222

    
223
				//parse top ten bandwidth abuser hosts
224
				for (var y=0; y<10; y++){
225
					if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
226
						hostinfo = hosts_split[y].split(";");
227

    
228
						$('#top10-hosts').append('<tr>'+
229
							'<td>'+ hostinfo[0] +'</td>'+
230
							'<td>'+ hostinfo[1] +' Bits/sec</td>'+
231
							'<td>'+ hostinfo[2] +' Bits/sec</td>'+
232
						'</tr>');
233
					}
234
				}
235
			},
236
	});
237
}
238

    
239
events.push(function(){
240
	$('form.auto-submit').on('change', function(){
241
		$(this).submit();
242
	});
243

    
244
	setInterval('updateBandwidth()', 1000);
245

    
246
	updateBandwidth();
247
});
248
</script>
249
<?php
250

    
251
/* link the ipsec interface magically */
252
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) {
253
	$ifdescrs['enc0'] = "IPsec";
254
}
255

    
256
?>
257
<div class="panel panel-default">
258
	<div class="panel-heading">
259
		<h2 class="panel-title">Traffic graph</h2>
260
	</div>
261
	<div class="panel-body">
262
		<div class="col-sm-6">
263
			<object data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&amp;ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>">
264
				<param name="id" value="graph" />
265
				<param name="type" value="image/svg+xml" />
266
				<param name="width" value="<? echo $width; ?>" />
267
				<param name="height" value="<? echo $height; ?>" />
268
				<param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
269
			</object>
270
		</div>
271
		<div class="col-sm-6">
272
			<table class="table table-striped table-condensed">
273
				<thead>
274
					<tr>
275
						<th><?=(($curhostipformat=="") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
276
						<th><?=gettext("Bandwidth In"); ?></th>
277
						<th><?=gettext("Bandwidth Out"); ?></th>
278
					</tr>
279
				</thead>
280
				<tbody id="top10-hosts">
281
					<!-- to be added by javascript -->
282
				</tbody>
283
			</table>
284
		</div>
285
	</div>
286
</div>
287
<?php include("foot.inc");
(172-172/234)