Skip to content

Commit

Permalink
Merge branch 'MDL-65094-36' of git://github.com/rezaies/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_36_STABLE
  • Loading branch information
stronk7 committed Apr 4, 2019
2 parents 8d98d2c + abe0e8f commit 9cc403d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
3 changes: 1 addition & 2 deletions admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,7 @@ protected function available_updates($updates, $fetch) {
*/
protected function registration_warning($registered) {

if (!$registered) {

if (!$registered && site_is_public()) {
if (has_capability('moodle/site:config', context_system::instance())) {
$registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
get_string('register', 'admin'));
Expand Down
11 changes: 4 additions & 7 deletions lib/classes/hub/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,10 @@ public static function show_after_install($markasviewed = null) {
$markasviewed = true;
} else {
$showregistration = !empty($CFG->registrationpending);
if ($showregistration) {
$host = parse_url($CFG->wwwroot, PHP_URL_HOST);
if ($host === 'localhost' || preg_match('|^127\.\d+\.\d+\.\d+$|', $host)) {
// If it's a localhost, don't redirect to registration, it won't work anyway.
$showregistration = false;
$markasviewed = true;
}
if ($showregistration && !site_is_public()) {
// If it's not a public site, don't redirect to registration, it won't work anyway.
$showregistration = false;
$markasviewed = true;
}
}
if ($markasviewed !== null) {
Expand Down
25 changes: 25 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -10262,3 +10262,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;
}

0 comments on commit 9cc403d

Please sign in to comment.