Project

General

Profile

Download (6.18 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_graph.php
5
	Part of pfSense
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7
	Copyright (C) 2004 Scott Ullrich
8
	All rights reserved.
9

    
10
	Originally part of m0n0wall (http://m0n0.ch/wall)
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23

    
24
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35
/*
36
	pfSense_MODULE:	routing
37
*/
38

    
39
##|+PRIV
40
##|*IDENT=page-status-trafficgraph
41
##|*NAME=Status: Traffic Graph page
42
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
43
##|*MATCH=status_graph.php*
44
##|*MATCH=bandwidth_by_ip.php*
45
##|*MATCH=graph.php*
46
##|*MATCH=ifstats.php*
47
##|-PRIV
48

    
49
require("guiconfig.inc");
50

    
51
if ($_POST['width']) {
52
	$width = $_POST['width'];
53
} else {
54
	$width = "100%";
55
}
56

    
57
if ($_POST['height']) {
58
	$height = $_POST['height'];
59
} else {
60
	$height = "200";
61
}
62

    
63
// Get configured interface list
64
$ifdescrs = get_configured_interface_with_descr();
65
if (isset($config['ipsec']['enable'])) {
66
	$ifdescrs['enc0'] = "IPsec";
67
}
68
foreach (array('server', 'client') as $mode) {
69
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
70
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
71
			if (!isset($setting['disable'])) {
72
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
73
			}
74
		}
75
	}
76
}
77

    
78
if ($_POST['if']) {
79
	$curif = $_POST['if'];
80
	$found = false;
81
	foreach ($ifdescrs as $descr => $ifdescr) {
82
		if ($descr == $curif) {
83
			$found = true;
84
			break;
85
		}
86
	}
87
	if ($found === false) {
88
		header("Location: status_graph.php");
89
		exit;
90
	}
91
} else {
92
	if (empty($ifdescrs["wan"])) {
93
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
94
		reset($ifdescrs);
95
		$curif = key($ifdescrs);
96
	} else {
97
		$curif = "wan";
98
	}
99
}
100
if ($_POST['sort']) {
101
	$cursort = $_POST['sort'];
102
} else {
103
	$cursort = "";
104
}
105
if ($_POST['filter']) {
106
	$curfilter = $_POST['filter'];
107
} else {
108
	$curfilter = "";
109
}
110
if ($_POST['hostipformat']) {
111
	$curhostipformat = $_POST['hostipformat'];
112
} else {
113
	$curhostipformat = "";
114
}
115

    
116
function iflist() {
117
	global $ifdescrs;
118

    
119
	$iflist = array();
120

    
121
	foreach ($ifdescrs as $ifn => $ifd) {
122
		$iflist[$ifn] = $ifd;
123
	}
124

    
125
	return($iflist);
126
}
127

    
128
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
129

    
130
include("head.inc");
131

    
132
require('classes/Form.class.php');
133

    
134
$form = new Form(false);
135
$form->addClass('auto-submit');
136

    
137
$section = new Form_Section('Graph settings');
138

    
139
$group = new Form_Group('');
140

    
141
$group->add(new Form_Select(
142
	'if',
143
	null,
144
	$curif,
145
	iflist()
146
))->setHelp('Interface');
147

    
148
$group->add(new Form_Select(
149
	'sort',
150
	null,
151
	$cursort,
152
	array (
153
		'in'	=> 'Bandwidth In',
154
		'out'	=> 'Bandwidth Out'
155
	)
156
))->setHelp('Sort by');
157

    
158
$group->add(new Form_Select(
159
	'filter',
160
	null,
161
	$curfilter,
162
	array (
163
		'local'	=> 'Local',
164
		'remote'=> 'Remote',
165
		'all'	=> 'All'
166
	)
167
))->setHelp('Filter');
168

    
169
$group->add(new Form_Select(
170
	'hostipformat',
171
	null,
172
	$curhostipformat,
173
	array (
174
		''			=> 'IP Address',
175
		'hostname'	=> 'Host Name',
176
		'fqdn'		=> 'FQDN'
177
	)
178
))->setHelp('Display');
179

    
180
$section->add($group);
181

    
182
$form->add($section);
183
print $form;
184

    
185
?>
186
<script>
187

    
188
function updateBandwidth(){
189
	$.ajax(
190
		'/bandwidth_by_ip.php',
191
		{
192
			type: 'get',
193
			data: $(document.forms[0]).serialize(),
194
			success: function (data) {
195
				var hosts_split = data.split("|");
196

    
197
				$('#top10-hosts').empty();
198

    
199
				//parse top ten bandwidth abuser hosts
200
				for (var y=0; y<10; y++){
201
					if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
202
						hostinfo = hosts_split[y].split(";");
203

    
204
						$('#top10-hosts').append('<tr>'+
205
							'<td>'+ hostinfo[0] +'</td>'+
206
							'<td>'+ hostinfo[1] +' Bits/sec</td>'+
207
							'<td>'+ hostinfo[2] +' Bits/sec</td>'+
208
						'</tr>');
209
					}
210
				}
211
			},
212
	});
213
}
214

    
215
events.push(function(){
216
	$('form.auto-submit').on('change', function(){
217
		$(this).submit();
218
	});
219

    
220
	setInterval('updateBandwidth()', 1000);
221

    
222
	updateBandwidth();
223
});
224
</script>
225
<?php
226

    
227
/* link the ipsec interface magically */
228
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) {
229
	$ifdescrs['enc0'] = "IPsec";
230
}
231

    
232
?>
233
<div class="panel panel-default">
234
	<div class="panel-heading">
235
		<h2 class="panel-title">Traffic graph</h2>
236
	</div>
237
	<div class="panel-body">
238
		<div class="col-sm-6">
239
			<object data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&amp;ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>">
240
				<param name="id" value="graph" />
241
				<param name="type" value="image/svg+xml" />
242
				<param name="width" value="<? echo $width; ?>" />
243
				<param name="height" value="<? echo $height; ?>" />
244
				<param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
245
			</object>
246
		</div>
247
		<div class="col-sm-6">
248
			<table class="table table-striped table-condensed">
249
				<thead>
250
					<tr>
251
						<th><?=(($curhostipformat=="") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
252
						<th><?=gettext("Bandwidth In"); ?></th>
253
						<th><?=gettext("Bandwidth Out"); ?></th>
254
					</tr>
255
				</thead>
256
				<tbody id="top10-hosts">
257
					<!-- to be added by javascript -->
258
				</tbody>
259
			</table>
260
		</div>
261
	</div>
262
</div>
263
<?php include("foot.inc");
(173-173/238)