Project

General

Profile

Download (7.54 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
			}
128
			$tab_array[] = array(gettext("Reset States"), false, "diag_resetstate.php");
129
			display_top_tabs($tab_array);
130
		?>
131
		</td>
132
	</tr>
133
	<tr>
134
		<td>
135
			<div id="mainarea">
136

    
137
<!-- Start of tab content -->
138

    
139
<?php
140
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
141
?>
142

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

    
188
	$line_split = preg_split("/\s+/", $line);
189

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

    
195
	// We may want to make this optional, with a large state table, this could get to be expensive.
196
	$iface = convert_real_interface_to_friendly_descr($iface);
197

    
198
	/* break up info and extract $srcip and $dstip */
199
	$ends = preg_split("/\<?-\>?/", $info);
200
	$parts = explode(":", $ends[0]);
201
	$srcip = trim($parts[0]);
202
	$parts = explode(":", $ends[count($ends) - 1]);
203
	$dstip = trim($parts[0]);
204

    
205
?>
206
	<tr valign="top" id="r:<?= $srcip ?>:<?= $dstip ?>">
207
		<td class="listlr"><?= $iface ?></td>
208
		<td class="listr"><?= $proto ?></td>
209
		<td class="listr"><?= $info ?></td>
210
		<td class="listr"><?= $state ?></td>
211
		<td class="list">
212
		<img src="/themes/<?= $g['theme'] ?>/images/icons/icon_x.gif" height="17" width="17" border="0"
213
			onclick="removeState('<?= $srcip ?>', '<?= $dstip ?>');" style="cursor:pointer;"
214
			name="i:<?= $srcip ?>:<?= $dstip ?>"
215
			title="<?= gettext('Remove all state entries from') ?> <?= $srcip ?> <?= gettext('to') ?> <?= $dstip ?>" alt="" />
216
		</td>
217
	</tr>
218
<?php
219
	$row++;
220
	ob_flush();
221
}
222

    
223
if ($row == 0): ?>
224
	<tr>
225
		<td class="list" colspan="4" align="center" valign="top">
226
		<?= gettext("No states were found.") ?>
227
		</td>
228
	</tr>
229
<?php
230
endif;
231
pclose($fd);
232
?>
233
			</tbody>
234
			</table>
235
		</td>
236
	</tr>
237
	<tr>
238
		<td class="list" colspan="4" align="center" valign="top">
239
		<?php if (isset($_POST['filter']) && !empty($_POST['filter'])): ?>
240
			<?=gettext("States matching current filter")?>: <?= $row ?>
241
		<?php endif; ?>
242
		</td>
243
	</tr>
244
</table>
245

    
246
<!-- End of tab content -->
247

    
248
		</div>
249
	</td>
250
  </tr>
251
</table>
252

    
253
<?php require("fend.inc"); ?>
254
</body>
255
</html>
(11-11/256)