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 sortable" 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" width="100%" border="0" cellspacing="0" cellpadding="0">
|
149
|
<tr>
|
150
|
<td class="listhdrr" width="10%"><?=gettext("Proto");?></td>
|
151
|
<td class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></td>
|
152
|
<td class="listhdr" width="24%"><?=gettext("State");?></td>
|
153
|
<td class="list sort_ignore" width="1%"></td>
|
154
|
</tr>
|
155
|
<?php
|
156
|
$row = 0;
|
157
|
if(count($states) > 0) {
|
158
|
foreach($states as $line) {
|
159
|
if($row >= 1000)
|
160
|
break;
|
161
|
|
162
|
$line_split = preg_split("/\s+/", $line);
|
163
|
$type = array_shift($line_split);
|
164
|
$proto = array_shift($line_split);
|
165
|
$state = array_pop($line_split);
|
166
|
$info = implode(" ", $line_split);
|
167
|
|
168
|
/* break up info and extract $srcip and $dstip */
|
169
|
$ends = preg_split("/\<?-\>?/", $info);
|
170
|
$parts = split(":", $ends[0]);
|
171
|
$srcip = trim($parts[0]);
|
172
|
$parts = split(":", $ends[count($ends) - 1]);
|
173
|
$dstip = trim($parts[0]);
|
174
|
|
175
|
echo "<tr valign='top' name='r:{$srcip}:{$dstip}'>
|
176
|
<td class='listlr'>{$proto}</td>
|
177
|
<td class='listr'>{$info}</td>
|
178
|
<td class='listr'>{$state}</td>
|
179
|
<td class='list'>
|
180
|
<img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0'
|
181
|
onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;'
|
182
|
name='i:{$srcip}:{$dstip}'
|
183
|
title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' />
|
184
|
</td>
|
185
|
</tr>";
|
186
|
$row++;
|
187
|
}
|
188
|
}
|
189
|
else {
|
190
|
echo "<tr>
|
191
|
<td class='list' colspan='4' align='center' valign='top'>
|
192
|
" . gettext("No states were found.") . "
|
193
|
</td>
|
194
|
</tr>";
|
195
|
}
|
196
|
?>
|
197
|
</table>
|
198
|
</td>
|
199
|
</tr>
|
200
|
</table>
|
201
|
|
202
|
<!-- End of tab content -->
|
203
|
|
204
|
</div>
|
205
|
</td>
|
206
|
</tr>
|
207
|
</table>
|
208
|
|
209
|
<?php require("fend.inc"); ?>
|
210
|
</body>
|
211
|
</html>
|