Project

General

Profile

Download (7.53 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_dump_states.php
4
	Copyright (C) 2005 Colin Smith
5
	Copyright (C) 2005-2009 Scott Ullrich
6
	Copyright (C) 2013-2015 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_BUILDER_BINARIES:	/sbin/pfctl
33
	pfSense_MODULE:	filter
34
*/
35

    
36
##|+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
require_once("guiconfig.inc");
44
require_once("interfaces.inc");
45

    
46
/* handle AJAX operations */
47
if(isset($_POST['action']) && $_POST['action'] == "remove") {
48
	if (isset($_POST['srcip']) && isset($_POST['dstip']) && is_ipaddr($_POST['srcip']) && is_ipaddr($_POST['dstip'])) {
49
		$retval = pfSense_kill_states($_POST['srcip'], $_POST['dstip']);
50
		echo htmlentities("|{$_POST['srcip']}|{$_POST['dstip']}|0|");
51
	} else {
52
		echo gettext("invalid input");
53
	}
54
	return;
55
}
56

    
57
if (isset($_POST['filter']) && isset($_POST['killfilter'])) {
58
	if (is_ipaddr($_POST['filter'])) {
59
		$tokill = $_POST['filter'] . "/32";
60
	} elseif (is_subnet($_POST['filter'])) {
61
		$tokill = $_POST['filter'];
62
	} else {
63
		// Invalid filter
64
		$tokill = "";
65
	}
66
	if (!empty($tokill)) {
67
		$retval = pfSense_kill_states($tokill);
68
		$retval = pfSense_kill_states("0.0.0.0/0", $tokill);
69
	}
70
}
71

    
72
$pgtitle = array(gettext("Diagnostics"),gettext("Show States"));
73
include("head.inc");
74

    
75
?>
76

    
77
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
78
<?php include("fbegin.inc"); ?>
79

    
80
<script type="text/javascript">
81
//<![CDATA[
82
	function removeState(srcip, dstip) {
83
		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
		}
88

    
89
		jQuery('img[name="i:' + srcip + ":" + dstip + '"]').each(busy);
90

    
91
		jQuery.ajax(
92
			"<?=$_SERVER['SCRIPT_NAME'];?>",
93
			{
94
				type: "post",
95
				data: {
96
					action: "remove",
97
					srcip: srcip,
98
					dstip: dstip
99
				},
100
				complete: removeComplete
101
			}
102
		);
103
	}
104

    
105
	function removeComplete(req) {
106
		var values = req.responseText.split("|");
107
		if(values[3] != "0") {
108
			alert('<?=gettext("An error occurred.");?>');
109
			return;
110
		}
111

    
112
		jQuery('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
113
			function(index,row) { jQuery(row).fadeOut(1000); }
114
		);
115
	}
116
//]]>
117
</script>
118

    
119
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tabcon">
120
	<tr>
121
		<td>
122
		<?php
123
			$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
			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
<?php
139
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
140
?>
141

    
142
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="states">
143
	<tr>
144
		<td>
145
			<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="post" name="iform">
146
			<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="filter">
147
				<tr>
148
					<td>
149
						<?=gettext("Current total state count");?>: <?= $current_statecount ?>
150
					</td>
151
					<td style="font-weight:bold;" align="right">
152
						<?=gettext("Filter expression:");?>
153
						<input type="text" name="filter" class="formfld search" value="<?=htmlspecialchars($_POST['filter']);?>" size="30" />
154
						<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" />
155
					<?php if (isset($_POST['filter']) && (is_ipaddr($_POST['filter']) || is_subnet($_POST['filter']))): ?>
156
						<input type="submit" class="formbtn" name="killfilter" value="<?=gettext("Kill");?>" />
157
					<?php endif; ?>
158
					</td>
159
				</tr>
160
			</table>
161
			</form>
162
		</td>
163
	</tr>
164
	<tr>
165
		<td>
166
			<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0" summary="results">
167
				<thead>
168
				<tr>
169
					<th class="listhdrr" width="5%"><?=gettext("Int");?></th>
170
					<th class="listhdrr" width="5%"><?=gettext("Proto");?></th>
171
					<th class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></th>
172
					<th class="listhdr" width="24%"><?=gettext("State");?></th>
173
					<th class="list sort_ignore" width="1%"></th>
174
				</tr>
175
				</thead>
176
				<tbody>
177
<?php
178
$row = 0;
179
/* get our states */
180
$grepline = (isset($_POST['filter'])) ? "| /usr/bin/egrep " . escapeshellarg(htmlspecialchars($_POST['filter'])) : "";
181
$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

    
188
	$iface  = array_shift($line_split);
189
	$proto = array_shift($line_split);
190
	$state = array_pop($line_split);
191
	$info  = implode(" ", $line_split);
192

    
193
	// 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
	/* 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
	<tr valign="top" id="r:<?= $srcip ?>:<?= $dstip ?>">
205
			<td class="listlr"><?= $iface ?></td>
206
			<td class="listr"><?= $proto ?></td>
207
			<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
			</td>
215
	</tr>
216
<?php
217
	$row++;
218
	ob_flush();
219
}
220

    
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
?>
230
			</tbody>
231
			</table>
232
		</td>
233
	</tr>
234
	<tr>
235
		<td class="list" colspan="4" align="center" valign="top">
236
		<?php if (isset($_POST['filter']) && !empty($_POST['filter'])): ?>
237
			<?=gettext("States matching current filter")?>: <?= $row ?>
238
		<?php endif; ?>
239
		</td>
240
	</tr>
241
</table>
242

    
243
<!-- End of tab content -->
244

    
245
		</div>
246
	</td>
247
  </tr>
248
</table>
249

    
250
<?php require("fend.inc"); ?>
251
</body>
252
</html>
(11-11/256)