aboutsummaryrefslogtreecommitdiffstats
path: root/config/pfblockerng/pfblockerng_update.php
diff options
context:
space:
mode:
authorChris Buechler <cmb@pfsense.org>2015-11-20 04:13:13 -0600
committerChris Buechler <cmb@pfsense.org>2015-11-20 04:13:13 -0600
commit93db1c7e80d14adb9105333a2fbb7fa002053c5f (patch)
treef8ac6294f25e6be8f5f7a2f787f7215cfd2527e1 /config/pfblockerng/pfblockerng_update.php
parentff93f32ea9da473792db0fa4eefe3e277a463989 (diff)
parent1dab6de7ab4cb66d19a0f89c4a162b8120a72f05 (diff)
downloadpfsense-packages-93db1c7e80d14adb9105333a2fbb7fa002053c5f.tar.gz
pfsense-packages-93db1c7e80d14adb9105333a2fbb7fa002053c5f.tar.bz2
pfsense-packages-93db1c7e80d14adb9105333a2fbb7fa002053c5f.zip
Merge pull request #1174 from BBcan177/pfBNG-11-15-15-1
Diffstat (limited to 'config/pfblockerng/pfblockerng_update.php')
-rw-r--r--config/pfblockerng/pfblockerng_update.php246
1 files changed, 82 insertions, 164 deletions
diff --git a/config/pfblockerng/pfblockerng_update.php b/config/pfblockerng/pfblockerng_update.php
index 7911a4e6..8a04f843 100644
--- a/config/pfblockerng/pfblockerng_update.php
+++ b/config/pfblockerng/pfblockerng_update.php
@@ -3,7 +3,7 @@
/* pfBlockerNG_Update.php
pfBlockerNG
- Copyright (C) 2015 BBcan177@gmail.com
+ Copyright (c) 2015 BBcan177@gmail.com
All rights reserved.
Portions of this code are based on original work done for
@@ -11,8 +11,9 @@
pkg_mgr_install.php
Part of pfSense (https://www.pfsense.org)
- Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
- Copyright (C) 2005 Colin Smith
+ Copyright (c) 2015 Electric Sheep Fencing, LLC. All rights reserved.
+ Copyright (c) 2005 Colin Smith
+ Copyright (c) 2004-2005 Scott Ullrich
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -39,18 +40,18 @@
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");
+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.
+// Collect pfBlockerNG log file and post live output to terminal window.
function pfbupdate_output($text) {
- $text = preg_replace("/\n/", "\\n", $text);
+ $text = str_replace("\n", "\\n", $text);
echo "\n<script type=\"text/javascript\">";
echo "\n//<![CDATA[";
echo "\nthis.document.forms[0].pfb_output.value = \"" . $text . "\";";
@@ -61,9 +62,9 @@ function pfbupdate_output($text) {
ob_flush();
}
-// Post Status Message to Terminal window.
+// Post status message to terminal window.
function pfbupdate_status($status) {
- $status = preg_replace("/\n/", "\\n", $status);
+ $status = str_replace("\n", "\\n", $status);
echo "\n<script type=\"text/javascript\">";
echo "\n//<![CDATA[";
echo "\nthis.document.forms[0].pfb_status.value=\"" . $status . "\";";
@@ -78,11 +79,10 @@ function pfbupdate_status($status) {
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"));
+ // Query for any active pfBlockerNG CRON jobs
+ exec('/bin/ps -wx', $result_cron);
+ if (preg_grep("/pfblockerng[.]php\s+?(cron|update)/", $result_cron)) {
+ pfbupdate_status(gettext("Force {$type} Terminated - Failed due to Active Running Task. Click 'View' for running process"));
exit;
}
@@ -90,103 +90,62 @@ function pfb_cron_update($type) {
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";
+ // Update status window with correct task
+ if ($type == 'update') {
+ pfbupdate_status(gettext('Running Force Update Task'));
+ } elseif ($type == 'reload') {
+ $reload_type = htmlspecialchars($_POST['rmode']);
+ pfbupdate_status(gettext("Running Force Reload Task - {$reload_type}"));
+
+ switch ($reload_type) {
+ case 'IP':
+ $type = 'updateip';
+ break;
+ case 'DNSBL':
+ $type = 'updatednsbl';
+ rmdir_recursive("{$pfb['dnsdir']}");
+ break;
+ case 'All':
+ default:
+ $type = 'update';
+ rmdir_recursive("{$pfb['dnsdir']}");
+ }
} else {
- pfbupdate_status(gettext("Running Force CRON Task"));
+ pfbupdate_status(gettext('Running Force CRON Task'));
}
// Remove any existing pfBlockerNG CRON Jobs
- install_cron_job("pfblockerng.php cron", false);
+ install_cron_job('pfblockerng.php cron', false);
- // Execute PHP Process in the Background
+ // 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();
- }
- }
+ // Execute Live Tail function
+ pfb_livetail($pfb['log'], 'force');
}
-$pgtitle = gettext("pfBlockerNG: Update");
-include_once("head.inc");
+$pgtitle = gettext('pfBlockerNG: Update');
+include_once('head.inc');
+include_once('fbegin.inc');
?>
<body link="#000000" vlink="#0000CC" alink="#000000">
-<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
-<?php include_once("fbegin.inc"); ?>
-
+<form action="/pfblockerng/pfblockerng_update.php" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<?php
$tab_array = array();
- $tab_array[] = array(gettext("General"), false, "/pkg_edit.php?xml=pfblockerng.xml&amp;id=0");
+ $tab_array[] = array(gettext("General"), false, "/pkg_edit.php?xml=pfblockerng.xml");
$tab_array[] = array(gettext("Update"), true, "/pfblockerng/pfblockerng_update.php");
$tab_array[] = array(gettext("Alerts"), false, "/pfblockerng/pfblockerng_alerts.php");
- $tab_array[] = array(gettext("Reputation"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_reputation.xml&id=0");
+ $tab_array[] = array(gettext("Reputation"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_reputation.xml");
$tab_array[] = array(gettext("IPv4"), false, "/pkg.php?xml=/pfblockerng/pfblockerng_v4lists.xml");
$tab_array[] = array(gettext("IPv6"), false, "/pkg.php?xml=/pfblockerng/pfblockerng_v6lists.xml");
- $tab_array[] = array(gettext("Top 20"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_top20.xml&id=0");
- $tab_array[] = array(gettext("Africa"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_Africa.xml&id=0");
- $tab_array[] = array(gettext("Asia"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_Asia.xml&id=0");
- $tab_array[] = array(gettext("Europe"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_Europe.xml&id=0");
- $tab_array[] = array(gettext("N.A."), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_NorthAmerica.xml&id=0");
- $tab_array[] = array(gettext("Oceania"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_Oceania.xml&id=0");
- $tab_array[] = array(gettext("S.A."), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_SouthAmerica.xml&id=0");
- $tab_array[] = array(gettext("P.S."), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_ProxyandSatellite.xml&id=0");
+ $tab_array[] = array(gettext("DNSBL"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_dnsbl.xml");
+ $tab_array[] = array(gettext("Country"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_top20.xml");
$tab_array[] = array(gettext("Logs"), false, "/pfblockerng/pfblockerng_log.php");
- $tab_array[] = array(gettext("Sync"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_sync.xml&id=0");
+ $tab_array[] = array(gettext("Sync"), false, "/pkg_edit.php?xml=/pfblockerng/pfblockerng_sync.xml");
display_top_tabs($tab_array, true);
?>
</td>
@@ -195,9 +154,9 @@ include_once("head.inc");
<div id="mainareapkg">
<table id="maintable" class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
- <td colspan="2" class="vncell" align="left"><?php echo gettext("LINKS :"); ?>&nbsp;
- <a href='/firewall_aliases.php' target="_blank"><?php echo gettext("Firewall Alias"); ?></a>&nbsp;
- <a href='/firewall_rules.php' target="_blank"><?php echo gettext("Firewall Rules"); ?></a>&nbsp;
+ <td colspan="2" class="vncell" align="left"><?php echo gettext("LINKS :"); ?>&emsp;
+ <a href='/firewall_aliases.php' target="_blank"><?php echo gettext("Firewall Alias"); ?></a>&emsp;
+ <a href='/firewall_rules.php' target="_blank"><?php echo gettext("Firewall Rules"); ?></a>&emsp;
<a href='/diag_logs_filter.php' target="_blank"><?php echo gettext("Firewall Logs"); ?></a><br />
</td>
</tr>
@@ -207,6 +166,7 @@ include_once("head.inc");
<tr>
<td colspan="2" class="listr">
<?php
+
if ($pfb['enable'] == 'on') {
/* Legend - Time variables
@@ -293,11 +253,11 @@ include_once("head.inc");
<font size=\"3\"><span class=\"red\">&nbsp;{$nextcron}&nbsp;</span></font> time remaining.";
// Query for any active pfBlockerNG CRON jobs
- exec ('/bin/ps -wax', $result_cron);
- if (preg_grep("/pfblockerng[.]php\s+cron/", $result_cron)) {
- echo "<font size=\"2\"><span class=\"red\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
- Active pfBlockerNG CRON Job </span></font>&nbsp;&nbsp;";
- echo "<img src = '/themes/{$g['theme']}/images/icons/icon_pass.gif' width='15' height='15'
+ exec('/bin/ps -wax', $result_cron);
+ if (preg_grep("/pfblockerng[.]php\s+?(cron|update)/", $result_cron)) {
+ echo "<font size=\"2\"><span class=\"red\">&emsp;&emsp;
+ Active pfBlockerNG CRON Job </span></font>&emsp;";
+ echo "<img src = '/themes/{$g['theme']}/images/icons/icon_pass.gif' alt='' width='15' height='15'
border='0' title='pfBockerNG Cron Task is Running.'/>";
}
echo "<br /><font size=\"3\"><span class=\"red\">Refresh</span></font> to update current Status and time remaining";
@@ -331,7 +291,10 @@ include_once("head.inc");
<input type="submit" class="formbtns" name="pfbcron" id="pfbcron" value="Force Cron"
title="<?=gettext("Run Force Cron Update");?>" />
<input type="submit" class="formbtns" name="pfbreload" id="pfbreload" value="Force Reload"
- title="<?=gettext("Run Force Reload");?>" />
+ title="<?=gettext("Run Force Reload");?>" />&emsp;<?=gettext("Reload Options:");?>
+ <input name="rmode" type="radio" value="All" <?php echo 'checked'; ?> /><?=gettext("All");?>
+ <input name="rmode" type="radio" value="IP" /><?=gettext("IP");?>
+ <input name="rmode" type="radio" value="DNSBL" /><?=gettext("DNSBL"); ?>
</td>
</tr>
<tr>
@@ -342,7 +305,7 @@ include_once("head.inc");
</tr>
<tr>
<td colspan="2" class="listr"><?php echo gettext("Selecting 'Live Log Viewer' will allow viewing a running Cron Update"); ?></td>
- </tr>
+ </tr>
<tr>
<td colspan="2" class="vncell">
<!-- Log Viewer Buttons -->
@@ -350,8 +313,8 @@ include_once("head.inc");
title="<?=gettext("VIEW pfBlockerNG LOG");?>"/>
<input type="submit" class="formbtns" name="pfbviewcancel" id="pfbviewcancel" value="End View"
title="<?=gettext("END VIEW of pfBlockerNG LOG");?>"/>
- <?php echo "&nbsp;&nbsp;" . gettext(" Select 'view' to open ") . "<strong>" . gettext(' pfBlockerNG ') . "</strong>" .
- gettext(" Log. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Select 'End View' to terminate the viewer.)"); ?><br /><br />
+ <?php echo "&emsp;" . gettext(" Select 'view' to open ") . "<strong>" . gettext(' pfBlockerNG ') . "</strong>" .
+ gettext(" Log. &emsp; (Select 'End View' to terminate the viewer.)"); ?><br /><br />
</td>
</tr>
<tr>
@@ -371,83 +334,38 @@ include_once("head.inc");
</div>
<?php
-include("fend.inc");
+include('fend.inc');
-// Execute the Viewer output Window
-if (isset($_POST['pfbview'])) {
- if (!file_exists("{$pfb['log']}")) {
- touch("{$pfb['log']}");
- }
-
- // Reference: http://stackoverflow.com/questions/3218895/php-how-to-read-a-file-live-that-is-constantly-being-written-to
+// Execute the viewer output window
+if (isset($_POST['pfbview'])) {
pfbupdate_status(gettext("Log Viewing in progress. ** Press 'END VIEW' to Exit ** "));
- $lastpos_old = "";
- $len = filesize("{$pfb['log']}");
-
- // Start at EOF ( - 15000)
- if ($len > 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);
- }
- }
+ pfb_livetail($pfb['log'], 'view');
}
-// End the Viewer output Window
+// End the viewer output Window
if (isset($_POST['pfbviewcancel'])) {
- clearstatcache(false,$pfb['log']);
+ clearstatcache(false, $pfb['log']);
ob_flush();
flush();
fclose("{$pfb['log']}");
}
// Execute a Force Update
-if (isset($_POST['pfbupdate']) && $pfb['enable'] == "on") {
+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") {
+// 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");
+// 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);
}