mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Fix: make access key and allowed ips OR conditional
Access keys and allowed IPs should be indpendant of each other and when at least one of them is satisfied the user should be allowed in.
This commit is contained in:
@@ -321,10 +321,10 @@ if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
|
||||
$ipblocked = !remoteip_in_list('{{ALLOWEDIPS}}');
|
||||
$accesskeyblocked = $useraccesskey != '{{ACCESSKEY}}';
|
||||
$blocked = ({{USEACCESSKEY}} && $accesskeyblocked) || ({{USEALLOWEDIPS}} && $ipblocked);
|
||||
$allowed = ({{USEACCESSKEY}} && !$accesskeyblocked) || ({{USEALLOWEDIPS}} && !$ipblocked);
|
||||
$isphpunit = defined('PHPUNIT_TEST');
|
||||
|
||||
if ($blocked) {
|
||||
if (!$allowed) {
|
||||
if (!$isphpunit) {
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
|
||||
header('Status: 503 Moodle under maintenance');
|
||||
@@ -347,19 +347,11 @@ if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
if ({{USEALLOWEDIPS}} && $ipblocked) {
|
||||
echo '<!-- Blocked by ip, your ip: '.getremoteaddr('n/a').' -->';
|
||||
}
|
||||
|
||||
if ({{USEALLOWEDIPS}} && !$ipblocked) {
|
||||
echo '<!-- Your IP is allowed: '.getremoteaddr('n/a').' -->';
|
||||
}
|
||||
|
||||
if ({{USEACCESSKEY}} && $accesskeyblocked) {
|
||||
echo '<!-- Blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
}
|
||||
|
||||
if ({{USEACCESSKEY}} && !$accesskeyblocked) {
|
||||
echo '<!-- Your access key is allowed: '. $useraccesskey .' -->';
|
||||
}
|
||||
|
||||
if (!$isphpunit) {
|
||||
if (file_exists($CFG->dataroot.'/climaintenance.template.html')) {
|
||||
require($CFG->dataroot.'/climaintenance.template.html');
|
||||
|
||||
Reference in New Issue
Block a user