Project

General

Profile

Download (7.43 KB) Statistics
| Branch: | Tag: | Revision:
1 92cc7528 Scott Ullrich
<?php
2
/*
3 a09d815a Scott Ullrich
	diag_dump_states.php
4 13d193c2 Scott Ullrich
	Copyright (C) 2005-2009 Scott Ullrich
5
	Copyright (C) 2005 Colin Smith
6 a09d815a 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 92cc7528 Scott Ullrich
*/
29
30 13d193c2 Scott Ullrich
/*
31 032d7999 jim-p
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
32 13d193c2 Scott Ullrich
	pfSense_MODULE:	filter
33
*/
34
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-diagnostics-showstates
37
##|*NAME=Diagnostics: Show States page
38
##|*DESCR=Allow access to the 'Diagnostics: Show States' page.
39
##|*MATCH=diag_dump_states.php*
40
##|-PRIV
41
42 92cc7528 Scott Ullrich
require_once("guiconfig.inc");
43 5344099a jim-p
require_once("interfaces.inc");
44 92cc7528 Scott Ullrich
45 a09d815a Scott Ullrich
/* handle AJAX operations */
46
if($_GET['action']) {
47 e8d93059 Bill Marquette
	if($_GET['action'] == "remove") {
48 29f76490 jim-p
		if (is_ipaddr($_GET['srcip']) and is_ipaddr($_GET['dstip'])) {
49
			$retval = mwexec("/sbin/pfctl -k " . escapeshellarg($_GET['srcip']) . " -k " . escapeshellarg($_GET['dstip']));
50
			echo htmlentities("|{$_GET['srcip']}|{$_GET['dstip']}|{$retval}|");
51 e8d93059 Bill Marquette
		} else {
52 f8ec8de4 Renato Botelho
			echo gettext("invalid input");
53 e8d93059 Bill Marquette
		}
54 5344099a jim-p
		return;
55 a09d815a Scott Ullrich
	}
56
}
57
58 c0ee2a01 jim-p
if ($_GET['filter'] && ($_GET['killfilter'] == "Kill")) {
59
	if (is_ipaddr($_GET['filter'])) {
60 032d7999 jim-p
		$tokill = escapeshellarg($_GET['filter'] . "/32");
61 c0ee2a01 jim-p
	} elseif (is_subnet($_GET['filter'])) {
62 032d7999 jim-p
		$tokill = escapeshellarg($_GET['filter']);
63 5344099a jim-p
	} else {
64
		// Invalid filter
65
		$tokill = "";
66
	}
67
	if (!empty($tokill)) {
68
		$retval = mwexec("/sbin/pfctl -k {$tokill} -k 0/0");
69
		$retval = mwexec("/sbin/pfctl -k 0.0.0.0/0 -k {$tokill}");
70 c0ee2a01 jim-p
	}
71
}
72
73 9733b7bb Vinicius Coque
$pgtitle = array(gettext("Diagnostics"),gettext("Show States"));
74 e8d93059 Bill Marquette
include("head.inc");
75
76 92cc7528 Scott Ullrich
?>
77
78 a09d815a Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
79 ca77763b Scott Ullrich
<?php include("fbegin.inc"); ?>
80 a09d815a Scott Ullrich
81
<script type="text/javascript">
82 a2b16c0c Colin Fleming
//<![CDATA[
83 a09d815a Scott Ullrich
	function removeState(srcip, dstip) {
84 e03ef9a0 Vinicius Coque
		var busy = function(index,icon) {
85
			jQuery(icon).bind("onclick","");
86
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
87
			jQuery(icon).css("cursor","wait");
88 a09d815a Scott Ullrich
		}
89
90 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + srcip + ":" + dstip + '"]').each(busy);
91 a09d815a Scott Ullrich
92 e03ef9a0 Vinicius Coque
		jQuery.ajax(
93 a09d815a Scott Ullrich
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
94
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
95 e03ef9a0 Vinicius Coque
			{ type: "get", complete: removeComplete }
96 a09d815a Scott Ullrich
		);
97
	}
98
99
	function removeComplete(req) {
100
		var values = req.responseText.split("|");
101
		if(values[3] != "0") {
102 30f302f9 Scott Ullrich
			alert('<?=gettext("An error occurred.");?>');
103 a09d815a Scott Ullrich
			return;
104
		}
105
106 df13b077 jim-p
		jQuery('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
107 e03ef9a0 Vinicius Coque
			function(index,row) { jQuery(row).fadeOut(1000); }
108 a09d815a Scott Ullrich
		);
109
	}
110 a2b16c0c Colin Fleming
//]]>
111 a09d815a Scott Ullrich
</script>
112
113 a2b16c0c Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tabcon">
114 a09d815a Scott Ullrich
	<tr>
115
		<td>
116
		<?php
117 f4c2d976 jim-p
			$tab_array = array();
118
			$tab_array[] = array(gettext("States"), true, "diag_dump_states.php");
119
			if (isset($config['system']['lb_use_sticky']))
120
				$tab_array[] = array(gettext("Source Tracking"), false, "diag_dump_states_sources.php");
121
			$tab_array[] = array(gettext("Reset States"), false, "diag_resetstate.php");
122 a09d815a Scott Ullrich
			display_top_tabs($tab_array);
123
		?>
124
		</td>
125
	</tr>
126
	<tr>
127
		<td>
128
			<div id="mainarea">
129
130
<!-- Start of tab content -->
131
132 b4031ab6 Scott Ullrich
<?php
133
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
134
?>
135
136 a2b16c0c Colin Fleming
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="states">
137 a09d815a Scott Ullrich
	<tr>
138
		<td>
139 729b9f01 Renato Botelho
			<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get" name="iform">
140 a2b16c0c Colin Fleming
			<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="filter">
141 ba6d49ff Scott Ullrich
				<tr>
142 c0ee2a01 jim-p
					<td>
143 032d7999 jim-p
						<?=gettext("Current total state count");?>: <?= $current_statecount ?>
144 c0ee2a01 jim-p
					</td>
145 a09d815a Scott Ullrich
					<td style="font-weight:bold;" align="right">
146 673ee314 Carlos Eduardo Ramos
						<?=gettext("Filter expression:");?>
147 034f08e7 Scott Ullrich
						<input type="text" name="filter" class="formfld search" value="<?=htmlspecialchars($_GET['filter']);?>" size="30" />
148 a09d815a Scott Ullrich
						<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" />
149 c0ee2a01 jim-p
					<?php if (is_ipaddr($_GET['filter']) || is_subnet($_GET['filter'])): ?>
150
						<input type="submit" class="formbtn" name="killfilter" value="<?=gettext("Kill");?>" />
151
					<?php endif; ?>
152 140ed85e Renato Botelho
					</td>
153 a09d815a Scott Ullrich
				</tr>
154
			</table>
155
			</form>
156
		</td>
157
	</tr>
158
	<tr>
159
		<td>
160 a2b16c0c Colin Fleming
			<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0" summary="results">
161 5b3f9124 jim-p
				<thead>
162 a09d815a Scott Ullrich
				<tr>
163 5344099a jim-p
					<th class="listhdrr" width="5%"><?=gettext("Int");?></th>
164
					<th class="listhdrr" width="5%"><?=gettext("Proto");?></th>
165 5b3f9124 jim-p
					<th class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></th>
166
					<th class="listhdr" width="24%"><?=gettext("State");?></th>
167 79633b6c Evgeny Yurchenko
					<th class="list sort_ignore" width="1%"></th>
168 ba6d49ff Scott Ullrich
				</tr>
169 5b3f9124 jim-p
				</thead>
170
				<tbody>
171 92cc7528 Scott Ullrich
<?php
172 a09d815a Scott Ullrich
$row = 0;
173 032d7999 jim-p
/* get our states */
174 5344099a jim-p
$grepline = ($_GET['filter']) ? "| /usr/bin/egrep " . escapeshellarg(htmlspecialchars($_GET['filter'])) : "";
175 032d7999 jim-p
$fd = popen("/sbin/pfctl -s state {$grepline}", "r" );
176
while ($line = chop(fgets($fd))) {
177
	if($row >= 10000)
178
		break;
179
180
	$line_split = preg_split("/\s+/", $line);
181 5344099a jim-p
182
	$iface  = array_shift($line_split);
183 032d7999 jim-p
	$proto = array_shift($line_split);
184
	$state = array_pop($line_split);
185
	$info  = implode(" ", $line_split);
186
187 5344099a jim-p
	// We may want to make this optional, with a large state table, this could get to be expensive.
188
	$iface = convert_real_interface_to_friendly_descr($iface);
189
190 032d7999 jim-p
	/* break up info and extract $srcip and $dstip */
191
	$ends = preg_split("/\<?-\>?/", $info);
192
	$parts = explode(":", $ends[0]);
193
	$srcip = trim($parts[0]);
194
	$parts = explode(":", $ends[count($ends) - 1]);
195
	$dstip = trim($parts[0]);
196
197
?>
198 df13b077 jim-p
	<tr valign="top" id="r:<?= $srcip ?>:<?= $dstip ?>">
199 5344099a jim-p
			<td class="listlr"><?= $iface ?></td>
200
			<td class="listr"><?= $proto ?></td>
201 032d7999 jim-p
			<td class="listr"><?= $info ?></td>
202
			<td class="listr"><?= $state ?></td>
203
			<td class="list">
204
			<img src="/themes/<?= $g['theme'] ?>/images/icons/icon_x.gif" height="17" width="17" border="0"
205
				onclick="removeState('<?= $srcip ?>', '<?= $dstip ?>');" style="cursor:pointer;"
206
				name="i:<?= $srcip ?>:<?= $dstip ?>"
207
				title="<?= gettext('Remove all state entries from') ?> <?= $srcip ?> <?= gettext('to') ?> <?= $dstip ?>" alt="" />
208 a09d815a Scott Ullrich
			</td>
209 032d7999 jim-p
	</tr>
210
<?php
211
	$row++;
212
	ob_flush();
213 a09d815a Scott Ullrich
}
214 032d7999 jim-p
215
if ($row == 0): ?>
216
	<tr>
217
		<td class="list" colspan="4" align="center" valign="top">
218
		<?= gettext("No states were found.") ?>
219
		</td>
220
	</tr>
221
<?php endif;
222
pclose($fd);
223 92cc7528 Scott Ullrich
?>
224 5b3f9124 jim-p
			</tbody>
225 a09d815a Scott Ullrich
			</table>
226
		</td>
227
	</tr>
228 032d7999 jim-p
	<tr>
229
		<td class="list" colspan="4" align="center" valign="top">
230
		<?php if (!empty($_GET['filter'])): ?>
231
			<?=gettext("States matching current filter")?>: <?= $row ?>
232
		<?php endif; ?>
233
		</td>
234
	</tr>
235 92cc7528 Scott Ullrich
</table>
236 a09d815a Scott Ullrich
237
<!-- End of tab content -->
238
239
		</div>
240
	</td>
241
  </tr>
242 92cc7528 Scott Ullrich
</table>
243 1f97829e Scott Ullrich
244 a09d815a Scott Ullrich
<?php require("fend.inc"); ?>
245 92cc7528 Scott Ullrich
</body>
246
</html>