1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
diag_system_pftop.php
|
5
|
Copyright (C) 2008-2009 Scott Ullrich
|
6
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
7
|
All rights reserved.
|
8
|
|
9
|
Redistribution and use in source and binary forms, with or without
|
10
|
modification, are permitted provided that the following conditions are met:
|
11
|
|
12
|
1. Redistributions of source code must retain the above copyright notice,
|
13
|
this list of conditions and the following disclaimer.
|
14
|
|
15
|
2. Redistributions in binary form must reproduce the above copyright
|
16
|
notice, this list of conditions and the following disclaimer in the
|
17
|
documentation and/or other materials provided with the distribution.
|
18
|
|
19
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
POSSIBILITY OF SUCH DAMAGE.
|
29
|
*/
|
30
|
|
31
|
/*
|
32
|
pfSense_MODULE: filter
|
33
|
*/
|
34
|
|
35
|
##|+PRIV
|
36
|
##|*IDENT=page-diagnostics-system-pftop
|
37
|
##|*NAME=Diagnostics: pfTop
|
38
|
##|*DESCR=Allows access to the 'Diagnostics: pfTop' page
|
39
|
##|*MATCH=diag_system_pftop.php*
|
40
|
##|-PRIV
|
41
|
|
42
|
require("guiconfig.inc");
|
43
|
|
44
|
$pgtitle = gettext("Diagnostics: pfTop");
|
45
|
|
46
|
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src');
|
47
|
$viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time');
|
48
|
$viewall = array('queue', 'label', 'rules');
|
49
|
$numstates = array('50', '100', '200', '500', '1000', 'all');
|
50
|
|
51
|
if($_REQUEST['getactivity']) {
|
52
|
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
|
53
|
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
|
54
|
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
55
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
56
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
57
|
$sorttype = "";
|
58
|
$numstate = "-a";
|
59
|
} else {
|
60
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
61
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
62
|
}
|
63
|
} else {
|
64
|
$sorttype = "bytes";
|
65
|
$viewtype = "default";
|
66
|
$numstate = "100";
|
67
|
}
|
68
|
|
69
|
$text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`;
|
70
|
echo trim($text);
|
71
|
exit;
|
72
|
}
|
73
|
|
74
|
include("head.inc");
|
75
|
|
76
|
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
|
77
|
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
|
78
|
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
79
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
80
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
81
|
$sorttype = "";
|
82
|
$numstate = "-a";
|
83
|
} else {
|
84
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
85
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
86
|
}
|
87
|
} else {
|
88
|
$sorttype = "bytes";
|
89
|
$viewtype = "default";
|
90
|
$numstate = "100";
|
91
|
}
|
92
|
|
93
|
if ($input_errors)
|
94
|
print_input_errors($input_errors);
|
95
|
|
96
|
require('classes/Form.class.php');
|
97
|
$form = new Form(false);
|
98
|
$form->addGlobal(new Form_Input(
|
99
|
'getactivity',
|
100
|
null,
|
101
|
'hidden',
|
102
|
'yes'
|
103
|
));
|
104
|
$section = new Form_Section('pfTop Configuration');
|
105
|
|
106
|
$validViews = array(
|
107
|
'default', 'label', 'long',
|
108
|
'queue', 'rules', 'size',
|
109
|
'speed', 'state', 'time',
|
110
|
);
|
111
|
$section->addInput(new Form_Select(
|
112
|
'viewtype',
|
113
|
'View',
|
114
|
$viewtype,
|
115
|
array_combine($validViews, $validViews)
|
116
|
));
|
117
|
|
118
|
$section->addInput(new Form_Select(
|
119
|
'sorttype',
|
120
|
'Sort by',
|
121
|
$sorttype,
|
122
|
array(
|
123
|
'none' => 'None',
|
124
|
'age' => 'Age',
|
125
|
'bytes' => 'Bytes',
|
126
|
'dest' => 'Destination Address',
|
127
|
'dport' => 'Destination Port',
|
128
|
'exp' => 'Expiry',
|
129
|
'peak' => 'Peak',
|
130
|
'pkt' => 'Packet',
|
131
|
'rate' => 'Rate',
|
132
|
'size' => 'Size',
|
133
|
'sport' => 'Source Port',
|
134
|
'src' => 'Source Address',
|
135
|
)
|
136
|
));
|
137
|
|
138
|
$validStates = array(50, 100, 200, 500, 100, 'all');
|
139
|
$section->addInput(new Form_Select(
|
140
|
'states',
|
141
|
'Maximum # of States',
|
142
|
$numstate,
|
143
|
array_combine($validStates, $validStates)
|
144
|
));
|
145
|
|
146
|
$form->add($section);
|
147
|
print $form;
|
148
|
?>
|
149
|
|
150
|
<script>
|
151
|
function getpftopactivity() {
|
152
|
$.ajax(
|
153
|
'/diag_system_pftop.php',
|
154
|
{
|
155
|
method: 'post',
|
156
|
data: $(document.forms[0]).serialize(),
|
157
|
dataType: "html",
|
158
|
success: function (data) {
|
159
|
$('#xhrOutput').html(data);
|
160
|
},
|
161
|
}
|
162
|
);
|
163
|
}
|
164
|
|
165
|
events.push(function(){
|
166
|
setInterval('getpftopactivity()', 2500);
|
167
|
getpftopactivity();
|
168
|
});
|
169
|
</script>
|
170
|
<?php
|
171
|
?>
|
172
|
<div class="panel panel-default">
|
173
|
<div class="panel-heading"><?=gettext('Output')?></div>
|
174
|
<div class="panel panel-body">
|
175
|
<pre id="xhrOutput"><?=gettext("Gathering pfTOP activity, please wait...")?></pre>
|
176
|
</div>
|
177
|
</div>
|
178
|
|
179
|
<script>
|
180
|
events.push(function(){
|
181
|
$('#viewtype').on('change', function(){
|
182
|
if (['queue', 'label', 'rules'].indexOf($(this).val()) > -1)
|
183
|
$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').hide();
|
184
|
else
|
185
|
$("#sorttype, #sorttypediv, #statesdiv, #states").parents('.form-group').show();
|
186
|
});
|
187
|
});
|
188
|
</script>
|
189
|
<?php include("foot.inc");
|