Project

General

Profile

Download (5.59 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 = "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
<?php include("fbegin.inc"); ?>
56
<p class="pgtitle"><?=$pgtitle?></p>
57
<form action="diag_dump_states.php" method="get" name="iform">
58

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

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

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

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

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

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

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

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

    
139
		$line_split = preg_split("/\s+/", $line);
140
		$type  = array_shift($line_split);
141
		$proto = array_shift($line_split);
142
		$state = array_pop($line_split);
143
		$info  = implode(" ", $line_split);
144

    
145
		/* break up info and extract $srcip and $dstip */
146
		$ends = preg_split("/\<?-\>?/", $info);
147
		$parts = split(":", $ends[0]);
148
		$srcip = trim($parts[0]);
149
		$parts = split(":", $ends[count($ends) - 1]);
150
		$dstip = trim($parts[0]);
151

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

    
179
<!-- End of tab content -->
180

    
181
		</div>
182
	</td>
183
  </tr>
184
</table>
185
<meta http-equiv="refresh" content="60;url=diag_dump_states.php?filter=<?php echo $_GET['filter']; ?>">
186

    
187
<?php require("fend.inc"); ?>
188
</body>
189
</html>
(9-9/167)