Project

General

Profile

Download (6.09 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
if ($_POST['height'])
57
	$height = $_POST['height'];
58
else
59
	$height = "200";
60

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

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

    
114
function iflist() {
115
	global $ifdescrs;
116

    
117
	$iflist = array();
118

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

    
123
	return($iflist);
124
}
125

    
126
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
127

    
128
include("head.inc");
129

    
130
require('classes/Form.class.php');
131

    
132
$form = new Form(false);
133
$form->addClass('auto-submit', 'form-inline');
134

    
135
$section = new Form_Section('Graph settings');
136

    
137
$section->addInput(new Form_Select(
138
	'if',
139
	'Interface ',
140
	$curif,
141
	iflist()
142
));
143

    
144
$section->addInput(new Form_Select(
145
	'sort',
146
	'Sort by',
147
	$cursort,
148
	array (
149
		'in'	=> 'Bandwidth In',
150
		'out'	=> 'Bandwidth Out'
151
	)
152
));
153

    
154
$section->addInput(new Form_Select(
155
	'filter',
156
	'Filter',
157
	$curfilter,
158
	array (
159
		'local'	=> 'Local',
160
		'remote'=> 'Remote',
161
		'all'	=> 'All'
162
	)
163
));
164

    
165
$section->addInput(new Form_Select(
166
	'hostipformat',
167
	'Display',
168
	$curhostipformat,
169
	array (
170
		''			=> 'IP Address',
171
		'hostname'	=> 'Host Name',
172
		'fqdn'		=> 'FQDN'
173
	)
174
));
175

    
176
$form->add($section);
177
print $form;
178

    
179
?>
180
<script>
181

    
182
function updateBandwidth(){
183
	$.ajax(
184
		'/bandwidth_by_ip.php',
185
		{
186
			type: 'get',
187
			data: $(document.forms[0]).serialize(),
188
			success: function (data) {
189
				var hosts_split = data.split("|");
190

    
191
				$('#top10-hosts').empty();
192

    
193
				//parse top ten bandwidth abuser hosts
194
				for (var y=0; y<10; y++){
195
					if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
196
						hostinfo = hosts_split[y].split(";");
197

    
198
						$('#top10-hosts').append('<tr>'+
199
							'<td>'+ hostinfo[0] +'</td>'+
200
							'<td>'+ hostinfo[1] +' Bits/sec</td>'+
201
							'<td>'+ hostinfo[2] +' Bits/sec</td>'+
202
						'</tr>');
203
					}
204
				}
205
			},
206
	});
207
}
208

    
209
events.push(function(){
210
	$('form.auto-submit').on('change', function(){
211
		$(this).submit();
212
	});
213

    
214
	setInterval('updateBandwidth()', 1000);
215

    
216
	updateBandwidth();
217
});
218
</script>
219
<?php
220

    
221
/* link the ipsec interface magically */
222
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
223
	$ifdescrs['enc0'] = "IPsec";
224

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