Project

General

Profile

Download (5.92 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
##|+PRIV
30
##|*IDENT=page-diagnostics-showstates
31
##|*NAME=Diagnostics: Show States page
32
##|*DESCR=Allow access to the 'Diagnostics: Show States' page.
33
##|*MATCH=diag_dump_states.php*
34
##|-PRIV
35

    
36

    
37
require_once("guiconfig.inc");
38

    
39

    
40
/* handle AJAX operations */
41
if($_GET['action']) {
42
	if($_GET['action'] == "remove") {
43
		$srcip  = $_GET['srcip'];
44
		$dstip  = $_GET['dstip'];
45
		if (is_ipaddr($srcip) and is_ipaddr($dstip)) {
46
			$retval = mwexec("/sbin/pfctl -k '{$srcip}' -k '{$dstip}'");
47
			echo htmlentities("|{$srcip}|{$dstip}|{$retval}|");
48
		} else {
49
			echo "invalid input";
50
		}
51
		exit;
52
	}
53
}
54

    
55
/* get our states */
56
if($_GET['filter']) {
57
	exec("/sbin/pfctl -s state | grep " . escapeshellarg($_GET['filter']), $states);
58
}
59
else {
60
	exec("/sbin/pfctl -s state", $states);
61
}
62

    
63
$pgtitle = array("Diagnostics","Show States");
64
include("head.inc");
65

    
66
?>
67

    
68
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
69
<script src="/javascript/sorttable.js" type="text/javascript"></script>
70
<?php include("fbegin.inc"); ?>
71
<form action="diag_dump_states.php" method="get" name="iform">
72

    
73
<script type="text/javascript">
74
	function removeState(srcip, dstip) {
75
		var busy = function(icon) {
76
			icon.onclick      = "";
77
			icon.src          = icon.src.replace("\.gif", "_d.gif");
78
			icon.style.cursor = "wait";
79
		}
80

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

    
83
		new Ajax.Request(
84
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
85
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
86
			{ method: "get", onComplete: removeComplete }
87
		);
88
	}
89

    
90
	function removeComplete(req) {
91
		var values = req.responseText.split("|");
92
		if(values[3] != "0") {
93
			alert('<?=gettext("An error occurred.");?>');
94
			return;
95
		}
96

    
97
		$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each(
98
			function(row) { Effect.Fade(row, { duration: 1.0 }); }
99
		);
100
	}
101
</script>
102

    
103
<table width="100%" border="0" cellpadding="0" cellspacing="0">
104
	<tr>
105
		<td>
106
		<?php
107
			$tab_array = array(
108
				array(gettext("States"),       true,  "diag_dump_states.php"),
109
				array(gettext("Reset states"), false, "diag_resetstate.php")
110
			);
111
			display_top_tabs($tab_array);
112
		?>
113
		</td>
114
	</tr>
115
	<tr>
116
		<td>
117
			<div id="mainarea">
118

    
119
<!-- Start of tab content -->
120

    
121
<?php
122
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
123
?>
124

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

    
158
		$line_split = preg_split("/\s+/", $line);
159
		$type  = array_shift($line_split);
160
		$proto = array_shift($line_split);
161
		$state = array_pop($line_split);
162
		$info  = implode(" ", $line_split);
163

    
164
		/* break up info and extract $srcip and $dstip */
165
		$ends = preg_split("/\<?-\>?/", $info);
166
		$parts = split(":", $ends[0]);
167
		$srcip = trim($parts[0]);
168
		$parts = split(":", $ends[count($ends) - 1]);
169
		$dstip = trim($parts[0]);
170

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

    
198
<!-- End of tab content -->
199

    
200
		</div>
201
	</td>
202
  </tr>
203
</table>
204

    
205
<?php require("fend.inc"); ?>
206
</body>
207
</html>
(7-7/207)