| 1 |
92cc7528
|
Scott Ullrich
|
<?php
|
| 2 |
|
|
/*
|
| 3 |
a09d815a
|
Scott Ullrich
|
diag_dump_states.php
|
| 4 |
13d193c2
|
Scott Ullrich
|
Copyright (C) 2005-2009 Scott Ullrich
|
| 5 |
|
|
Copyright (C) 2005 Colin Smith
|
| 6 |
a09d815a
|
Scott Ullrich
|
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 |
92cc7528
|
Scott Ullrich
|
*/
|
| 29 |
|
|
|
| 30 |
13d193c2
|
Scott Ullrich
|
/*
|
| 31 |
|
|
pfSense_BUILDER_BINARIES: /sbin/pfctl
|
| 32 |
|
|
pfSense_MODULE: filter
|
| 33 |
|
|
*/
|
| 34 |
|
|
|
| 35 |
6b07c15a
|
Matthew Grooms
|
##|+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 |
92cc7528
|
Scott Ullrich
|
require_once("guiconfig.inc");
|
| 43 |
|
|
|
| 44 |
a09d815a
|
Scott Ullrich
|
/* handle AJAX operations */
|
| 45 |
|
|
if($_GET['action']) {
|
| 46 |
e8d93059
|
Bill Marquette
|
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 |
80b5ddf0
|
Scott Ullrich
|
echo htmlentities("|{$srcip}|{$dstip}|{$retval}|");
|
| 52 |
e8d93059
|
Bill Marquette
|
} else {
|
| 53 |
|
|
echo "invalid input";
|
| 54 |
|
|
}
|
| 55 |
a09d815a
|
Scott Ullrich
|
exit;
|
| 56 |
|
|
}
|
| 57 |
|
|
}
|
| 58 |
|
|
|
| 59 |
ca77763b
|
Scott Ullrich
|
/* get our states */
|
| 60 |
|
|
if($_GET['filter']) {
|
| 61 |
a09d815a
|
Scott Ullrich
|
exec("/sbin/pfctl -s state | grep " . escapeshellarg($_GET['filter']), $states);
|
| 62 |
|
|
}
|
| 63 |
|
|
else {
|
| 64 |
|
|
exec("/sbin/pfctl -s state", $states);
|
| 65 |
ca77763b
|
Scott Ullrich
|
}
|
| 66 |
92cc7528
|
Scott Ullrich
|
|
| 67 |
e8d93059
|
Bill Marquette
|
$pgtitle = array("Diagnostics","Show States");
|
| 68 |
|
|
include("head.inc");
|
| 69 |
|
|
|
| 70 |
92cc7528
|
Scott Ullrich
|
?>
|
| 71 |
|
|
|
| 72 |
a09d815a
|
Scott Ullrich
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
|
| 73 |
|
|
<script src="/javascript/sorttable.js" type="text/javascript"></script>
|
| 74 |
ca77763b
|
Scott Ullrich
|
<?php include("fbegin.inc"); ?>
|
| 75 |
742ee135
|
Scott Ullrich
|
<form action="diag_dump_states.php" method="get" name="iform">
|
| 76 |
a09d815a
|
Scott Ullrich
|
|
| 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 |
30f302f9
|
Scott Ullrich
|
alert('<?=gettext("An error occurred.");?>');
|
| 98 |
a09d815a
|
Scott Ullrich
|
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 |
92cc7528
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
| 108 |
a09d815a
|
Scott Ullrich
|
<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 |
b4031ab6
|
Scott Ullrich
|
<?php
|
| 126 |
|
|
$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;
|
| 127 |
|
|
?>
|
| 128 |
|
|
|
| 129 |
3473bb6a
|
Scott Ullrich
|
<table class="tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0">
|
| 130 |
a09d815a
|
Scott Ullrich
|
<tr>
|
| 131 |
|
|
<td>
|
| 132 |
|
|
<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get">
|
| 133 |
|
|
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
|
| 134 |
ba6d49ff
|
Scott Ullrich
|
<tr>
|
| 135 |
b4031ab6
|
Scott Ullrich
|
<td>Current state count: <?=$current_statecount?></td>
|
| 136 |
a09d815a
|
Scott Ullrich
|
<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 |
ff9d6728
|
Scott Ullrich
|
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
|
| 149 |
a09d815a
|
Scott Ullrich
|
<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 |
ba6d49ff
|
Scott Ullrich
|
</tr>
|
| 155 |
92cc7528
|
Scott Ullrich
|
<?php
|
| 156 |
a09d815a
|
Scott Ullrich
|
$row = 0;
|
| 157 |
ca77763b
|
Scott Ullrich
|
if(count($states) > 0) {
|
| 158 |
|
|
foreach($states as $line) {
|
| 159 |
a09d815a
|
Scott Ullrich
|
if($row >= 1000)
|
| 160 |
ca77763b
|
Scott Ullrich
|
break;
|
| 161 |
a09d815a
|
Scott Ullrich
|
|
| 162 |
ca77763b
|
Scott Ullrich
|
$line_split = preg_split("/\s+/", $line);
|
| 163 |
a09d815a
|
Scott Ullrich
|
$type = array_shift($line_split);
|
| 164 |
ca77763b
|
Scott Ullrich
|
$proto = array_shift($line_split);
|
| 165 |
a09d815a
|
Scott Ullrich
|
$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 |
92cc7528
|
Scott Ullrich
|
}
|
| 188 |
|
|
}
|
| 189 |
a09d815a
|
Scott Ullrich
|
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 |
92cc7528
|
Scott Ullrich
|
?>
|
| 197 |
a09d815a
|
Scott Ullrich
|
</table>
|
| 198 |
|
|
</td>
|
| 199 |
|
|
</tr>
|
| 200 |
92cc7528
|
Scott Ullrich
|
</table>
|
| 201 |
a09d815a
|
Scott Ullrich
|
|
| 202 |
|
|
<!-- End of tab content -->
|
| 203 |
|
|
|
| 204 |
|
|
</div>
|
| 205 |
|
|
</td>
|
| 206 |
|
|
</tr>
|
| 207 |
92cc7528
|
Scott Ullrich
|
</table>
|
| 208 |
1f97829e
|
Scott Ullrich
|
|
| 209 |
a09d815a
|
Scott Ullrich
|
<?php require("fend.inc"); ?>
|
| 210 |
92cc7528
|
Scott Ullrich
|
</body>
|
| 211 |
|
|
</html>
|