-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [FIX] Parse forwarded IP addresses when getting client IP address. …
…Related #498
- Loading branch information
Showing
5 changed files
with
24 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ class Util | |
/** | ||
* Generar una clave aleatoria | ||
* | ||
* @param int $length Longitud de la clave | ||
* @param int $length Longitud de la clave | ||
* @param bool $useNumbers Usar números | ||
* @param bool $useSpecial Usar carácteres especiales | ||
* @param bool $checKStrength | ||
|
@@ -247,10 +247,10 @@ public static function checkUpdates() | |
/** | ||
* Obtener datos desde una URL usando CURL | ||
* | ||
* @param string $url | ||
* @param array $data | ||
* @param string $url | ||
* @param array $data | ||
* @param bool|null $useCookie | ||
* @param bool $weak | ||
* @param bool $weak | ||
* @return bool|string | ||
* @throws SPException | ||
*/ | ||
|
@@ -488,8 +488,8 @@ public static function getMaxUpload() | |
* such as 'false','N','yes','on','off', etc. | ||
* | ||
* @author Samuel Levy <[email protected]> | ||
* @param mixed $in The variable to check | ||
* @param bool $strict If set to false, consider everything that is not false to | ||
* @param mixed $in The variable to check | ||
* @param bool $strict If set to false, consider everything that is not false to | ||
* be true. | ||
* @return bool The boolean equivalent or null (if strict, and no exact equivalent) | ||
*/ | ||
|
@@ -563,7 +563,7 @@ public static function getServerUrl() | |
/** | ||
* Cast an object to another class, keeping the properties, but changing the methods | ||
* | ||
* @param string $class Class name | ||
* @param string $class Class name | ||
* @param string|object $object | ||
* @return mixed | ||
* @link http://blog.jasny.net/articles/a-dark-corner-of-php-class-casting/ | ||
|
@@ -619,9 +619,9 @@ public static function traceLastCall($function = null) | |
/** | ||
* Comprobar si un valor existe en un array de objetos | ||
* | ||
* @param array $objectArray | ||
* @param array $objectArray | ||
* @param string $method | ||
* @param mixed $value | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public static function checkInObjectArray(array $objectArray, $method, $value) | ||
|
@@ -699,10 +699,19 @@ public static function getETA($startTime, $numItems, $totalItems) | |
/** | ||
* Devolver la dirección IP del cliente | ||
* | ||
* @param bool $fullForwarded Devolver la cadena de forward completa | ||
* @return string | ||
*/ | ||
public static function getClientAddress() | ||
public static function getClientAddress($fullForwarded = false) | ||
{ | ||
return Request::getRequestHeaders('X-Forwarded-For') ?: $_SERVER['REMOTE_ADDR']; | ||
$forwarded = Request::getRequestHeaders('X-Forwarded-For'); | ||
|
||
if ($forwarded !== '') { | ||
if (preg_match_all('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $forwarded, $matches)) { | ||
return $fullForwarded ? implode(',', $matches[0]) : $matches[0][0]; | ||
} | ||
} | ||
|
||
return $_SERVER['REMOTE_ADDR']; | ||
} | ||
} |