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"); ?>