Project

General

Profile

Download (6.14 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
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-status-trafficgraph
28
##|*NAME=Status: Traffic Graph
29
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
30
##|*MATCH=status_graph.php*
31
##|*MATCH=bandwidth_by_ip.php*
32
##|*MATCH=graph.php*
33
##|*MATCH=ifstats.php*
34
##|-PRIV
35

    
36
require_once("guiconfig.inc");
37
require_once("ipsec.inc");
38

    
39
if ($_POST['width']) {
40
	$width = $_POST['width'];
41
} else {
42
	$width = "100%";
43
}
44

    
45
if ($_POST['height']) {
46
	$height = $_POST['height'];
47
} else {
48
	$height = "200";
49
}
50

    
51
// Get configured interface list
52
$ifdescrs = get_configured_interface_with_descr();
53
if (ipsec_enabled()) {
54
	$ifdescrs['enc0'] = gettext("IPsec");
55
}
56

    
57
foreach (array('server', 'client') as $mode) {
58
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
59
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
60
			if (!isset($setting['disable'])) {
61
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " " . $mode . ": ".htmlspecialchars($setting['description']);
62
			}
63
		}
64
	}
65
}
66

    
67
// Compatiblity to restore GET parameters used pre-2.3
68
// Useful to save a URL for a given graph configuration
69
if (isset($_GET['if']) && !isset($_POST['if'])) {
70
	$_POST['if'] = $_GET['if'];
71
}
72
if (isset($_GET['sort']) && !isset($_POST['sort'])) {
73
	$_POST['sort'] = $_GET['sort'];
74
}
75
if (isset($_GET['filter']) && !isset($_POST['filter'])) {
76
	$_POST['filter'] = $_GET['filter'];
77
}
78
if (isset($_GET['hostipformat']) && !isset($_POST['hostipformat'])) {
79
	$_POST['hostipformat'] = $_GET['hostipformat'];
80
}
81

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

    
120
function iflist() {
121
	global $ifdescrs;
122

    
123
	$iflist = array();
124

    
125
	foreach ($ifdescrs as $ifn => $ifd) {
126
		$iflist[$ifn] = $ifd;
127
	}
128

    
129
	return($iflist);
130
}
131

    
132
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
133

    
134
include("head.inc");
135

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

    
139
$section = new Form_Section('Graph Settings');
140

    
141
$group = new Form_Group('');
142

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

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

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

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

    
183
$section->add($group);
184

    
185
$form->add($section);
186
print $form;
187

    
188
?>
189
<script type="text/javascript">
190
//<![CDATA[
191

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

    
201
				$('#top10-hosts').empty();
202

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

    
208
						$('#top10-hosts').append('<tr>'+
209
							'<td>'+ hostinfo[0] +'</td>'+
210
							'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
211
							'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
212
						'</tr>');
213
					}
214
				}
215
			},
216
	});
217
}
218

    
219
events.push(function() {
220
	$('form.auto-submit').on('change', function() {
221
		$(this).submit();
222
	});
223

    
224
	setInterval('updateBandwidth()', 3000);
225

    
226
	updateBandwidth();
227
});
228
//]]>
229
</script>
230
<?php
231

    
232
/* link the ipsec interface magically */
233
if (ipsec_enabled()) {
234
	$ifdescrs['enc0'] = gettext("IPsec");
235
}
236

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