Copyright (C) 2005 Colin Smith All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); require_once("globals.inc"); require_once("pfsense-utils.inc"); require_once("functions.inc"); require_once("util.inc"); require_once("/usr/local/pkg/pfblockerng/pfblockerng.inc"); pfb_global(); // Collect pfBlockerNG log file and post Live output to Terminal window. function pfbupdate_output($text) { $text = preg_replace("/\n/", "\\n", $text); echo "\n"; /* ensure that contents are written out */ ob_flush(); } // Post Status Message to Terminal window. function pfbupdate_status($status) { $status = preg_replace("/\n/", "\\n", $status); echo "\n"; /* ensure that contents are written out */ ob_flush(); } // Function to perform a Force Update, Cron or Reload 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(); } } } $pgtitle = gettext("pfBlockerNG: Update"); include_once("head.inc"); ?>
     
= 24) { $cron_hour_next = $pfb['hour']; } $max_min_remain = 60 + $pfb['min']; } elseif ($pfb['interval'] == 24) { $cron_hour_next = $cron_hour_begin = $pfb['24hour'] != '' ? $pfb['24hour'] : '00'; } else { // Find Next Cron hour schedule $crondata = pfb_cron_base_hour(); if (!empty($crondata)) { foreach ($crondata as $key => $line) { if ($key == 0) { $cron_hour_begin = $line; } if ($line > $currenthour) { $cron_hour_next = $line; break; } } } // Roll over to First cron hour setting if (!isset($cron_hour_next)) { if (empty($cron_hour_begin)) { // $cron_hour_begin is hour '0' $cron_hour_next = (24 - $currenthour); } else { $cron_hour_next = $cron_hour_begin; } } } if ($pfb['interval'] != 1) { if (($currenthour + ($currentmin/60)) <= ($cron_hour_next + ($pfb['min']/60))) { $max_min_remain = (($cron_hour_next - $currenthour) * 60) + $pfb['min']; } else { $max_min_remain = ((24 - $currenthour + $cron_hour_begin) * 60) + $pfb['min']; $cron_hour_next = $cron_hour_begin; } } $min_remain = ($max_min_remain - $currentmin); $min_final = ($min_remain % 60); $sec_final = (60 - date('s')); if (strlen($sec_final) == 1) { $sec_final = '0' . $sec_final; } if (strlen($min_final) == 1) { $min_final = '0' . $min_final; } if (strlen($cron_hour_next) == 1) { $cron_hour_next = '0' . $cron_hour_next; } if ($min_remain > 59) { $nextcron = floor($min_remain / 60) . ':' . $min_final . ':' . $sec_final; } else { $nextcron = '00:' . $min_final . ':' . $sec_final; } if ($pfb['min'] == 0) { $pfb['min'] = '00'; } $cronreal = "{$cron_hour_next}:{$pfb['min']}"; } if (empty($pfb['enable']) || empty($cron_hour_next)) { $cronreal = ' [ Disabled ]'; $nextcron = '--'; } echo "NEXT Scheduled CRON Event will run at  {$cronreal}  with  {$nextcron}  time remaining."; // Query for any Active pfBlockerNG CRON Jobs $result_cron = array(); $cron_event = exec ("/bin/ps -wax", $result_cron); if (preg_grep("/pfblockerng[.]php\s+cron/", $result_cron)) { echo "        Active pfBlockerNG CRON Job   "; echo ""; } echo "
Refresh to update current Status and time remaining"; ?>
"); ?>
" . gettext("** AVOID ** ") . " " . "" . gettext("Running these Options - when CRON is expected to RUN!") . gettext("

") . "" . gettext("Force Update") . "" . gettext(" will download any new Alias/Lists.") . gettext("
") . "" . gettext("Force Cron") . "" . gettext(" will download any Alias/Lists that are within the Frequency Setting (due for Update).") . gettext("
") . "" . gettext("Force Reload") . "" . gettext(" will reload all Lists using the existing Downloaded files.") . gettext(" This is useful when Lists are out of 'sync' or Reputation changes were made.") ;?>
" /> " /> " />
"); ?>
"/> "/> " . gettext(' pfBlockerNG ') . "" . gettext(" Log.        (Select 'End View' to terminate the viewer.)"); ?>

15000) { $lastpos = ($len - 15000); } else { $lastpos = 0; } 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, 4096); $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); } } } // End the Viewer output Window if (isset($_POST['pfbviewcancel'])) { clearstatcache(false,$pfb['log']); ob_flush(); flush(); fclose("{$pfb['log']}"); } // Execute a Force Update if (isset($_POST['pfbupdate']) && $pfb['enable'] == "on") { pfb_cron_update(update); } // Execute a CRON Command to update any Lists within the Frequency Settings if (isset($_POST['pfbcron']) && $pfb['enable'] == "on") { pfb_cron_update(cron); } // Execute a Reload of all Aliases and Lists if (isset($_POST['pfbreload']) && $pfb['enable'] == "on") { // Set 'Reuse' Flag for Reload process $config['installedpackages']['pfblockerng']['config'][0]['pfb_reuse'] = "on"; write_config("pfBlockerNG: Executing Force Reload"); pfb_cron_update(reload); } ?>