Revision a09d815a
Added by Scott Ullrich over 18 years ago
usr/local/www/diag_dump_states.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
/* |
3 |
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.
|
|
3 |
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 | 27 |
*/ |
28 | 28 |
|
29 | 29 |
require_once("guiconfig.inc"); |
... | ... | |
31 | 31 |
$pgtitle = "Diagnostics: Show States"; |
32 | 32 |
include("head.inc"); |
33 | 33 |
|
34 |
/* handle AJAX operations */ |
|
35 |
if($_GET['action']) { |
|
36 |
if($_GET['action'] == "remove") { |
|
37 |
$retval = mwexec("/sbin/pfctl -k '{$_GET['srcip']}' -k '{$_GET['dstip']}'"); |
|
38 |
echo "|{$_GET['srcip']}|{$_GET['dstip']}|{$retval}|"; |
|
39 |
exit; |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
34 | 43 |
/* get our states */ |
35 | 44 |
if($_GET['filter']) { |
36 |
exec("/sbin/pfctl -ss | grep {$_GET['filter']}", $states); |
|
37 |
} else { |
|
38 |
exec("/sbin/pfctl -ss", $states); |
|
45 |
exec("/sbin/pfctl -s state | grep " . escapeshellarg($_GET['filter']), $states); |
|
46 |
} |
|
47 |
else { |
|
48 |
exec("/sbin/pfctl -s state", $states); |
|
39 | 49 |
} |
40 | 50 |
|
41 | 51 |
?> |
42 | 52 |
|
43 |
<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> |
|
44 |
<script src="/javascript/sorttable.js"></script> |
|
53 |
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
|
|
54 |
<script src="/javascript/sorttable.js" type="text/javascript"></script>
|
|
45 | 55 |
<?php include("fbegin.inc"); ?> |
46 | 56 |
<p class="pgtitle"><?=$pgtitle?></p> |
47 | 57 |
<form action="diag_dump_states.php" method="get" name="iform"> |
58 |
|
|
59 |
<script type="text/javascript"> |
|
60 |
function removeState(srcip, dstip) { |
|
61 |
var busy = function(icon) { |
|
62 |
icon.onclick = ""; |
|
63 |
icon.src = icon.src.replace("\.gif", "_d.gif"); |
|
64 |
icon.style.cursor = "wait"; |
|
65 |
} |
|
66 |
|
|
67 |
$A(document.getElementsByName("i:" + srcip + ":" + dstip)).each(busy); |
|
68 |
|
|
69 |
new Ajax.Request( |
|
70 |
"<?=$_SERVER['SCRIPT_NAME'];?>" + |
|
71 |
"?action=remove&srcip=" + srcip + "&dstip=" + dstip, |
|
72 |
{ method: "get", onComplete: removeComplete } |
|
73 |
); |
|
74 |
} |
|
75 |
|
|
76 |
function removeComplete(req) { |
|
77 |
var values = req.responseText.split("|"); |
|
78 |
if(values[3] != "0") { |
|
79 |
alert('<?=gettext("An error occured.");?>'); |
|
80 |
return; |
|
81 |
} |
|
82 |
|
|
83 |
$A(document.getElementsByName("r:" + values[1] + ":" + values[2])).each( |
|
84 |
function(row) { Effect.Fade(row, { duration: 1.0 }); } |
|
85 |
); |
|
86 |
} |
|
87 |
</script> |
|
88 |
|
|
48 | 89 |
<table width="100%" border="0" cellpadding="0" cellspacing="0"> |
49 |
<tr><td> |
|
50 |
<?php |
|
51 |
$tab_array = array(); |
|
52 |
$tab_array[0] = array("States", true, "diag_dump_states.php"); |
|
53 |
$tab_array[1] = array("Reset States", false, "diag_resetstate.php"); |
|
54 |
display_top_tabs($tab_array); |
|
55 |
?> |
|
56 |
</td></tr> |
|
57 |
|
|
58 |
<tr><td> |
|
59 |
<div id="mainarea"> |
|
60 |
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0"> |
|
61 |
<tr> |
|
62 |
<td colspan="9"> |
|
63 |
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0"> |
|
64 |
<tr> |
|
65 |
<td style="font-weight:bold;" width="50" align="right">Filter: |
|
66 |
|
|
67 |
<input name="filter" type="text" id="" value="<?=$_GET['filter'];?>" size="30" style="font-size:11px;"> |
|
68 |
<input type="submit" class="formbtn" value="Filter"> |
|
69 |
</form> |
|
70 |
<td> |
|
71 |
</tr> |
|
72 |
</table> |
|
73 |
</td> |
|
74 |
</tr> |
|
75 |
<tr><td> |
|
76 |
<table id="sortabletable" name="sortabletable" class="sortable" width="100%" border="0" cellspacing="0" cellpadding="0"> |
|
90 |
<tr> |
|
91 |
<td> |
|
92 |
<?php |
|
93 |
$tab_array = array( |
|
94 |
array(gettext("States"), true, "diag_dump_states.php"), |
|
95 |
array(gettext("Reset states"), false, "diag_resetstate.php") |
|
96 |
); |
|
97 |
display_top_tabs($tab_array); |
|
98 |
?> |
|
99 |
</td> |
|
100 |
</tr> |
|
101 |
<tr> |
|
102 |
<td> |
|
103 |
<div id="mainarea"> |
|
104 |
|
|
105 |
<!-- Start of tab content --> |
|
106 |
|
|
107 |
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0"> |
|
108 |
<tr> |
|
109 |
<td> |
|
110 |
<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get"> |
|
111 |
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0"> |
|
77 | 112 |
<tr> |
78 |
<td class="listhdrr" width="10%">Proto</td> |
|
79 |
<td class="listhdrr" width="65">Source -> Router -> Destination</td> |
|
80 |
<td class="listhdr" width="15%">State</td> |
|
81 |
<td class="list" width="1%"></td> |
|
113 |
<td style="font-weight:bold;" align="right"> |
|
114 |
<?=gettext("Filter expression:");?> |
|
115 |
<input type="text" name="filter" class="formfld search" value="<?=$_GET['filter'];?>" size="30" /> |
|
116 |
<input type="submit" class="formbtn" value="<?=gettext("Filter");?>" /> |
|
117 |
<td> |
|
118 |
</tr> |
|
119 |
</table> |
|
120 |
</form> |
|
121 |
</td> |
|
122 |
</tr> |
|
123 |
<tr> |
|
124 |
<td> |
|
125 |
<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0"> |
|
126 |
<tr> |
|
127 |
<td class="listhdrr" width="10%"><?=gettext("Proto");?></td> |
|
128 |
<td class="listhdrr" width="65"><?=gettext("Source -> Router -> Destination");?></td> |
|
129 |
<td class="listhdr" width="24%"><?=gettext("State");?></td> |
|
130 |
<td class="list sort_ignore" width="1%"></td> |
|
82 | 131 |
</tr> |
83 | 132 |
<?php |
84 |
$state_counter = 0;
|
|
133 |
$row = 0;
|
|
85 | 134 |
if(count($states) > 0) { |
86 | 135 |
foreach($states as $line) { |
87 |
$state_counter++; |
|
88 |
if($state_counter > 1000) |
|
136 |
if($row >= 1000) |
|
89 | 137 |
break; |
90 |
|
|
138 |
|
|
91 | 139 |
$line_split = preg_split("/\s+/", $line); |
92 |
$state = array_pop($line_split); |
|
93 |
$type = array_shift($line_split); |
|
140 |
$type = array_shift($line_split); |
|
94 | 141 |
$proto = array_shift($line_split); |
95 |
$info = implode(" ", $line_split); |
|
96 |
|
|
97 |
$towrite = <<<EOD |
|
98 |
<tr valign="top"> |
|
99 |
<td class="listlr">{$proto}</td> |
|
100 |
<td class="listr">{$info}</td> |
|
101 |
<td class="listr">{$state}</td> |
|
102 |
</tr> |
|
103 |
EOD; |
|
104 |
print $towrite; |
|
142 |
$state = array_pop($line_split); |
|
143 |
$info = implode(" ", $line_split); |
|
144 |
|
|
145 |
/* break up info and extract $srcip and $dstip */ |
|
146 |
$ends = preg_split("/\<?-\>?/", $info); |
|
147 |
$parts = split(":", $ends[0]); |
|
148 |
$srcip = trim($parts[0]); |
|
149 |
$parts = split(":", $ends[count($ends) - 1]); |
|
150 |
$dstip = trim($parts[0]); |
|
151 |
|
|
152 |
echo "<tr valign='top' name='r:{$srcip}:{$dstip}'> |
|
153 |
<td class='listlr'>{$proto}</td> |
|
154 |
<td class='listr'>{$info}</td> |
|
155 |
<td class='listr'>{$state}</td> |
|
156 |
<td class='list'> |
|
157 |
<img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0' |
|
158 |
onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;' |
|
159 |
name='i:{$srcip}:{$dstip}' |
|
160 |
title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' /> |
|
161 |
</td> |
|
162 |
</tr>"; |
|
163 |
$row++; |
|
105 | 164 |
} |
106 |
} else { |
|
107 |
print '<tr><td colspan="4"><center>No states were found.</center></td></tr>'; |
|
108 | 165 |
} |
109 |
|
|
166 |
else { |
|
167 |
echo "<tr> |
|
168 |
<td class='list' colspan='4' align='center' valign='top'> |
|
169 |
" . gettext("No states were found.") . " |
|
170 |
</td> |
|
171 |
</tr>"; |
|
172 |
} |
|
110 | 173 |
?> |
111 |
</td></tr></table> |
|
174 |
</table> |
|
175 |
</td> |
|
176 |
</tr> |
|
112 | 177 |
</table> |
113 |
</div> |
|
114 |
</center> |
|
115 |
</td></tr> |
|
178 |
|
|
179 |
<!-- End of tab content --> |
|
180 |
|
|
181 |
</div> |
|
182 |
</td> |
|
183 |
</tr> |
|
116 | 184 |
</table> |
117 |
<?php include("fend.inc"); ?> |
|
118 |
<?php if($_GET['filter']): ?> |
|
119 | 185 |
<meta http-equiv="refresh" content="60;url=diag_dump_states.php?filter=<?php echo $_GET['filter']; ?>"> |
120 |
<?php else: ?> |
|
121 |
<meta http-equiv="refresh" content="60;url=diag_dump_states.php"> |
|
122 |
<?php endif; ?> |
|
123 | 186 |
|
187 |
<?php require("fend.inc"); ?> |
|
124 | 188 |
</body> |
125 | 189 |
</html> |
Also available in: Unified diff
Backport diagnostics, show states which now includes a kill state feature.