Project

General

Profile

Download (6.91 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
if ($_GET['filter'] && ($_GET['killfilter'] == "Kill")) {
58
	if (is_ipaddr($_GET['filter'])) {
59
		$tokill = $_GET['filter'] . "/32";
60
	} elseif (is_subnet($_GET['filter'])) {
61
		$tokill = $_GET['filter'];
62
	}
63
	$retval = mwexec("/sbin/pfctl -k {$tokill} -k 0/0");
64
	$retval = mwexec("/sbin/pfctl -k 0.0.0.0/0 -k {$tokill}");
65
}
66

    
67
/* get our states */
68
if($_GET['filter']) {
69
	exec("/sbin/pfctl -s state | grep " . escapeshellarg(htmlspecialchars($_GET['filter'])), $states);
70
}
71
else {
72
	exec("/sbin/pfctl -s state", $states);
73
}
74

    
75
$pgtitle = array(gettext("Diagnostics"),gettext("Show States"));
76
include("head.inc");
77

    
78
?>
79

    
80
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
81
<?php include("fbegin.inc"); ?>
82
<form action="diag_dump_states.php" method="get" name="iform">
83

    
84
<script type="text/javascript">
85
	function removeState(srcip, dstip) {
86
		var busy = function(index,icon) {
87
			jQuery(icon).bind("onclick","");
88
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
89
			jQuery(icon).css("cursor","wait");
90
		}
91

    
92
		jQuery('img[name="i:' + srcip + ":" + dstip + '"]').each(busy);
93

    
94
		jQuery.ajax(
95
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
96
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
97
			{ type: "get", complete: removeComplete }
98
		);
99
	}
100

    
101
	function removeComplete(req) {
102
		var values = req.responseText.split("|");
103
		if(values[3] != "0") {
104
			alert('<?=gettext("An error occurred.");?>');
105
			return;
106
		}
107

    
108
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
109
			function(index,row) { jQuery(row).fadeOut(1000); }
110
		);
111
	}
112
</script>
113

    
114
<table width="100%" border="0" cellpadding="0" cellspacing="0">
115
	<tr>
116
		<td>
117
		<?php
118
			$tab_array = array();
119
			$tab_array[] = array(gettext("States"), true, "diag_dump_states.php");
120
			if (isset($config['system']['lb_use_sticky']))
121
				$tab_array[] = array(gettext("Source Tracking"), false, "diag_dump_states_sources.php");
122
			$tab_array[] = array(gettext("Reset States"), false, "diag_resetstate.php");
123
			display_top_tabs($tab_array);
124
		?>
125
		</td>
126
	</tr>
127
	<tr>
128
		<td>
129
			<div id="mainarea">
130

    
131
<!-- Start of tab content -->
132

    
133
<?php
134
	$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
135
?>
136

    
137
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
138
	<tr>
139
		<td>
140
			<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get">
141
			<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
142
				<tr>
143
					<td>
144
						<?=gettext("Current state count");?>: <?= $current_statecount ?>
145
						<?php if (!empty($_GET['filter'])): ?>
146
							(<?=gettext("Matching filter")?>: <?= count($states) ?>)
147
						<?php endif; ?>
148
					</td>
149
					<td style="font-weight:bold;" align="right">
150
						<?=gettext("Filter expression:");?>
151
						<input type="text" name="filter" class="formfld search" value="<?=htmlspecialchars($_GET['filter']);?>" size="30" />
152
						<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" />
153
					<?php if (is_ipaddr($_GET['filter']) || is_subnet($_GET['filter'])): ?>
154
						<input type="submit" class="formbtn" name="killfilter" value="<?=gettext("Kill");?>" />
155
					<?php endif; ?>
156
					<td>
157
				</tr>
158
			</table>
159
			</form>
160
		</td>
161
	</tr>
162
	<tr>
163
		<td>
164
			<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0">
165
				<thead>
166
				<tr>
167
					<th class="listhdrr" width="10%"><?=gettext("Proto");?></th>
168
					<th class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></th>
169
					<th class="listhdr" width="24%"><?=gettext("State");?></th>
170
					<th class="list sort_ignore" width="1%"></th>
171
				</tr>
172
				</thead>
173
				<tbody>
174
<?php
175
$row = 0;
176
if(count($states) > 0) {
177
	foreach($states as $line) {
178
		if($row >= 1000)
179
			break;
180

    
181
		$line_split = preg_split("/\s+/", $line);
182
		$type  = array_shift($line_split);
183
		$proto = array_shift($line_split);
184
		$state = array_pop($line_split);
185
		$info  = implode(" ", $line_split);
186

    
187
		/* break up info and extract $srcip and $dstip */
188
		$ends = preg_split("/\<?-\>?/", $info);
189
		$parts = explode(":", $ends[0]);
190
		$srcip = trim($parts[0]);
191
		$parts = explode(":", $ends[count($ends) - 1]);
192
		$dstip = trim($parts[0]);
193

    
194
		echo "<tr valign='top' name='r:{$srcip}:{$dstip}'>
195
				<td class='listlr'>{$proto}</td>
196
				<td class='listr'>{$info}</td>
197
				<td class='listr'>{$state}</td>
198
				<td class='list'>
199
				  <img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0'
200
				  	   onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;'
201
				       name='i:{$srcip}:{$dstip}'
202
				       title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' />
203
				</td>
204
			  </tr>";
205
		$row++;
206
	}
207
}
208
else {
209
	echo "<tr>
210
			<td class='list' colspan='4' align='center' valign='top'>
211
			  " . gettext("No states were found.") . "
212
			</td>
213
		  </tr>";
214
}
215
?>
216
			</tbody>
217
			</table>
218
		</td>
219
	</tr>
220
</table>
221

    
222
<!-- End of tab content -->
223

    
224
		</div>
225
	</td>
226
  </tr>
227
</table>
228

    
229
<?php require("fend.inc"); ?>
230
</body>
231
</html>
(11-11/246)