Project

General

Profile

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