Project

General

Profile

Download (4.94 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 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 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 14f84bc9 Scott Ullrich
33 c668eaed Warren Baker
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src');
34
$viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time');
35 38de3c9d Warren Baker
$viewall = array('queue', 'label', 'rules');
36
$numstates = array('50', '100', '200', '500', '1000', 'all');
37 c668eaed Warren Baker
38 5f601060 Phil Davis
if ($_REQUEST['getactivity']) {
39
	if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) &&
40
	    $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) &&
41
	    $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
42 c668eaed Warren Baker
		$viewtype = escapeshellarg($_REQUEST['viewtype']);
43 ea031bde Warren Baker
		if (in_array($_REQUEST['viewtype'], $viewall)) {
44
			$sorttype = "";
45
			$numstate = "-a";
46
		} else {
47
			$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
48
			$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
49
		}
50 c668eaed Warren Baker
	} else {
51 19f7146a bcyrill
		$sorttype = "bytes";
52
		$viewtype = "default";
53 38de3c9d Warren Baker
		$numstate = "100";
54 c668eaed Warren Baker
	}
55 ba17b457 Warren Baker
56 9a966125 jim-p
	$text = `pftop -b {$sorttype} -w 135 -v {$viewtype} {$numstate}`;
57 45d6ada5 Sjon Hortensius
	echo trim($text);
58 14f84bc9 Scott Ullrich
	exit;
59
}
60
61
include("head.inc");
62
63 5f601060 Phil Davis
if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) &&
64
    $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) &&
65
    $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
66 ea031bde Warren Baker
	$viewtype = escapeshellarg($_REQUEST['viewtype']);
67
	if (in_array($_REQUEST['viewtype'], $viewall)) {
68
		$sorttype = "";
69
		$numstate = "-a";
70
	} else {
71
		$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
72
		$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
73
	}
74 c668eaed Warren Baker
} else {
75 19f7146a bcyrill
	$sorttype = "bytes";
76
	$viewtype = "default";
77 38de3c9d Warren Baker
	$numstate = "100";
78 c668eaed Warren Baker
}
79 14f84bc9 Scott Ullrich
80 947141fd Phil Davis
if ($input_errors) {
81 45d6ada5 Sjon Hortensius
	print_input_errors($input_errors);
82 947141fd Phil Davis
}
83 45d6ada5 Sjon Hortensius
84
$form = new Form(false);
85
$form->addGlobal(new Form_Input(
86
	'getactivity',
87
	null,
88
	'hidden',
89
	'yes'
90
));
91
$section = new Form_Section('pfTop Configuration');
92
93
$validViews = array(
94 ff30e319 bruno
	'default' => gettext('default'), 
95
	'label' => gettext('label'), 
96
	'long' => gettext('long'),
97
	'queue' => gettext('queue'), 
98
	'rules' => gettext('rules'), 
99
	'size' => gettext('size'),
100
	'speed' => gettext('speed'), 
101
	'state' => gettext('state'), 
102
	'time' => gettext('time'),
103 45d6ada5 Sjon Hortensius
);
104
$section->addInput(new Form_Select(
105
	'viewtype',
106
	'View',
107
	$viewtype,
108 ff30e319 bruno
	$validViews
109 45d6ada5 Sjon Hortensius
));
110
111
$section->addInput(new Form_Select(
112
	'sorttype',
113
	'Sort by',
114
	$sorttype,
115
	array(
116 ff30e319 bruno
		'none' => gettext('None'),
117
		'age' => gettext('Age'),
118
		'bytes' => gettext('Bytes'),
119
		'dest' => gettext('Destination Address'),
120
		'dport' => gettext('Destination Port'),
121
		'exp' => gettext('Expiry'),
122
		'peak' => gettext('Peak'),
123
		'pkt' => gettext('Packet'),
124
		'rate' => gettext('Rate'),
125
		'size' => gettext('Size'),
126
		'sport' => gettext('Source Port'),
127
		'src' => gettext('Source Address'),
128 45d6ada5 Sjon Hortensius
	)
129
));
130
131
$validStates = array(50, 100, 200, 500, 100, 'all');
132
$section->addInput(new Form_Select(
133
	'states',
134
	'Maximum # of States',
135
	$numstate,
136
	array_combine($validStates, $validStates)
137
));
138
139
$form->add($section);
140
print $form;
141 14f84bc9 Scott Ullrich
?>
142 45d6ada5 Sjon Hortensius
143 8fd9052f Colin Fleming
<script type="text/javascript">
144
//<![CDATA[
145 c668eaed Warren Baker
	function getpftopactivity() {
146 45d6ada5 Sjon Hortensius
		$.ajax(
147 1af5edbf Stephen Beaver
			'/diag_pftop.php',
148 14f84bc9 Scott Ullrich
			{
149 45d6ada5 Sjon Hortensius
				method: 'post',
150
				data: $(document.forms[0]).serialize(),
151
				dataType: "html",
152
				success: function (data) {
153
					$('#xhrOutput').html(data);
154
				},
155
			}
156
		);
157 14f84bc9 Scott Ullrich
	}
158 45d6ada5 Sjon Hortensius
159 947141fd Phil Davis
	events.push(function() {
160 45d6ada5 Sjon Hortensius
		setInterval('getpftopactivity()', 2500);
161
		getpftopactivity();
162
	});
163 8fd9052f Colin Fleming
//]]>
164 14f84bc9 Scott Ullrich
</script>
165 00271265 NewEraCracker
166 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
167 f17594c7 Sjon Hortensius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Output')?></h2></div>
168 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
169
		<pre id="xhrOutput"><?=gettext("Gathering pfTOP activity, please wait...")?></pre>
170 14f84bc9 Scott Ullrich
	</div>
171 99f089be Colin Fleming
</div>
172 45d6ada5 Sjon Hortensius
173 8fd9052f Colin Fleming
<script type="text/javascript">
174
//<![CDATA[
175 947141fd Phil Davis
events.push(function() {
176
	$('#viewtype').on('change', function() {
177
		if (['queue', 'label', 'rules'].indexOf($(this).val()) > -1) {
178 45d6ada5 Sjon Hortensius
			$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').hide();
179 947141fd Phil Davis
		} else {
180 45d6ada5 Sjon Hortensius
			$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').show();
181 947141fd Phil Davis
		}
182 45d6ada5 Sjon Hortensius
	});
183 c668eaed Warren Baker
});
184 8fd9052f Colin Fleming
//]]>
185 c668eaed Warren Baker
</script>
186 c10cb196 Stephen Beaver
<?php include("foot.inc");