1
|
<?php
|
2
|
/*
|
3
|
diag_pftop.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
*
|
8
|
* Redistribution and use in source and binary forms, with or without modification,
|
9
|
* are permitted provided that the following conditions are met:
|
10
|
*
|
11
|
* 1. Redistributions of source code must retain the above copyright notice,
|
12
|
* this list of conditions and the following disclaimer.
|
13
|
*
|
14
|
* 2. Redistributions in binary form must reproduce the above copyright
|
15
|
* notice, this list of conditions and the following disclaimer in
|
16
|
* the documentation and/or other materials provided with the
|
17
|
* distribution.
|
18
|
*
|
19
|
* 3. All advertising materials mentioning features or use of this software
|
20
|
* must display the following acknowledgment:
|
21
|
* "This product includes software developed by the pfSense Project
|
22
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
23
|
*
|
24
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
25
|
* endorse or promote products derived from this software without
|
26
|
* prior written permission. For written permission, please contact
|
27
|
* coreteam@pfsense.org.
|
28
|
*
|
29
|
* 5. Products derived from this software may not be called "pfSense"
|
30
|
* nor may "pfSense" appear in their names without prior written
|
31
|
* permission of the Electric Sheep Fencing, LLC.
|
32
|
*
|
33
|
* 6. Redistributions of any form whatsoever must retain the following
|
34
|
* acknowledgment:
|
35
|
*
|
36
|
* "This product includes software developed by the pfSense Project
|
37
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
38
|
*
|
39
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
40
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
41
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
42
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
43
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
44
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
45
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
46
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
48
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
49
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
50
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
51
|
*
|
52
|
* ====================================================================
|
53
|
*
|
54
|
*/
|
55
|
|
56
|
##|+PRIV
|
57
|
##|*IDENT=page-diagnostics-system-pftop
|
58
|
##|*NAME=Diagnostics: pfTop
|
59
|
##|*DESCR=Allows access to the 'Diagnostics: pfTop' page
|
60
|
##|*MATCH=diag_pftop.php*
|
61
|
##|-PRIV
|
62
|
|
63
|
require("guiconfig.inc");
|
64
|
|
65
|
$pgtitle = array(gettext("Diagnostics"), gettext("pfTop"));
|
66
|
|
67
|
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src');
|
68
|
$viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time');
|
69
|
$viewall = array('queue', 'label', 'rules');
|
70
|
$numstates = array('50', '100', '200', '500', '1000', 'all');
|
71
|
|
72
|
if ($_REQUEST['getactivity']) {
|
73
|
if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) &&
|
74
|
$_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) &&
|
75
|
$_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
76
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
77
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
78
|
$sorttype = "";
|
79
|
$numstate = "-a";
|
80
|
} else {
|
81
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
82
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
83
|
}
|
84
|
} else {
|
85
|
$sorttype = "bytes";
|
86
|
$viewtype = "default";
|
87
|
$numstate = "100";
|
88
|
}
|
89
|
|
90
|
$text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`;
|
91
|
echo trim($text);
|
92
|
exit;
|
93
|
}
|
94
|
|
95
|
include("head.inc");
|
96
|
|
97
|
if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) &&
|
98
|
$_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) &&
|
99
|
$_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
100
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
101
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
102
|
$sorttype = "";
|
103
|
$numstate = "-a";
|
104
|
} else {
|
105
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
106
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
107
|
}
|
108
|
} else {
|
109
|
$sorttype = "bytes";
|
110
|
$viewtype = "default";
|
111
|
$numstate = "100";
|
112
|
}
|
113
|
|
114
|
if ($input_errors) {
|
115
|
print_input_errors($input_errors);
|
116
|
}
|
117
|
|
118
|
$form = new Form(false);
|
119
|
$form->addGlobal(new Form_Input(
|
120
|
'getactivity',
|
121
|
null,
|
122
|
'hidden',
|
123
|
'yes'
|
124
|
));
|
125
|
$section = new Form_Section('pfTop Configuration');
|
126
|
|
127
|
$validViews = array(
|
128
|
'default' => gettext('default'),
|
129
|
'label' => gettext('label'),
|
130
|
'long' => gettext('long'),
|
131
|
'queue' => gettext('queue'),
|
132
|
'rules' => gettext('rules'),
|
133
|
'size' => gettext('size'),
|
134
|
'speed' => gettext('speed'),
|
135
|
'state' => gettext('state'),
|
136
|
'time' => gettext('time'),
|
137
|
);
|
138
|
$section->addInput(new Form_Select(
|
139
|
'viewtype',
|
140
|
'View',
|
141
|
$viewtype,
|
142
|
$validViews
|
143
|
));
|
144
|
|
145
|
$section->addInput(new Form_Select(
|
146
|
'sorttype',
|
147
|
'Sort by',
|
148
|
$sorttype,
|
149
|
array(
|
150
|
'none' => gettext('None'),
|
151
|
'age' => gettext('Age'),
|
152
|
'bytes' => gettext('Bytes'),
|
153
|
'dest' => gettext('Destination Address'),
|
154
|
'dport' => gettext('Destination Port'),
|
155
|
'exp' => gettext('Expiry'),
|
156
|
'peak' => gettext('Peak'),
|
157
|
'pkt' => gettext('Packet'),
|
158
|
'rate' => gettext('Rate'),
|
159
|
'size' => gettext('Size'),
|
160
|
'sport' => gettext('Source Port'),
|
161
|
'src' => gettext('Source Address'),
|
162
|
)
|
163
|
));
|
164
|
|
165
|
$validStates = array(50, 100, 200, 500, 100, 'all');
|
166
|
$section->addInput(new Form_Select(
|
167
|
'states',
|
168
|
'Maximum # of States',
|
169
|
$numstate,
|
170
|
array_combine($validStates, $validStates)
|
171
|
));
|
172
|
|
173
|
$form->add($section);
|
174
|
print $form;
|
175
|
?>
|
176
|
|
177
|
<script type="text/javascript">
|
178
|
//<![CDATA[
|
179
|
function getpftopactivity() {
|
180
|
$.ajax(
|
181
|
'/diag_pftop.php',
|
182
|
{
|
183
|
method: 'post',
|
184
|
data: $(document.forms[0]).serialize(),
|
185
|
dataType: "html",
|
186
|
success: function (data) {
|
187
|
$('#xhrOutput').html(data);
|
188
|
},
|
189
|
}
|
190
|
);
|
191
|
}
|
192
|
|
193
|
events.push(function() {
|
194
|
setInterval('getpftopactivity()', 2500);
|
195
|
getpftopactivity();
|
196
|
});
|
197
|
//]]>
|
198
|
</script>
|
199
|
|
200
|
<div class="panel panel-default">
|
201
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Output')?></h2></div>
|
202
|
<div class="panel panel-body">
|
203
|
<pre id="xhrOutput"><?=gettext("Gathering pfTOP activity, please wait...")?></pre>
|
204
|
</div>
|
205
|
</div>
|
206
|
|
207
|
<script type="text/javascript">
|
208
|
//<![CDATA[
|
209
|
events.push(function() {
|
210
|
$('#viewtype').on('change', function() {
|
211
|
if (['queue', 'label', 'rules'].indexOf($(this).val()) > -1) {
|
212
|
$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').hide();
|
213
|
} else {
|
214
|
$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').show();
|
215
|
}
|
216
|
});
|
217
|
});
|
218
|
//]]>
|
219
|
</script>
|
220
|
<?php include("foot.inc");
|