";
$in = "";
if (is_array($config['aliases']['alias'])) {
foreach ($config['aliases']['alias'] as $cbalias) {
if (preg_match("/pfB_/", $cbalias['name'])) {
if (file_exists("{$pfb['aliasdir']}/{$cbalias['name']}.txt")) {
preg_match("/(\d+)/", exec("/usr/bin/grep -cv \"^1\.1\.1\.1\" {$pfb['aliasdir']}/{$cbalias['name']}.txt"), $matches);
$pfb_table[$cbalias['name']] = array("count" => $matches[1], "img" => $out);
$updates = exec("ls -ld {$pfb['aliasdir']}/{$cbalias['name']}.txt | awk '{ print $6,$7,$8 }'", $update);
$pfb_table[$cbalias['name']]['up'] = $updates;
}
}
}
}
// Collect if Rules are defined using pfBlockerNG Aliases.
if (is_array($config['filter']['rule'])) {
foreach ($config['filter']['rule'] as $rule) {
if (preg_match("/pfB_/",$rule['source']['address']) || preg_match("/pfb_/",$rule['source']['address'])) {
$pfb_table[$rule['source']['address']]['img'] = $in;
}
if (preg_match("/pfB_/",$rule['destination']['address']) || preg_match("/pfb_/",$rule['destination']['address'])) {
$pfb_table[$rule['destination']['address']]['img'] = $in;
}
}
return $pfb_table;
}
}
// Status Indicator if pfBlockerNG is Enabled/Disabled
if ("{$pfb['enable']}" == "on") {
$pfb_status = "/themes/{$g['theme']}/images/icons/icon_pass.gif";
$pfb_msg = "pfBlockerNG is Active.";
} else {
$pfb_status = "/themes/{$g['theme']}/images/icons/icon_block.gif";
$pfb_msg = "pfBlockerNG is Disabled.";
}
// Collect Total IP/Cidr Counts
$dcount = exec("cat {$pfb['denydir']}/*.txt | grep -cv '^#\|^$\|^1\.1\.1\.1'");
$pcount = exec("cat {$pfb['permitdir']}/*.txt | grep -cv '^#\|^$\|^1\.1\.1\.1'");
$mcount = exec("cat {$pfb['matchdir']}/*.txt | grep -cv '^#\|^$\|^1\.1\.1\.1'");
// Collect Number of Suppressed Hosts
if (file_exists("{$pfb['supptxt']}")) {
$pfbsupp_cnt = exec ("/usr/bin/grep -c ^ {$pfb['supptxt']}");
} else {
$pfbsupp_cnt = 0;
}
#check rule count
#(label, evaluations,packets total, bytes total, packets in, bytes in,packets out, bytes out)
$packets = exec("/sbin/pfctl -s labels", $debug);
if (!empty($packets)) {
foreach ($debug as $line) {
// Auto-Rules start with 'pfB_', Alias Rules should start with 'pfb_' and exact spelling of Alias Name.
$line = str_replace("pfb_","pfB_",$line);
if ("{$pfb['pfsenseversion']}" >= '2.2') {
#USER_RULE: pfB_Top auto rule 8494 17 900 17 900 0 0 0
if (preg_match("/USER_RULE: (\w+).*\s+\d+\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+/", $line, $matches)) {
if (isset($matches)) {
${$matches[1]}+=$matches[2];
} else {
${$matches[1]} = 'Err';
}
}
} else {
#USER_RULE: pfB_Top auto rule 1656 0 0 0 0 0 0
if (preg_match("/USER_RULE: (\w+).*\s+\d+\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+/", $line, $matches)) {
if (isset($matches)) {
${$matches[1]}+=$matches[2];
} else {
${$matches[1]} = 'Err';
}
}
}
}
}
// Called by Ajax to update alerts table contents
if (isset($_GET['getNewCounts'])) {
$response = "";
$pfb_table = pfBlockerNG_get_counts();
if (!empty($pfb_table)) {
foreach ($pfb_table as $alias => $values){
if (!isset(${$alias})) { ${$alias} = "-";}
$response .= $alias . "||" . $values['count'] . "||" . ${$alias} . "||" . $values['up'] . "||" . $values['img'] . "\n";
}
echo $response;
return;
}
}
$out = "";
$in = "";
// Report any Failed Downloads
$results = array();
$fails = exec("grep $(date +%m/%d/%y) {$pfb['errlog']} | grep 'FAIL'", $results);
// Print widget Status Bar Items
?>
=gettext("Status") ?> |
|
=gettext("Deny:"); echo(" " . $dcount . "") ?>
=gettext(" Permit:"); echo(" " . $pcount . "") ?>
=gettext(" Match:"); echo(" " . $mcount . ""); ?>
=gettext(" Suppress:"); echo(" " . $pfbsupp_cnt . ""); ?>
|
|
">
|
|
'2.0') {
$alertRowEvenClass = "listMReven";
$alertRowOddClass = "listMRodd";
$alertColClass = "listMRr";
} else {
$alertRowEvenClass = "listr";
$alertRowOddClass = "listr";
$alertColClass = "listr";
}
# Last errors first
$results = array_reverse($results);
$counter = 0;
# Max errors to display
$maxfailcount = 3;
if (!empty($results)) {
foreach ($results as $result) {
$alertRowClass = $counter % 2 ? $alertRowEvenClass : $alertRowOddClass;
if (!isset(${$alias})) { ${$alias} = "-";}
echo(" " . $result . " |
");
$counter++;
if ($counter > $maxfailcount) {
# To many errors stop displaying
echo("
" . (count($results) - $maxfailcount) . " more error(s)... |
");
break;
}
}
}
// Print Main Table Header
?>
$values) {
$evenRowClass = $counter % 2 ? " listMReven" : " listMRodd";
if (!isset(${$alias})) { ${$alias} = "-";}
echo("
{$alias} |
{$values['count']} |
{${$alias}} |
{$values['up']} |
{$values['img']} |
");
$counter++;
}
}
?>