From a65a77ecf95a2f7c1092755c9978b38f3a361d89 Mon Sep 17 00:00:00 2001 From: BBcan177 Date: Tue, 3 Feb 2015 14:20:48 -0500 Subject: pfBlockerNG - Fix Cron Update process and other improvements Changes: 1) Add missing $pfbfolder variable to Cron Update function 2) Modify how the include files get loaded. 3) Reputation Tab only requires IPv4, simplify code to use IPv4 only for this function. 4) Update geoipupdate.sh to use the New PBI folder location and remove Archive folders after MaxMind Update process --- config/pfblockerng/pfblockerng.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'config/pfblockerng/pfblockerng.php') diff --git a/config/pfblockerng/pfblockerng.php b/config/pfblockerng/pfblockerng.php index 1db36334..ca8a23a9 100644 --- a/config/pfblockerng/pfblockerng.php +++ b/config/pfblockerng/pfblockerng.php @@ -44,9 +44,13 @@ require_once("functions.inc"); require_once("pkg-utils.inc"); require_once("globals.inc"); require_once("services.inc"); -require_once("/usr/local/pkg/pfblockerng/pfblockerng.inc"); -pfb_global(); +// Call Include File and Collect updated Global Settings +if (in_array($argv[1], array( 'update','dc','uc','gc','cron' ))) { + require_once("/usr/local/pkg/pfblockerng/pfblockerng.inc"); + pfb_global(); +} + // IPv6 Range to CIDR function used courtesey from: // https://github.com/stilez/pfsense-leases/blob/50cc0fa81dba5fe91bcddaea016c245d1b8479cc/etc/inc/util.inc @@ -147,7 +151,7 @@ $uname = posix_uname(); if ($uname['machine'] == "amd64") ini_set('memory_limit', '256M'); -function pfb_update_check($header_url, $list_url, $url_format) { +function pfb_update_check($header_url, $list_url, $url_format, $pfbfolder) { global $pfb; $pfb['cron_update'] = FALSE; @@ -230,6 +234,12 @@ if ($argv[1] == 'dc') { } pfblockerng_uc_countries(); pfblockerng_get_countries(); + + // Remove Original Maxmind Database Files + @unlink_if_exists("{$pfb['dbdir']}/GeoIPCountryCSV.zip"); + @unlink_if_exists("{$pfb['dbdir']}/GeoIPCountryWhois.csv"); + @unlink_if_exists("{$pfb['dbdir']}/GeoIPv6.csv"); + @unlink_if_exists("{$pfb['dbdir']}/country_continent.csv"); } if ($argv[1] == 'uc') { @@ -425,7 +435,6 @@ if ($argv[1] == 'cron') { // Function to process the downloaded Maxmind Database and format into Continent txt files. function pfblockerng_uc_countries() { global $g,$pfb; - pfb_global(); $maxmind_cont = "{$pfb['dbdir']}/country_continent.csv"; $maxmind_cc4 = "{$pfb['dbdir']}/GeoIPCountryWhois.csv"; @@ -584,7 +593,6 @@ function pfblockerng_uc_countries() { // Function to process Continent txt files and create Country ISO files and to Generate GUI XML files. function pfblockerng_get_countries() { global $g,$pfb; - pfb_global(); $files = array ( "Africa" => "{$pfb['ccdir']}/Africa_v4.txt", "Asia" => "{$pfb['ccdir']}/Asia_v4.txt", @@ -622,7 +630,9 @@ function pfblockerng_get_countries() { if (preg_match("/#/",$line)) { if ($pfb['complete']) { ${'coptions' . $type}[] = $country . '-' . $isocode . ' ('. $total .') ' . ' ' . $isocode . ''; - ${'roptions' . $type}[] = $country . '-' . $isocode . ' ('. $total .') ' . ' ' . $isocode . ''; + // Only collect IPv4 for Reputation Tab + if ($type == "4") + $roptions4[] = $country . '-' . $isocode . ' ('. $total .') ' . ' ' . $isocode . ''; // Save ISO data @file_put_contents($pfb['ccdir'] . '/' . $isocode . '_v' . $type . '.txt', $xml_data, LOCK_EX); @@ -646,7 +656,8 @@ function pfblockerng_get_countries() { if ($keycount == $lastkey) { if (preg_match("/Total Networks: 0/", $line)) { continue;} // Dont Display Countries with Null Data ${'coptions' . $type}[] = $country . '-' . $isocode . ' ('. $total .') ' . ' ' . $isocode . ''; - ${'roptions' . $type}[] = $country . '-' . $isocode . ' ('. $total .') ' . ' ' . $isocode . ''; + if ($type == "4") + $roptions4[] = $country . '-' . $isocode . ' ('. $total .') ' . ' ' . $isocode . ''; @file_put_contents($pfb['ccdir'] . '/' . $isocode . '_v' . $type . '.txt', $xml_data, LOCK_EX); unset($total, $xml_data); } @@ -962,13 +973,12 @@ EOF; // Sort Countries IPv4 Alphabetically and Build XML