Project

General

Profile

Download (4.83 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', 'pkt', '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
		'pkt' => gettext('Packet'),
123
		'sport' => gettext('Source Port'),
124
		'src' => gettext('Source Address'),
125
	)
126
));
127

    
128
$validStates = array(50, 100, 200, 500, 100, 'all');
129
$section->addInput(new Form_Select(
130
	'states',
131
	'Maximum # of States',
132
	$numstate,
133
	array_combine($validStates, $validStates)
134
));
135

    
136
$form->add($section);
137
print $form;
138
?>
139

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

    
156
	events.push(function() {
157
		setInterval('getpftopactivity()', 2500);
158
		getpftopactivity();
159
	});
160
//]]>
161
</script>
162

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

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