Project

General

Profile

Download (6.98 KB) Statistics
| Branch: | Tag: | Revision:
1 92cc7528 Scott Ullrich
<?php
2
/*
3 a09d815a Scott Ullrich
	diag_dump_states.php
4 13d193c2 Scott Ullrich
	Copyright (C) 2005-2009 Scott Ullrich
5
	Copyright (C) 2005 Colin Smith
6 a09d815a Scott Ullrich
	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 92cc7528 Scott Ullrich
*/
29
30 13d193c2 Scott Ullrich
/*
31
	pfSense_BUILDER_BINARIES:	/sbin/pfctl	
32
	pfSense_MODULE:	filter
33
*/
34
35 6b07c15a Matthew Grooms
##|+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 92cc7528 Scott Ullrich
require_once("guiconfig.inc");
43
44 a09d815a Scott Ullrich
/* handle AJAX operations */
45
if($_GET['action']) {
46 e8d93059 Bill Marquette
	if($_GET['action'] == "remove") {
47 29f76490 jim-p
		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 e8d93059 Bill Marquette
		} else {
51 f8ec8de4 Renato Botelho
			echo gettext("invalid input");
52 e8d93059 Bill Marquette
		}
53 a09d815a Scott Ullrich
		exit;
54
	}
55
}
56
57 c0ee2a01 jim-p
if ($_GET['filter'] && ($_GET['killfilter'] == "Kill")) {
58
	if (is_ipaddr($_GET['filter'])) {
59
		$tokill = $_GET['filter'] . "/32";
60
	} elseif (is_subnet($_GET['filter'])) {
61
		$tokill = $_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 ca77763b Scott Ullrich
/* get our states */
68
if($_GET['filter']) {
69 034f08e7 Scott Ullrich
	exec("/sbin/pfctl -s state | grep " . escapeshellarg(htmlspecialchars($_GET['filter'])), $states);
70 a09d815a Scott Ullrich
}
71
else {
72
	exec("/sbin/pfctl -s state", $states);
73 ca77763b Scott Ullrich
}
74 92cc7528 Scott Ullrich
75 9733b7bb Vinicius Coque
$pgtitle = array(gettext("Diagnostics"),gettext("Show States"));
76 e8d93059 Bill Marquette
include("head.inc");
77
78 92cc7528 Scott Ullrich
?>
79
80 a09d815a Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
81
<script src="/javascript/sorttable.js" type="text/javascript"></script>
82 ca77763b Scott Ullrich
<?php include("fbegin.inc"); ?>
83 742ee135 Scott Ullrich
<form action="diag_dump_states.php" method="get" name="iform">
84 a09d815a Scott Ullrich
85
<script type="text/javascript">
86
	function removeState(srcip, dstip) {
87 e03ef9a0 Vinicius Coque
		var busy = function(index,icon) {
88
			jQuery(icon).bind("onclick","");
89
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
90
			jQuery(icon).css("cursor","wait");
91 a09d815a Scott Ullrich
		}
92
93 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + srcip + ":" + dstip + '"]').each(busy);
94 a09d815a Scott Ullrich
95 e03ef9a0 Vinicius Coque
		jQuery.ajax(
96 a09d815a Scott Ullrich
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
97
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
98 e03ef9a0 Vinicius Coque
			{ type: "get", complete: removeComplete }
99 a09d815a Scott Ullrich
		);
100
	}
101
102
	function removeComplete(req) {
103
		var values = req.responseText.split("|");
104
		if(values[3] != "0") {
105 30f302f9 Scott Ullrich
			alert('<?=gettext("An error occurred.");?>');
106 a09d815a Scott Ullrich
			return;
107
		}
108
109 e03ef9a0 Vinicius Coque
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
110
			function(index,row) { jQuery(row).fadeOut(1000); }
111 a09d815a Scott Ullrich
		);
112
	}
113
</script>
114
115 92cc7528 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
116 a09d815a Scott Ullrich
	<tr>
117
		<td>
118
		<?php
119 f4c2d976 jim-p
			$tab_array = array();
120
			$tab_array[] = array(gettext("States"), true, "diag_dump_states.php");
121
			if (isset($config['system']['lb_use_sticky']))
122
				$tab_array[] = array(gettext("Source Tracking"), false, "diag_dump_states_sources.php");
123
			$tab_array[] = array(gettext("Reset States"), false, "diag_resetstate.php");
124 a09d815a Scott Ullrich
			display_top_tabs($tab_array);
125
		?>
126
		</td>
127
	</tr>
128
	<tr>
129
		<td>
130
			<div id="mainarea">
131
132
<!-- Start of tab content -->
133
134 b4031ab6 Scott Ullrich
<?php
135
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
136
?>
137
138 5b3f9124 jim-p
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
139 a09d815a Scott Ullrich
	<tr>
140
		<td>
141
			<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get">
142
			<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
143 ba6d49ff Scott Ullrich
				<tr>
144 c0ee2a01 jim-p
					<td>
145
						<?=gettext("Current state count");?>: <?= $current_statecount ?>
146
						<?php if (!empty($_GET['filter'])): ?>
147
							(<?=gettext("Matching filter")?>: <?= count($states) ?>)
148
						<?php endif; ?>
149
					</td>
150 a09d815a Scott Ullrich
					<td style="font-weight:bold;" align="right">
151 673ee314 Carlos Eduardo Ramos
						<?=gettext("Filter expression:");?>
152 034f08e7 Scott Ullrich
						<input type="text" name="filter" class="formfld search" value="<?=htmlspecialchars($_GET['filter']);?>" size="30" />
153 a09d815a Scott Ullrich
						<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" />
154 c0ee2a01 jim-p
					<?php if (is_ipaddr($_GET['filter']) || is_subnet($_GET['filter'])): ?>
155
						<input type="submit" class="formbtn" name="killfilter" value="<?=gettext("Kill");?>" />
156
					<?php endif; ?>
157 a09d815a Scott Ullrich
					<td>
158
				</tr>
159
			</table>
160
			</form>
161
		</td>
162
	</tr>
163
	<tr>
164
		<td>
165 79633b6c Evgeny Yurchenko
			<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0">
166 5b3f9124 jim-p
				<thead>
167 a09d815a Scott Ullrich
				<tr>
168 5b3f9124 jim-p
					<th class="listhdrr" width="10%"><?=gettext("Proto");?></th>
169
					<th class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></th>
170
					<th class="listhdr" width="24%"><?=gettext("State");?></th>
171 79633b6c Evgeny Yurchenko
					<th class="list sort_ignore" width="1%"></th>
172 ba6d49ff Scott Ullrich
				</tr>
173 5b3f9124 jim-p
				</thead>
174
				<tbody>
175 92cc7528 Scott Ullrich
<?php
176 a09d815a Scott Ullrich
$row = 0;
177 ca77763b Scott Ullrich
if(count($states) > 0) {
178
	foreach($states as $line) {
179 a09d815a Scott Ullrich
		if($row >= 1000)
180 ca77763b Scott Ullrich
			break;
181 a09d815a Scott Ullrich
182 ca77763b Scott Ullrich
		$line_split = preg_split("/\s+/", $line);
183 a09d815a Scott Ullrich
		$type  = array_shift($line_split);
184 ca77763b Scott Ullrich
		$proto = array_shift($line_split);
185 a09d815a Scott Ullrich
		$state = array_pop($line_split);
186
		$info  = implode(" ", $line_split);
187
188
		/* break up info and extract $srcip and $dstip */
189
		$ends = preg_split("/\<?-\>?/", $info);
190 cfbfd941 smos
		$parts = explode(":", $ends[0]);
191 a09d815a Scott Ullrich
		$srcip = trim($parts[0]);
192 cfbfd941 smos
		$parts = explode(":", $ends[count($ends) - 1]);
193 a09d815a Scott Ullrich
		$dstip = trim($parts[0]);
194
195 ac8c0663 Renato Botelho
		echo "<tr valign='top' name='r:{$srcip}:{$dstip}'>
196 a09d815a Scott Ullrich
				<td class='listlr'>{$proto}</td>
197
				<td class='listr'>{$info}</td>
198
				<td class='listr'>{$state}</td>
199
				<td class='list'>
200
				  <img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0'
201 ac8c0663 Renato Botelho
				  	   onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;'
202 a09d815a Scott Ullrich
				       name='i:{$srcip}:{$dstip}'
203
				       title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' />
204
				</td>
205 ac8c0663 Renato Botelho
			  </tr>";
206 a09d815a Scott Ullrich
		$row++;
207 92cc7528 Scott Ullrich
	}
208
}
209 a09d815a Scott Ullrich
else {
210 ac8c0663 Renato Botelho
	echo "<tr>
211 a09d815a Scott Ullrich
			<td class='list' colspan='4' align='center' valign='top'>
212
			  " . gettext("No states were found.") . "
213
			</td>
214 ac8c0663 Renato Botelho
		  </tr>";
215 a09d815a Scott Ullrich
}
216 92cc7528 Scott Ullrich
?>
217 5b3f9124 jim-p
			</tbody>
218 a09d815a Scott Ullrich
			</table>
219
		</td>
220
	</tr>
221 92cc7528 Scott Ullrich
</table>
222 a09d815a Scott Ullrich
223
<!-- End of tab content -->
224
225
		</div>
226
	</td>
227
  </tr>
228 92cc7528 Scott Ullrich
</table>
229 1f97829e Scott Ullrich
230 a09d815a Scott Ullrich
<?php require("fend.inc"); ?>
231 92cc7528 Scott Ullrich
</body>
232
</html>