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