diag_dump_states_sources.php 6.19 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2
<?php
/*
3
	Copyright (C) 2014 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
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
	Copyright (C) 2005-2009 Scott Ullrich
	Copyright (C) 2005 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.
*/

require_once("guiconfig.inc");

/* handle AJAX operations */
if($_GET['action']) {
	if($_GET['action'] == "remove") {
		if (is_ipaddr($_GET['srcip']) and is_ipaddr($_GET['dstip'])) {
			$retval = mwexec("/sbin/pfctl -K " . escapeshellarg($_GET['srcip']) . " -K " . escapeshellarg($_GET['dstip']));
			echo htmlentities("|{$_GET['srcip']}|{$_GET['dstip']}|{$retval}|");
		} else {
			echo gettext("invalid input");
		}
		exit;
	}
}

/* get our states */
if($_GET['filter']) {
	exec("/sbin/pfctl -s Sources | grep " . escapeshellarg(htmlspecialchars($_GET['filter'])), $sources);
}
else {
	exec("/sbin/pfctl -s Sources", $sources);
}

$pgtitle = array(gettext("Diagnostics"),gettext("Show Source Tracking"));
include("head.inc");

?>

58
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
Ad Schellevis's avatar
Ad Schellevis committed
59 60 61 62 63 64 65 66 67 68 69 70
<?php include("fbegin.inc"); ?>
<form action="diag_dump_states_sources.php" method="get" name="iform">

<script type="text/javascript">
//<![CDATA[
	function removeSource(srcip, dstip) {
		var busy = function(index,icon) {
			jQuery(icon).bind("onclick","");
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
			jQuery(icon).css("cursor","wait");
		}

71
		jQuery('span[name="i:' + srcip + ":" + dstip + '"]').each(busy);
Ad Schellevis's avatar
Ad Schellevis committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

		jQuery.ajax(
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
				"?action=remove&srcip=" + srcip + "&dstip=" + dstip,
			{ type: "get", complete: removeComplete }
		);
	}

	function removeComplete(req) {
		var values = req.responseText.split("|");
		if(values[3] != "0") {
			alert('<?=gettext("An error occurred.");?>');
			return;
		}

		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
			function(index,row) { jQuery(row).fadeOut(1000); }
		);
	}
//]]>
</script>

94
<table class="table table-striped" width="100%" border="0" cellpadding="0" cellspacing="0">
Ad Schellevis's avatar
Ad Schellevis committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	<tr>
		<td>
		<?php
			$tab_array = array();
			$tab_array[] = array(gettext("States"), false, "diag_dump_states.php");
			$tab_array[] = array(gettext("Source Tracking"), true, "diag_dump_states_sources.php");
			$tab_array[] = array(gettext("Reset States"), false, "diag_resetstate.php");
			display_top_tabs($tab_array);
		?>
		</td>
	</tr>
	<tr>
		<td>
			<div id="mainarea">

<!-- Start of tab content -->

112
<table class="table table-striped tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
Ad Schellevis's avatar
Ad Schellevis committed
113 114 115 116 117 118 119
	<tr>
		<td>
			<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="get">
			<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td style="font-weight:bold;" align="right">
						<?=gettext("Filter expression:");?>
120 121 122 123 124 125 126
					</td>
					<td>
					</td>
				</tr>

				<tr>
					<td style="font-weight:bold;" align="right">
Ad Schellevis's avatar
Ad Schellevis committed
127
						<input type="text" name="filter" class="formfld search" value="<?=htmlspecialchars($_GET['filter']);?>" size="30" />
128 129 130
					</td>
					<td>
						<input type="submit" class="btn btn-primary formbtn" value="<?=gettext("Filter");?>" />
Ad Schellevis's avatar
Ad Schellevis committed
131 132 133 134 135 136 137 138
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<tr>
		<td>
139
			<table class="table table-striped tabcont sortable" width="100%" border="0" cellspacing="0" cellpadding="0">
Ad Schellevis's avatar
Ad Schellevis committed
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
				<thead>
				<tr>
					<th class="listhdrr" width="40%"><?=gettext("Source -> Destination");?></th>
					<th class="listhdrr" width="15%"><?=gettext("# States");?></th>
					<th class="listhdrr" width="15%"><?=gettext("# Connections");?></th>
					<th class="listhdr" width="15%"><?=gettext("Rate");?></th>
					<th class="list sort_ignore" width="1%"></th>
				</tr>
				</thead>
				<tbody>
<?php
$row = 0;
if(count($sources) > 0) {
	foreach($sources as $line) {
		if($row >= 1000)
			break;

		// 192.168.20.2 -> 216.252.56.1 ( states 10, connections 0, rate 0.0/0s )

		$source_split = "";
		preg_match("/(.*)\s\(\sstates\s(.*),\sconnections\s(.*),\srate\s(.*)\s\)/", $line, $source_split);
		list($all, $info, $numstates, $numconnections, $rate) = $source_split;

		$source_split = "";
		preg_match("/(.*)\s\<?-\>?\s(.*)/", $info, $source_split);
		list($all, $srcip, $dstip) = $source_split;

		?>
		<tr valign='top' name='r:<?php echo "{$srcip}:{$dstip}" ?>'>
				<td class='listlr'><?php echo $info;?></td>
				<td class='listr'><?php echo $numstates;?></td>
				<td class='listr'><?php echo $numconnections;?></td>
				<td class='listr'><?php echo $rate;?></td>
				<td class='list'>
174
				<span class='glyphicon glyphicon-remove'
Ad Schellevis's avatar
Ad Schellevis committed
175 176
					onclick="removeSource(<?php echo "'{$srcip}', '{$dstip}'"; ?>);" style='cursor:pointer;'
					name='i:<?php echo "{$srcip}:{$dstip}"; ?>'
177 178
					title='<?php echo gettext("Remove all source tracking entries from") . " {$srcip} " . gettext("to") . " {$dstip}";?>' alt='' >
				</span>
Ad Schellevis's avatar
Ad Schellevis committed
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
				</td>
			  </tr>
		<?php
		$row++;
	}
}
else {
	echo "<tr>
			<td class='list' colspan='5' align='center' valign='top'>
			  " . gettext("No source tracking entries were found.") . "
			</td>
		  </tr>";
}
?>
			</tbody>
			</table>
		</td>
	</tr>
</table>

<!-- End of tab content -->

		</div>
	</td>
  </tr>
</table>

Ad Schellevis's avatar
Ad Schellevis committed
206
<?php include("foot.inc"); ?>
Ad Schellevis's avatar
Ad Schellevis committed
207 208
</body>
</html>