Project

General

Profile

Download (5.9 KB) Statistics
| Branch: | Tag: | Revision:
1 14f84bc9 Scott Ullrich
<?php
2
/*
3 c5d81585 Renato Botelho
 * diag_pftop.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8
 *
9 b12ea3fb Renato Botelho
 * 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 c5d81585 Renato Botelho
 *
13 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
14 c5d81585 Renato Botelho
 *
15 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
21 14f84bc9 Scott Ullrich
22
##|+PRIV
23 7997ed44 Renato Botelho
##|*IDENT=page-diagnostics-system-pftop
24
##|*NAME=Diagnostics: pfTop
25
##|*DESCR=Allows access to the 'Diagnostics: pfTop' page
26 1af5edbf Stephen Beaver
##|*MATCH=diag_pftop.php*
27 14f84bc9 Scott Ullrich
##|-PRIV
28
29 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
30 14f84bc9 Scott Ullrich
31 0da0d43e Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("pfTop"));
32 10085279 luckman212
$pftop = "/usr/local/sbin/pftop";
33 14f84bc9 Scott Ullrich
34 c07a2b86 jim-p
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'pkt', 'sport', 'src');
35 c668eaed Warren Baker
$viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time');
36 38de3c9d Warren Baker
$viewall = array('queue', 'label', 'rules');
37
$numstates = array('50', '100', '200', '500', '1000', 'all');
38 c668eaed Warren Baker
39 5f601060 Phil Davis
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 c668eaed Warren Baker
		$viewtype = escapeshellarg($_REQUEST['viewtype']);
44 ea031bde Warren Baker
		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 c668eaed Warren Baker
	} else {
52 19f7146a bcyrill
		$sorttype = "bytes";
53
		$viewtype = "default";
54 38de3c9d Warren Baker
		$numstate = "100";
55 c668eaed Warren Baker
	}
56 10085279 luckman212
	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 14f84bc9 Scott Ullrich
	exit;
68
}
69
70
include("head.inc");
71
72 5f601060 Phil Davis
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 ea031bde Warren Baker
	$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 c668eaed Warren Baker
} else {
84 19f7146a bcyrill
	$sorttype = "bytes";
85
	$viewtype = "default";
86 38de3c9d Warren Baker
	$numstate = "100";
87 c668eaed Warren Baker
}
88 10085279 luckman212
if ($_REQUEST['filter'] != "") {
89
	$filter = "-f " . escapeshellarg($_REQUEST['filter']);
90
} else {
91
	$filter = "";
92
}
93 14f84bc9 Scott Ullrich
94 947141fd Phil Davis
if ($input_errors) {
95 45d6ada5 Sjon Hortensius
	print_input_errors($input_errors);
96 947141fd Phil Davis
}
97 45d6ada5 Sjon Hortensius
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 ff30e319 bruno
	'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 45d6ada5 Sjon Hortensius
);
118
$section->addInput(new Form_Select(
119
	'viewtype',
120
	'View',
121
	$viewtype,
122 ff30e319 bruno
	$validViews
123 45d6ada5 Sjon Hortensius
));
124
125 10085279 luckman212
$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 &lt;ip|ip6|ah|carp|esp|icmp|ipv6-icmp|pfsync|tcp|udp&gt;]</code><br />' .
133
	'<code>[src|dst|gw] [host|net|port] &lt;host/network/port&gt;</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 45d6ada5 Sjon Hortensius
$section->addInput(new Form_Select(
143
	'sorttype',
144
	'Sort by',
145
	$sorttype,
146
	array(
147 ff30e319 bruno
		'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 45d6ada5 Sjon Hortensius
	)
157
));
158
159 10085279 luckman212
$validStates = array(50, 100, 200, 500, 1000, 'all');
160 45d6ada5 Sjon Hortensius
$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 14f84bc9 Scott Ullrich
?>
170 45d6ada5 Sjon Hortensius
171 8fd9052f Colin Fleming
<script type="text/javascript">
172
//<![CDATA[
173 c668eaed Warren Baker
	function getpftopactivity() {
174 45d6ada5 Sjon Hortensius
		$.ajax(
175 1af5edbf Stephen Beaver
			'/diag_pftop.php',
176 14f84bc9 Scott Ullrich
			{
177 45d6ada5 Sjon Hortensius
				method: 'post',
178
				data: $(document.forms[0]).serialize(),
179
				dataType: "html",
180
				success: function (data) {
181
					$('#xhrOutput').html(data);
182
				},
183
			}
184
		);
185 14f84bc9 Scott Ullrich
	}
186 45d6ada5 Sjon Hortensius
187 947141fd Phil Davis
	events.push(function() {
188 45d6ada5 Sjon Hortensius
		setInterval('getpftopactivity()', 2500);
189
		getpftopactivity();
190
	});
191 8fd9052f Colin Fleming
//]]>
192 14f84bc9 Scott Ullrich
</script>
193 00271265 NewEraCracker
194 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
195 f17594c7 Sjon Hortensius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Output')?></h2></div>
196 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
197
		<pre id="xhrOutput"><?=gettext("Gathering pfTOP activity, please wait...")?></pre>
198 14f84bc9 Scott Ullrich
	</div>
199 99f089be Colin Fleming
</div>
200 45d6ada5 Sjon Hortensius
201 8fd9052f Colin Fleming
<script type="text/javascript">
202
//<![CDATA[
203 947141fd Phil Davis
events.push(function() {
204
	$('#viewtype').on('change', function() {
205
		if (['queue', 'label', 'rules'].indexOf($(this).val()) > -1) {
206 45d6ada5 Sjon Hortensius
			$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').hide();
207 947141fd Phil Davis
		} else {
208 45d6ada5 Sjon Hortensius
			$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').show();
209 947141fd Phil Davis
		}
210 45d6ada5 Sjon Hortensius
	});
211 c668eaed Warren Baker
});
212 8fd9052f Colin Fleming
//]]>
213 c668eaed Warren Baker
</script>
214 c10cb196 Stephen Beaver
<?php include("foot.inc");