Project

General

Profile

Download (5.78 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	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
*/
28

    
29
require_once("guiconfig.inc");
30

    
31
$pgtitle = array("Diagnostics","Show States");
32
include("head.inc");
33

    
34
/* handle AJAX operations */
35
if($_GET['action']) {
36
	if($_GET['action'] == "remove") {
37
		$retval = mwexec("/sbin/pfctl -k '{$_GET['srcip']}' -k '{$_GET['dstip']}'");
38
		echo "|{$_GET['srcip']}|{$_GET['dstip']}|{$retval}|";
39
		exit;
40
	}
41
}
42

    
43
/* get our states */
44
if($_GET['filter']) {
45
	exec("/sbin/pfctl -s state | grep " . escapeshellarg($_GET['filter']), $states);
46
}
47
else {
48
	exec("/sbin/pfctl -s state", $states);
49
}
50

    
51
?>
52

    
53
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
54
<script src="/javascript/sorttable.js" type="text/javascript"></script>
55
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
56
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
57
<?php include("fbegin.inc"); ?>
58
<form action="diag_dump_states.php" method="get" name="iform">
59

    
60
<script type="text/javascript">
61
	function removeState(srcip, dstip) {
62
		var busy = function(icon) {
63
			icon.onclick      = "";
64
			icon.src          = icon.src.replace("\.gif", "_d.gif");
65
			icon.style.cursor = "wait";
66
		}
67

    
68
		$A(document.getElementsByName("i:" + srcip + ":" + dstip)).each(busy);
69

    
70
		new Ajax.Request(
71
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
72
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
73
			{ method: "get", onComplete: removeComplete }
74
		);
75
	}
76

    
77
	function removeComplete(req) {
78
		var values = req.responseText.split("|");
79
		if(values[3] != "0") {
80
			alert('<?=gettext("An error occurred.");?>');
81
			return;
82
		}
83

    
84
		$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each(
85
			function(row) { Effect.Fade(row, { duration: 1.0 }); }
86
		);
87
	}
88
</script>
89

    
90
<table width="100%" border="0" cellpadding="0" cellspacing="0">
91
	<tr>
92
		<td>
93
		<?php
94
			$tab_array = array(
95
				array(gettext("States"),       true,  "diag_dump_states.php"),
96
				array(gettext("Reset states"), false, "diag_resetstate.php")
97
			);
98
			display_top_tabs($tab_array);
99
		?>
100
		</td>
101
	</tr>
102
	<tr>
103
		<td>
104
			<div id="mainarea">
105

    
106
<!-- Start of tab content -->
107

    
108
<?php
109
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
110
?>
111

    
112
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
113
	<tr>
114
		<td>
115
			<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get">
116
			<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
117
				<tr>
118
					<td>Current state count: <?=$current_statecount?></td>
119
					<td style="font-weight:bold;" align="right">
120
						<?=gettext("Filter expression:");?>
121
						<input type="text" name="filter" class="formfld search" value="<?=$_GET['filter'];?>" size="30" />
122
						<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" />
123
					<td>
124
				</tr>
125
			</table>
126
			</form>
127
		</td>
128
	</tr>
129
	<tr>
130
		<td>
131
			<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0">
132
				<tr>
133
					<td class="listhdrr" width="10%"><?=gettext("Proto");?></td>
134
					<td class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></td>
135
					<td class="listhdr" width="24%"><?=gettext("State");?></td>
136
					<td class="list sort_ignore" width="1%"></td>
137
				</tr>
138
<?php
139
$row = 0;
140
if(count($states) > 0) {
141
	foreach($states as $line) {
142
		if($row >= 1000)
143
			break;
144

    
145
		$line_split = preg_split("/\s+/", $line);
146
		$type  = array_shift($line_split);
147
		$proto = array_shift($line_split);
148
		$state = array_pop($line_split);
149
		$info  = implode(" ", $line_split);
150

    
151
		/* break up info and extract $srcip and $dstip */
152
		$ends = preg_split("/\<?-\>?/", $info);
153
		$parts = split(":", $ends[0]);
154
		$srcip = trim($parts[0]);
155
		$parts = split(":", $ends[count($ends) - 1]);
156
		$dstip = trim($parts[0]);
157

    
158
		echo "<tr valign='top' name='r:{$srcip}:{$dstip}'>
159
				<td class='listlr'>{$proto}</td>
160
				<td class='listr'>{$info}</td>
161
				<td class='listr'>{$state}</td>
162
				<td class='list'>
163
				  <img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0'
164
				  	   onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;'
165
				       name='i:{$srcip}:{$dstip}'
166
				       title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' />
167
				</td>
168
			  </tr>";
169
		$row++;
170
	}
171
}
172
else {
173
	echo "<tr>
174
			<td class='list' colspan='4' align='center' valign='top'>
175
			  " . gettext("No states were found.") . "
176
			</td>
177
		  </tr>";
178
}
179
?>
180
			</table>
181
		</td>
182
	</tr>
183
</table>
184

    
185
<!-- End of tab content -->
186

    
187
		</div>
188
	</td>
189
  </tr>
190
</table>
191

    
192
<?php require("fend.inc"); ?>
193
</body>
194
</html>
(9-9/187)