1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
diag_system_pftop.php
|
5
|
Copyright (C) 2008-2009 Scott Ullrich
|
6
|
All rights reserved.
|
7
|
|
8
|
Redistribution and use in source and binary forms, with or without
|
9
|
modification, 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 the
|
16
|
documentation and/or other materials provided with the distribution.
|
17
|
|
18
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
19
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
21
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
22
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27
|
POSSIBILITY OF SUCH DAMAGE.
|
28
|
*/
|
29
|
|
30
|
/*
|
31
|
pfSense_MODULE: filter
|
32
|
*/
|
33
|
|
34
|
##|+PRIV
|
35
|
##|*IDENT=page-diagnostics-system-pftop
|
36
|
##|*NAME=Diagnostics: pfTop
|
37
|
##|*DESCR=Allows access to the 'Diagnostics: pfTop' page
|
38
|
##|*MATCH=diag_system_pftop.php*
|
39
|
##|-PRIV
|
40
|
|
41
|
require("guiconfig.inc");
|
42
|
|
43
|
$pgtitle = gettext("Diagnostics: pfTop");
|
44
|
|
45
|
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src');
|
46
|
$viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time');
|
47
|
$viewall = array('queue', 'label', 'rules');
|
48
|
$numstates = array('50', '100', '200', '500', '1000', 'all');
|
49
|
|
50
|
if($_REQUEST['getactivity']) {
|
51
|
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
|
52
|
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
|
53
|
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
54
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
55
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
56
|
$sorttype = "";
|
57
|
$numstate = "-a";
|
58
|
} else {
|
59
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
60
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
61
|
}
|
62
|
} else {
|
63
|
$sorttype = "bytes";
|
64
|
$viewtype = "default";
|
65
|
$numstate = "100";
|
66
|
}
|
67
|
|
68
|
$text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`;
|
69
|
echo $text;
|
70
|
exit;
|
71
|
}
|
72
|
|
73
|
include("head.inc");
|
74
|
|
75
|
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
|
76
|
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
|
77
|
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
78
|
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
79
|
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
80
|
$sorttype = "";
|
81
|
$numstate = "-a";
|
82
|
} else {
|
83
|
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
84
|
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
85
|
}
|
86
|
} else {
|
87
|
$sorttype = "bytes";
|
88
|
$viewtype = "default";
|
89
|
$numstate = "100";
|
90
|
}
|
91
|
|
92
|
?>
|
93
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
94
|
<?php include("fbegin.inc"); ?>
|
95
|
<form method="post" action="diag_system_pftop.php">
|
96
|
<script type="text/javascript">
|
97
|
//<![CDATA[
|
98
|
function getpftopactivity() {
|
99
|
var url = "/diag_system_pftop.php";
|
100
|
var pars = 'getactivity=yes&sorttype=' + jQuery('#sorttype').val() + '&viewtype=' + jQuery('#viewtype').val() + '&states=' + jQuery('#states').val();
|
101
|
jQuery.ajax(
|
102
|
url,
|
103
|
{
|
104
|
type: 'post',
|
105
|
data: pars,
|
106
|
complete: activitycallback
|
107
|
});
|
108
|
}
|
109
|
function activitycallback(transport) {
|
110
|
jQuery('#pftopactivitydiv').html('<font face="Courier" size="2"><pre style="text-align:left;">' + transport.responseText + '<\/pre><\/font>');
|
111
|
setTimeout('getpftopactivity()', 2500);
|
112
|
}
|
113
|
setTimeout('getpftopactivity()', 1000);
|
114
|
//]]>
|
115
|
</script>
|
116
|
<div id="maincontent">
|
117
|
<?php
|
118
|
if($savemsg) {
|
119
|
echo "<div id=\"savemsg\">";
|
120
|
print_info_box($savemsg);
|
121
|
echo "</div>";
|
122
|
}
|
123
|
if ($input_errors)
|
124
|
print_input_errors($input_errors);
|
125
|
?>
|
126
|
<div id="mainarea" style="padding-bottom: 0px;">
|
127
|
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="diag system pftop">
|
128
|
<tr>
|
129
|
<td class="list">
|
130
|
<div id='viewtypediv'><?=gettext("View type:"); ?>
|
131
|
<select name='viewtype' id='viewtype'>
|
132
|
<option value='default' <?php echo ($viewtype == "default") ? "selected=\"selected\"" : ""; ?>><?=gettext("Default");?></option>
|
133
|
<option value='label' <?php echo ($viewtype == "label") ? "selected=\"selected\"" : ""; ?>><?=gettext("Label");?></option>
|
134
|
<option value='long' <?php echo ($viewtype == "long") ? "selected=\"selected\"" : ""; ?>><?=gettext("Long");?></option>
|
135
|
<option value='queue' <?php echo ($viewtype == "queue") ? "selected=\"selected\"" : ""; ?>><?=gettext("Queue");?></option>
|
136
|
<option value='rules' <?php echo ($viewtype == "rules") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rules");?></option>
|
137
|
<option value='size' <?php echo ($viewtype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
|
138
|
<option value='speed' <?php echo ($viewtype == "speed") ? "selected=\"selected\"" : ""; ?>><?=gettext("Speed");?></option>
|
139
|
<option value='state' <?php echo ($viewtype == "state") ? "selected=\"selected\"" : ""; ?>><?=gettext("State");?></option>
|
140
|
<option value='time' <?php echo ($viewtype == "time") ? "selected=\"selected\"" : ""; ?>><?=gettext("Time");?></option>
|
141
|
</select>
|
142
|
</div>
|
143
|
</td>
|
144
|
<td class="list">
|
145
|
<div id='sorttypediv'><?=gettext("Sort type:"); ?>
|
146
|
<select name='sorttype' id='sorttype'>
|
147
|
<option value='age' <?php echo ($sorttype == "age") ? "selected=\"selected\"" : ""; ?>><?=gettext("Age");?></option>
|
148
|
<option value='bytes' <?php echo ($sorttype == "bytes") ? "selected=\"selected\"" : ""; ?>><?=gettext("Bytes");?></option>
|
149
|
<option value='dest' <?php echo ($sorttype == "dest") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Address");?></option>
|
150
|
<option value='dport' <?php echo ($sorttype == "dport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Port");?></option>
|
151
|
<option value='exp' <?php echo ($sorttype == "exp") ? "selected=\"selected\"" : ""; ?>><?=gettext("Expiry");?></option>
|
152
|
<option value='none' <?php echo ($sorttype == "none") ? "selected=\"selected\"" : ""; ?>><?=gettext("None");?></option>
|
153
|
<option value='peak' <?php echo ($sorttype == "peak") ? "selected=\"selected\"" : ""; ?>><?=gettext("Peak");?></option>
|
154
|
<option value='pkt' <?php echo ($sorttype == "pkt") ? "selected=\"selected\"" : ""; ?>><?=gettext("Packet");?></option>
|
155
|
<option value='rate' <?php echo ($sorttype == "rate") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rate");?></option>
|
156
|
<option value='size' <?php echo ($sorttype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
|
157
|
<option value='sport' <?php echo ($sorttype == "sport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Port");?></option>
|
158
|
<option value='src' <?php echo ($sorttype == "src") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Address");?></option>
|
159
|
</select>
|
160
|
</div>
|
161
|
</td>
|
162
|
<td class="list">
|
163
|
<div id='statesdiv'><?=gettext("Number of States:"); ?>
|
164
|
<select name='states' id='states'>
|
165
|
<option value='50' <?php echo ($numstate == "50") ? "selected=\"selected\"" : ""; ?>>50</option>
|
166
|
<option value='100' <?php echo ($numstate == "100") ? "selected=\"selected\"" : ""; ?>>100</option>
|
167
|
<option value='200' <?php echo ($numstate == "200") ? "selected=\"selected\"" : ""; ?>>200</option>
|
168
|
<option value='500' <?php echo ($numstate == "500") ? "selected=\"selected\"" : ""; ?>>500</option>
|
169
|
<option value='1000' <?php echo ($numstate == "1000") ? "selected=\"selected\"" : ""; ?>>1000</option>
|
170
|
<option value='all' <?php echo ($numstate == "all") ? "selected=\"selected\"" : ""; ?>>all</option>
|
171
|
</select>
|
172
|
</div>
|
173
|
</td>
|
174
|
</tr>
|
175
|
<tr>
|
176
|
<td colspan="3" align="center">
|
177
|
<table id="backuptable" class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
|
178
|
<tr>
|
179
|
<td align="center">
|
180
|
<table summary="results">
|
181
|
<tr>
|
182
|
<td>
|
183
|
<div id="pftopactivitydiv"><?=gettext("Gathering pfTOP activity, please wait...");?></div>
|
184
|
</td>
|
185
|
</tr>
|
186
|
</table>
|
187
|
</td>
|
188
|
</tr>
|
189
|
</table>
|
190
|
</td>
|
191
|
</tr>
|
192
|
</table>
|
193
|
</div>
|
194
|
</div>
|
195
|
</form>
|
196
|
<?php include("fend.inc"); ?>
|
197
|
<script type="text/javascript">
|
198
|
//<![CDATA[
|
199
|
jQuery("#viewtype").change(function() {
|
200
|
var selected = jQuery("#viewtype option:selected");
|
201
|
switch(selected.val()) {
|
202
|
case "queue":
|
203
|
case "label":
|
204
|
case "rules":
|
205
|
jQuery("#sorttype, #sorttypediv, #statesdiv, #states").hide();
|
206
|
break;
|
207
|
default:
|
208
|
jQuery("#sorttype, #sorttypediv, #statesdiv, #states").show();
|
209
|
}
|
210
|
});
|
211
|
//]]>
|
212
|
</script>
|
213
|
</body>
|
214
|
</html>
|