Projet

Général

Profil

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

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

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

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

    
57
if ($_GET['filter'] && ($_GET['killfilter'] == "Kill")) {
58
	if (is_ipaddr($_GET['filter'])) {
59
		$tokill = escapeshellarg($_GET['filter'] . "/32");
60
	} elseif (is_subnet($_GET['filter'])) {
61
		$tokill = escapeshellarg($_GET['filter']);
62
	}
63
	$retval = mwexec("/sbin/pfctl -k {$tokill} -k 0/0");
64
	$retval = mwexec("/sbin/pfctl -k 0.0.0.0/0 -k {$tokill}");
65
}
66

    
67
$pgtitle = array(gettext("Diagnostics"),gettext("Show States"));
68
include("head.inc");
69

    
70
?>
71

    
72
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
73
<?php include("fbegin.inc"); ?>
74
<form action="diag_dump_states.php" method="get" name="iform">
75

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

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

    
87
		jQuery.ajax(
88
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
89
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
90
			{ type: "get", complete: removeComplete }
91
		);
92
	}
93

    
94
	function removeComplete(req) {
95
		var values = req.responseText.split("|");
96
		if(values[3] != "0") {
97
			alert('<?=gettext("An error occurred.");?>');
98
			return;
99
		}
100

    
101
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
102
			function(index,row) { jQuery(row).fadeOut(1000); }
103
		);
104
	}
105
//]]>
106
</script>
107

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

    
125
<!-- Start of tab content -->
126

    
127
<?php
128
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
129
?>
130

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

    
174
	$line_split = preg_split("/\s+/", $line);
175
	$type  = array_shift($line_split);
176
	$proto = array_shift($line_split);
177
	$state = array_pop($line_split);
178
	$info  = implode(" ", $line_split);
179

    
180
	/* break up info and extract $srcip and $dstip */
181
	$ends = preg_split("/\<?-\>?/", $info);
182
	$parts = explode(":", $ends[0]);
183
	$srcip = trim($parts[0]);
184
	$parts = explode(":", $ends[count($ends) - 1]);
185
	$dstip = trim($parts[0]);
186

    
187
?>
188
	<tr valign="top" id="r:<?= $srcip ?>:<?= $dstip ?>">
189
			<td class="listlr"><?= $proto ?></td>
190
			<td class="listr"><?= $info ?></td>
191
			<td class="listr"><?= $state ?></td>
192
			<td class="list">
193
			<img src="/themes/<?= $g['theme'] ?>/images/icons/icon_x.gif" height="17" width="17" border="0"
194
				onclick="removeState('<?= $srcip ?>', '<?= $dstip ?>');" style="cursor:pointer;"
195
				name="i:<?= $srcip ?>:<?= $dstip ?>"
196
				title="<?= gettext('Remove all state entries from') ?> <?= $srcip ?> <?= gettext('to') ?> <?= $dstip ?>" alt="" />
197
			</td>
198
	</tr>
199
<?php
200
	$row++;
201
	ob_flush();
202
}
203

    
204
if ($row == 0): ?>
205
	<tr>
206
		<td class="list" colspan="4" align="center" valign="top">
207
		<?= gettext("No states were found.") ?>
208
		</td>
209
	</tr>
210
<?php endif;
211
pclose($fd);
212
?>
213
			</tbody>
214
			</table>
215
		</td>
216
	</tr>
217
	<tr>
218
		<td class="list" colspan="4" align="center" valign="top">
219
		<?php if (!empty($_GET['filter'])): ?>
220
			<?=gettext("States matching current filter")?>: <?= $row ?>
221
		<?php endif; ?>
222
		</td>
223
	</tr>
224
</table>
225

    
226
<!-- End of tab content -->
227

    
228
		</div>
229
	</td>
230
  </tr>
231
</table>
232
</form>
233

    
234
<?php require("fend.inc"); ?>
235
</body>
236
</html>
(11-11/254)