Project

General

Profile

Download (9.14 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-2014 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
		<div id="mainarea" style="padding-bottom: 0px;">
128
		<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="diag system pftop">
129
			<tr>
130
				<td class="list">
131
					<div id='viewtypediv'><?=gettext("View type:"); ?>
132
						<select name='viewtype' id='viewtype'>
133
							<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
						</select>
143
					</div>
144
				</td>
145
				<td class="list">
146
					<div id='sorttypediv'><?=gettext("Sort type:"); ?>
147
						<select name='sorttype' id='sorttype'>
148
							<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
						</select>
161
					</div>
162
				</td>
163
				<td class="list">
164
					<div id='statesdiv'><?=gettext("Number of States:"); ?>
165
						<select name='states' id='states'>
166
							<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
						</select>
173
					</div>
174
				</td>
175
			</tr>
176
			<tr>
177
				<td colspan="3" align="center">
178
					<table id="backuptable" class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="tabcont">
179
						<tr>
180
							<td align="center">
181
									<table summary="results">
182
										<tr>
183
											<td>
184
												<div id="pftopactivitydiv"><?=gettext("Gathering pfTOP activity, please wait...");?></div>
185
											</td>
186
										</tr>
187
									</table>
188
							</td>
189
						</tr>
190
					</table>
191
				</td>
192
		  </tr>
193
		</table>
194
	</div>
195
</div>
196
</form>
197
<?php include("fend.inc"); ?>
198
<script type="text/javascript">
199
//<![CDATA[
200
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
			jQuery("#sorttype, #sorttypediv, #statesdiv, #states").hide();
207
			break;
208
		default:
209
			jQuery("#sorttype, #sorttypediv, #statesdiv, #states").show();
210
	}
211
});
212
//]]>
213
</script>
214
</body>
215
</html>
(50-50/256)