Project

General

Profile

Download (4.94 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_pftop.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 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

    
33
$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
$viewall = array('queue', 'label', 'rules');
36
$numstates = array('50', '100', '200', '500', '1000', 'all');
37

    
38
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
		$viewtype = escapeshellarg($_REQUEST['viewtype']);
43
		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
	} else {
51
		$sorttype = "bytes";
52
		$viewtype = "default";
53
		$numstate = "100";
54
	}
55

    
56
	$text = `pftop -b {$sorttype} -w 135 -v {$viewtype} {$numstate}`;
57
	echo trim($text);
58
	exit;
59
}
60

    
61
include("head.inc");
62

    
63
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
	$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
} else {
75
	$sorttype = "bytes";
76
	$viewtype = "default";
77
	$numstate = "100";
78
}
79

    
80
if ($input_errors) {
81
	print_input_errors($input_errors);
82
}
83

    
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
	'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
);
104
$section->addInput(new Form_Select(
105
	'viewtype',
106
	'View',
107
	$viewtype,
108
	$validViews
109
));
110

    
111
$section->addInput(new Form_Select(
112
	'sorttype',
113
	'Sort by',
114
	$sorttype,
115
	array(
116
		'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
	)
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
?>
142

    
143
<script type="text/javascript">
144
//<![CDATA[
145
	function getpftopactivity() {
146
		$.ajax(
147
			'/diag_pftop.php',
148
			{
149
				method: 'post',
150
				data: $(document.forms[0]).serialize(),
151
				dataType: "html",
152
				success: function (data) {
153
					$('#xhrOutput').html(data);
154
				},
155
			}
156
		);
157
	}
158

    
159
	events.push(function() {
160
		setInterval('getpftopactivity()', 2500);
161
		getpftopactivity();
162
	});
163
//]]>
164
</script>
165

    
166
<div class="panel panel-default">
167
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Output')?></h2></div>
168
	<div class="panel panel-body">
169
		<pre id="xhrOutput"><?=gettext("Gathering pfTOP activity, please wait...")?></pre>
170
	</div>
171
</div>
172

    
173
<script type="text/javascript">
174
//<![CDATA[
175
events.push(function() {
176
	$('#viewtype').on('change', function() {
177
		if (['queue', 'label', 'rules'].indexOf($(this).val()) > -1) {
178
			$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').hide();
179
		} else {
180
			$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').show();
181
		}
182
	});
183
});
184
//]]>
185
</script>
186
<?php include("foot.inc");
(20-20/223)