1 |
14f84bc9
|
Scott Ullrich
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
45d6ada5
|
Sjon Hortensius
|
diag_system_pftop.php
|
5 |
|
|
Copyright (C) 2008-2009 Scott Ullrich
|
6 |
|
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
7 |
|
|
All rights reserved.
|
8 |
|
|
|
9 |
|
|
Redistribution and use in source and binary forms, with or without
|
10 |
|
|
modification, are permitted provided that the following conditions are met:
|
11 |
|
|
|
12 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
13 |
|
|
this list of conditions and the following disclaimer.
|
14 |
|
|
|
15 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
16 |
|
|
notice, this list of conditions and the following disclaimer in the
|
17 |
|
|
documentation and/or other materials provided with the distribution.
|
18 |
|
|
|
19 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
29 |
14f84bc9
|
Scott Ullrich
|
*/
|
30 |
|
|
|
31 |
13d193c2
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_MODULE: filter
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
14f84bc9
|
Scott Ullrich
|
##|+PRIV
|
36 |
7997ed44
|
Renato Botelho
|
##|*IDENT=page-diagnostics-system-pftop
|
37 |
|
|
##|*NAME=Diagnostics: pfTop
|
38 |
|
|
##|*DESCR=Allows access to the 'Diagnostics: pfTop' page
|
39 |
fce938b3
|
jim-p
|
##|*MATCH=diag_system_pftop.php*
|
40 |
14f84bc9
|
Scott Ullrich
|
##|-PRIV
|
41 |
|
|
|
42 |
|
|
require("guiconfig.inc");
|
43 |
|
|
|
44 |
a1054b46
|
Scott Ullrich
|
$pgtitle = gettext("Diagnostics: pfTop");
|
45 |
14f84bc9
|
Scott Ullrich
|
|
46 |
c668eaed
|
Warren Baker
|
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src');
|
47 |
|
|
$viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time');
|
48 |
38de3c9d
|
Warren Baker
|
$viewall = array('queue', 'label', 'rules');
|
49 |
|
|
$numstates = array('50', '100', '200', '500', '1000', 'all');
|
50 |
c668eaed
|
Warren Baker
|
|
51 |
14f84bc9
|
Scott Ullrich
|
if($_REQUEST['getactivity']) {
|
52 |
38de3c9d
|
Warren Baker
|
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
|
53 |
|
|
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
|
54 |
|
|
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
55 |
c668eaed
|
Warren Baker
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
56 |
ea031bde
|
Warren Baker
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
57 |
|
|
$sorttype = "";
|
58 |
|
|
$numstate = "-a";
|
59 |
|
|
} else {
|
60 |
|
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
61 |
|
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
62 |
|
|
}
|
63 |
c668eaed
|
Warren Baker
|
} else {
|
64 |
19f7146a
|
bcyrill
|
$sorttype = "bytes";
|
65 |
|
|
$viewtype = "default";
|
66 |
38de3c9d
|
Warren Baker
|
$numstate = "100";
|
67 |
c668eaed
|
Warren Baker
|
}
|
68 |
ba17b457
|
Warren Baker
|
|
69 |
|
|
$text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`;
|
70 |
45d6ada5
|
Sjon Hortensius
|
echo trim($text);
|
71 |
14f84bc9
|
Scott Ullrich
|
exit;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
include("head.inc");
|
75 |
|
|
|
76 |
38de3c9d
|
Warren Baker
|
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
|
77 |
|
|
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
|
78 |
|
|
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
79 |
ea031bde
|
Warren Baker
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
80 |
|
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
81 |
|
|
$sorttype = "";
|
82 |
|
|
$numstate = "-a";
|
83 |
|
|
} else {
|
84 |
|
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
85 |
|
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
86 |
|
|
}
|
87 |
c668eaed
|
Warren Baker
|
} else {
|
88 |
19f7146a
|
bcyrill
|
$sorttype = "bytes";
|
89 |
|
|
$viewtype = "default";
|
90 |
38de3c9d
|
Warren Baker
|
$numstate = "100";
|
91 |
c668eaed
|
Warren Baker
|
}
|
92 |
14f84bc9
|
Scott Ullrich
|
|
93 |
45d6ada5
|
Sjon Hortensius
|
if ($input_errors)
|
94 |
|
|
print_input_errors($input_errors);
|
95 |
|
|
|
96 |
|
|
require('classes/Form.class.php');
|
97 |
|
|
$form = new Form(false);
|
98 |
|
|
$form->addGlobal(new Form_Input(
|
99 |
|
|
'getactivity',
|
100 |
|
|
null,
|
101 |
|
|
'hidden',
|
102 |
|
|
'yes'
|
103 |
|
|
));
|
104 |
|
|
$section = new Form_Section('pfTop Configuration');
|
105 |
|
|
|
106 |
|
|
$validViews = array(
|
107 |
|
|
'default', 'label', 'long',
|
108 |
|
|
'queue', 'rules', 'size',
|
109 |
|
|
'speed', 'state', 'time',
|
110 |
|
|
);
|
111 |
|
|
$section->addInput(new Form_Select(
|
112 |
|
|
'viewtype',
|
113 |
|
|
'View',
|
114 |
|
|
$viewtype,
|
115 |
|
|
array_combine($validViews, $validViews)
|
116 |
|
|
));
|
117 |
|
|
|
118 |
|
|
$section->addInput(new Form_Select(
|
119 |
|
|
'sorttype',
|
120 |
|
|
'Sort by',
|
121 |
|
|
$sorttype,
|
122 |
|
|
array(
|
123 |
|
|
'none' => 'None',
|
124 |
|
|
'age' => 'Age',
|
125 |
|
|
'bytes' => 'Bytes',
|
126 |
|
|
'dest' => 'Destination Address',
|
127 |
|
|
'dport' => 'Destination Port',
|
128 |
|
|
'exp' => 'Expiry',
|
129 |
|
|
'peak' => 'Peak',
|
130 |
|
|
'pkt' => 'Packet',
|
131 |
|
|
'rate' => 'Rate',
|
132 |
|
|
'size' => 'Size',
|
133 |
|
|
'sport' => 'Source Port',
|
134 |
|
|
'src' => 'Source Address',
|
135 |
|
|
)
|
136 |
|
|
));
|
137 |
|
|
|
138 |
|
|
$validStates = array(50, 100, 200, 500, 100, 'all');
|
139 |
|
|
$section->addInput(new Form_Select(
|
140 |
|
|
'states',
|
141 |
|
|
'Maximum # of States',
|
142 |
|
|
$numstate,
|
143 |
|
|
array_combine($validStates, $validStates)
|
144 |
|
|
));
|
145 |
|
|
|
146 |
|
|
$form->add($section);
|
147 |
|
|
print $form;
|
148 |
14f84bc9
|
Scott Ullrich
|
?>
|
149 |
45d6ada5
|
Sjon Hortensius
|
|
150 |
|
|
<script>
|
151 |
c668eaed
|
Warren Baker
|
function getpftopactivity() {
|
152 |
45d6ada5
|
Sjon Hortensius
|
$.ajax(
|
153 |
|
|
'/diag_system_pftop.php',
|
154 |
14f84bc9
|
Scott Ullrich
|
{
|
155 |
45d6ada5
|
Sjon Hortensius
|
method: 'post',
|
156 |
|
|
data: $(document.forms[0]).serialize(),
|
157 |
|
|
dataType: "html",
|
158 |
|
|
success: function (data) {
|
159 |
|
|
$('#xhrOutput').html(data);
|
160 |
|
|
},
|
161 |
|
|
}
|
162 |
|
|
);
|
163 |
14f84bc9
|
Scott Ullrich
|
}
|
164 |
45d6ada5
|
Sjon Hortensius
|
|
165 |
|
|
events.push(function(){
|
166 |
|
|
setInterval('getpftopactivity()', 2500);
|
167 |
|
|
getpftopactivity();
|
168 |
|
|
});
|
169 |
14f84bc9
|
Scott Ullrich
|
</script>
|
170 |
|
|
<?php
|
171 |
|
|
?>
|
172 |
45d6ada5
|
Sjon Hortensius
|
<div class="panel panel-default">
|
173 |
|
|
<div class="panel-heading"><?=gettext('Output')?></div>
|
174 |
|
|
<div class="panel panel-body">
|
175 |
|
|
<pre id="xhrOutput"><?=gettext("Gathering pfTOP activity, please wait...")?></pre>
|
176 |
14f84bc9
|
Scott Ullrich
|
</div>
|
177 |
99f089be
|
Colin Fleming
|
</div>
|
178 |
45d6ada5
|
Sjon Hortensius
|
|
179 |
|
|
<script>
|
180 |
|
|
events.push(function(){
|
181 |
|
|
$('#viewtype').on('change', function(){
|
182 |
|
|
if (['queue', 'label', 'rules'].indexOf($(this).val()) > -1)
|
183 |
|
|
$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').hide();
|
184 |
|
|
else
|
185 |
|
|
$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').show();
|
186 |
|
|
});
|
187 |
c668eaed
|
Warren Baker
|
});
|
188 |
|
|
</script>
|
189 |
45d6ada5
|
Sjon Hortensius
|
<?php include("foot.inc");
|