function pfb_cron_update($type) { global $pfb; // Query for any active pfBlockerNG CRON jobs exec('/bin/ps -wx', $result_cron); if (preg_grep("/pfblockerng[.]php\\s+?(cron|update)/", $result_cron)) { pfbupdate_status(gettext("Force {$type} Terminated - Failed due to Active Running Task. Click 'View' for running process")); exit; } if (!file_exists("{$pfb['log']}")) { touch("{$pfb['log']}"); } // Update status window with correct task if ($type == 'update') { pfbupdate_status(gettext('Running Force Update Task')); } elseif ($type == 'reload') { $reload_type = htmlspecialchars($_POST['rmode']); pfbupdate_status(gettext("Running Force Reload Task - {$reload_type}")); switch ($reload_type) { case 'IP': $type = 'updateip'; break; case 'DNSBL': $type = 'updatednsbl'; rmdir_recursive("{$pfb['dnsdir']}"); break; case 'All': default: $type = 'update'; rmdir_recursive("{$pfb['dnsdir']}"); } } else { pfbupdate_status(gettext('Running Force CRON Task')); } // Remove any existing pfBlockerNG CRON Jobs install_cron_job('pfblockerng.php cron', false); // Execute PHP process in the background mwexec_bg("/usr/local/bin/php /usr/local/www/pfblockerng/pfblockerng.php {$type} >> {$pfb['log']} 2>&1"); // Execute Live Tail function pfb_livetail($pfb['log'], 'force'); }
function pfb_cron_update($type) { global $pfb; // Query for any Active pfBlockerNG CRON Jobs $result_cron = array(); $cron_event = exec("/bin/ps -wx", $result_cron); if (preg_grep("/pfblockerng[.]php\\s+cron/", $result_cron) || preg_grep("/pfblockerng[.]php\\s+update/", $result_cron)) { pfbupdate_status(gettext("Force {$type} Terminated - Failed due to Active Running Task")); exit; } if (!file_exists("{$pfb['log']}")) { touch("{$pfb['log']}"); } // Update Status Window with correct Task if ($type == "update") { pfbupdate_status(gettext("Running Force Update Task")); } elseif ($type == "reload") { pfbupdate_status(gettext("Running Force Reload Task")); $type = "update"; } else { pfbupdate_status(gettext("Running Force CRON Task")); } // Remove any existing pfBlockerNG CRON Jobs install_cron_job("pfblockerng.php cron", false); // Execute PHP Process in the Background mwexec_bg("/usr/local/bin/php /usr/local/www/pfblockerng/pfblockerng.php {$type} >> {$pfb['log']} 2>&1"); // Start at EOF $lastpos_old = ""; $len = filesize("{$pfb['log']}"); $lastpos = $len; while (true) { usleep(300000); //0.3s clearstatcache(false, $pfb['log']); $len = filesize("{$pfb['log']}"); if ($len < $lastpos) { //file deleted or reset $lastpos = $len; } else { $f = fopen($pfb['log'], "rb"); if ($f === false) { die; } fseek($f, $lastpos); while (!feof($f)) { $pfb_buffer = fread($f, 2048); $pfb_output .= str_replace(array("\r", "\")"), "", $pfb_buffer); // Refresh on new lines only. This allows Scrolling. if ($lastpos != $lastpos_old) { pfbupdate_output($pfb_output); } $lastpos_old = $lastpos; ob_flush(); flush(); } $lastpos = ftell($f); fclose($f); } // Capture Remaining Output before closing File if (preg_match("/(UPDATE PROCESS ENDED)/", $pfb_output)) { $f = fopen($pfb['log'], "rb"); fseek($f, $lastpos); $pfb_buffer = fread($f, 2048); $pfb_output .= str_replace("\r", "", $pfb_buffer); pfbupdate_output($pfb_output); clearstatcache(false, $pfb['log']); ob_flush(); flush(); fclose($f); // Call Log Mgmt Function pfb_log_mgmt(); die; } } }