Commit 4a2943f7 authored by Franco Fichtner's avatar Franco Fichtner

diagnostics: merge reworked firewall pages from master

parent 9033011d
......@@ -29,68 +29,73 @@
require_once("guiconfig.inc");
$pgtitle = gettext("Diagnostics: pfInfo");
$data_tabs = array("info", "memory", "timeouts", "interfaces");
if($_REQUEST['getactivity']) {
$text = `/sbin/pfctl -vvsi`;
$text .= "<p/>";
$text .= `/sbin/pfctl -vvsm`;
$text .= "<p/>";
$text .= `/sbin/pfctl -vvst`;
$text .= "<p/>";
$text .= `/sbin/pfctl -vvsI`;
echo $text;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['getactivity'])) {
$diag = configd_run("filter diag info json");
echo $diag;
}
exit;
}
include("head.inc");
?>
<body>
<?php include("fbegin.inc"); ?>
<script type="text/javascript">
jQuery(document).ready(function() {setTimeout('getpfinfo()', 500);});
//<![CDATA[
$( document ).ready(function() {
function getpfinfo() {
jQuery.ajax({
type: "POST",
type: "post",
url: "/diag_pf_info.php",
data: 'getactivity=yes',
async: false,
complete: activitycallback
dataType: "json",
success: function(data) {
// push data into tabs
$.each(data, function(key, value) {
if ($("#data_"+key.toLowerCase()).length) {
$("#data_"+key.toLowerCase()).html(value);
}
});
setTimeout(getpfinfo, 2000);
}
function activitycallback(transport) {
jQuery('#pfactivitydiv').html('<font face="Courier" size="2"><pre style="text-align:left;">' + transport.responseText + '<\/pre><\/font>');
setTimeout('getpfinfo()', 2000);
});
}
//]]>
</script>
getpfinfo();
});
</script>
<section class="page-content-main">
<div class="container-fluid col-xs-12 col-sm-10 col-md-9">
<div class="container-fluid col-xs-12">
<div class="row">
<section class="col-xs-12">
<?php
if($savemsg) {
echo "<div id=\"savemsg\">";
print_info_box($savemsg);
echo "</div>";
}
if (isset($input_errors) && count($input_errors) > 0)
print_input_errors($input_errors);
?>
<div id="pfactivitydiv">
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<?php
foreach($data_tabs as $i => $tabname):?>
<li <?= $i == 0 ? 'class="active"' : '';?>>
<a data-toggle="tab" href="#<?=$tabname;?>" id="<?=$tabname;?>_tab">
<?=ucfirst($tabname);?>
</a>
</li>
<?php
endforeach;?>
</ul>
<div class="tab-content content-box tab-content">
<?php
foreach($data_tabs as $i => $tabname):?>
<div id="<?=$tabname;?>" class="tab-pane fade in <?= $i == 0 ? 'active' : '';?>">
<div class="container-fluid">
<pre id="data_<?=$tabname;?>" class="pre-scrollable" >
<?=gettext("Gathering PF information, please wait...");?>
</pre>
</div>
</div>
<?php
endforeach;?>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
......@@ -27,18 +27,21 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
exec("/sbin/pfctl -s state", $states);
$srcipinfo = array();
$dstipinfo = array();
$allipinfo = array();
$pairipinfo = array();
require_once("guiconfig.inc");
function addipinfo(&$iparr, $ip, $proto, $srcport, $dstport) {
if (!isset($iparr[$ip]['seen'])) {
$iparr[$ip] = array("seen" => 0, "protos" => array());
}
if (!isset($iparr[$ip]['protos'][$proto])) {
$iparr[$ip]['protos'][$proto] = array("seen" => 0, 'srcports' => array(), 'dstports' => array());
}
$iparr[$ip]['seen']++;
$iparr[$ip]['protos'][$proto]['seen']++;
if (!empty($srcport)) {
if (!isset($iparr[$ip]['protos'][$proto]['srcports'][$srcport])) {
$iparr[$ip]['protos'][$proto]['srcports'][$srcport] = 0;
}
$iparr[$ip]['protos'][$proto]['srcports'][$srcport]++;
}
if (!empty($dstport)) {
......@@ -46,58 +49,46 @@ function addipinfo(&$iparr, $ip, $proto, $srcport, $dstport) {
}
}
$row = 0;
if(count($states) > 0) {
foreach($states as $line) {
$line_split = preg_split("/\s+/", $line);
$iface = array_shift($line_split);
$proto = array_shift($line_split);
$state = array_pop($line_split);
$info = implode(" ", $line_split);
/* Handle NAT cases
Replaces an external IP + NAT by the internal IP */
if (strpos($info, ') ->') !== FALSE) {
/* Outbound NAT */
$info = preg_replace('/(\S+) \((\S+)\)/U', "$2", $info);
} elseif (strpos($info, ') <-') !== FALSE) {
/* Inbound NAT/Port Forward */
$info = preg_replace('/(\S+) \((\S+)\)/U', "$1", $info);
}
/* break up info and extract $srcip and $dstip */
$ends = preg_split("/\<?-\>?/", $info);
function sort_by_ip($a, $b) {
return ip2ulong($a) < ip2ulong($b) ? -1 : 1;
}
if (strpos($info, '->') === FALSE) {
$srcinfo = $ends[count($ends) - 1];
$dstinfo = $ends[0];
} else {
$srcinfo = $ends[0];
$dstinfo = $ends[count($ends) - 1];
function build_port_info($portarr, $proto) {
if (empty($portarr)) {
return '';
}
/* Handle IPv6 */
$parts = explode(":", $srcinfo);
$partcount = count($parts);
if ($partcount <= 2) {
$srcip = trim($parts[0]);
$srcport = trim($parts[1]);
} else {
preg_match("/([0-9a-f:]+)(\[([0-9]+)\])?/i", $srcinfo, $matches);
$srcip = $matches[1];
$srcport = trim($matches[3]);
$ports = array();
asort($portarr);
foreach (array_reverse($portarr, TRUE) as $port => $count) {
$str = "";
$service = getservbyport($port, strtolower($proto));
$port = "{$proto}/{$port}";
if (!empty($service)) {
$port = "{$port} ({$service})";
}
$ports[] = "{$port}: {$count}";
}
return implode($ports, ', ');
}
$srcipinfo = array();
$dstipinfo = array();
$allipinfo = array();
$pairipinfo = array();
$parts = explode(":", $dstinfo);
$partcount = count($parts);
if ($partcount <= 2) {
$dstip = trim($parts[0]);
$dstport = trim($parts[1]);
$states = json_decode(configd_run("filter list states json"), true);
if(isset($states['details'])) {
foreach($states['details'] as $state) {
if (isset($state['nat_addr']) && $states['direction'] == 'out') {
$srcip = $state['nat_addr'] ;
$srcport = $state['nat_port'] ;
} else {
preg_match("/([0-9a-f:]+)(\[([0-9]+)\])?/i", $dstinfo, $matches);
$dstip = $matches[1];
$dstport = trim($matches[3]);
$srcip = $state['src_addr'] ;
$srcport = $state['src_port'] ;
}
$dstip = $state['dst_addr'] ;
$dstport = $state['dst_port'] ;
$proto = $state['proto'];
addipinfo($srcipinfo, $srcip, $proto, $srcport, $dstport);
addipinfo($dstipinfo, $dstip, $proto, $srcport, $dstport);
......@@ -109,76 +100,52 @@ if(count($states) > 0) {
}
}
function sort_by_ip($a, $b) {
return ip2ulong($a) < ip2ulong($b) ? -1 : 1;
}
function build_port_info($portarr, $proto) {
if (!$portarr)
return '';
$ports = array();
asort($portarr);
foreach (array_reverse($portarr, TRUE) as $port => $count) {
$str = "";
$service = getservbyport($port, strtolower($proto));
$port = "{$proto}/{$port}";
if ($service)
$port = "{$port} ({$service})";
$ports[] = "{$port}: {$count}";
function print_summary_table($label, $iparr, $sort = TRUE) {
if ($sort) {
uksort($iparr, "sort_by_ip");
}
return implode($ports, ', ');
}
function print_summary_table($label, $iparr, $sort = TRUE) { ?>
?>
<section class="col-xs-12">
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?php echo $label; ?></h3>
<h3><?=$label; ?></h3>
</header>
<div class="table-responsive">
<table class="table table-striped table-sort sortable __nomb">
<table class="table table-striped">
<tr>
<td class="listhdrr"><?=gettext("IP");?></td>
<td class="listhdrr"># <?=gettext("States");?></td>
<td class="listhdrr"><?=gettext("Proto");?></td>
<td class="listhdrr"># <?=gettext("States");?></td>
<td class="listhdrr"><?=gettext("Src Ports");?></td>
<td class="listhdrr"><?=gettext("Dst Ports");?></td>
<td><?=gettext("IP");?></td>
<td># <?=gettext("States");?></td>
<td><?=gettext("Proto");?></td>
<td># <?=gettext("States");?></td>
<td><?=gettext("Src Ports");?></td>
<td><?=gettext("Dst Ports");?></td>
</tr>
<?php if ($sort)
uksort($iparr, "sort_by_ip");
<?php
foreach($iparr as $ip => $ipinfo) { ?>
<tr>
<td class="vncell"><?php echo $ip; ?></td>
<td class="vncell"><?php echo $ipinfo['seen']; ?></td>
<td class="vncell">&nbsp;</td>
<td class="vncell">&nbsp;</td>
<td class="vncell">&nbsp;</td>
<td class="vncell">&nbsp;</td>
<td><?= $ip; ?></td>
<td><?= $ipinfo['seen']; ?></td>
<td colspan="4">&nbsp;</td>
</tr>
<?php foreach($ipinfo['protos'] as $proto => $protoinfo) { ?>
<?php foreach($ipinfo['protos'] as $proto => $protoinfo) { ?>
<tr>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="listlr"><?php echo $proto; ?></td>
<td class="listr" align="center"><?php echo $protoinfo['seen']; ?></td>
<td class="listr" align="center"><span title="<?php echo build_port_info($protoinfo['srcports'], $proto); ?>"><?php echo count($protoinfo['srcports']); ?></span></td>
<td class="listr" align="center"><span title="<?php echo build_port_info($protoinfo['dstports'], $proto); ?>"><?php echo count($protoinfo['dstports']); ?></span></td>
<td colspan="2">&nbsp;</td>
<td><?=$proto; ?></td>
<td ><?=$protoinfo['seen']; ?></td>
<td ><span data-toggle="tooltip" title="<?=build_port_info($protoinfo['srcports'], $proto); ?>"><?=count($protoinfo['srcports']); ?></span></td>
<td ><span data-toggle="tooltip" title="<?=build_port_info($protoinfo['dstports'], $proto); ?>"><?=count($protoinfo['dstports']); ?></span></td>
</tr>
<?php } ?>
<?php } ?>
</table>
</div>
</div>
</section>
<?php
}
$pgtitle = array(gettext("Diagnostics"),gettext("State Table Summary"));
require_once("guiconfig.inc");
include("head.inc");
echo "<body>";
include("fbegin.inc");
......@@ -186,18 +153,12 @@ include("fbegin.inc");
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?
print_summary_table(gettext("By Source IP"), $srcipinfo);
print_summary_table(gettext("By Destination IP"), $dstipinfo);
print_summary_table(gettext("Total per IP"), $allipinfo);
print_summary_table(gettext("By IP Pair"), $pairipinfo, FALSE);
?>
</section>
</div>
</div>
</section>
......
......@@ -28,178 +28,142 @@
require_once("guiconfig.inc");
$pgtitle = gettext("Diagnostics: pfTop");
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src');
$viewtypes = array('default', 'label', 'long', 'rules', 'size', 'speed', 'state', 'time');
$viewall = array('label', 'rules');
$numstates = array('50', '100', '200', '500', '1000', 'all');
if($_REQUEST['getactivity']) {
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
$viewtype = escapeshellarg($_REQUEST['viewtype']);
if (in_array($_REQUEST['viewtype'], $viewall)) {
$sorttype = "";
$numstate = "-a";
} else {
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
$numstates = array('50', '100', '200', '500', '1000', '99999999999');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// fetch only valid input data (items from above lists)
$viewtype = 'default';
$numstate = '200';
$sorttype ='bytes';
if (isset($_POST['viewtype']) && in_array($_POST['viewtype'], $viewtypes)) {
$viewtype = $_POST['viewtype'];
}
} else {
$sorttype = "bytes";
$viewtype = "default";
$numstate = "100";
if (isset($_POST['states']) && in_array($_POST['states'], $numstates)) {
$numstate = $_POST['states'];
}
if (isset($_POST['sorttype']) && in_array($_POST['sorttype'], $sorttypes)) {
$sorttype = $_POST['sorttype'];
}
$text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`;
echo $text;
// fetch pftop data
echo configd_run("filter diag top {$sorttype} {$viewtype} {$numstate}");
exit;
}
$pgtitle = gettext("Diagnostics: pfTop");
include("head.inc");
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
$viewtype = escapeshellarg($_REQUEST['viewtype']);
if (in_array($_REQUEST['viewtype'], $viewall)) {
$sorttype = "";
$numstate = "-a";
} else {
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
}
} else {
$sorttype = "bytes";
$viewtype = "default";
$numstate = "100";
}
?>
<body>
<?php include("fbegin.inc"); ?>
<script type="text/javascript">
//<![CDATA[
$( document ).ready(function() {
/**
* fetch pftop data from backend
*/
function getpftopactivity() {
var url = "/diag_system_pftop.php";
var pars = 'getactivity=yes&sorttype=' + jQuery('#sorttype').val() + '&viewtype=' + jQuery('#viewtype').val() + '&states=' + jQuery('#states').val();
jQuery.ajax(
url,
$.ajax(
'/diag_system_pftop.php',
{
type: 'post',
data: pars,
complete: activitycallback
data: {'getactivity':'yes'
,'sorttype':$('#sorttype').val()
,'viewtype':$('#viewtype').val()
,'states':$('#states').val()
},
complete: function(transport) {
$('#pftopactivitydiv').html('<pre>' + transport.responseText + '<\/pre>');
setTimeout(getpftopactivity, 2500);
}
});
}
function activitycallback(transport) {
jQuery('#pftopactivitydiv').html('<pre>' + transport.responseText + '<\/pre>');
setTimeout('getpftopactivity()', 2500);
$("#viewtype").change(function() {
var selected = $("#viewtype option:selected").val();
switch(selected) {
case "rules":
$(".show_opt").addClass("hidden");
break;
default:
$(".show_opt").removeClass("hidden");
}
setTimeout('getpftopactivity()', 1000);
//]]>
</script>
});
// toggle initial viewtype select
$("#viewtype").change();
// start initial fetch
getpftopactivity();
});
</script>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<div class="table-responsive">
<form method="post" action="<?=$_SERVER['REQUEST_URI'];?>">
<table class="table table-striped __nomb">
<table class="table table-striped">
<thead>
<tr>
<th><?=gettext("View type:"); ?></th>
<th><?=gettext("Sort type:"); ?></th>
<th><?=gettext("Number of States:"); ?></th>
<th class="show_opt"><?=gettext("Sort type:"); ?></th>
<th class="show_opt"><?=gettext("Number of States:"); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td><select name='viewtype' id='viewtype' class="form-control">
<option value='default' <?php echo ($viewtype == "default") ? "selected=\"selected\"" : ""; ?>><?=gettext("Default");?></option>
<option value='label' <?php echo ($viewtype == "label") ? "selected=\"selected\"" : ""; ?>><?=gettext("Label");?></option>
<option value='long' <?php echo ($viewtype == "long") ? "selected=\"selected\"" : ""; ?>><?=gettext("Long");?></option>
<option value='rules' <?php echo ($viewtype == "rules") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rules");?></option>
<option value='size' <?php echo ($viewtype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
<option value='speed' <?php echo ($viewtype == "speed") ? "selected=\"selected\"" : ""; ?>><?=gettext("Speed");?></option>
<option value='state' <?php echo ($viewtype == "state") ? "selected=\"selected\"" : ""; ?>><?=gettext("State");?></option>
<option value='time' <?php echo ($viewtype == "time") ? "selected=\"selected\"" : ""; ?>><?=gettext("Time");?></option>
</select></td>
<td><select name='sorttype' id='sorttype' class="form-control">
<option value='age' <?php echo ($sorttype == "age") ? "selected=\"selected\"" : ""; ?>><?=gettext("Age");?></option>
<option value='bytes' <?php echo ($sorttype == "bytes") ? "selected=\"selected\"" : ""; ?>><?=gettext("Bytes");?></option>
<option value='dest' <?php echo ($sorttype == "dest") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Address");?></option>
<option value='dport' <?php echo ($sorttype == "dport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Port");?></option>
<option value='exp' <?php echo ($sorttype == "exp") ? "selected=\"selected\"" : ""; ?>><?=gettext("Expiry");?></option>
<option value='none' <?php echo ($sorttype == "none") ? "selected=\"selected\"" : ""; ?>><?=gettext("None");?></option>
<option value='peak' <?php echo ($sorttype == "peak") ? "selected=\"selected\"" : ""; ?>><?=gettext("Peak");?></option>
<option value='pkt' <?php echo ($sorttype == "pkt") ? "selected=\"selected\"" : ""; ?>><?=gettext("Packet");?></option>
<option value='rate' <?php echo ($sorttype == "rate") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rate");?></option>
<option value='size' <?php echo ($sorttype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
<option value='sport' <?php echo ($sorttype == "sport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Port");?></option>
<option value='src' <?php echo ($sorttype == "src") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Address");?></option>
</select></td>
<td><select name='states' id='states' class="form-control">
<option value='50' <?php echo ($numstate == "50") ? "selected=\"selected\"" : ""; ?>>50</option>
<option value='100' <?php echo ($numstate == "100") ? "selected=\"selected\"" : ""; ?>>100</option>
<option value='200' <?php echo ($numstate == "200") ? "selected=\"selected\"" : ""; ?>>200</option>
<option value='500' <?php echo ($numstate == "500") ? "selected=\"selected\"" : ""; ?>>500</option>
<option value='1000' <?php echo ($numstate == "1000") ? "selected=\"selected\"" : ""; ?>>1000</option>
<option value='all' <?php echo ($numstate == "all") ? "selected=\"selected\"" : ""; ?>>all</option>
</select></td>
<td>
<select name='viewtype' id='viewtype' class="selectpicker" data-width="auto" data-live-search="true">
<option value='default' selected="selected"><?=gettext("Default");?></option>
<option value='label'><?=gettext("Label");?></option>
<option value='long'><?=gettext("Long");?></option>
<option value='rules'><?=gettext("Rules");?></option>
<option value='size'><?=gettext("Size");?></option>
<option value='speed'><?=gettext("Speed");?></option>
<option value='state'><?=gettext("State");?></option>
<option value='time'><?=gettext("Time");?></option>
</select>
</td>
<td class="show_opt">
<div>
<select name='sorttype' id='sorttype' class="selectpicker" data-width="auto" data-live-search="true">
<option value='age'><?=gettext("Age");?></option>
<option value='bytes'><?=gettext("Bytes");?></option>
<option value='dest'><?=gettext("Destination Address");?></option>
<option value='dport'><?=gettext("Destination Port");?></option>
<option value='exp'><?=gettext("Expiry");?></option>
<option value='none'><?=gettext("None");?></option>
<option value='peak'><?=gettext("Peak");?></option>
<option value='pkt'><?=gettext("Packet");?></option>
<option value='rate'><?=gettext("Rate");?></option>
<option value='size'><?=gettext("Size");?></option>
<option value='sport'><?=gettext("Source Port");?></option>
<option value='src'><?=gettext("Source Address");?></option>
</select>
</div>
</td>
<td class="show_opt">
<div id='statesdiv'>
<select name='states' id='states' class="selectpicker" data-width="auto" data-live-search="true">
<option value='50'>50</option>
<option value='100'>100</option>
<option value='200' selected="selected">200</option>
<option value='500'>500</option>
<option value='1000'>1000</option>
<option value='9999999999'>all</option>
</select>
</div>
</td>
</tr>
</tbody>
</table>
</form>
</div>
<section class="col-xs-12">
<?php
if($savemsg) {
echo "<div id=\"savemsg\">";
print_info_box($savemsg);
echo "</div>";
}
if (isset($input_errors) && count($input_errors) > 0)
print_input_errors($input_errors);
?>
<div id="pftopactivitydiv"><?=gettext("Gathering pfTOP activity, please wait...");?></div>
</section>
</section>
</div>
</div>
</section>
<script type="text/javascript">
//<![CDATA[
jQuery("#viewtype").change(function() {
var selected = jQuery("#viewtype option:selected");
switch(selected.val()) {
case "label":
case "rules":
jQuery("#sorttype, #sorttypediv, #statesdiv, #states").hide();
break;
default:
jQuery("#sorttype, #sorttypediv, #statesdiv, #states").show();
}
});
//]]>
</script>
<?php include("foot.inc"); ?>
......@@ -30,55 +30,59 @@
POSSIBILITY OF SUCH DAMAGE.
*/
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
$shortcut_section = "aliases";
require_once("guiconfig.inc");
// Set default table
$tablename = "sshlockout";
if($_REQUEST['type'])
$tablename = $_REQUEST['type'];
if($_REQUEST['delete']) {
if(is_ipaddr($_REQUEST['delete']) || is_subnet($_REQUEST['delete'])) {
exec("/sbin/pfctl -t " . escapeshellarg($_REQUEST['type']) . " -T delete " . escapeshellarg($_REQUEST['delete']), $delete);
echo htmlentities($_REQUEST['delete']);
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (!empty($_GET['tablename'])) {
$tablename = htmlspecialchars($_GET['tablename']);
} else {
// Set default table
$tablename = "sshlockout";
}
if (isset($_GET['savemsg'])) {
$savemsg = htmlspecialchars($_GET['savemsg']);
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['tablename'])) {
$tablename = $_POST['tablename'];
}
if (isset($_POST['act']) && $_POST['act'] == 'update_bogons') {
try {
configd_run("filter update bogons");
} catch (Exception $e) {
$savemsg = gettext("The bogons database has NOT been updated.");
} finally {
$savemsg = gettext("The bogons database has been updated.");
}
echo $savemsg;
exit;
} elseif (isset($_POST['act']) && $_POST['act'] == 'delete') {
// delete entry
if((is_ipaddr($_REQUEST['address']) || is_subnet($_REQUEST['address'])) && !empty($tablename)) {
$delEntry = escapeshellarg($_REQUEST['address']);
$delTable = escapeshellarg($tablename);
configd_run("filter delete table {$delTable} {$delEntry}");
header("Location: diag_tables.php?tablename=" . $tablename);
exit;
}
if($_REQUEST['deleteall']) {
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
if(is_array($entries)) {
foreach($entries as $entryA) {
$entry = trim($entryA);
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T delete " . escapeshellarg($entry), $delete);
}
} elseif (isset($_POST['act']) && $_POST['act'] == 'flush') {
$delTable = escapeshellarg($tablename);
configd_run("filter delete table {$delTable} ALL");
header("Location: diag_tables.php?tablename=" . $tablename);
exit;
}
}
if((($tablename == "bogons") || ($tablename == "bogonsv6")) && ($_POST['Download'])) {
mwexec_bg('/usr/local/etc/rc.update_bogons now');
$maxtimetowait = 0;
$loading = true;
while($loading == true) {
$isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`;
if($isrunning == "")
$loading = false;
$maxtimetowait++;
if($maxtimetowait > 89)
$loading = false;
sleep(1);
}
if($maxtimetowait < 90)
$savemsg = gettext("The bogons database has been updated.");
$pgtitle = array(gettext("Diagnostics"), gettext("Tables"));
$shortcut_section = "aliases";
// fetch list of tables and content of selected table
$tables = json_decode(configd_run("filter list tables json"));
if (in_array($tablename, $tables)) {
$entries = json_decode(configd_run("filter list table {$tablename} json"));
} else {
$entries = array();
}
exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries);
exec("/sbin/pfctl -sT", $tables);
include("head.inc");
?>
<body>
......@@ -86,100 +90,113 @@ include("head.inc");
<script type="text/javascript">
//<![CDATA[
function method_change(entrytype) {
window.location='diag_tables.php?type=' + entrytype;
}
function del_entry(entry) {
jQuery.ajax("diag_tables.php?type=<?php echo htmlspecialchars($tablename);?>&delete=" + entry, {
complete: function(response) {
if (200 == response.status) {
// Escape all dots to not confuse jQuery selectors
name = response.responseText.replace(/\./g,'\\.');
name = name.replace(/\//g,'\\/');
jQuery('#' + name).fadeOut(1000);
}
$( document ).ready(function() {
// on change pfTable selection
$("#tablename").change(function(){
window.location='diag_tables.php?tablename=' + $(this).val();
});
// delete entry
$(".act_delete").click(function(event){
event.preventDefault()
var address = $(this).attr("data-address");
$("#address").val(address);
$("#action").val("delete");
$("#iform").submit();
});
// update bogons
$("#update_bogons").click(function(event){
event.preventDefault()
$("#update_bogons_progress").addClass("fa fa-spinner fa-pulse");
//update_bogons
jQuery.ajax({
type: "post",
url: "/diag_tables.php",
data:{'act':'update_bogons'},
success: function(data) {
// reload page when finished, send result as savemessage.
window.location='diag_tables.php?tablename=' + $("#tablename").val()+'&savemsg='+data;
}
});
});
// flush table.. first ask user if it's ok to do so..
$("#flushtable").click(function(event){
event.preventDefault()
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Tables");?>",
message: "<?=gettext("Do you really want to flush this table?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#action").val("flush");
$("#iform").submit()
}
//]]>
}]
});
});
});
</script>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<form method="post" action="<?=$_SERVER['REQUEST_URI'];?>">
<section class="col-xs-12">
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<select id="type" onchange="method_change(jQuery('#type').val());" name="type" class='form-control'>
<option value="">Table</option>
<?php foreach ($tables as $table) {
echo "<option value=\"{$table}\"";
if ($tablename == $table)
echo " selected=\"selected\"";
echo ">{$table}</option>\n";
}
?>
<form method="post" id="iform" action="<?=$_SERVER['REQUEST_URI'];?>">
<input type="hidden" name="act" id="action"/>
<input type="hidden" name="address" id="address"/>
<section class="col-xs-12">
<select id="tablename" name="tablename" class="selectpicker" data-width="auto" data-live-search="true">
<?php
foreach ($tables as $table):?>
<option value="<?=$table;?>" <?=$tablename == $table ? " selected=\"selected\"" : "";?>>
<?=$table;?>
</option>
<?php
endforeach;?>
</select>
<button class="btn btn-default" id="flushtable"><?=gettext("Flush");?></button>
<button class="btn btn-default pull-right" id="update_bogons"><i id="update_bogons_progress" class=""></i>
<?=gettext("Update bogons");?>
</button>
</section>
<section class="col-xs-12">
<div class="content-box">
<div class="table-responsive">
<table class="table table-striped table-sort sortable __nomb">
<table class="table table-striped">
<tr>
<td class="listhdrr"><?=gettext("IP Address");?></td>
<td colspan="2"><?=gettext("IP Address");?></td>
</tr>
<?php $count = 0; foreach($entries as $entryA): ?>
<?php $entry = trim($entryA); ?>
<tr id="<?=$entry?>">
<td>
<?php echo $entry; ?>
</td>
<?php
if (count($entries) ==0):?>
<tr>
<td colspan="2"><?=gettext("No entries exist in this table.");?></td>
</tr>
<?php
endif;
foreach ($entries as $entry):?>
<tr>
<td><?=$entry;?></td>
<td>
<?php if ( ($tablename != "bogons") && ($tablename != "bogonsv6") ) { ?>
<a onclick="del_entry('<?=htmlspecialchars($entry)?>');" alt="delete">
<a data-address="<?=$entry;?>" title="<?=gettext("delete this entry"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</a>
<?php } ?>
</td>
</tr>
<?php $count++; endforeach; ?>
<?php
if($count == 0)
if( ($tablename == "bogons") || ($tablename == "bogonsv6") )
echo "<tr><td>" . gettext("No entries exist in this table.") . "&nbsp;&nbsp;" . "<input name=\"Download\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("Download") . "\" /> " . gettext(" the latest bogon data.");
else
echo "<tr><td>" . gettext("No entries exist in this table.");
?>
<?php
if($count > 0)
if( ($tablename == "bogons") || ($tablename == "bogonsv6") ) {
$last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename));
echo "<tr><td>&nbsp;<b>$count</b> " . gettext("entries in this table.") . "&nbsp;&nbsp;" . "<input name=\"Download\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("Download") . "\" /> " . gettext(" the latest bogon data.") . "<br />" . "$last_updated";
}
else
echo "<tr><td>" . gettext("Delete") . " <a href=\"diag_tables.php?deleteall=true&amp;type=" . htmlspecialchars($tablename) . "\">" . gettext("all") . "</a> " . "<b>$count</b> " . gettext("entries in this table.");
?>
</td></tr>
<?php
endforeach;?>
</table>
</div>
</div>
</section>
</form>
</div>
</div>
</section>
<?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