Reversed and obsolete code removed (was for admin area, we don't rewrite links in...
authorRoland Häder <roland@mxchange.org>
Tue, 10 Mar 2009 20:46:10 +0000 (20:46 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 10 Mar 2009 20:46:10 +0000 (20:46 +0000)
inc/functions.php
inc/libs/rewrite_functions.php

index 44ba689b58698b62acb3820db3fe324c990c9053..d6c84e21874b9a6429210d85e831a3c66ef63798 100644 (file)
@@ -3331,10 +3331,34 @@ function TRANSLATE_POOL_TYPE ($type) {
        return $translated;
 }
 
+// Determines the real remote address
+function determineRealRemoteAddress () {
+       // Is a proxy in use?
+       if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
+               // Proxy was used
+               $address = $_SERVER['HTTP_X_FORWARDED_FOR'];
+       } elseif (isset($_SERVER['HTTP_CLIENT_IP'])){
+               // Yet, another proxy
+               $address = $_SERVER['HTTP_CLIENT_IP'];
+       } else {
+               // The regular address when no proxy was used
+               $address = $_SERVER['REMOTE_ADDR'];
+       }
+
+       // This strips out the real address from proxy output
+       if (strstr($address, ",")){
+               $addressArray = explode(",", $address);
+               $address = $addressArray[0];
+       } // END - if
+
+       // Return the result
+       return $address;
+}
+
 // "Getter" for remote IP number
 function GET_REMOTE_ADDR () {
        // Get remote ip from environment
-       $remoteAddr = getenv('REMOTE_ADDR');
+       $remoteAddr = determineRealRemoteAddress();
 
        // Is removeip installed?
        if (EXT_IS_ACTIVE("removeip")) {
index 36399f1662a418a971f643f5436067f8076a9c56..121f0c4579a3e063d6840658856b46b0f1bb0a25 100644 (file)
@@ -54,11 +54,14 @@ function REWRITE_LINKS ($HTML) {
        $target = constant('URL')."/cms/";
 
        // Convert modules.php?module=...
-       $test = preg_replace("/".$URL."/modules.php?module=/i", $target, $HTML);
+       $output = preg_replace("/".$URL."\\/modules.php\\?module=/i", $target, $HTML);
+
+       if (eregi(constant('SERVER_URL'), $output)) {
+               // Strip slashes with double-backslashes for the preg_replace() function
+               $URL = str_replace("/", "\\/", constant('SERVER_URL'));
 
-       if (eregi(SERVER_URL, $test)) {
                // Convert URLs from my server
-               $test = preg_replace("/".constant('SERVER_URL')."/modules.php?module=/i", constant('SERVER_URL')."/cms/", $test);
+               $output = preg_replace("/".$URL."\\/modules.php\\?module=/i", constant('SERVER_URL')."/cms/", $output);
        } // END - if
 
        // Strip slashes as above for the main URL
@@ -68,50 +71,19 @@ function REWRITE_LINKS ($HTML) {
        $act = $target."\$1/act/";
 
        // Convert &amp;|&action=...
-       $test = preg_replace("/".$target2."(.*)&amp;action=/i", $act, $test);
+       $output = preg_replace("/".$target2."(.*)&amp;action=/i", $act, $output);
 
        // "The same procedure as last variable"... now for &amp;what=
        $wht = $target."\$1/wht/";
-       $target2 = str_replace("/", "\\/", $target);
-       $test = preg_replace("/".$target2."(.*)&amp;what=/i", $wht, $test);
-
-       if ((EXT_IS_ACTIVE("rallye")) && (eregi("rallye=", $test))) {
-               // Replace data when rallye extension is active
-               // Add more if you need more like these entries
-               $REPLACE = array("rallye", "activate", "auto", "notify", "sub");
-               foreach ($REPLACE as $var) {
-                       // This will replace "&amp;var=" to "/var/"
-                       $test = preg_replace("/&amp;".$var."=/i", "/".$var."/", $test);
-               } // END - foreach
-       } // END - if
-
-       // Simple from->to replacements
-       $REPLACE = array(
-               'search'  => array("uid", "url", "page", "offset", "mid", "bid", "sub", "home"),
-               'replace' => array("u"   , "url", "page", "offset", "m"  , "b"  , "s"  , "h")
-       );
-
-       if ((EXT_IS_ACTIVE("admins")) && (eregi("admin=", $test))) {
-               // Replace &amp;admin= with "/aid/"
-               $REPLACE['search'][]  = "admin";
-               $REPLACE['replace'][] = "aid";
-       } // END - if
-
-       // Replace all array elements through
-       foreach ($REPLACE['search'] as $k => $v) {
-               if (eregi("$v=", $test)) {
-                       // Replace &amp;uid= with /u/
-                       $test = preg_replace("/&amp;".$v."=/i", "/".$REPLACE['replace'][$k]."/", $test);
-               } // END - if
-       } // END - foreach
+       $output = preg_replace("/".$target2."(.*)&amp;what=/i", $wht, $output);
 
        // Repair missed &amp;what=??? entries
-       while (preg_match("/&amp;what=(.*)\/(.*)\/(.*)/i", $test)) {
-               $test = preg_replace("/&amp;what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $test);
+       while (preg_match("/&amp;what=(.*)\/(.*)\/(.*)/i", $output)) {
+               $output = preg_replace("/&amp;what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $output);
        } // END - while
 
        // Return rewritten code
-       return $test;
+       return $output;
 }
 //
 ?>