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
|
if ($_POST['if']) {
|
101
|
$curif = $_POST['if'];
|
102
|
$found = false;
|
103
|
foreach ($ifdescrs as $descr => $ifdescr) {
|
104
|
if ($descr == $curif) {
|
105
|
$found = true;
|
106
|
break;
|
107
|
}
|
108
|
}
|
109
|
if ($found === false) {
|
110
|
header("Location: status_graph.php");
|
111
|
exit;
|
112
|
}
|
113
|
} else {
|
114
|
if (empty($ifdescrs["wan"])) {
|
115
|
/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
|
116
|
reset($ifdescrs);
|
117
|
$curif = key($ifdescrs);
|
118
|
} else {
|
119
|
$curif = "wan";
|
120
|
}
|
121
|
}
|
122
|
if ($_POST['sort']) {
|
123
|
$cursort = $_POST['sort'];
|
124
|
} else {
|
125
|
$cursort = "";
|
126
|
}
|
127
|
if ($_POST['filter']) {
|
128
|
$curfilter = $_POST['filter'];
|
129
|
} else {
|
130
|
$curfilter = "";
|
131
|
}
|
132
|
if ($_POST['hostipformat']) {
|
133
|
$curhostipformat = $_POST['hostipformat'];
|
134
|
} else {
|
135
|
$curhostipformat = "";
|
136
|
}
|
137
|
|
138
|
function iflist() {
|
139
|
global $ifdescrs;
|
140
|
|
141
|
$iflist = array();
|
142
|
|
143
|
foreach ($ifdescrs as $ifn => $ifd) {
|
144
|
$iflist[$ifn] = $ifd;
|
145
|
}
|
146
|
|
147
|
return($iflist);
|
148
|
}
|
149
|
|
150
|
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
|
151
|
|
152
|
include("head.inc");
|
153
|
|
154
|
$form = new Form(false);
|
155
|
$form->addClass('auto-submit');
|
156
|
|
157
|
$section = new Form_Section('Graph Settings');
|
158
|
|
159
|
$group = new Form_Group('');
|
160
|
|
161
|
$group->add(new Form_Select(
|
162
|
'if',
|
163
|
null,
|
164
|
$curif,
|
165
|
iflist()
|
166
|
))->setHelp('Interface');
|
167
|
|
168
|
$group->add(new Form_Select(
|
169
|
'sort',
|
170
|
null,
|
171
|
$cursort,
|
172
|
array (
|
173
|
'in' => gettext('Bandwidth In'),
|
174
|
'out' => gettext('Bandwidth Out')
|
175
|
)
|
176
|
))->setHelp('Sort by');
|
177
|
|
178
|
$group->add(new Form_Select(
|
179
|
'filter',
|
180
|
null,
|
181
|
$curfilter,
|
182
|
array (
|
183
|
'local' => gettext('Local'),
|
184
|
'remote'=> gettext('Remote'),
|
185
|
'all' => gettext('All')
|
186
|
)
|
187
|
))->setHelp('Filter');
|
188
|
|
189
|
$group->add(new Form_Select(
|
190
|
'hostipformat',
|
191
|
null,
|
192
|
$curhostipformat,
|
193
|
array (
|
194
|
'' => gettext('IP Address'),
|
195
|
'hostname' => gettext('Host Name'),
|
196
|
'descr' => gettext('Description'),
|
197
|
'fqdn' => gettext('FQDN')
|
198
|
)
|
199
|
))->setHelp('Display');
|
200
|
|
201
|
$section->add($group);
|
202
|
|
203
|
$form->add($section);
|
204
|
print $form;
|
205
|
|
206
|
?>
|
207
|
<script type="text/javascript">
|
208
|
//<![CDATA[
|
209
|
|
210
|
function updateBandwidth() {
|
211
|
$.ajax(
|
212
|
'/bandwidth_by_ip.php',
|
213
|
{
|
214
|
type: 'get',
|
215
|
data: $(document.forms[0]).serialize(),
|
216
|
success: function (data) {
|
217
|
var hosts_split = data.split("|");
|
218
|
|
219
|
$('#top10-hosts').empty();
|
220
|
|
221
|
//parse top ten bandwidth abuser hosts
|
222
|
for (var y=0; y<10; y++) {
|
223
|
if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
|
224
|
hostinfo = hosts_split[y].split(";");
|
225
|
|
226
|
$('#top10-hosts').append('<tr>'+
|
227
|
'<td>'+ hostinfo[0] +'</td>'+
|
228
|
'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
|
229
|
'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
|
230
|
'</tr>');
|
231
|
}
|
232
|
}
|
233
|
},
|
234
|
});
|
235
|
}
|
236
|
|
237
|
events.push(function() {
|
238
|
$('form.auto-submit').on('change', function() {
|
239
|
$(this).submit();
|
240
|
});
|
241
|
|
242
|
setInterval('updateBandwidth()', 3000);
|
243
|
|
244
|
updateBandwidth();
|
245
|
});
|
246
|
//]]>
|
247
|
</script>
|
248
|
<?php
|
249
|
|
250
|
/* link the ipsec interface magically */
|
251
|
if (ipsec_enabled()) {
|
252
|
$ifdescrs['enc0'] = gettext("IPsec");
|
253
|
}
|
254
|
|
255
|
?>
|
256
|
<div class="panel panel-default">
|
257
|
<div class="panel-heading">
|
258
|
<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
|
259
|
</div>
|
260
|
<div class="panel-body">
|
261
|
<div class="col-sm-6">
|
262
|
<object data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>">
|
263
|
<param name="id" value="graph" />
|
264
|
<param name="type" value="image/svg+xml" />
|
265
|
<param name="width" value="<?=$width;?>" />
|
266
|
<param name="height" value="<?=$height;?>" />
|
267
|
<param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
|
268
|
</object>
|
269
|
</div>
|
270
|
<div class="col-sm-6">
|
271
|
<table class="table table-striped table-condensed">
|
272
|
<thead>
|
273
|
<tr>
|
274
|
<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
|
275
|
<th><?=gettext("Bandwidth In"); ?></th>
|
276
|
<th><?=gettext("Bandwidth Out"); ?></th>
|
277
|
</tr>
|
278
|
</thead>
|
279
|
<tbody id="top10-hosts">
|
280
|
<!-- to be added by javascript -->
|
281
|
</tbody>
|
282
|
</table>
|
283
|
</div>
|
284
|
</div>
|
285
|
</div>
|
286
|
<?php include("foot.inc");
|