Project

General

Profile

Download (5.76 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
<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
<p class="pgtitle"><?=$pgtitle?></p>
59
<form action="diag_dump_states.php" method="get" name="iform">
60

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

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

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

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

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

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

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

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

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

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

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

    
181
<!-- End of tab content -->
182

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

    
189
<?php require("fend.inc"); ?>
190
</body>
191
</html>
(9-9/171)