1
|
<?php
|
2
|
/*
|
3
|
* diag_pftop.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
|
7
|
* All rights reserved.
|
8
|
*
|
9
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
* you may not use this file except in compliance with the License.
|
11
|
* You may obtain a copy of the License at
|
12
|
*
|
13
|
* http://www.apache.org/licenses/LICENSE-2.0
|
14
|
*
|
15
|
* Unless required by applicable law or agreed to in writing, software
|
16
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
* See the License for the specific language governing permissions and
|
19
|
* limitations under the License.
|
20
|
*/
|
21
|
|
22
|
##|+PRIV
|
23
|
##|*IDENT=page-diagnostics-system-pftop
|
24
|
##|*NAME=Diagnostics: pfTop
|
25
|
##|*DESCR=Allows access to the 'Diagnostics: pfTop' page
|
26
|
##|*MATCH=diag_pftop.php*
|
27
|
##|-PRIV
|
28
|
|
29
|
require_once("guiconfig.inc");
|
30
|
|
31
|
$pgtitle = array(gettext("Diagnostics"), gettext("pfTop"));
|
32
|
$pftop = "/usr/local/sbin/pftop";
|
33
|
|
34
|
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'pkt', 'sport', 'src');
|
35
|
$viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time');
|
36
|
$viewall = array('queue', 'label', 'rules');
|
37
|
$numstates = array('50', '100', '200', '500', '1000', 'all');
|
38
|
|
39
|
if ($_REQUEST['getactivity']) {
|
40
|
if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) &&
|
41
|
$_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) &&
|
42
|
$_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
43
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
44
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
45
|
$sorttype = "";
|
46
|
$numstate = "-a";
|
47
|
} else {
|
48
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
49
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
50
|
}
|
51
|
} else {
|
52
|
$sorttype = "bytes";
|
53
|
$viewtype = "default";
|
54
|
$numstate = "100";
|
55
|
}
|
56
|
if ($_REQUEST['filter'] != "") {
|
57
|
$filter = "-f " . escapeshellarg($_REQUEST['filter']);
|
58
|
} else {
|
59
|
$filter = "";
|
60
|
}
|
61
|
$text = shell_exec("$pftop {$filter} -b {$sorttype} -w 135 -v {$viewtype} {$numstate}");
|
62
|
if (empty($text)) {
|
63
|
echo "Invalid filter, check syntax";
|
64
|
} else {
|
65
|
echo trim($text);
|
66
|
}
|
67
|
exit;
|
68
|
}
|
69
|
|
70
|
include("head.inc");
|
71
|
|
72
|
if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) &&
|
73
|
$_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) &&
|
74
|
$_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
75
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
76
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
77
|
$sorttype = "";
|
78
|
$numstate = "-a";
|
79
|
} else {
|
80
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
81
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
82
|
}
|
83
|
} else {
|
84
|
$sorttype = "bytes";
|
85
|
$viewtype = "default";
|
86
|
$numstate = "100";
|
87
|
}
|
88
|
if ($_REQUEST['filter'] != "") {
|
89
|
$filter = "-f " . escapeshellarg($_REQUEST['filter']);
|
90
|
} else {
|
91
|
$filter = "";
|
92
|
}
|
93
|
|
94
|
if ($input_errors) {
|
95
|
print_input_errors($input_errors);
|
96
|
}
|
97
|
|
98
|
$form = new Form(false);
|
99
|
$form->addGlobal(new Form_Input(
|
100
|
'getactivity',
|
101
|
null,
|
102
|
'hidden',
|
103
|
'yes'
|
104
|
));
|
105
|
$section = new Form_Section('pfTop Configuration');
|
106
|
|
107
|
$validViews = array(
|
108
|
'default' => gettext('default'),
|
109
|
'label' => gettext('label'),
|
110
|
'long' => gettext('long'),
|
111
|
'queue' => gettext('queue'),
|
112
|
'rules' => gettext('rules'),
|
113
|
'size' => gettext('size'),
|
114
|
'speed' => gettext('speed'),
|
115
|
'state' => gettext('state'),
|
116
|
'time' => gettext('time'),
|
117
|
);
|
118
|
$section->addInput(new Form_Select(
|
119
|
'viewtype',
|
120
|
'View',
|
121
|
$viewtype,
|
122
|
$validViews
|
123
|
));
|
124
|
|
125
|
$section->addInput(new Form_Input(
|
126
|
'filter',
|
127
|
'Filter expression',
|
128
|
'text',
|
129
|
$_REQUEST['filter'],
|
130
|
['placeholder' => 'e.g. tcp, ip6 or dst net 208.123.73.0/24']
|
131
|
))->setHelp('<em>click for filter help</em>%1$s' .
|
132
|
'<code>[proto <ip|ip6|ah|carp|esp|icmp|ipv6-icmp|pfsync|tcp|udp>]</code><br />' .
|
133
|
'<code>[src|dst|gw] [host|net|port] <host/network/port></code><br />' .
|
134
|
'<code>[in|out]</code><br /><br />' .
|
135
|
'These are the most common selectors. Some expressions can be combined using "and" / "or". ' .
|
136
|
'See %2$s for more detailed expression syntax.%3$s',
|
137
|
'<span class="infoblock"><br />',
|
138
|
'<a target="_blank" href="https://www.freebsd.org/cgi/man.cgi?query=pftop#STATE_FILTERING">pftop(8)</a>',
|
139
|
'</span></p>'
|
140
|
);
|
141
|
|
142
|
$section->addInput(new Form_Select(
|
143
|
'sorttype',
|
144
|
'Sort by',
|
145
|
$sorttype,
|
146
|
array(
|
147
|
'none' => gettext('None'),
|
148
|
'age' => gettext('Age'),
|
149
|
'bytes' => gettext('Bytes'),
|
150
|
'dest' => gettext('Destination Address'),
|
151
|
'dport' => gettext('Destination Port'),
|
152
|
'exp' => gettext('Expiry'),
|
153
|
'pkt' => gettext('Packet'),
|
154
|
'sport' => gettext('Source Port'),
|
155
|
'src' => gettext('Source Address'),
|
156
|
)
|
157
|
));
|
158
|
|
159
|
$validStates = array(50, 100, 200, 500, 1000, 'all');
|
160
|
$section->addInput(new Form_Select(
|
161
|
'states',
|
162
|
'Maximum # of States',
|
163
|
$numstate,
|
164
|
array_combine($validStates, $validStates)
|
165
|
));
|
166
|
|
167
|
$form->add($section);
|
168
|
print $form;
|
169
|
?>
|
170
|
|
171
|
<script type="text/javascript">
|
172
|
//<![CDATA[
|
173
|
function getpftopactivity() {
|
174
|
$.ajax(
|
175
|
'/diag_pftop.php',
|
176
|
{
|
177
|
method: 'post',
|
178
|
data: $(document.forms[0]).serialize(),
|
179
|
dataType: "html",
|
180
|
success: function (data) {
|
181
|
$('#xhrOutput').html(data);
|
182
|
},
|
183
|
}
|
184
|
);
|
185
|
}
|
186
|
|
187
|
events.push(function() {
|
188
|
setInterval('getpftopactivity()', 2500);
|
189
|
getpftopactivity();
|
190
|
});
|
191
|
//]]>
|
192
|
</script>
|
193
|
|
194
|
<div class="panel panel-default">
|
195
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Output')?></h2></div>
|
196
|
<div class="panel panel-body">
|
197
|
<pre id="xhrOutput"><?=gettext("Gathering pfTOP activity, please wait...")?></pre>
|
198
|
</div>
|
199
|
</div>
|
200
|
|
201
|
<script type="text/javascript">
|
202
|
//<![CDATA[
|
203
|
events.push(function() {
|
204
|
$('#viewtype').on('change', function() {
|
205
|
if (['queue', 'label', 'rules'].indexOf($(this).val()) > -1) {
|
206
|
$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').hide();
|
207
|
} else {
|
208
|
$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').show();
|
209
|
}
|
210
|
});
|
211
|
$('#filter').on('keypress keyup', function(event) {
|
212
|
var keyPressed = event.keyCode || event.which;
|
213
|
if (keyPressed === 13) {
|
214
|
event.preventDefault();
|
215
|
return false;
|
216
|
}
|
217
|
});
|
218
|
});
|
219
|
//]]>
|
220
|
</script>
|
221
|
<?php include("foot.inc");
|