Project

General

Profile

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