Project

General

Profile

Download (5.89 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
require_once("guiconfig.inc");
30
31 695b0580 Scott Ullrich
32 a09d815a Scott Ullrich
/* handle AJAX operations */
33
if($_GET['action']) {
34 e8d93059 Bill Marquette
	if($_GET['action'] == "remove") {
35
		$srcip  = $_GET['srcip'];
36
		$dstip  = $_GET['dstip'];
37
		if (is_ipaddr($srcip) and is_ipaddr($dstip)) {
38
			$retval = mwexec("/sbin/pfctl -k '{$srcip}' -k '{$dstip}'");
39
			echo "|{$srcip}|{$dstip}|{$retval}|";
40
		} else {
41
			echo "invalid input";
42
		}
43 a09d815a Scott Ullrich
		exit;
44
	}
45
}
46
47 ca77763b Scott Ullrich
/* get our states */
48
if($_GET['filter']) {
49 a09d815a Scott Ullrich
	exec("/sbin/pfctl -s state | grep " . escapeshellarg($_GET['filter']), $states);
50
}
51
else {
52
	exec("/sbin/pfctl -s state", $states);
53 ca77763b Scott Ullrich
}
54 92cc7528 Scott Ullrich
55 e8d93059 Bill Marquette
$pgtitle = array("Diagnostics","Show States");
56
include("head.inc");
57
58 92cc7528 Scott Ullrich
?>
59
60 a09d815a Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
61
<script src="/javascript/sorttable.js" type="text/javascript"></script>
62 e415bfab Scott Ullrich
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
63
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
64 ca77763b Scott Ullrich
<?php include("fbegin.inc"); ?>
65 742ee135 Scott Ullrich
<form action="diag_dump_states.php" method="get" name="iform">
66 a09d815a Scott Ullrich
67
<script type="text/javascript">
68
	function removeState(srcip, dstip) {
69
		var busy = function(icon) {
70
			icon.onclick      = "";
71
			icon.src          = icon.src.replace("\.gif", "_d.gif");
72
			icon.style.cursor = "wait";
73
		}
74
75
		$A(document.getElementsByName("i:" + srcip + ":" + dstip)).each(busy);
76
77
		new Ajax.Request(
78
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
79
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
80
			{ method: "get", onComplete: removeComplete }
81
		);
82
	}
83
84
	function removeComplete(req) {
85
		var values = req.responseText.split("|");
86
		if(values[3] != "0") {
87 30f302f9 Scott Ullrich
			alert('<?=gettext("An error occurred.");?>');
88 a09d815a Scott Ullrich
			return;
89
		}
90
91
		$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each(
92
			function(row) { Effect.Fade(row, { duration: 1.0 }); }
93
		);
94
	}
95
</script>
96
97 92cc7528 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
98 a09d815a Scott Ullrich
	<tr>
99
		<td>
100
		<?php
101
			$tab_array = array(
102
				array(gettext("States"),       true,  "diag_dump_states.php"),
103
				array(gettext("Reset states"), false, "diag_resetstate.php")
104
			);
105
			display_top_tabs($tab_array);
106
		?>
107
		</td>
108
	</tr>
109
	<tr>
110
		<td>
111
			<div id="mainarea">
112
113
<!-- Start of tab content -->
114
115 b4031ab6 Scott Ullrich
<?php
116
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
117
?>
118
119 a09d815a Scott Ullrich
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
120
	<tr>
121
		<td>
122
			<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get">
123
			<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
124 ba6d49ff Scott Ullrich
				<tr>
125 b4031ab6 Scott Ullrich
					<td>Current state count: <?=$current_statecount?></td>
126 a09d815a Scott Ullrich
					<td style="font-weight:bold;" align="right">
127
						<?=gettext("Filter expression:");?>
128
						<input type="text" name="filter" class="formfld search" value="<?=$_GET['filter'];?>" size="30" />
129
						<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" />
130
					<td>
131
				</tr>
132
			</table>
133
			</form>
134
		</td>
135
	</tr>
136
	<tr>
137
		<td>
138
			<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0">
139
				<tr>
140
					<td class="listhdrr" width="10%"><?=gettext("Proto");?></td>
141
					<td class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></td>
142
					<td class="listhdr" width="24%"><?=gettext("State");?></td>
143
					<td class="list sort_ignore" width="1%"></td>
144 ba6d49ff Scott Ullrich
				</tr>
145 92cc7528 Scott Ullrich
<?php
146 a09d815a Scott Ullrich
$row = 0;
147 ca77763b Scott Ullrich
if(count($states) > 0) {
148
	foreach($states as $line) {
149 a09d815a Scott Ullrich
		if($row >= 1000)
150 ca77763b Scott Ullrich
			break;
151 a09d815a Scott Ullrich
152 ca77763b Scott Ullrich
		$line_split = preg_split("/\s+/", $line);
153 a09d815a Scott Ullrich
		$type  = array_shift($line_split);
154 ca77763b Scott Ullrich
		$proto = array_shift($line_split);
155 a09d815a Scott Ullrich
		$state = array_pop($line_split);
156
		$info  = implode(" ", $line_split);
157
158
		/* break up info and extract $srcip and $dstip */
159
		$ends = preg_split("/\<?-\>?/", $info);
160
		$parts = split(":", $ends[0]);
161
		$srcip = trim($parts[0]);
162
		$parts = split(":", $ends[count($ends) - 1]);
163
		$dstip = trim($parts[0]);
164
165
		echo "<tr valign='top' name='r:{$srcip}:{$dstip}'>
166
				<td class='listlr'>{$proto}</td>
167
				<td class='listr'>{$info}</td>
168
				<td class='listr'>{$state}</td>
169
				<td class='list'>
170
				  <img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0'
171
				  	   onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;'
172
				       name='i:{$srcip}:{$dstip}'
173
				       title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' />
174
				</td>
175
			  </tr>";
176
		$row++;
177 92cc7528 Scott Ullrich
	}
178
}
179 a09d815a Scott Ullrich
else {
180
	echo "<tr>
181
			<td class='list' colspan='4' align='center' valign='top'>
182
			  " . gettext("No states were found.") . "
183
			</td>
184
		  </tr>";
185
}
186 92cc7528 Scott Ullrich
?>
187 a09d815a Scott Ullrich
			</table>
188
		</td>
189
	</tr>
190 92cc7528 Scott Ullrich
</table>
191 a09d815a Scott Ullrich
192
<!-- End of tab content -->
193
194
		</div>
195
	</td>
196
  </tr>
197 92cc7528 Scott Ullrich
</table>
198 1f97829e Scott Ullrich
199 a09d815a Scott Ullrich
<?php require("fend.inc"); ?>
200 92cc7528 Scott Ullrich
</body>
201
</html>