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