Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pfblockerng.inc #37

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ function pfb_global() {
$pfb['dnsbl_port_ssl'] = $pfb['dnsblconfig']['pfb_dnsport_ssl']; // Lighttpd web server https port setting
$pfb['dnsbl_alexa'] = $pfb['dnsblconfig']['alexa_enable']; // Alexa whitelist

// Restore previous download on failure (default to 'on')
$pfb['restore'] = $pfb['config']['restore_feed'] != '' ? $pfb['config']['restore_feed'] : 'on';
// Max daily download failure threshold (default to '0')
// Max daily download failure threshold (default to '0' unlimited failures)
$pfb['skipfeed'] = $pfb['config']['skipfeed'] != '' ? $pfb['config']['skipfeed'] : 0;

if (isset($config['unbound']['enable'])) {
Expand Down Expand Up @@ -1068,7 +1066,7 @@ function find_reported_header($ip, $pfbfolder, $exclude=FALSE) {

// Query for any active pfBlockerNG CRON jobs
exec('/bin/ps -wax', $result_cron);
if (preg_grep("/pfblockerng[.]php\s+?(cron|update)/", $result_cron)) {
if (preg_grep("/pfblockerng[.]php\s+?(cron|update|updatednsbl)/", $result_cron)) {
return array('updating..', 'CRON Task');
}
return array('', 'no match', FALSE);
Expand Down Expand Up @@ -1350,15 +1348,13 @@ function pfb_download_failure($alias, $header, $pfbfolder, $vtype, $list_url) {
}
}

// On download failure, create file marker for subsequent download attempts
if ($pfb['restore'] == 'on' && $pfb['skipfeed'] != 0) {
// Call function to get all previous download fails
pfb_failures();
// Call function to get all previous download fails
pfb_failures();

if ($pfb['failed'][$header] <= $pfb['skipfeed']) {
touch("{$pfbfolder}/{$header}.fail");
return;
}
// On download failure, create file marker for subsequent download attempts. ('0' no download failure threshold)
if ($pfb['skipfeed'] == 0 || $pfb['failed'][$header] <= $pfb['skipfeed']) {
touch("{$pfbfolder}/{$header}.fail");
return;
}

unlink_if_exists("{$pfbfolder}/{$header}.fail");
Expand Down Expand Up @@ -1525,7 +1521,7 @@ function pfb_firewall_rule($action, $pfb_alias, $vtype='', $pfb_log, $adest='',
$rule['log'] = '';
}
$rule['created'] = array('time' => (int)microtime(true), 'username' => 'Auto');
$rule['match_outbound'][] = $rule;
$pfb['match_outbound'][] = $rule;
if ($action != 'Match_Both') {
break;
}
Expand Down Expand Up @@ -1777,6 +1773,7 @@ function sync_package_pfblockerng($cron='') {
// Reloads existing lists without downloading new lists when defined 'on'
$pfb['reuse'] = $pfb['config']['pfb_reuse'];
$pfb['reuse_dnsbl'] = '';
$pfb['updatednsbl'] = FALSE; // Set flag to allow DNSBL Reload, only when called via background cmd.

// Define update process (update or reload)
switch ($cron) {
Expand All @@ -1794,6 +1791,7 @@ function sync_package_pfblockerng($cron='') {
case 'updatednsbl':
$pfb['reuse'] = '';
$pfb['reuse_dnsbl'] = 'on';
$pfb['updatednsbl'] = TRUE;
break;
case 'updateip':
$pfb['reuse'] = 'on';
Expand Down Expand Up @@ -2206,7 +2204,7 @@ function sync_package_pfblockerng($cron='') {
// Query for any active pfBlockerNG CRON jobs
$result_cron = array();
exec('/bin/ps -wax', $result_cron);
if (preg_grep("/pfblockerng[.]php\s+?(cron|update)/", $result_cron)) {
if (preg_grep("/pfblockerng[.]php\s+?(cron|update|updatednsbl)/", $result_cron)) {
$log = "\n ** DNSBL Reload Terminated due to active pfBlockerNG cron process\n";
pfb_logger("{$log}", 1);
} else {
Expand All @@ -2215,7 +2213,7 @@ function sync_package_pfblockerng($cron='') {
// Clear any existing pfBlockerNG Cron Jobs to avoid collision
install_cron_job('pfblockerng.php cron', false);
$cmd = "/usr/local/bin/php /usr/local/www/pfblockerng/pfblockerng.php";
mwexec_bg("${cmd} updatednsbl >> {$pfb['log']} 2>&1");
mwexec_bg("{$cmd} updatednsbl >> {$pfb['log']} 2>&1");
}
}
}
Expand Down Expand Up @@ -2296,6 +2294,17 @@ function sync_package_pfblockerng($cron='') {
pfb_logger("{$log}", 1);
$dnsbl_error = TRUE;
}

if (!$pfb['updatednsbl']) {
// Determine if a DNSBL Reload is running
$result_cron = array();
exec('/bin/ps -wax', $result_cron);
if (preg_grep("/pfblockerng[.]php\s+?(updatednsbl)/", $result_cron)) {
$log = "\n ** DNSBL Update Terminated due to active pfBlockerNG cron process\n";
pfb_logger("{$log}", 1);
$dnsbl_error = TRUE;
}
}
}

if ($pfb['dnsbl'] == 'on' && !$pfb['save'] && !$dnsbl_error) {
Expand Down