Project

General

Profile

Download (6.08 KB) Statistics
| Branch: | Tag: | Revision:
1 92cc7528 Scott Ullrich
<?php
2
/*
3 a09d815a Scott Ullrich
	diag_dump_states.php
4
	Copyright (C) 2005 Scott Ullrich, Colin Smith
5
	All rights reserved.
6
7
	Redistribution and use in source and binary forms, with or without
8
	modification, are permitted provided that the following conditions are met:
9
10
	1. Redistributions of source code must retain the above copyright notice,
11
	   this list of conditions and the following disclaimer.
12
13
	2. Redistributions in binary form must reproduce the above copyright
14
	   notice, this list of conditions and the following disclaimer in the
15
	   documentation and/or other materials provided with the distribution.
16
17
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
	POSSIBILITY OF SUCH DAMAGE.
27 92cc7528 Scott Ullrich
*/
28
29 6b07c15a Matthew Grooms
##|+PRIV
30
##|*IDENT=page-diagnostics-showstates
31
##|*NAME=Diagnostics: Show States page
32
##|*DESCR=Allow access to the 'Diagnostics: Show States' page.
33
##|*MATCH=diag_dump_states.php*
34
##|-PRIV
35
36
37 92cc7528 Scott Ullrich
require_once("guiconfig.inc");
38
39 695b0580 Scott Ullrich
40 a09d815a Scott Ullrich
/* handle AJAX operations */
41
if($_GET['action']) {
42 e8d93059 Bill Marquette
	if($_GET['action'] == "remove") {
43
		$srcip  = $_GET['srcip'];
44
		$dstip  = $_GET['dstip'];
45
		if (is_ipaddr($srcip) and is_ipaddr($dstip)) {
46
			$retval = mwexec("/sbin/pfctl -k '{$srcip}' -k '{$dstip}'");
47
			echo "|{$srcip}|{$dstip}|{$retval}|";
48
		} else {
49
			echo "invalid input";
50
		}
51 a09d815a Scott Ullrich
		exit;
52
	}
53
}
54
55 ca77763b Scott Ullrich
/* get our states */
56
if($_GET['filter']) {
57 a09d815a Scott Ullrich
	exec("/sbin/pfctl -s state | grep " . escapeshellarg($_GET['filter']), $states);
58
}
59
else {
60
	exec("/sbin/pfctl -s state", $states);
61 ca77763b Scott Ullrich
}
62 92cc7528 Scott Ullrich
63 e8d93059 Bill Marquette
$pgtitle = array("Diagnostics","Show States");
64
include("head.inc");
65
66 92cc7528 Scott Ullrich
?>
67
68 a09d815a Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
69
<script src="/javascript/sorttable.js" type="text/javascript"></script>
70 e415bfab Scott Ullrich
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
71
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
72 ca77763b Scott Ullrich
<?php include("fbegin.inc"); ?>
73 742ee135 Scott Ullrich
<form action="diag_dump_states.php" method="get" name="iform">
74 a09d815a Scott Ullrich
75
<script type="text/javascript">
76
	function removeState(srcip, dstip) {
77
		var busy = function(icon) {
78
			icon.onclick      = "";
79
			icon.src          = icon.src.replace("\.gif", "_d.gif");
80
			icon.style.cursor = "wait";
81
		}
82
83
		$A(document.getElementsByName("i:" + srcip + ":" + dstip)).each(busy);
84
85
		new Ajax.Request(
86
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
87
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
88
			{ method: "get", onComplete: removeComplete }
89
		);
90
	}
91
92
	function removeComplete(req) {
93
		var values = req.responseText.split("|");
94
		if(values[3] != "0") {
95 30f302f9 Scott Ullrich
			alert('<?=gettext("An error occurred.");?>');
96 a09d815a Scott Ullrich
			return;
97
		}
98
99
		$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each(
100
			function(row) { Effect.Fade(row, { duration: 1.0 }); }
101
		);
102
	}
103
</script>
104
105 92cc7528 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
106 a09d815a Scott Ullrich
	<tr>
107
		<td>
108
		<?php
109
			$tab_array = array(
110
				array(gettext("States"),       true,  "diag_dump_states.php"),
111
				array(gettext("Reset states"), false, "diag_resetstate.php")
112
			);
113
			display_top_tabs($tab_array);
114
		?>
115
		</td>
116
	</tr>
117
	<tr>
118
		<td>
119
			<div id="mainarea">
120
121
<!-- Start of tab content -->
122
123 b4031ab6 Scott Ullrich
<?php
124
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
125
?>
126
127 a09d815a Scott Ullrich
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
128
	<tr>
129
		<td>
130
			<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get">
131
			<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
132 ba6d49ff Scott Ullrich
				<tr>
133 b4031ab6 Scott Ullrich
					<td>Current state count: <?=$current_statecount?></td>
134 a09d815a Scott Ullrich
					<td style="font-weight:bold;" align="right">
135
						<?=gettext("Filter expression:");?>
136
						<input type="text" name="filter" class="formfld search" value="<?=$_GET['filter'];?>" size="30" />
137
						<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" />
138
					<td>
139
				</tr>
140
			</table>
141
			</form>
142
		</td>
143
	</tr>
144
	<tr>
145
		<td>
146
			<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0">
147
				<tr>
148
					<td class="listhdrr" width="10%"><?=gettext("Proto");?></td>
149
					<td class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></td>
150
					<td class="listhdr" width="24%"><?=gettext("State");?></td>
151
					<td class="list sort_ignore" width="1%"></td>
152 ba6d49ff Scott Ullrich
				</tr>
153 92cc7528 Scott Ullrich
<?php
154 a09d815a Scott Ullrich
$row = 0;
155 ca77763b Scott Ullrich
if(count($states) > 0) {
156
	foreach($states as $line) {
157 a09d815a Scott Ullrich
		if($row >= 1000)
158 ca77763b Scott Ullrich
			break;
159 a09d815a Scott Ullrich
160 ca77763b Scott Ullrich
		$line_split = preg_split("/\s+/", $line);
161 a09d815a Scott Ullrich
		$type  = array_shift($line_split);
162 ca77763b Scott Ullrich
		$proto = array_shift($line_split);
163 a09d815a Scott Ullrich
		$state = array_pop($line_split);
164
		$info  = implode(" ", $line_split);
165
166
		/* break up info and extract $srcip and $dstip */
167
		$ends = preg_split("/\<?-\>?/", $info);
168
		$parts = split(":", $ends[0]);
169
		$srcip = trim($parts[0]);
170
		$parts = split(":", $ends[count($ends) - 1]);
171
		$dstip = trim($parts[0]);
172
173
		echo "<tr valign='top' name='r:{$srcip}:{$dstip}'>
174
				<td class='listlr'>{$proto}</td>
175
				<td class='listr'>{$info}</td>
176
				<td class='listr'>{$state}</td>
177
				<td class='list'>
178
				  <img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0'
179
				  	   onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;'
180
				       name='i:{$srcip}:{$dstip}'
181
				       title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' />
182
				</td>
183
			  </tr>";
184
		$row++;
185 92cc7528 Scott Ullrich
	}
186
}
187 a09d815a Scott Ullrich
else {
188
	echo "<tr>
189
			<td class='list' colspan='4' align='center' valign='top'>
190
			  " . gettext("No states were found.") . "
191
			</td>
192
		  </tr>";
193
}
194 92cc7528 Scott Ullrich
?>
195 a09d815a Scott Ullrich
			</table>
196
		</td>
197
	</tr>
198 92cc7528 Scott Ullrich
</table>
199 a09d815a Scott Ullrich
200
<!-- End of tab content -->
201
202
		</div>
203
	</td>
204
  </tr>
205 92cc7528 Scott Ullrich
</table>
206 1f97829e Scott Ullrich
207 a09d815a Scott Ullrich
<?php require("fend.inc"); ?>
208 92cc7528 Scott Ullrich
</body>
209
</html>