From 7226ba64594f816a9097a7fb1e9da19e26263a54 Mon Sep 17 00:00:00 2001 From: BBcan177 Date: Mon, 8 Dec 2014 07:34:51 -0500 Subject: Mods to Update TAB --- config/pfblockerng/pfblockerng_update.php | 435 +++++++++++++++--------------- 1 file changed, 214 insertions(+), 221 deletions(-) (limited to 'config/pfblockerng/pfblockerng_update.php') diff --git a/config/pfblockerng/pfblockerng_update.php b/config/pfblockerng/pfblockerng_update.php index 3f89a8d4..a4964df6 100644 --- a/config/pfblockerng/pfblockerng_update.php +++ b/config/pfblockerng/pfblockerng_update.php @@ -15,11 +15,6 @@ 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: @@ -48,14 +43,11 @@ 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(); -$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); @@ -82,64 +74,137 @@ function pfbupdate_status($status) { } +// 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( "\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"); ?> -
+ + - + + + + +
+ +
- +
- -
- +   +   +   +
- - - - - - - - - - - - - + - "> - + + + + - - "> - + + + + + + + + + +
  -   -   -
-
"); ?>
- "/> - "/> - " . gettext(' pfBlockerNG ') . "" . gettext(" Log :        (Select 'End View' to terminate the viewer)

"); ?> -
+ {$min_remain} Minutes."; + // Next Scheduled Cron Time + if ($pfb_min == "0") + $pfb_min = "00"; + $nextcron = (date('H') +1) . ":{$pfb_min}"; + + // If pfBlockerNG is Disabled or Cron Task is Missing + if (empty($pfb['enable']) || empty($pfb_min)) { + $min_remain = " -- "; + $nextcron = " [ Disabled ] "; + } + + echo "NEXT Scheduled CRON Event will run at  {$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 ""; + $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
"; + echo "
Refresh to update current Status and Minute(s) remaining"; ?>
"); ?>
- " onclick="enable_showFilter();" title="" /> +
+ + " . 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("** AVOID ** ") . " " . "" . gettext("Running a -Manual Update- when CRON is expected to RUN!"); ?>
- " /> - " /> +
+ + " /> + " /> + " />
" . gettext("NOTE: ") . "" . " " . gettext("Running this command will 'Disable' the next Scheduled pfBlockerNG CRON job until this process has completed.") ;?>
- " onclick="enable_hideFilter();" title="" /> -
+
"); ?>
+ + "/> + "/> + " . gettext(' pfBlockerNG ') . "" . + gettext(" Log.        (Select 'End View' to terminate the viewer.)"); ?>

- +
- +
-
- - - 15000) { @@ -280,13 +364,13 @@ if (isset($_POST['pfbview'])) { while (true) { usleep(300000); //0.3s - clearstatcache(false,$pfblog); - $len = filesize($pfblog); + clearstatcache(false,$pfb['log']); + $len = filesize("{$pfb['log']}"); if ($len < $lastpos) { //file deleted or reset $lastpos = $len; } else { - $f = fopen($pfblog, "rb"); + $f = fopen($pfb['log'], "rb"); if ($f === false) die(); fseek($f, $lastpos); @@ -296,7 +380,7 @@ if (isset($_POST['pfbview'])) { $pfb_buffer = fread($f, 4096); $pfb_output .= str_replace( "\r", "", $pfb_buffer); - // Refresh on new lines only + // Refresh on new lines only. This allows scrolling. if ($lastpos != $lastpos_old) { pfbupdate_output($pfb_output); } @@ -310,123 +394,32 @@ if (isset($_POST['pfbview'])) { } } - +// End the Viewer output Window if (isset($_POST['pfbviewcancel'])) { - clearstatcache(false,$pfblog); + clearstatcache(false,$pfb['log']); ob_flush(); flush(); - fclose($pfblog); + fclose("{$pfb['log']}"); } - -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(); - } - } +// 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); +} -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); +// 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(); - - clearstatcache(false,$pfblog); - ob_flush(); - flush(); - fclose($pfblog); + pfb_cron_update(reload); } -?> \ No newline at end of file +?> + + + \ No newline at end of file -- cgit v1.2.3