MDL-66732 core: improve detection of non-public sites.
This commit is contained in:
@@ -245,4 +245,22 @@ final class ip_utils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return IP address for given hostname, or null on failure
|
||||
*
|
||||
* @param string $hostname
|
||||
* @return string|null
|
||||
*/
|
||||
public static function get_ip_address(string $hostname): ?string {
|
||||
if (self::is_domain_name($hostname)) {
|
||||
$address = gethostbyname($hostname);
|
||||
|
||||
// If address is different from hostname, we have success.
|
||||
if (strcasecmp($address, $hostname) !== 0) {
|
||||
return $address;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10444,6 +10444,8 @@ function site_is_public() {
|
||||
$ispublic = false;
|
||||
} else if (\core\ip_utils::is_ip_address($host) && !ip_is_public($host)) {
|
||||
$ispublic = false;
|
||||
} else if (($address = \core\ip_utils::get_ip_address($host)) && !ip_is_public($address)) {
|
||||
$ispublic = false;
|
||||
} else {
|
||||
$ispublic = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user