1 |
9573d170
|
Scott Ullrich
|
<?php
|
2 |
5b237745
|
Scott Ullrich
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* status_graph.php
|
4 |
191cb31d
|
Stephen Beaver
|
*
|
5 |
c5d81585
|
Renato Botelho
|
* part of pfSense (https://www.pfsense.org)
|
6 |
81299b5c
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7 |
c5d81585
|
Renato Botelho
|
* All rights reserved.
|
8 |
191cb31d
|
Stephen Beaver
|
*
|
9 |
c5d81585
|
Renato Botelho
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
10 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11 |
|
|
* All rights reserved.
|
12 |
191cb31d
|
Stephen Beaver
|
*
|
13 |
0f3f6cc9
|
Jared Dillard
|
* 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 |
191cb31d
|
Stephen Beaver
|
*
|
17 |
0f3f6cc9
|
Jared Dillard
|
* http://www.apache.org/licenses/LICENSE-2.0
|
18 |
191cb31d
|
Stephen Beaver
|
*
|
19 |
0f3f6cc9
|
Jared Dillard
|
* 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 |
191cb31d
|
Stephen Beaver
|
*/
|
25 |
5b237745
|
Scott Ullrich
|
|
26 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
27 |
|
|
##|*IDENT=page-status-trafficgraph
|
28 |
5230f468
|
jim-p
|
##|*NAME=Status: Traffic Graph
|
29 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'Status: Traffic Graph' page.
|
30 |
|
|
##|*MATCH=status_graph.php*
|
31 |
8e95a671
|
jim-p
|
##|*MATCH=bandwidth_by_ip.php*
|
32 |
8a2f80b2
|
jim-p
|
##|*MATCH=graph.php*
|
33 |
|
|
##|*MATCH=ifstats.php*
|
34 |
6b07c15a
|
Matthew Grooms
|
##|-PRIV
|
35 |
|
|
|
36 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
37 |
179ab6b3
|
Luiz Otavio O Souza
|
require_once("ipsec.inc");
|
38 |
5b237745
|
Scott Ullrich
|
|
39 |
94556105
|
Scott Ullrich
|
// Get configured interface list
|
40 |
61ab4cd3
|
Scott Ullrich
|
$ifdescrs = get_configured_interface_with_descr();
|
41 |
abe98adb
|
Phil Davis
|
if (ipsec_enabled()) {
|
42 |
98128ad6
|
Phil Davis
|
$ifdescrs['enc0'] = gettext("IPsec");
|
43 |
abe98adb
|
Phil Davis
|
}
|
44 |
|
|
|
45 |
9f5d14ce
|
jim-p
|
foreach (array('server', 'client') as $mode) {
|
46 |
|
|
if (is_array($config['openvpn']["openvpn-{$mode}"])) {
|
47 |
|
|
foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
|
48 |
|
|
if (!isset($setting['disable'])) {
|
49 |
98128ad6
|
Phil Davis
|
$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " " . $mode . ": ".htmlspecialchars($setting['description']);
|
50 |
9f5d14ce
|
jim-p
|
}
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
43a0ac8a
|
Scott Ullrich
|
|
55 |
1a8b6554
|
Steve Beaver
|
if ($_REQUEST['if']) {
|
56 |
|
|
$curif = $_REQUEST['if'];
|
57 |
50b2f6ab
|
Scott Ullrich
|
$found = false;
|
58 |
6c07db48
|
Phil Davis
|
foreach ($ifdescrs as $descr => $ifdescr) {
|
59 |
b406c78a
|
Ermal
|
if ($descr == $curif) {
|
60 |
|
|
$found = true;
|
61 |
|
|
break;
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
if ($found === false) {
|
65 |
6f3d2063
|
Renato Botelho
|
header("Location: status_graph.php");
|
66 |
50b2f6ab
|
Scott Ullrich
|
exit;
|
67 |
|
|
}
|
68 |
|
|
} else {
|
69 |
76165eac
|
Phil Davis
|
if (empty($ifdescrs["wan"])) {
|
70 |
|
|
/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
|
71 |
|
|
reset($ifdescrs);
|
72 |
|
|
$curif = key($ifdescrs);
|
73 |
42b0c921
|
Phil Davis
|
} else {
|
74 |
76165eac
|
Phil Davis
|
$curif = "wan";
|
75 |
|
|
}
|
76 |
50b2f6ab
|
Scott Ullrich
|
}
|
77 |
1a8b6554
|
Steve Beaver
|
if ($_REQUEST['sort']) {
|
78 |
|
|
$cursort = $_REQUEST['sort'];
|
79 |
893fb622
|
Michele Di Maria
|
} else {
|
80 |
|
|
$cursort = "";
|
81 |
|
|
}
|
82 |
1a8b6554
|
Steve Beaver
|
if ($_REQUEST['filter']) {
|
83 |
|
|
$curfilter = $_REQUEST['filter'];
|
84 |
da11e022
|
Phil Davis
|
} else {
|
85 |
|
|
$curfilter = "";
|
86 |
|
|
}
|
87 |
1a8b6554
|
Steve Beaver
|
if ($_REQUEST['hostipformat']) {
|
88 |
|
|
$curhostipformat = $_REQUEST['hostipformat'];
|
89 |
4006a437
|
Phil Davis
|
} else {
|
90 |
|
|
$curhostipformat = "";
|
91 |
|
|
}
|
92 |
1a8b6554
|
Steve Beaver
|
if ($_REQUEST['backgroundupdate']) {
|
93 |
|
|
$curbackgroundupdate = $_REQUEST['backgroundupdate'];
|
94 |
fe5c31bb
|
PiBa-NL
|
} else {
|
95 |
|
|
$curbackgroundupdate = "";
|
96 |
|
|
}
|
97 |
769cdf3b
|
Bill Marquette
|
|
98 |
e31aa678
|
sbeaver
|
function iflist() {
|
99 |
|
|
global $ifdescrs;
|
100 |
|
|
|
101 |
|
|
$iflist = array();
|
102 |
|
|
|
103 |
|
|
foreach ($ifdescrs as $ifn => $ifd) {
|
104 |
|
|
$iflist[$ifn] = $ifd;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
return($iflist);
|
108 |
|
|
}
|
109 |
|
|
|
110 |
abe98adb
|
Phil Davis
|
$pgtitle = array(gettext("Status"), gettext("Traffic Graph"));
|
111 |
f0a3b883
|
Scott Ullrich
|
|
112 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
113 |
|
|
|
114 |
e31aa678
|
sbeaver
|
$form = new Form(false);
|
115 |
a4af095c
|
Renato Botelho
|
$form->addClass('auto-submit');
|
116 |
e31aa678
|
sbeaver
|
|
117 |
5f88f964
|
k-paulius
|
$section = new Form_Section('Graph Settings');
|
118 |
5b237745
|
Scott Ullrich
|
|
119 |
a4af095c
|
Renato Botelho
|
$group = new Form_Group('');
|
120 |
|
|
|
121 |
|
|
$group->add(new Form_Select(
|
122 |
e31aa678
|
sbeaver
|
'if',
|
123 |
a4af095c
|
Renato Botelho
|
null,
|
124 |
e31aa678
|
sbeaver
|
$curif,
|
125 |
|
|
iflist()
|
126 |
a4af095c
|
Renato Botelho
|
))->setHelp('Interface');
|
127 |
e31aa678
|
sbeaver
|
|
128 |
a4af095c
|
Renato Botelho
|
$group->add(new Form_Select(
|
129 |
e31aa678
|
sbeaver
|
'sort',
|
130 |
a4af095c
|
Renato Botelho
|
null,
|
131 |
e31aa678
|
sbeaver
|
$cursort,
|
132 |
|
|
array (
|
133 |
b50d30c3
|
Stephen Beaver
|
'in' => gettext('Bandwidth In'),
|
134 |
|
|
'out' => gettext('Bandwidth Out')
|
135 |
e31aa678
|
sbeaver
|
)
|
136 |
a4af095c
|
Renato Botelho
|
))->setHelp('Sort by');
|
137 |
e31aa678
|
sbeaver
|
|
138 |
a4af095c
|
Renato Botelho
|
$group->add(new Form_Select(
|
139 |
e31aa678
|
sbeaver
|
'filter',
|
140 |
a4af095c
|
Renato Botelho
|
null,
|
141 |
e31aa678
|
sbeaver
|
$curfilter,
|
142 |
|
|
array (
|
143 |
b50d30c3
|
Stephen Beaver
|
'local' => gettext('Local'),
|
144 |
|
|
'remote'=> gettext('Remote'),
|
145 |
|
|
'all' => gettext('All')
|
146 |
e31aa678
|
sbeaver
|
)
|
147 |
a4af095c
|
Renato Botelho
|
))->setHelp('Filter');
|
148 |
e31aa678
|
sbeaver
|
|
149 |
a4af095c
|
Renato Botelho
|
$group->add(new Form_Select(
|
150 |
e31aa678
|
sbeaver
|
'hostipformat',
|
151 |
a4af095c
|
Renato Botelho
|
null,
|
152 |
e31aa678
|
sbeaver
|
$curhostipformat,
|
153 |
|
|
array (
|
154 |
b50d30c3
|
Stephen Beaver
|
'' => gettext('IP Address'),
|
155 |
|
|
'hostname' => gettext('Host Name'),
|
156 |
|
|
'descr' => gettext('Description'),
|
157 |
|
|
'fqdn' => gettext('FQDN')
|
158 |
e31aa678
|
sbeaver
|
)
|
159 |
a4af095c
|
Renato Botelho
|
))->setHelp('Display');
|
160 |
|
|
|
161 |
fe5c31bb
|
PiBa-NL
|
$group->add(new Form_Select(
|
162 |
|
|
'backgroundupdate',
|
163 |
|
|
null,
|
164 |
|
|
$curbackgroundupdate,
|
165 |
|
|
array (
|
166 |
|
|
'false' => gettext('Clear graphs when not visible.'),
|
167 |
|
|
'true' => gettext('Keep graphs updated on inactive tab. (increases cpu usage)'),
|
168 |
|
|
)
|
169 |
|
|
))->setHelp('Background updates');
|
170 |
|
|
|
171 |
a4af095c
|
Renato Botelho
|
$section->add($group);
|
172 |
e31aa678
|
sbeaver
|
|
173 |
|
|
$form->add($section);
|
174 |
|
|
print $form;
|
175 |
|
|
|
176 |
d3fd2bbe
|
PiBa-NL
|
$realif = get_real_interface($curif);
|
177 |
e31aa678
|
sbeaver
|
?>
|
178 |
849d3a37
|
Jared Dillard
|
|
179 |
d8837d57
|
PiBa-NL
|
<script src="/vendor/d3/d3.min.js?v=<?=filemtime('/usr/local/www/vendor/d3/d3.min.js')?>"></script>
|
180 |
|
|
<script src="/vendor/nvd3/nv.d3.js?v=<?=filemtime('/usr/local/www/vendor/nvd3/nv.d3.js')?>"></script>
|
181 |
|
|
<script src="/vendor/visibility/visibility-1.2.3.min.js?v=<?=filemtime('/usr/local/www/vendor/visibility/visibility-1.2.3.min.js')?>"></script>
|
182 |
849d3a37
|
Jared Dillard
|
|
183 |
|
|
<link href="/vendor/nvd3/nv.d3.css" media="screen, projection" rel="stylesheet" type="text/css">
|
184 |
|
|
|
185 |
|
|
<script type="text/javascript">
|
186 |
|
|
|
187 |
52229047
|
PiBa-NL
|
|
188 |
849d3a37
|
Jared Dillard
|
//<![CDATA[
|
189 |
|
|
events.push(function() {
|
190 |
|
|
|
191 |
|
|
var InterfaceString = "<?=$curif?>";
|
192 |
d3fd2bbe
|
PiBa-NL
|
var RealInterfaceString = "<?=$realif?>";
|
193 |
52229047
|
PiBa-NL
|
window.graph_backgroundupdate = $('#backgroundupdate').val() === "true";
|
194 |
849d3a37
|
Jared Dillard
|
|
195 |
52229047
|
PiBa-NL
|
window.interval = 1;
|
196 |
|
|
window.invert = "true";
|
197 |
|
|
window.size = 8;
|
198 |
|
|
window.interfaces = InterfaceString.split("|").filter(function(entry) { return entry.trim() != ''; });
|
199 |
|
|
window.realinterfaces = RealInterfaceString.split("|").filter(function(entry) { return entry.trim() != ''; });
|
200 |
849d3a37
|
Jared Dillard
|
|
201 |
52229047
|
PiBa-NL
|
graph_init();
|
202 |
|
|
graph_visibilitycheck();
|
203 |
849d3a37
|
Jared Dillard
|
|
204 |
|
|
});
|
205 |
|
|
//]]>
|
206 |
|
|
</script>
|
207 |
|
|
|
208 |
d8837d57
|
PiBa-NL
|
<script src="/js/traffic-graphs.js?v=<?=filemtime('/usr/local/www/js/traffic-graphs.js')?>"></script>
|
209 |
849d3a37
|
Jared Dillard
|
|
210 |
8fd9052f
|
Colin Fleming
|
<script type="text/javascript">
|
211 |
|
|
//<![CDATA[
|
212 |
f0a3b883
|
Scott Ullrich
|
|
213 |
fe5c31bb
|
PiBa-NL
|
var graph_interfacenames = <?php
|
214 |
|
|
foreach ($ifdescrs as $ifname => $ifdescr) {
|
215 |
|
|
$iflist[$ifname] = $ifdescr;
|
216 |
|
|
}
|
217 |
|
|
echo json_encode($iflist);
|
218 |
|
|
?>;
|
219 |
abe98adb
|
Phil Davis
|
function updateBandwidth() {
|
220 |
607b1c39
|
Sjon Hortensius
|
$.ajax(
|
221 |
|
|
'/bandwidth_by_ip.php',
|
222 |
|
|
{
|
223 |
|
|
type: 'get',
|
224 |
|
|
data: $(document.forms[0]).serialize(),
|
225 |
|
|
success: function (data) {
|
226 |
|
|
var hosts_split = data.split("|");
|
227 |
|
|
|
228 |
|
|
$('#top10-hosts').empty();
|
229 |
|
|
|
230 |
|
|
//parse top ten bandwidth abuser hosts
|
231 |
abe98adb
|
Phil Davis
|
for (var y=0; y<10; y++) {
|
232 |
607b1c39
|
Sjon Hortensius
|
if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
|
233 |
|
|
hostinfo = hosts_split[y].split(";");
|
234 |
|
|
|
235 |
|
|
$('#top10-hosts').append('<tr>'+
|
236 |
|
|
'<td>'+ hostinfo[0] +'</td>'+
|
237 |
3bd74348
|
bruno
|
'<td>'+ hostinfo[1] +' <?=gettext("Bits/sec");?></td>'+
|
238 |
|
|
'<td>'+ hostinfo[2] +' <?=gettext("Bits/sec");?></td>'+
|
239 |
607b1c39
|
Sjon Hortensius
|
'</tr>');
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
|
|
},
|
243 |
|
|
});
|
244 |
f0a3b883
|
Scott Ullrich
|
}
|
245 |
|
|
|
246 |
abe98adb
|
Phil Davis
|
events.push(function() {
|
247 |
|
|
$('form.auto-submit').on('change', function() {
|
248 |
607b1c39
|
Sjon Hortensius
|
$(this).submit();
|
249 |
|
|
});
|
250 |
f0a3b883
|
Scott Ullrich
|
|
251 |
889f9ee0
|
heper
|
setInterval('updateBandwidth()', 3000);
|
252 |
e31aa678
|
sbeaver
|
|
253 |
607b1c39
|
Sjon Hortensius
|
updateBandwidth();
|
254 |
|
|
});
|
255 |
8fd9052f
|
Colin Fleming
|
//]]>
|
256 |
f0a3b883
|
Scott Ullrich
|
</script>
|
257 |
5b237745
|
Scott Ullrich
|
<?php
|
258 |
9573d170
|
Scott Ullrich
|
|
259 |
872ce0dd
|
Ermal Luçi
|
/* link the ipsec interface magically */
|
260 |
abe98adb
|
Phil Davis
|
if (ipsec_enabled()) {
|
261 |
98128ad6
|
Phil Davis
|
$ifdescrs['enc0'] = gettext("IPsec");
|
262 |
abe98adb
|
Phil Davis
|
}
|
263 |
c1abd446
|
Seth Mos
|
|
264 |
5b237745
|
Scott Ullrich
|
?>
|
265 |
607b1c39
|
Sjon Hortensius
|
<div class="panel panel-default">
|
266 |
|
|
<div class="panel-heading">
|
267 |
3d7a8696
|
k-paulius
|
<h2 class="panel-title"><?=gettext("Traffic Graph");?></h2>
|
268 |
e31aa678
|
sbeaver
|
</div>
|
269 |
607b1c39
|
Sjon Hortensius
|
<div class="panel-body">
|
270 |
|
|
<div class="col-sm-6">
|
271 |
849d3a37
|
Jared Dillard
|
<div id="traffic-chart-<?=$curif?>" class="d3-chart traffic-widget-chart">
|
272 |
|
|
<svg></svg>
|
273 |
|
|
</div>
|
274 |
607b1c39
|
Sjon Hortensius
|
</div>
|
275 |
|
|
<div class="col-sm-6">
|
276 |
|
|
<table class="table table-striped table-condensed">
|
277 |
|
|
<thead>
|
278 |
|
|
<tr>
|
279 |
abe98adb
|
Phil Davis
|
<th><?=(($curhostipformat == "") ? gettext("Host IP") : gettext("Host Name or IP")); ?></th>
|
280 |
607b1c39
|
Sjon Hortensius
|
<th><?=gettext("Bandwidth In"); ?></th>
|
281 |
|
|
<th><?=gettext("Bandwidth Out"); ?></th>
|
282 |
|
|
</tr>
|
283 |
|
|
</thead>
|
284 |
|
|
<tbody id="top10-hosts">
|
285 |
|
|
<!-- to be added by javascript -->
|
286 |
|
|
</tbody>
|
287 |
|
|
</table>
|
288 |
|
|
</div>
|
289 |
e57c91a2
|
Renato Botelho
|
</div>
|
290 |
8ab3e9ed
|
Erik Kristensen
|
</div>
|
291 |
c10cb196
|
Stephen Beaver
|
<?php include("foot.inc");
|