diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php
index 5a09ace..6d76759 100644
--- a/classes/local/outagelib.php
+++ b/classes/local/outagelib.php
@@ -168,7 +168,12 @@ class outagelib {
}
}
- return (object)array_merge(self::get_config_defaults(), $config);
+ $config = array_merge(self::get_config_defaults(), $config);
+ // Combine allowed IPs config values together.
+ if (isset($config['allowedips_forced'])) {
+ $config['allowedips'] = trim($config['allowedips'] . "\n" . $config['allowedips_forced']);
+ }
+ return (object)$config;
}
/**
diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php
index 8842f8a..3192e85 100644
--- a/lang/en/auth_outage.php
+++ b/lang/en/auth_outage.php
@@ -158,6 +158,10 @@ $string['warningduration'] = 'Warning duration';
$string['warningduration_help'] = 'How long before the start of the outage should the warning be displayed.';
$string['warningreenablemaintenancemode'] = 'Please note that saving this outage will re-enable maintenance mode.
Untick "Auto start maintenance mode" if you want to prevent this.';
+$string['builtinallowediplist'] = 'Builtin Allowed IP List';
+$string['builtinallowediplist_desc'] = 'Allowed IP list defined via configuration';
+$string['ips_combine'] = 'The IPs listed above will be combined with the IPs listed below.';
+
/*
* Privacy provider (GDPR)
*/
diff --git a/settings.php b/settings.php
index c86670e..cfb919e 100644
--- a/settings.php
+++ b/settings.php
@@ -110,6 +110,8 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
$description .= $OUTPUT->notification(get_string($message, 'auth_outage', ['ip' => getremoteaddr()]), $type);
$description .= '
'.get_string('ipblockersyntax', 'admin').'
'; + $description .= ''.get_string('ips_combine', 'auth_outage').'
'; + $iplist = new admin_setting_configiplist( 'auth_outage/allowedips', get_string('allowediplist', 'admin'), @@ -119,6 +121,14 @@ if ($hassiteconfig && is_enabled_auth('outage')) { $iplist->set_updatedcallback('auth_outage_outagelib_prepare_next_outage'); $settings->add($iplist); + $iplist = new admin_setting_configiplist( + 'auth_outage/allowedips_forced', + get_string('builtinallowediplist', 'auth_outage'), + get_string('builtinallowediplist_desc', 'auth_outage'), + '' + ); + $settings->add($iplist); + // Create 'Static Page - Elements to Remove' settings. $toremove = new admin_setting_configtextarea( 'auth_outage/remove_selectors', diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index 2a7b687..942fa1b 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -216,6 +216,10 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase { foreach ($keys as $k) { self::assertSame($config->$k, $k.'_value', 'auth_outage'); } + + set_config('allowedips_forced', 'allowedips_forced_value', 'auth_outage'); + $config = outagelib::get_config(); + self::assertSame($config->allowedips, "allowedips_value\nallowedips_forced_value", 'auth_outage'); } /** @@ -336,8 +340,10 @@ EOT; /** * Test create maintenance php code without age + * + * @dataProvider test_createmaintenancephpcode_withoutage_provider */ - public function test_createmaintenancephpcode_withoutage() { + public function test_createmaintenancephpcode_withoutage($configkey) { global $CFG; $this->resetAfterTest(true); @@ -380,7 +386,7 @@ EOT; 'stoptime' => 456, ]); $file = $CFG->dataroot.'/climaintenance.php'; - set_config('allowedips', '127.0.0.1', 'auth_outage'); + set_config($configkey, '127.0.0.1', 'auth_outage'); outagelib::update_climaintenance_code($outage); self::assertFileExists($file); @@ -388,6 +394,10 @@ EOT; self::assertSame($found, $expected); } + public function test_createmaintenancephpcode_withoutage_provider(): array { + return [['allowedips'], ['allowedips_forced']]; + } + /** * Test create maintenance php code without IPs */ @@ -401,6 +411,7 @@ EOT; ]); $file = $CFG->dataroot.'/climaintenance.php'; set_config('allowedips', '', 'auth_outage'); + set_config('allowedips_forced', '', 'auth_outage'); touch($file); outagelib::update_climaintenance_code($outage); diff --git a/version.php b/version.php index 4925c76..304b90b 100644 --- a/version.php +++ b/version.php @@ -28,8 +28,8 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = "auth_outage"; -$plugin->version = 2022011400; // The current plugin version (Date: YYYYMMDDXX). -$plugin->release = 2022011400; // Human-readable release information. +$plugin->version = 2022042800; // The current plugin version (Date: YYYYMMDDXX). +$plugin->release = 2022042800; // Human-readable release information. $plugin->requires = 2017111309; // 2017111309 = T13, but this really requires 3.9 and higher. $plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments! $plugin->supported = [39, 311]; // A range of branch numbers of supported moodle versions.