Skip to content

Commit b3955a3

Browse files
committed
Improve IP address resolution strategy.
1 parent 9abeacc commit b3955a3

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
6969
[2022.02.01; Bug-fix; Maikuolan]: Failed to correctly determine the client's IP address under certain circumstances (e.g., multiple choices available via HTTP_X_FORWARDED_FOR); Fixed.
7070

7171
[2022.02.14; Maikuolan]: Maintenance release.
72+
73+
### v3.3.2
74+
75+
[2022.02.21; Maikuolan]: Improved IP address resolution strategy.

assets/config.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# License: GNU/GPLv2
88
# @see LICENSE.txt
99
#
10-
# This file: Configuration defaults file (last modified: 2021.11.27).
10+
# This file: Configuration defaults file (last modified: 2022.02.20).
1111
##/
1212

1313
core:
@@ -128,10 +128,12 @@ core:
128128
CF-Connecting-IP: "CF-Connecting-IP (Cloudflare)"
129129
HTTP_X_FORWARDED_FOR: "HTTP_X_FORWARDED_FOR (Cloudbric)"
130130
X-Forwarded-For: "X-Forwarded-For (Squid)"
131+
Forwarded: "Forwarded"
131132
REMOTE_ADDR: "REMOTE_ADDR ({label_default})"
132133
See also:
133-
NGINX Reverse Proxy: "https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/"
134-
Squid configuration directive forwarded_for: "http://www.squid-cache.org/Doc/config/forwarded_for/"
134+
"NGINX Reverse Proxy": "https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/"
135+
"Squid configuration directive forwarded_for": "http://www.squid-cache.org/Doc/config/forwarded_for/"
136+
"Forwarded - HTTP | MDN": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded"
135137
delete_on_sight:
136138
type: "bool"
137139
default: false

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"require": {
1414
"php": ">=7.2.0",
15-
"maikuolan/common": "^2.8",
15+
"maikuolan/common": "^2.9",
1616
"ext-pcre": "*"
1717
},
1818
"suggest": {

src/Loader.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2022.02.14).
11+
* This file: The loader (last modified: 2022.02.21).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -320,23 +320,8 @@ public function __construct(
320320
$this->$Path = $$Path;
321321
}
322322

323-
/** Failsafe for weird ipaddr configuration. */
324-
$this->IPAddr = (
325-
$this->Configuration['core']['ipaddr'] !== 'REMOTE_ADDR' && empty($_SERVER[$this->Configuration['core']['ipaddr']])
326-
) ? 'REMOTE_ADDR' : $this->Configuration['core']['ipaddr'];
327-
328-
/** Ensure we have an IP address available to work with. */
329-
$this->IPAddr = $_SERVER[$this->IPAddr] ?? '';
330-
331-
/** Ensure the IP address we're working with is a string. */
332-
if (is_array($this->IPAddr)) {
333-
$this->IPAddr = array_shift($this->IPAddr);
334-
}
335-
if (is_string($this->IPAddr) && ($Pos = strpos($this->IPAddr, ', ')) !== false) {
336-
$this->IPAddr = substr($this->IPAddr, 0, $Pos);
337-
}
338-
$this->IPAddr = (string)$this->IPAddr;
339-
unset($Pos);
323+
/** Fetch the IP address of the current request. */
324+
$this->IPAddr = (new \Maikuolan\Common\IPHeader($this->Configuration['core']['ipaddr']))->Resolution;
340325

341326
/** Set timezone. */
342327
if (!empty($this->Configuration['core']['timezone']) && $this->Configuration['core']['timezone'] !== 'SYSTEM') {

0 commit comments

Comments
 (0)