mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 11:46:19 +01:00
Merge branch 'MDL-66732' of https://github.com/paulholden/moodle
This commit is contained in:
commit
9be6c16a37
@ -742,6 +742,9 @@ $CFG->admin = 'admin';
|
||||
// Force developer level debug and add debug info to the output of cron
|
||||
// $CFG->showcrondebugging = true;
|
||||
//
|
||||
// Force result of checks used to determine whether a site is considered "public" or not (such as for site registration).
|
||||
// $CFG->site_is_public = false;
|
||||
//
|
||||
//=========================================================================
|
||||
// 8. FORCED SETTINGS
|
||||
//=========================================================================
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -10571,18 +10571,26 @@ function get_callable_name($callable) {
|
||||
* It just performs some simple checks, and mainly is used for places where we want to hide some options
|
||||
* such as site registration when $CFG->wwwroot is not publicly accessible.
|
||||
* Good thing is there is no false negative.
|
||||
* Note that it's possible to force the result of this check by specifying $CFG->site_is_public in config.php
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function site_is_public() {
|
||||
global $CFG;
|
||||
|
||||
// Return early if site admin has forced this setting.
|
||||
if (isset($CFG->site_is_public)) {
|
||||
return (bool)$CFG->site_is_public;
|
||||
}
|
||||
|
||||
$host = parse_url($CFG->wwwroot, PHP_URL_HOST);
|
||||
|
||||
if ($host === 'localhost' || preg_match('|^127\.\d+\.\d+\.\d+$|', $host)) {
|
||||
$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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user