Project

General

Profile

Download (9.09 KB) Statistics
| Branch: | Tag: | Revision:
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 $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
?>
94
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
95
<?php include("fbegin.inc"); ?>
96
<form method="post" action="diag_system_pftop.php">
97
<script type="text/javascript">
98
//<![CDATA[
99
	function getpftopactivity() {
100
		var url = "/diag_system_pftop.php";
101
		var pars = 'getactivity=yes&sorttype=' + jQuery('#sorttype').val() + '&viewtype=' + jQuery('#viewtype').val() + '&states=' + jQuery('#states').val();
102
		jQuery.ajax(
103
			url,
104
			{
105
				type: 'post',
106
				data: pars,
107
				complete: activitycallback
108
			});
109
	}
110
	function activitycallback(transport) {
111
		jQuery('#pftopactivitydiv').html('<font face="Courier" size="2"><pre style="text-align:left;">' + transport.responseText + '<\/pre><\/font>');
112
		setTimeout('getpftopactivity()', 2500);
113
	}
114
	setTimeout('getpftopactivity()', 1000);
115
//]]>
116
</script>
117
<div id="maincontent">
118
<?php
119
	if ($savemsg) {
120
		echo "<div id=\"savemsg\">";
121
		print_info_box($savemsg);
122
		echo "</div>";
123
	}
124
	if ($input_errors) {
125
		print_input_errors($input_errors);
126
	}
127
?>
128
	<div id="mainarea" style="padding-bottom: 0px;">
129
		<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="diag system pftop">
130
			<tr>
131
				<td class="list">
132
					<div id='viewtypediv'><?=gettext("View type:"); ?>
133
						<select name='viewtype' id='viewtype'>
134
							<option value='default' <?php echo ($viewtype == "default") ? "selected=\"selected\"" : ""; ?>><?=gettext("Default");?></option>
135
							<option value='label' <?php echo ($viewtype == "label") ? "selected=\"selected\"" : ""; ?>><?=gettext("Label");?></option>
136
							<option value='long' <?php echo ($viewtype == "long") ? "selected=\"selected\"" : ""; ?>><?=gettext("Long");?></option>
137
							<option value='queue' <?php echo ($viewtype == "queue") ? "selected=\"selected\"" : ""; ?>><?=gettext("Queue");?></option>
138
							<option value='rules' <?php echo ($viewtype == "rules") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rules");?></option>
139
							<option value='size' <?php echo ($viewtype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
140
							<option value='speed' <?php echo ($viewtype == "speed") ? "selected=\"selected\"" : ""; ?>><?=gettext("Speed");?></option>
141
							<option value='state' <?php echo ($viewtype == "state") ? "selected=\"selected\"" : ""; ?>><?=gettext("State");?></option>
142
							<option value='time' <?php echo ($viewtype == "time") ? "selected=\"selected\"" : ""; ?>><?=gettext("Time");?></option>
143
						</select>
144
					</div>
145
				</td>
146
				<td class="list">
147
					<div id='sorttypediv'><?=gettext("Sort type:"); ?>
148
						<select name='sorttype' id='sorttype'>
149
							<option value='age' <?php echo ($sorttype == "age") ? "selected=\"selected\"" : ""; ?>><?=gettext("Age");?></option>
150
							<option value='bytes' <?php echo ($sorttype == "bytes") ? "selected=\"selected\"" : ""; ?>><?=gettext("Bytes");?></option>
151
							<option value='dest' <?php echo ($sorttype == "dest") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Address");?></option>
152
							<option value='dport' <?php echo ($sorttype == "dport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Port");?></option>
153
							<option value='exp' <?php echo ($sorttype == "exp") ? "selected=\"selected\"" : ""; ?>><?=gettext("Expiry");?></option>
154
							<option value='none' <?php echo ($sorttype == "none") ? "selected=\"selected\"" : ""; ?>><?=gettext("None");?></option>
155
							<option value='peak' <?php echo ($sorttype == "peak") ? "selected=\"selected\"" : ""; ?>><?=gettext("Peak");?></option>
156
							<option value='pkt' <?php echo ($sorttype == "pkt") ? "selected=\"selected\"" : ""; ?>><?=gettext("Packet");?></option>
157
							<option value='rate' <?php echo ($sorttype == "rate") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rate");?></option>
158
							<option value='size' <?php echo ($sorttype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
159
							<option value='sport' <?php echo ($sorttype == "sport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Port");?></option>
160
							<option value='src' <?php echo ($sorttype == "src") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Address");?></option>
161
						</select>
162
					</div>
163
				</td>
164
				<td class="list">
165
					<div id='statesdiv'><?=gettext("Number of States:"); ?>
166
						<select name='states' id='states'>
167
							<option value='50' <?php echo ($numstate == "50") ? "selected=\"selected\"" : ""; ?>>50</option>
168
							<option value='100' <?php echo ($numstate == "100") ? "selected=\"selected\"" : ""; ?>>100</option>
169
							<option value='200' <?php echo ($numstate == "200") ? "selected=\"selected\"" : ""; ?>>200</option>
170
							<option value='500' <?php echo ($numstate == "500") ? "selected=\"selected\"" : ""; ?>>500</option>
171
							<option value='1000' <?php echo ($numstate == "1000") ? "selected=\"selected\"" : ""; ?>>1000</option>
172
							<option value='all' <?php echo ($numstate == "all") ? "selected=\"selected\"" : ""; ?>>all</option>
173
						</select>
174
					</div>
175
				</td>
176
			</tr>
177
			<tr>
178
				<td colspan="3" align="center">
179
					<table id="backuptable" class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
180
						<tr>
181
							<td align="center">
182
								<table summary="results">
183
									<tr>
184
										<td>
185
											<div id="pftopactivitydiv"><?=gettext("Gathering pfTOP activity, please wait...");?></div>
186
										</td>
187
									</tr>
188
								</table>
189
							</td>
190
						</tr>
191
					</table>
192
				</td>
193
			</tr>
194
		</table>
195
	</div>
196
</div>
197
</form>
198
<?php include("fend.inc"); ?>
199
<script type="text/javascript">
200
//<![CDATA[
201
jQuery("#viewtype").change(function() {
202
	var selected = jQuery("#viewtype option:selected");
203
	switch (selected.val()) {
204
		case "queue":
205
		case "label":
206
		case "rules":
207
			jQuery("#sorttype, #sorttypediv, #statesdiv, #states").hide();
208
			break;
209
		default:
210
			jQuery("#sorttype, #sorttypediv, #statesdiv, #states").show();
211
	}
212
});
213
//]]>
214
</script>
215
</body>
216
</html>
(50-50/252)