Project

General

Profile

Download (7.23 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_graph.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10
 *
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
/*
59
	pfSense_MODULE:	routing
60
*/
61

    
62
##|+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
##|*MATCH=bandwidth_by_ip.php*
68
##|*MATCH=graph.php*
69
##|*MATCH=ifstats.php*
70
##|-PRIV
71

    
72
require("guiconfig.inc");
73
require_once("ipsec.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 (ipsec_enabled())
90
	$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

    
101
if ($_POST['if']) {
102
	$curif = $_POST['if'];
103
	$found = false;
104
	foreach ($ifdescrs as $descr => $ifdescr) {
105
		if ($descr == $curif) {
106
			$found = true;
107
			break;
108
		}
109
	}
110
	if ($found === false) {
111
		header("Location: status_graph.php");
112
		exit;
113
	}
114
} else {
115
	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
	} else {
120
		$curif = "wan";
121
	}
122
}
123
if ($_POST['sort']) {
124
	$cursort = $_POST['sort'];
125
} else {
126
	$cursort = "";
127
}
128
if ($_POST['filter']) {
129
	$curfilter = $_POST['filter'];
130
} else {
131
	$curfilter = "";
132
}
133
if ($_POST['hostipformat']) {
134
	$curhostipformat = $_POST['hostipformat'];
135
} else {
136
	$curhostipformat = "";
137
}
138

    
139
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
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
152

    
153
include("head.inc");
154

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

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

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

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

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

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

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

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

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

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

    
208
?>
209
<script>
210

    
211
function updateBandwidth(){
212
	$.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
}
237

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

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

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

    
250
/* link the ipsec interface magically */
251
if (ipsec_enabled())
252
	$ifdescrs['enc0'] = "IPsec";
253

    
254
?>
255
<div class="panel panel-default">
256
	<div class="panel-heading">
257
		<h2 class="panel-title">Traffic graph</h2>
258
	</div>
259
	<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
	</div>
284
</div>
285
<?php include("foot.inc");
(172-172/234)