1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
<?php
/*
diag_dump_states.php
Copyright (C) 2005 Scott Ullrich, Colin Smith
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
##|+PRIV
##|*IDENT=page-diagnostics-showstates
##|*NAME=Diagnostics: Show States page
##|*DESCR=Allow access to the 'Diagnostics: Show States' page.
##|*MATCH=diag_dump_states.php*
##|-PRIV
require_once("guiconfig.inc");
/* handle AJAX operations */
if($_GET['action']) {
if($_GET['action'] == "remove") {
$srcip = $_GET['srcip'];
$dstip = $_GET['dstip'];
if (is_ipaddr($srcip) and is_ipaddr($dstip)) {
$retval = mwexec("/sbin/pfctl -k '{$srcip}' -k '{$dstip}'");
echo htmlentities("|{$srcip}|{$dstip}|{$retval}|");
} else {
echo "invalid input";
}
exit;
}
}
/* get our states */
if($_GET['filter']) {
exec("/sbin/pfctl -s state | grep " . escapeshellarg($_GET['filter']), $states);
}
else {
exec("/sbin/pfctl -s state", $states);
}
$pgtitle = array("Diagnostics","Show States");
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
<script src="/javascript/sorttable.js" type="text/javascript"></script>
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
<?php include("fbegin.inc"); ?>
<form action="diag_dump_states.php" method="get" name="iform">
<script type="text/javascript">
function removeState(srcip, dstip) {
var busy = function(icon) {
icon.onclick = "";
icon.src = icon.src.replace("\.gif", "_d.gif");
icon.style.cursor = "wait";
}
$A(document.getElementsByName("i:" + srcip + ":" + dstip)).each(busy);
new Ajax.Request(
"<?=$_SERVER['SCRIPT_NAME'];?>" +
"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
{ method: "get", onComplete: removeComplete }
);
}
function removeComplete(req) {
var values = req.responseText.split("|");
if(values[3] != "0") {
alert('<?=gettext("An error occurred.");?>');
return;
}
$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each(
function(row) { Effect.Fade(row, { duration: 1.0 }); }
);
}
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<?php
$tab_array = array(
array(gettext("States"), true, "diag_dump_states.php"),
array(gettext("Reset states"), false, "diag_resetstate.php")
);
display_top_tabs($tab_array);
?>
</td>
</tr>
<tr>
<td>
<div id="mainarea">
<!-- Start of tab content -->
<?php
$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
?>
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get">
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Current state count: <?=$current_statecount?></td>
<td style="font-weight:bold;" align="right">
<?=gettext("Filter expression:");?>
<input type="text" name="filter" class="formfld search" value="<?=$_GET['filter'];?>" size="30" />
<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" />
<td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td>
<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="listhdrr" width="10%"><?=gettext("Proto");?></td>
<td class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></td>
<td class="listhdr" width="24%"><?=gettext("State");?></td>
<td class="list sort_ignore" width="1%"></td>
</tr>
<?php
$row = 0;
if(count($states) > 0) {
foreach($states as $line) {
if($row >= 1000)
break;
$line_split = preg_split("/\s+/", $line);
$type = array_shift($line_split);
$proto = array_shift($line_split);
$state = array_pop($line_split);
$info = implode(" ", $line_split);
/* break up info and extract $srcip and $dstip */
$ends = preg_split("/\<?-\>?/", $info);
$parts = split(":", $ends[0]);
$srcip = trim($parts[0]);
$parts = split(":", $ends[count($ends) - 1]);
$dstip = trim($parts[0]);
echo "<tr valign='top' name='r:{$srcip}:{$dstip}'>
<td class='listlr'>{$proto}</td>
<td class='listr'>{$info}</td>
<td class='listr'>{$state}</td>
<td class='list'>
<img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0'
onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;'
name='i:{$srcip}:{$dstip}'
title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' />
</td>
</tr>";
$row++;
}
}
else {
echo "<tr>
<td class='list' colspan='4' align='center' valign='top'>
" . gettext("No states were found.") . "
</td>
</tr>";
}
?>
</table>
</td>
</tr>
</table>
<!-- End of tab content -->
</div>
</td>
</tr>
</table>
<?php require("fend.inc"); ?>
</body>
</html>
|