aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBBcan177 <bbcan177@gmail.com>2014-12-20 20:54:37 -0500
committerBBcan177 <bbcan177@gmail.com>2014-12-20 20:54:37 -0500
commit0b255cfb7df9354f2037acaaa8d76868d05e6161 (patch)
tree19827b075c3c2e65dbe77b9ed9db9da6ae0fad04
parent58af3a0e22b6b3af740a626491f8dbe6e80459ef (diff)
downloadpfsense-packages-0b255cfb7df9354f2037acaaa8d76868d05e6161.tar.gz
pfsense-packages-0b255cfb7df9354f2037acaaa8d76868d05e6161.tar.bz2
pfsense-packages-0b255cfb7df9354f2037acaaa8d76868d05e6161.zip
Mods to pfblockerng.php
- Modify code to use fopen() and fgetcsv() instead of array_map() and str_getcsv(). This reduces the memory requirements dramatically. This version has now been tested on an ALIX board. - Change Maxmind Cron Task from Cron Shell script task to Cron php task using the 'dc' Arg. (Refer to the next commit for INC file Changes)
-rw-r--r--config/pfblockerng/pfblockerng.php45
1 files changed, 30 insertions, 15 deletions
diff --git a/config/pfblockerng/pfblockerng.php b/config/pfblockerng/pfblockerng.php
index 4e643cd6..79f6c108 100644
--- a/config/pfblockerng/pfblockerng.php
+++ b/config/pfblockerng/pfblockerng.php
@@ -142,8 +142,10 @@ function ip_range_to_subnet_array_temp($ip1, $ip2) {
return $out;
}
-# Set php Memory Limit to 256M. This is required to process the MaxMind IP Database
-ini_set('memory_limit', '256M');
+# Set php Memory Limit
+$uname = posix_uname();
+if ($uname['machine'] == "amd64")
+ ini_set('memory_limit', '256M');
function pfb_update_check($header_url, $list_url, $url_format) {
global $pfb;
@@ -209,11 +211,21 @@ if ($argv[1] == 'update') {
sync_package_pfblockerng("cron");
}
-if ($argv[1] == 'uc') {
+if ($argv[1] == 'dc') {
+ # (Options - 'bu' Binary Update for Reputation/Alerts Page, 'all' for Country update and 'bu' options.
+ if ($pfb['cc'] == "") {
+ exec("/bin/sh /usr/local/pkg/pfblockerng/geoipupdate.sh all >> {$pfb['geolog']} 2>&1");
+ } else {
+ exec("/bin/sh /usr/local/pkg/pfblockerng/geoipupdate.sh bu >> {$pfb['geolog']} 2>&1");
+ }
pfblockerng_uc_countries();
pfblockerng_get_countries();
}
+if ($argv[1] == 'uc') {
+ pfblockerng_uc_countries();
+}
+
if ($argv[1] == 'gc') {
pfblockerng_get_countries();
}
@@ -500,9 +512,9 @@ function pfblockerng_uc_countries() {
pfb_logger("{$log}","3");
$cont_array = array ( array($AF),array($AS),array($EU),array($NA),array($OC),array($SA));
- $csv = array_map('str_getcsv', @file($maxmind_cont));
- if (isset($csv)) {
- foreach ($csv as $cc) {
+ if (($handle = fopen("{$maxmind_cont}",'r')) !== FALSE) {
+ while (($cc = fgetcsv($handle)) !== FALSE) {
+
$cc_key = $cc[0];
$cont_key = $cc[1];
switch ($cont_key) {
@@ -545,16 +557,17 @@ function pfblockerng_uc_countries() {
}
}
}
- unset($csv);
+ unset($cc);
+ fclose($handle);
// Collect Country ISO Data IPv4 and Sort to Continent Array
$log = "Processing ISO IPv4 Continent/Country Data \n";
print $log;
pfb_logger("{$log}","3");
- $csv2 = array_map('str_getcsv', @file($maxmind_cc4));
- if (isset($csv2)) {
- foreach ($csv2 as $cc) {
+ if (($handle = fopen("{$maxmind_cc4}",'r')) !== FALSE) {
+ while (($cc = fgetcsv($handle)) !== FALSE) {
+
$ip1_key = $cc[0];
$ip2_key = $cc[1];
$var1_key = $cc[2];
@@ -574,7 +587,8 @@ function pfblockerng_uc_countries() {
}
}
}
- unset($csv2);
+ unset($cc);
+ fclose($handle);
// Build Continent IPv4 CIDR Files
$counter = 0;
@@ -605,9 +619,9 @@ function pfblockerng_uc_countries() {
print $log;
pfb_logger("{$log}","3");
- $csv3 = array_map('str_getcsv', @file($maxmind_cc6));
- if (isset($csv3)) {
- foreach ($csv3 as $cc) {
+ if (($handle = fopen("{$maxmind_cc6}",'r')) !== FALSE) {
+ while (($cc = fgetcsv($handle)) !== FALSE) {
+
$ip1_key = $cc[0];
$ip2_key = $cc[1];
$var1_key = $cc[2];
@@ -626,7 +640,8 @@ function pfblockerng_uc_countries() {
}
}
}
- unset ($csv3);
+ unset($cc);
+ fclose($handle);
// Build Continent IPv6 Files
$counter = 0;