Merge branch 'MDL-65094-35' of git://github.com/rezaies/moodle into MOODLE_35_STABLE
This commit is contained in:
@@ -10206,3 +10206,28 @@ function get_callable_name($callable) {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to guess if $CFG->wwwroot is publicly accessible or not.
|
||||
* Never put your faith on this function and rely on its accuracy as there might be false positives.
|
||||
* 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.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function site_is_public() {
|
||||
global $CFG;
|
||||
|
||||
$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 {
|
||||
$ispublic = true;
|
||||
}
|
||||
|
||||
return $ispublic;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user