Project

General

Profile

Download (7.87 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
##|+PRIV
60
##|*IDENT=page-status-trafficgraph
61
##|*NAME=Status: Traffic Graph
62
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
63
##|*MATCH=status_graph.php*
64
##|*MATCH=bandwidth_by_ip.php*
65
##|*MATCH=graph.php*
66
##|*MATCH=ifstats.php*
67
##|-PRIV
68

    
69
require("guiconfig.inc");
70
require_once("ipsec.inc");
71

    
72
if ($_POST['width']) {
73
	$width = $_POST['width'];
74
} else {
75
	$width = "100%";
76
}
77

    
78
if ($_POST['height']) {
79
	$height = $_POST['height'];
80
} else {
81
	$height = "200";
82
}
83

    
84
// Get configured interface list
85
$ifdescrs = get_configured_interface_with_descr();
86
if (ipsec_enabled()) {
87
	$ifdescrs['enc0'] = gettext("IPsec");
88
}
89

    
90
foreach (array('server', 'client') as $mode) {
91
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
92
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
93
			if (!isset($setting['disable'])) {
94
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " " . $mode . ": ".htmlspecialchars($setting['description']);
95
			}
96
		}
97
	}
98
}
99

    
100
// Compatiblity to restore GET parameters used pre-2.3
101
// Useful to save a URL for a given graph configuration
102
if (isset($_GET['if']) && !isset($_POST['if'])) {
103
	$_POST['if'] = $_GET['if'];
104
}
105
if (isset($_GET['sort']) && !isset($_POST['sort'])) {
106
	$_POST['sort'] = $_GET['sort'];
107
}
108
if (isset($_GET['filter']) && !isset($_POST['filter'])) {
109
	$_POST['filter'] = $_GET['filter'];
110
}
111
if (isset($_GET['hostipformat']) && !isset($_POST['hostipformat'])) {
112
	$_POST['hostipformat'] = $_GET['hostipformat'];
113
}
114

    
115
if ($_POST['if']) {
116
	$curif = $_POST['if'];
117
	$found = false;
118
	foreach ($ifdescrs as $descr => $ifdescr) {
119
		if ($descr == $curif) {
120
			$found = true;
121
			break;
122
		}
123
	}
124
	if ($found === false) {
125
		header("Location: status_graph.php");
126
		exit;
127
	}
128
} else {
129
	if (empty($ifdescrs["wan"])) {
130
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
131
		reset($ifdescrs);
132
		$curif = key($ifdescrs);
133
	} else {
134
		$curif = "wan";
135
	}
136
}
137
if ($_POST['sort']) {
138
	$cursort = $_POST['sort'];
139
} else {
140
	$cursort = "";
141
}
142
if ($_POST['filter']) {
143
	$curfilter = $_POST['filter'];
144
} else {
145
	$curfilter = "";
146
}
147
if ($_POST['hostipformat']) {
148
	$curhostipformat = $_POST['hostipformat'];
149
} else {
150
	$curhostipformat = "";
151
}
152

    
153
function iflist() {
154
	global $ifdescrs;
155

    
156
	$iflist = array();
157

    
158
	foreach ($ifdescrs as $ifn => $ifd) {
159
		$iflist[$ifn] = $ifd;
160
	}
161

    
162
	return($iflist);
163
}
164

    
165
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
166

    
167
include("head.inc");
168

    
169
$form = new Form(false);
170
$form->addClass('auto-submit');
171

    
172
$section = new Form_Section('Graph Settings');
173

    
174
$group = new Form_Group('');
175

    
176
$group->add(new Form_Select(
177
	'if',
178
	null,
179
	$curif,
180
	iflist()
181
))->setHelp('Interface');
182

    
183
$group->add(new Form_Select(
184
	'sort',
185
	null,
186
	$cursort,
187
	array (
188
		'in'	=> gettext('Bandwidth In'),
189
		'out'	=> gettext('Bandwidth Out')
190
	)
191
))->setHelp('Sort by');
192

    
193
$group->add(new Form_Select(
194
	'filter',
195
	null,
196
	$curfilter,
197
	array (
198
		'local'	=> gettext('Local'),
199
		'remote'=> gettext('Remote'),
200
		'all'	=> gettext('All')
201
	)
202
))->setHelp('Filter');
203

    
204
$group->add(new Form_Select(
205
	'hostipformat',
206
	null,
207
	$curhostipformat,
208
	array (
209
		''			=> gettext('IP Address'),
210
		'hostname'	=> gettext('Host Name'),
211
		'descr'		=> gettext('Description'),
212
		'fqdn'		=> gettext('FQDN')
213
	)
214
))->setHelp('Display');
215

    
216
$section->add($group);
217

    
218
$form->add($section);
219
print $form;
220

    
221
?>
222
<script type="text/javascript">
223
//<![CDATA[
224

    
225
function updateBandwidth() {
226
	$.ajax(
227
		'/bandwidth_by_ip.php',
228
		{
229
			type: 'get',
230
			data: $(document.forms[0]).serialize(),
231
			success: function (data) {
232
				var hosts_split = data.split("|");
233

    
234
				$('#top10-hosts').empty();
235

    
236
				//parse top ten bandwidth abuser hosts
237
				for (var y=0; y<10; y++) {
238
					if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
239
						hostinfo = hosts_split[y].split(";");
240

    
241
						$('#top10-hosts').append('<tr>'+
242
							'<td>'+ hostinfo[0] +'</td>'+
243
							'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
244
							'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
245
						'</tr>');
246
					}
247
				}
248
			},
249
	});
250
}
251

    
252
events.push(function() {
253
	$('form.auto-submit').on('change', function() {
254
		$(this).submit();
255
	});
256

    
257
	setInterval('updateBandwidth()', 3000);
258

    
259
	updateBandwidth();
260
});
261
//]]>
262
</script>
263
<?php
264

    
265
/* link the ipsec interface magically */
266
if (ipsec_enabled()) {
267
	$ifdescrs['enc0'] = gettext("IPsec");
268
}
269

    
270
?>
271
<div class="panel panel-default">
272
	<div class="panel-heading">
273
		<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
274
	</div>
275
	<div class="panel-body">
276
		<div class="col-sm-6">
277
			<object data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&amp;ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>">
278
				<param name="id" value="graph" />
279
				<param name="type" value="image/svg+xml" />
280
				<param name="width" value="<?=$width;?>" />
281
				<param name="height" value="<?=$height;?>" />
282
				<param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
283
			</object>
284
		</div>
285
		<div class="col-sm-6">
286
			<table class="table table-striped table-condensed">
287
				<thead>
288
					<tr>
289
						<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
290
						<th><?=gettext("Bandwidth In"); ?></th>
291
						<th><?=gettext("Bandwidth Out"); ?></th>
292
					</tr>
293
				</thead>
294
				<tbody id="top10-hosts">
295
					<!-- to be added by javascript -->
296
				</tbody>
297
			</table>
298
		</div>
299
	</div>
300
</div>
301
<?php include("foot.inc");
(162-162/225)