[opw-web] Allow skipping multiple proxy IPs



commit 679868e154ddc2f3f437eb2cfeb6fb4ffb938323
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Thu Dec 3 00:21:48 2015 -0500

    Allow skipping multiple proxy IPs
    
    There might not just be one proxy IP address to ignore when recording
    the source IP, so change the config variable to allow skip multiple IPs.

 classes/class_core.php |   10 +++++++++-
 config.sample.php      |    6 ++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/classes/class_core.php b/classes/class_core.php
index 3fa0e77..934b427 100644
--- a/classes/class_core.php
+++ b/classes/class_core.php
@@ -143,13 +143,21 @@ class core
         if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
             $ips .= $_SERVER['HTTP_X_FORWARDED_FOR'];
 
-        if (!$config->skip_proxy_ip && isset($_SERVER['REMOTE_ADDR'])) {
+        if (isset($_SERVER['REMOTE_ADDR'])) {
             if ($ips != '')
                 $ips .= ' ';
 
             $ips .= $_SERVER['REMOTE_ADDR'];
         }
 
+        $ips = trim($ips);
+
+        if ($config->skip_proxy_ip_count > 0) {
+            $ip_arr = preg_split("/ +/", $ips);
+            $ip_arr = array_slice($ip_arr, 0, count($ip_arr) - $config->skip_proxy_ip_count);
+            $ips = join(" ", $ip_arr);
+        }
+
         return $ips;
     }
 
diff --git a/config.sample.php b/config.sample.php
index d4b8e10..c78a8ca 100644
--- a/config.sample.php
+++ b/config.sample.php
@@ -75,8 +75,10 @@ $per_page = 20;
 // Show debug info in the footer
 $show_debug = true;
 
-// Whether when recording the source IP for a request, the immediate
-// remote address should be skipped
+// When recording the source IP for a request, how many
+// remote addresses should be skipped
+$skip_proxy_ip_count = 0;
+
 $skip_proxy_ip = false;
 
 // LDAP server address


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]