Project

General

Profile

Download (9.14 KB) Statistics
| Branch: | Tag: | Revision:
1 14f84bc9 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4 83c56e9c Scott Ullrich
    diag_system_pftop.php
5 13d193c2 Scott Ullrich
    Copyright (C) 2008-2009 Scott Ullrich
6 ed2d1343 Renato Botelho
    Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7 14f84bc9 Scott Ullrich
    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 13d193c2 Scott Ullrich
/*
32
	pfSense_MODULE:	filter
33
*/
34
35 14f84bc9 Scott Ullrich
##|+PRIV
36 7997ed44 Renato Botelho
##|*IDENT=page-diagnostics-system-pftop
37
##|*NAME=Diagnostics: pfTop
38
##|*DESCR=Allows access to the 'Diagnostics: pfTop' page
39 fce938b3 jim-p
##|*MATCH=diag_system_pftop.php*
40 14f84bc9 Scott Ullrich
##|-PRIV
41
42
require("guiconfig.inc");
43
44 a1054b46 Scott Ullrich
$pgtitle = gettext("Diagnostics: pfTop");
45 14f84bc9 Scott Ullrich
46 c668eaed Warren Baker
$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 38de3c9d Warren Baker
$viewall = array('queue', 'label', 'rules');
49
$numstates = array('50', '100', '200', '500', '1000', 'all');
50 c668eaed Warren Baker
51 14f84bc9 Scott Ullrich
if($_REQUEST['getactivity']) {
52 38de3c9d Warren Baker
	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 c668eaed Warren Baker
		$viewtype = escapeshellarg($_REQUEST['viewtype']);
56 ea031bde Warren Baker
		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 c668eaed Warren Baker
	} else {
64 19f7146a bcyrill
		$sorttype = "bytes";
65
		$viewtype = "default";
66 38de3c9d Warren Baker
		$numstate = "100";
67 c668eaed Warren Baker
	}
68 ba17b457 Warren Baker
69
	$text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`;
70 14f84bc9 Scott Ullrich
	echo $text;
71
	exit;
72
}
73
74
include("head.inc");
75
76 38de3c9d Warren Baker
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 ea031bde Warren Baker
	$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 c668eaed Warren Baker
} else {
88 19f7146a bcyrill
	$sorttype = "bytes";
89
	$viewtype = "default";
90 38de3c9d Warren Baker
	$numstate = "100";
91 c668eaed Warren Baker
}
92 14f84bc9 Scott Ullrich
93
?>
94
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
95 99f089be Colin Fleming
<?php include("fbegin.inc"); ?>
96 6a594976 Scott Ullrich
<form method="post" action="diag_system_pftop.php">
97 14f84bc9 Scott Ullrich
<script type="text/javascript">
98 99f089be Colin Fleming
//<![CDATA[
99 c668eaed Warren Baker
	function getpftopactivity() {
100 14f84bc9 Scott Ullrich
		var url = "/diag_system_pftop.php";
101 38de3c9d Warren Baker
		var pars = 'getactivity=yes&sorttype=' + jQuery('#sorttype').val() + '&viewtype=' + jQuery('#viewtype').val() + '&states=' + jQuery('#states').val();
102 ebfc87d6 Vinicius Coque
		jQuery.ajax(
103 14f84bc9 Scott Ullrich
			url,
104
			{
105 ebfc87d6 Vinicius Coque
				type: 'post',
106
				data: pars,
107
				complete: activitycallback
108 14f84bc9 Scott Ullrich
			});
109
	}
110
	function activitycallback(transport) {
111 99f089be Colin Fleming
		jQuery('#pftopactivitydiv').html('<font face="Courier" size="2"><pre style="text-align:left;">' + transport.responseText  + '<\/pre><\/font>');
112 c668eaed Warren Baker
		setTimeout('getpftopactivity()', 2500);
113 14f84bc9 Scott Ullrich
	}
114 c668eaed Warren Baker
	setTimeout('getpftopactivity()', 1000);
115 99f089be Colin Fleming
//]]>
116 14f84bc9 Scott Ullrich
</script>
117 99f089be Colin Fleming
<div id="maincontent">
118 14f84bc9 Scott Ullrich
<?php
119
	if($savemsg) {
120 99f089be Colin Fleming
		echo "<div id=\"savemsg\">";
121 14f84bc9 Scott Ullrich
		print_info_box($savemsg);
122
		echo "</div>";	
123
	}
124
	if ($input_errors)
125
		print_input_errors($input_errors);
126
?>
127 38de3c9d Warren Baker
		<div id="mainarea" style="padding-bottom: 0px;">
128 99f089be Colin Fleming
		<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="diag system pftop">
129 38de3c9d Warren Baker
			<tr>
130
				<td class="list">
131
					<div id='viewtypediv'><?=gettext("View type:"); ?>
132
						<select name='viewtype' id='viewtype'>
133 99f089be Colin Fleming
							<option value='default' <?php echo ($viewtype == "default") ? "selected=\"selected\"" : ""; ?>><?=gettext("Default");?></option>
134
							<option value='label' <?php echo ($viewtype == "label") ? "selected=\"selected\"" : ""; ?>><?=gettext("Label");?></option>
135
							<option value='long' <?php echo ($viewtype == "long") ? "selected=\"selected\"" : ""; ?>><?=gettext("Long");?></option>
136
							<option value='queue' <?php echo ($viewtype == "queue") ? "selected=\"selected\"" : ""; ?>><?=gettext("Queue");?></option>
137
							<option value='rules' <?php echo ($viewtype == "rules") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rules");?></option>
138
							<option value='size' <?php echo ($viewtype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
139
							<option value='speed' <?php echo ($viewtype == "speed") ? "selected=\"selected\"" : ""; ?>><?=gettext("Speed");?></option>
140
							<option value='state' <?php echo ($viewtype == "state") ? "selected=\"selected\"" : ""; ?>><?=gettext("State");?></option>
141
							<option value='time' <?php echo ($viewtype == "time") ? "selected=\"selected\"" : ""; ?>><?=gettext("Time");?></option>
142 38de3c9d Warren Baker
						</select>
143
					</div>
144
				</td>
145
				<td class="list">
146
					<div id='sorttypediv'><?=gettext("Sort type:"); ?>
147
						<select name='sorttype' id='sorttype'>
148 99f089be Colin Fleming
							<option value='age' <?php echo ($sorttype == "age") ? "selected=\"selected\"" : ""; ?>><?=gettext("Age");?></option>
149
							<option value='bytes' <?php echo ($sorttype == "bytes") ? "selected=\"selected\"" : ""; ?>><?=gettext("Bytes");?></option>
150
							<option value='dest' <?php echo ($sorttype == "dest") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Address");?></option>
151
							<option value='dport' <?php echo ($sorttype == "dport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Port");?></option>
152
							<option value='exp' <?php echo ($sorttype == "exp") ? "selected=\"selected\"" : ""; ?>><?=gettext("Expiry");?></option>
153
							<option value='none' <?php echo ($sorttype == "none") ? "selected=\"selected\"" : ""; ?>><?=gettext("None");?></option>
154
							<option value='peak' <?php echo ($sorttype == "peak") ? "selected=\"selected\"" : ""; ?>><?=gettext("Peak");?></option>
155
							<option value='pkt' <?php echo ($sorttype == "pkt") ? "selected=\"selected\"" : ""; ?>><?=gettext("Packet");?></option>
156
							<option value='rate' <?php echo ($sorttype == "rate") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rate");?></option>
157
							<option value='size' <?php echo ($sorttype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
158
							<option value='sport' <?php echo ($sorttype == "sport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Port");?></option>
159
							<option value='src' <?php echo ($sorttype == "src") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Address");?></option>
160 38de3c9d Warren Baker
						</select>
161
					</div>
162
				</td>
163
				<td class="list">
164
					<div id='statesdiv'><?=gettext("Number of States:"); ?>
165
						<select name='states' id='states'>
166 99f089be Colin Fleming
							<option value='50' <?php echo ($numstate == "50") ? "selected=\"selected\"" : ""; ?>>50</option>
167
							<option value='100' <?php echo ($numstate == "100") ? "selected=\"selected\"" : ""; ?>>100</option>
168
							<option value='200' <?php echo ($numstate == "200") ? "selected=\"selected\"" : ""; ?>>200</option>
169
							<option value='500' <?php echo ($numstate == "500") ? "selected=\"selected\"" : ""; ?>>500</option>
170
							<option value='1000' <?php echo ($numstate == "1000") ? "selected=\"selected\"" : ""; ?>>1000</option>
171
							<option value='all' <?php echo ($numstate == "all") ? "selected=\"selected\"" : ""; ?>>all</option>
172 38de3c9d Warren Baker
						</select>
173
					</div>
174
				</td>
175
			</tr>
176
			<tr>
177 99f089be Colin Fleming
				<td colspan="3" align="center">
178
					<table id="backuptable" class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
179 38de3c9d Warren Baker
						<tr>
180 99f089be Colin Fleming
							<td align="center">
181
									<table summary="results">
182 38de3c9d Warren Baker
										<tr>
183
											<td>
184 99f089be Colin Fleming
												<div id="pftopactivitydiv"><?=gettext("Gathering pfTOP activity, please wait...");?></div>
185 38de3c9d Warren Baker
											</td>
186
										</tr>
187
									</table>
188
							</td>
189
						</tr>
190
					</table>
191
				</td>
192
		  </tr>
193
		</table>
194 14f84bc9 Scott Ullrich
	</div>
195 99f089be Colin Fleming
</div>
196 14f84bc9 Scott Ullrich
</form>
197
<?php include("fend.inc"); ?>
198 91f026b0 ayvis
<script type="text/javascript">
199 99f089be Colin Fleming
//<![CDATA[
200 c668eaed Warren Baker
jQuery("#viewtype").change(function() {
201
	var selected = jQuery("#viewtype option:selected");
202
	switch(selected.val()) {
203
		case "queue":
204
		case "label":
205
		case "rules":
206 38de3c9d Warren Baker
			jQuery("#sorttype, #sorttypediv, #statesdiv, #states").hide();
207 c668eaed Warren Baker
			break;
208
		default:
209 38de3c9d Warren Baker
			jQuery("#sorttype, #sorttypediv, #statesdiv, #states").show();
210 c668eaed Warren Baker
	}
211
});
212 99f089be Colin Fleming
//]]>
213 c668eaed Warren Baker
</script>
214 14f84bc9 Scott Ullrich
</body>
215 7997ed44 Renato Botelho
</html>