Projet

Général

Profil

Télécharger (7,59 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_dump_states.php @ ac5934df

1
<?php
2
/*
3
	diag_dump_states.php
4
	Copyright (C) 2005-2009 Scott Ullrich
5
	Copyright (C) 2005 Colin Smith
6
	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
*/
29

    
30
/*
31
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
32
	pfSense_MODULE:	filter
33
*/
34

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

    
45
/* handle AJAX operations */
46
if(isset($_POST['action']) && $_POST['action'] == "remove") {
47
	if (isset($_POST['srcip']) && isset($_POST['dstip']) && is_ipaddr($_POST['srcip']) && is_ipaddr($_POST['dstip'])) {
48
		$retval = mwexec("/sbin/pfctl -k " . escapeshellarg($_POST['srcip']) . " -k " . escapeshellarg($_POST['dstip']));
49
		echo htmlentities("|{$_POST['srcip']}|{$_POST['dstip']}|{$retval}|");
50
	} else {
51
		echo gettext("invalid input");
52
	}
53
	return;
54
}
55

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

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

    
74
?>
75

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

    
79
<script type="text/javascript">
80
//<![CDATA[
81
	function removeState(srcip, dstip) {
82
		var busy = function(index,icon) {
83
			jQuery(icon).bind("onclick","");
84
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
85
			jQuery(icon).css("cursor","wait");
86
		}
87

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

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

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

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

    
118
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="tabcon">
119
	<tr>
120
		<td>
121
		<?php
122
			$tab_array = array();
123
			$tab_array[] = array(gettext("States"), true, "diag_dump_states.php");
124
			if (isset($config['system']['lb_use_sticky']))
125
				$tab_array[] = array(gettext("Source Tracking"), false, "diag_dump_states_sources.php");
126
			$tab_array[] = array(gettext("Reset States"), false, "diag_resetstate.php");
127
			display_top_tabs($tab_array);
128
		?>
129
		</td>
130
	</tr>
131
	<tr>
132
		<td>
133
			<div id="mainarea">
134

    
135
<!-- Start of tab content -->
136

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

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

    
185
	$line_split = preg_split("/\s+/", $line);
186

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

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

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

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

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

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

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

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