Project

General

Profile

Download (5.9 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
$srcip  = htmlentities($_GET['srcip']);
35
$dstip  = htmlentities($_GET['dstip']);
36
$action = htmlentities($_GET['action']);
37
$filter = htmlentities($_GET['filter']);
38

    
39
/* handle AJAX operations */
40
if($_GET['action']) {
41
	if($action == "remove") {
42
		$retval = mwexec("/sbin/pfctl -k '{$srcip}' -k '{$dstip}'");
43
		echo "|{$srcip}|{$dstip}|{$retval}|";
44
		exit;
45
	}
46
}
47

    
48
/* get our states */
49
if($_GET['filter']) {
50
	exec("/sbin/pfctl -s state | grep " . escapeshellarg($_GET['filter']), $states);
51
}
52
else {
53
	exec("/sbin/pfctl -s state", $states);
54
}
55

    
56
?>
57

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

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

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

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

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

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

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

    
111
<!-- Start of tab content -->
112

    
113
<?php
114
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
115
?>
116

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

    
150
		$line_split = preg_split("/\s+/", $line);
151
		$type  = array_shift($line_split);
152
		$proto = array_shift($line_split);
153
		$state = array_pop($line_split);
154
		$info  = implode(" ", $line_split);
155

    
156
		/* break up info and extract $srcip and $dstip */
157
		$ends = preg_split("/\<?-\>?/", $info);
158
		$parts = split(":", $ends[0]);
159
		$srcip = trim($parts[0]);
160
		$parts = split(":", $ends[count($ends) - 1]);
161
		$dstip = trim($parts[0]);
162

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

    
190
<!-- End of tab content -->
191

    
192
		</div>
193
	</td>
194
  </tr>
195
</table>
196

    
197
<?php require("fend.inc"); ?>
198
</body>
199
</html>
(9-9/189)