Project

General

Profile

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