Project

General

Profile

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

    
58
##|+PRIV
59
##|*IDENT=page-status-trafficgraph
60
##|*NAME=Status: Traffic Graph
61
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
62
##|*MATCH=status_graph.php*
63
##|*MATCH=bandwidth_by_ip.php*
64
##|*MATCH=graph.php*
65
##|*MATCH=ifstats.php*
66
##|-PRIV
67

    
68
require_once("guiconfig.inc");
69
require_once("ipsec.inc");
70

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

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

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

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

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

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

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

    
155
	$iflist = array();
156

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

    
161
	return($iflist);
162
}
163

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

    
166
include("head.inc");
167

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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