Project

General

Profile

Download (6.17 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_dump_states.php
4
	Copyright (C) 2005-2009 Scott Ullrich
5
	Copyright (C) 2005 Colin Smith
6
	All rights reserved.
7

    
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10

    
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13

    
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17

    
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
/*
31
	pfSense_BUILDER_BINARIES:	/sbin/pfctl	
32
	pfSense_MODULE:	filter
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-diagnostics-showstates
37
##|*NAME=Diagnostics: Show States page
38
##|*DESCR=Allow access to the 'Diagnostics: Show States' page.
39
##|*MATCH=diag_dump_states.php*
40
##|-PRIV
41

    
42
require_once("guiconfig.inc");
43

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

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

    
65
$pgtitle = array(gettext("Diagnostics"),gettext("Show States"));
66
include("head.inc");
67

    
68
?>
69

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

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

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

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

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

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

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

    
121
<!-- Start of tab content -->
122

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

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

    
163
		$line_split = preg_split("/\s+/", $line);
164
		$type  = array_shift($line_split);
165
		$proto = array_shift($line_split);
166
		$state = array_pop($line_split);
167
		$info  = implode(" ", $line_split);
168

    
169
		/* break up info and extract $srcip and $dstip */
170
		$ends = preg_split("/\<?-\>?/", $info);
171
		$parts = split(":", $ends[0]);
172
		$srcip = trim($parts[0]);
173
		$parts = split(":", $ends[count($ends) - 1]);
174
		$dstip = trim($parts[0]);
175

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

    
204
<!-- End of tab content -->
205

    
206
		</div>
207
	</td>
208
  </tr>
209
</table>
210

    
211
<?php require("fend.inc"); ?>
212
</body>
213
</html>
(10-10/222)