Project

General

Profile

Download (6.1 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
		$srcip  = $_GET['srcip'];
48
		$dstip  = $_GET['dstip'];
49
		if (is_ipaddr($srcip) and is_ipaddr($dstip)) {
50
			$retval = mwexec("/sbin/pfctl -k '{$srcip}' -k '{$dstip}'");
51
			echo htmlentities("|{$srcip}|{$dstip}|{$retval}|");
52
		} else {
53
			echo gettext("invalid input");
54
		}
55
		exit;
56
	}
57
}
58

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

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

    
70
?>
71

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

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

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

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

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

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

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

    
123
<!-- Start of tab content -->
124

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

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

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

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

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

    
206
<!-- End of tab content -->
207

    
208
		</div>
209
	</td>
210
  </tr>
211
</table>
212

    
213
<?php require("fend.inc"); ?>
214
</body>
215
</html>
(10-10/220)