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); write_config(); // 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"); ?>
     
 {$nextcron}  in  {$min_remain}  Minutes."; // 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 Minute(s) 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") { $config['installedpackages']['pfblockerng']['config'][0]['pfb_reuse'] = "on"; write_config(); pfb_cron_update(reload); } ?>