Copyright (C) 2005 Colin Smith All rights reserved. Hide/Show Rollup Code originally coded in Suricata_alerts.php Copyright (C) 2014 Bill Meeks 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("/usr/local/pkg/pfblockerng/pfblockerng.inc"); pfb_global(); $filterlogentries = FALSE; $pfblog = "{$pfb['log']}"; $pfb_output = ""; // 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(); } $pgtitle = gettext("pfBlockerNG: Update"); include_once("head.inc"); ?>
15000) { $lastpos = ($len - 15000); } else { $lastpos = 0; } while (true) { usleep(300000); //0.3s clearstatcache(false,$pfblog); $len = filesize($pfblog); if ($len < $lastpos) { //file deleted or reset $lastpos = $len; } else { $f = fopen($pfblog, "rb"); if ($f === false) die(); fseek($f, $lastpos); while (!feof($f)) { $pfb_buffer = fread($f, 4096); $pfb_output .= str_replace( "\r", "", $pfb_buffer); // Refresh on new lines only if ($lastpos != $lastpos_old) { pfbupdate_output($pfb_output); } $lastpos_old = $lastpos; ob_flush(); flush(); } $lastpos = ftell($f); fclose($f); } } } if (isset($_POST['pfbviewcancel'])) { clearstatcache(false,$pfblog); ob_flush(); flush(); fclose($pfblog); } if (isset($_POST['pfbconfirm'])) { // 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)) { pfbupdate_status(gettext("Manual Update Standby - Previous Attempt Failed due to Active Running CRON Task")); exit; } if (!file_exists($pfblog)) touch($pfblog); pfbupdate_status(gettext("Manual CRON Job will run within ( ** one minute ** ). Please Wait.")); // Remove any existing pfBlockerNG CRON Jobs install_cron_job("pfblockerng.php cron", false); install_cron_job("pfblockerng.php update", false); write_config(); // Define 'Manual' pfBlockerNG CRON Job $date_min_now = date('i'); $pfb_cmd = "/usr/local/bin/php /usr/local/www/pfblockerng/pfblockerng.php update >> {$pfb['log']} 2>&1"; $pfb_c_min = ($date_min_now + 1); if ($pfb_c_min == "60") $pfb_c_min = 0; $pfb_hour = "*"; $pfb_mday = "*"; $pfb_month = "*"; $pfb_wday = "*"; $pfb_who = "root"; // Write CRON job (When pfBlockerNG CRON Task is complete. It will re-enable User Defined CRON Job) install_cron_job($pfb_cmd, true, $pfb_c_min, $pfb_hour, $pfb_mday, $pfb_month, $pfb_wday, $pfb_who); write_config(); // Start at EOF $lastpos_old = ""; $len = filesize($pfblog); $lastpos = $len; while (true) { usleep(300000); //0.3s clearstatcache(false,$pfblog); $len = filesize($pfblog); if ($len < $lastpos) { //file deleted or reset $lastpos = $len; } else { $f = fopen($pfblog, "rb"); if ($f === false) die(); fseek($f, $lastpos); while (!feof($f)) { $pfb_buffer = fread($f, 2048); $pfb_output .= str_replace( "\r", "", $pfb_buffer); // Refresh on new lines only 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($pfblog, "rb"); fseek($f, $lastpos); $pfb_buffer = fread($f, 2048); $pfb_output .= str_replace( "\r", "", $pfb_buffer); pfbupdate_output($pfb_output); clearstatcache(false,$pfblog); ob_flush(); flush(); fclose($f); # Call Log Mgmt Function pfb_log_mgmt(); die(); } } } if (isset($_POST['pfbcancel'])) { // Remove any pfBlockerNG CRON Jobs install_cron_job("pfblockerng.php update", false); install_cron_job("pfblockerng.php cron", false); // Define pfBlockerNG CRON Job $pfb_cmd = "/usr/local/bin/php /usr/local/www/pfblockerng/pfblockerng.php cron >> {$pfb['log']} 2>&1"; $pfb_min = $config['installedpackages']['pfblockerng']['config'][0]['pfb_min']; $pfb_hour = "*"; $pfb_mday = "*"; $pfb_month = "*"; $pfb_wday = "*"; $pfb_who = "root"; install_cron_job($pfb_cmd, true, $pfb_min, $pfb_hour, $pfb_mday, $pfb_month, $pfb_wday, $pfb_who); write_config(); clearstatcache(false,$pfblog); ob_flush(); flush(); fclose($pfblog); } ?>