Projet

Général

Profil

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

univnautes / usr / local / www / diag_dump_states.php @ 729b9f01

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($_GET['action']) {
47
	if($_GET['action'] == "remove") {
48
		if (is_ipaddr($_GET['srcip']) and is_ipaddr($_GET['dstip'])) {
49
			$retval = mwexec("/sbin/pfctl -k " . escapeshellarg($_GET['srcip']) . " -k " . escapeshellarg($_GET['dstip']));
50
			echo htmlentities("|{$_GET['srcip']}|{$_GET['dstip']}|{$retval}|");
51
		} else {
52
			echo gettext("invalid input");
53
		}
54
		return;
55
	}
56
}
57

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

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

    
76
?>
77

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

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

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

    
92
		jQuery.ajax(
93
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
94
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
95
			{ type: "get", complete: removeComplete }
96
		);
97
	}
98

    
99
	function removeComplete(req) {
100
		var values = req.responseText.split("|");
101
		if(values[3] != "0") {
102
			alert('<?=gettext("An error occurred.");?>');
103
			return;
104
		}
105

    
106
		jQuery('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
107
			function(index,row) { jQuery(row).fadeOut(1000); }
108
		);
109
	}
110
//]]>
111
</script>
112

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

    
130
<!-- Start of tab content -->
131

    
132
<?php
133
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
134
?>
135

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

    
180
	$line_split = preg_split("/\s+/", $line);
181

    
182
	$iface  = array_shift($line_split);
183
	$proto = array_shift($line_split);
184
	$state = array_pop($line_split);
185
	$info  = implode(" ", $line_split);
186

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

    
190
	/* break up info and extract $srcip and $dstip */
191
	$ends = preg_split("/\<?-\>?/", $info);
192
	$parts = explode(":", $ends[0]);
193
	$srcip = trim($parts[0]);
194
	$parts = explode(":", $ends[count($ends) - 1]);
195
	$dstip = trim($parts[0]);
196

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

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

    
237
<!-- End of tab content -->
238

    
239
		</div>
240
	</td>
241
  </tr>
242
</table>
243

    
244
<?php require("fend.inc"); ?>
245
</body>
246
</html>
(11-11/256)