Commit 56f3f564 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) refactor diag_dump_states.php

parent 3492708a
<?php <?php
/* /*
Copyright (C) 2014 Deciso B.V. Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2005-2009 Scott Ullrich Copyright (C) 2005-2009 Scott Ullrich
Copyright (C) 2005 Colin Smith Copyright (C) 2005 Colin Smith
All rights reserved. All rights reserved.
...@@ -39,7 +39,7 @@ if(isset($_POST['action']) && $_POST['action'] == "remove") { ...@@ -39,7 +39,7 @@ if(isset($_POST['action']) && $_POST['action'] == "remove") {
} else { } else {
echo gettext("invalid input"); echo gettext("invalid input");
} }
return; exit;
} }
if (isset($_POST['filter']) && isset($_POST['killfilter'])) { if (isset($_POST['filter']) && isset($_POST['killfilter'])) {
...@@ -52,156 +52,95 @@ if (isset($_POST['filter']) && isset($_POST['killfilter'])) { ...@@ -52,156 +52,95 @@ if (isset($_POST['filter']) && isset($_POST['killfilter'])) {
$tokill = ""; $tokill = "";
} }
if (!empty($tokill)) { if (!empty($tokill)) {
$retval = mwexec("/sbin/pfctl -k {$tokill} -k 0/0"); mwexec("/sbin/pfctl -k {$tokill} -k 0/0");
$retval = mwexec("/sbin/pfctl -k 0.0.0.0/0 -k {$tokill}"); mwexec("/sbin/pfctl -k 0.0.0.0/0 -k {$tokill}");
} }
} }
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
<?php include("fbegin.inc"); ?> <?php include("fbegin.inc"); ?>
<script type="text/javascript">
<script type="text/javascript"> $( document ).ready(function() {
//<![CDATA[ // delete state
function removeState(srcip, dstip) { $(".act_del").click(function(event){
var busy = function(index,icon) { event.preventDefault();
jQuery(icon).bind("onclick",""); var srcip = $(this).data('srcip');
jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif")); var dstip = $(this).data('dstip');
jQuery(icon).css("cursor","wait"); var rowid = $(this).data('rowid');
}
$.post(window.location, {action: 'remove', srcip: srcip, dstip: dstip}, function(data) {
jQuery('span[name="i:' + srcip + ":" + dstip + '"]').each(busy); $("."+rowid).hide();
});
jQuery.ajax( });
"<?=$_SERVER['SCRIPT_NAME'];?>", });
{
type: "post",
data: {
action: "remove",
srcip: srcip,
dstip: dstip
},
complete: removeComplete
}
);
}
function removeComplete(req) {
var values = req.responseText.split("|");
if(values[3] != "0") {
alert('<?=gettext("An error occurred.");?>');
return;
}
jQuery('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
function(index,row) { jQuery(row).fadeOut(1000); }
);
}
//]]>
</script> </script>
<section class="page-content-main">
<section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<section class="col-xs-12"> <section class="col-xs-12">
<div class="tab-content content-box col-xs-12"> <div class="content-box">
<form action="<?=$_SERVER['SCRIPT_NAME'];?>" method="post" name="iform"> <form method="post" name="iform">
<?php <?php
$current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`; $current_statecount=`pfctl -si | grep "current entries" | awk '{ print $3 }'`;?>
?>
<table class="table table-striped"> <table class="table table-striped">
<thead>
<tr>
<th><?=gettext("Current total state count");?></th>
<th><?=gettext("Filter expression:");?></th>
<th></th>
</tr>
</thead>
<tbody> <tbody>
<tr> <tr>
<td><?=gettext("Current total state count");?>: <?= $current_statecount ?></td> <td><?=$current_statecount?></td>
<td><?=gettext("Filter expression:");?></td> <td>
<td><input type="text" name="filter" class="form-control search" value="<?=htmlspecialchars($_POST['filter']);?>" size="30" /></td> <input type="text" name="filter" value="<?=!empty($_POST['filter']) ? htmlspecialchars($_POST['filter']) : "";?>"/>
<td> <input type="submit" class="btn btn-primary" value="<?=gettext("Filter");?>" /> </td>
<td>
<input type="submit" class="btn btn-primary" value="<?=gettext("Filter");?>" />
<?php if (isset($_POST['filter']) && (is_ipaddr($_POST['filter']) || is_subnet($_POST['filter']))): ?> <?php if (isset($_POST['filter']) && (is_ipaddr($_POST['filter']) || is_subnet($_POST['filter']))): ?>
<input type="submit" class="btn" name="killfilter" value="<?=gettext("Kill");?>" /> <input type="submit" class="btn btn-primary" name="killfilter" value="<?=gettext("Kill");?>" />
<?php endif; ?> <?php endif; ?>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</form> </form>
</div>
<div class="container-fluid tab-content"> </section>
<section class="col-xs-12">
<div class="tab-pane active" id="system">
<div class="content-box"> <div class="content-box">
<div class="content-box-main">
<div class="table-responsive"> <div class="table-responsive">
<table id="state_table" class="table table-condensed table-hover table-striped">
<table class="table table-striped table-sort sortable __nomb"> <thead>
<tr class="content-box-head">
<th>
<table>
<tr>
<td><?=gettext("Int");?></td>
<td>
<span class="table-sort-icon glyphicon glyphicon-sort"></span>
</td>
</tr>
</table>
</th>
<th>
<table>
<tr> <tr>
<td><?=gettext("Proto");?></td> <th data-column-id="int"><?=gettext("Int");?></th>
<td> <th data-column-id="proto"><?=gettext("Proto");?></th>
<span class="table-sort-icon glyphicon glyphicon-sort"></span> <th data-column-id="path"><?=gettext("Source -> Router -> Destination");?></th>
</td> <th data-column-id="state"><?=gettext("State");?></th>
</tr> </tr>
</table> </thead>
</th> <tbody>
<th> <?php
<table>
<tr>
<td><?=gettext("Source -> Router -> Destination");?></td>
<td>
<span class="table-sort-icon glyphicon glyphicon-sort"></span>
</td>
</tr>
</table>
</th>
<th>
<table>
<tr>
<td><?=gettext("State");?></td>
<td>
<span class="table-sort-icon glyphicon glyphicon-sort"></span>
</td>
</tr>
</table>
</th>
<th></th>
</tr>
<?php
$row = 0; $row = 0;
/* get our states */ /* get our states */
$grepline = (isset($_POST['filter'])) ? "| /usr/bin/egrep " . escapeshellarg(htmlspecialchars($_POST['filter'])) : ""; $grepline = (isset($_POST['filter'])) ? "| /usr/bin/egrep " . escapeshellarg(htmlspecialchars($_POST['filter'])) : "";
$fd = popen("/sbin/pfctl -s state {$grepline}", "r" ); $fd = popen("/sbin/pfctl -s state {$grepline}", "r" );
while ($line = chop(fgets($fd))) { while ($line = chop(fgets($fd))):
if($row >= 10000) if ($row >= 10000) {
break; break;
}
$line_split = preg_split("/\s+/", $line); $line_split = preg_split("/\s+/", $line);
$iface = array_shift($line_split); $iface = array_shift($line_split);
$proto = array_shift($line_split); $proto = array_shift($line_split);
$state = array_pop($line_split); $state = array_pop($line_split);
$info = implode(" ", $line_split); $info = htmlspecialchars(implode(" ", $line_split));
// We may want to make this optional, with a large state table, this could get to be expensive. // We may want to make this optional, with a large state table, this could get to be expensive.
$iface = convert_real_interface_to_friendly_descr($iface); $iface = convert_real_interface_to_friendly_descr($iface);
...@@ -212,50 +151,46 @@ include("head.inc"); ...@@ -212,50 +151,46 @@ include("head.inc");
$srcip = trim($parts[0]); $srcip = trim($parts[0]);
$parts = explode(":", $ends[count($ends) - 1]); $parts = explode(":", $ends[count($ends) - 1]);
$dstip = trim($parts[0]); $dstip = trim($parts[0]);
// states can be deleted by source / dest combination, all matching records use the same class.
$rowid = str_replace(array('.', ':'), '_', $srcip.$dstip);
?> ?>
<tr id="r:<?= $srcip ?>:<?= $dstip ?>"> <tr class="r<?=$rowid;?>">
<td class="listlr"><?= $iface ?></td> <td><?= $iface ?></td>
<td class="listr"><?= $proto ?></td> <td><?= $proto ?></td>
<td class="listr"><?= $info ?></td> <td><?= $info ?></td>
<td class="listr"><?= $state ?></td> <td><?= $state ?></td>
<td class="list"> <td>
<a href="#" onclick="removeState('<?= $srcip ?>', '<?= $dstip ?>');" name="i:<?= $srcip ?>:<?= $dstip ?>" class="btn btn-default" title="<?= gettext('Remove all state entries from') ?> <?= $srcip ?> <?= gettext('to') ?> <?= $dstip ?>"><span class="glyphicon glyphicon-remove"></span></a> <a href="#" data-rowid="r<?=$rowid?>" data-srcip="<?=$srcip?>" data-dstip="<?=$dstip;?>" class="act_del btn btn-default" title="<?= gettext('Remove all state entries from') ?> <?= $srcip ?> <?= gettext('to') ?> <?= $dstip ?>"><span class="glyphicon glyphicon-remove"></span></a>
</td> </td>
</tr> </tr>
<?php <?php
$row++; $row++;
ob_flush(); endwhile;
}
if ($row == 0): ?> if ($row == 0): ?>
<tr> <tr>
<td class="list" colspan="5" align="center" valign="top"> <td colspan="5"><?= gettext("No states were found.") ?></td>
<?= gettext("No states were found.") ?>
</td>
</tr> </tr>
<?php endif; <?php
pclose($fd); endif;
?> pclose($fd);?>
</tbody>
<tfoot>
<?php
if (!empty($_POST['filter'])): ?>
<tr>
<td colspan="5"><?=gettext("States matching current filter")?>: <?= $row ?></td>
</tr>
<?php
endif;?>
</tfoot>
</table> </table>
<?php if (isset($_POST['filter']) && !empty($_POST['filter'])): ?>
<div class="col-xs-12"><p><?=gettext("States matching current filter")?>: <?= $row ?></p></div>
<?php endif; ?>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</section> </section>
<?php include('foot.inc');?> <?php include('foot.inc');?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment