Project

General

Profile

Download (6.49 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_pftop.php
4
*/
5
/* ====================================================================
6
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *  Redistribution and use in source and binary forms, with or without modification,
9
 *  are permitted provided that the following conditions are met:
10
 *
11
 *  1. Redistributions of source code must retain the above copyright notice,
12
 *      this list of conditions and the following disclaimer.
13
 *
14
 *  2. Redistributions in binary form must reproduce the above copyright
15
 *      notice, this list of conditions and the following disclaimer in
16
 *      the documentation and/or other materials provided with the
17
 *      distribution.
18
 *
19
 *  3. All advertising materials mentioning features or use of this software
20
 *      must display the following acknowledgment:
21
 *      "This product includes software developed by the pfSense Project
22
 *       for use in the pfSense software distribution. (http://www.pfsense.org/).
23
 *
24
 *  4. The names "pfSense" and "pfSense Project" must not be used to
25
 *       endorse or promote products derived from this software without
26
 *       prior written permission. For written permission, please contact
27
 *       coreteam@pfsense.org.
28
 *
29
 *  5. Products derived from this software may not be called "pfSense"
30
 *      nor may "pfSense" appear in their names without prior written
31
 *      permission of the Electric Sheep Fencing, LLC.
32
 *
33
 *  6. Redistributions of any form whatsoever must retain the following
34
 *      acknowledgment:
35
 *
36
 *  "This product includes software developed by the pfSense Project
37
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
38
 *
39
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
40
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
43
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
51
 *
52
 *  ====================================================================
53
 *
54
 */
55

    
56
/*
57
	pfSense_MODULE:	filter
58
*/
59

    
60
##|+PRIV
61
##|*IDENT=page-diagnostics-system-pftop
62
##|*NAME=Diagnostics: pfTop
63
##|*DESCR=Allows access to the 'Diagnostics: pfTop' page
64
##|*MATCH=diag_pftop.php*
65
##|-PRIV
66

    
67
require("guiconfig.inc");
68

    
69
$pgtitle = array(gettext("Diagnostics"), gettext("pfTop"));
70

    
71
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src');
72
$viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time');
73
$viewall = array('queue', 'label', 'rules');
74
$numstates = array('50', '100', '200', '500', '1000', 'all');
75

    
76
if ($_REQUEST['getactivity']) {
77
	if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) &&
78
	    $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) &&
79
	    $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
80
		$viewtype = escapeshellarg($_REQUEST['viewtype']);
81
		if (in_array($_REQUEST['viewtype'], $viewall)) {
82
			$sorttype = "";
83
			$numstate = "-a";
84
		} else {
85
			$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
86
			$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
87
		}
88
	} else {
89
		$sorttype = "bytes";
90
		$viewtype = "default";
91
		$numstate = "100";
92
	}
93

    
94
	$text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`;
95
	echo trim($text);
96
	exit;
97
}
98

    
99
include("head.inc");
100

    
101
if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) &&
102
    $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) &&
103
    $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
104
	$viewtype = escapeshellarg($_REQUEST['viewtype']);
105
	if (in_array($_REQUEST['viewtype'], $viewall)) {
106
		$sorttype = "";
107
		$numstate = "-a";
108
	} else {
109
		$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
110
		$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
111
	}
112
} else {
113
	$sorttype = "bytes";
114
	$viewtype = "default";
115
	$numstate = "100";
116
}
117

    
118
if ($input_errors)
119
	print_input_errors($input_errors);
120

    
121
$form = new Form(false);
122
$form->addGlobal(new Form_Input(
123
	'getactivity',
124
	null,
125
	'hidden',
126
	'yes'
127
));
128
$section = new Form_Section('pfTop Configuration');
129

    
130
$validViews = array(
131
	'default', 'label', 'long',
132
	'queue', 'rules', 'size',
133
	'speed', 'state', 'time',
134
);
135
$section->addInput(new Form_Select(
136
	'viewtype',
137
	'View',
138
	$viewtype,
139
	array_combine($validViews, $validViews)
140
));
141

    
142
$section->addInput(new Form_Select(
143
	'sorttype',
144
	'Sort by',
145
	$sorttype,
146
	array(
147
		'none' => 'None',
148
		'age' => 'Age',
149
		'bytes' => 'Bytes',
150
		'dest' => 'Destination Address',
151
		'dport' => 'Destination Port',
152
		'exp' => 'Expiry',
153
		'peak' => 'Peak',
154
		'pkt' => 'Packet',
155
		'rate' => 'Rate',
156
		'size' => 'Size',
157
		'sport' => 'Source Port',
158
		'src' => 'Source Address',
159
	)
160
));
161

    
162
$validStates = array(50, 100, 200, 500, 100, 'all');
163
$section->addInput(new Form_Select(
164
	'states',
165
	'Maximum # of States',
166
	$numstate,
167
	array_combine($validStates, $validStates)
168
));
169

    
170
$form->add($section);
171
print $form;
172
?>
173

    
174
<script type="text/javascript">
175
//<![CDATA[
176
	function getpftopactivity() {
177
		$.ajax(
178
			'/diag_pftop.php',
179
			{
180
				method: 'post',
181
				data: $(document.forms[0]).serialize(),
182
				dataType: "html",
183
				success: function (data) {
184
					$('#xhrOutput').html(data);
185
				},
186
			}
187
		);
188
	}
189

    
190
	events.push(function(){
191
		setInterval('getpftopactivity()', 2500);
192
		getpftopactivity();
193
	});
194
//]]>
195
</script>
196
<?php
197
?>
198
<div class="panel panel-default">
199
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Output')?></h2></div>
200
	<div class="panel panel-body">
201
		<pre id="xhrOutput"><?=gettext("Gathering pfTOP activity, please wait...")?></pre>
202
	</div>
203
</div>
204

    
205
<script type="text/javascript">
206
//<![CDATA[
207
events.push(function(){
208
	$('#viewtype').on('change', function(){
209
		if (['queue', 'label', 'rules'].indexOf($(this).val()) > -1)
210
			$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').hide();
211
		else
212
			$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').show();
213
	});
214
});
215
//]]>
216
</script>
217
<?php include("foot.inc");
(20-20/228)