mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Compare commits
1 Commits
m42-php81-
...
TOTARA_13_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d650fb23e8 |
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@@ -1,10 +1,9 @@
|
||||
# .github/workflows/ci.yml
|
||||
name: ci
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
|
||||
test:
|
||||
uses: catalyst/catalyst-moodle-workflows/.github/workflows/group-39-plus-ci.yml@main
|
||||
with:
|
||||
disable_behat: true
|
||||
|
||||
@@ -59,9 +59,6 @@ Basic Usage
|
||||
|
||||
_Anyone who tries to use Moodle now will receive a maintenance message._
|
||||
|
||||
**Note:** If the outage starts with the option `Auto start maintenance mode` checked, the maint mode won't exit automatically.
|
||||
It will need to be disabled through command line.
|
||||
|
||||
1) Perform the maintenance activities.
|
||||
|
||||
At this point it is safe to perform the required maintenance as no one can use the system, not even admins.
|
||||
|
||||
44
README.md
44
README.md
@@ -1,4 +1,4 @@
|
||||

|
||||
[](https://github.com/catalyst/moodle-auth_outage/actions)
|
||||
|
||||
# Moodle Outage manager plugin
|
||||
* [Version Support](#version-support)
|
||||
@@ -100,48 +100,6 @@ This can be found at:
|
||||
|
||||
|
||||
|
||||
Custom Theme Additional SCSS
|
||||
-------------------
|
||||
|
||||
Custom themes generally do not have the same `$navbar-height` variable set to 80px (MOODLE), therefore custom themes will not calculate the change in navbar height with page elements that calculate the navbar total height.
|
||||
|
||||
Add the following SCSS For Moodle 3.11+
|
||||
|
||||
```
|
||||
body.auth_outage {
|
||||
#page-wrapper {
|
||||
#nav-drawer {
|
||||
top: $navbar-height + 100px;
|
||||
height: calc(100% - (#{$navbar-height} + 100px));
|
||||
}
|
||||
#page {
|
||||
margin-top: $navbar-height + 100px;
|
||||
}
|
||||
}
|
||||
[data-region=right-hand-drawer].drawer {
|
||||
top: $navbar-height + 100px;
|
||||
height: calc(100% - (#{$navbar-height} + 100px));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Totara is a little different with version 13+ and no variables are used to set the `totaraNav` height
|
||||
|
||||
Add the following CSS For Totara 13+
|
||||
|
||||
```
|
||||
.totaraNav {
|
||||
margin-top: 100px;
|
||||
}
|
||||
.local_envbar .totaraNav {
|
||||
margin-top: 50px;
|
||||
}
|
||||
body.auth_outage #page {
|
||||
margin-top: 0;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
How to use
|
||||
----------
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
// This call is required by Moodle, but this script should have been called by config.php anyway.
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once(__DIR__.'/../../../config.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
// We need the CFG->dataroot, if not set yet this script is called too early in config.php file.
|
||||
@@ -42,13 +42,13 @@ if (!isset($CFG->dataroot)) {
|
||||
// 1) Make sure we replace the configurations for behat as we have not ran 'lib/setup.php' yet.
|
||||
if (!empty($CFG->behat_wwwroot) or !empty($CFG->behat_dataroot) or !empty($CFG->behat_prefix)) {
|
||||
require_once(__DIR__.'/../../lib/behat/lib.php');
|
||||
behat_update_vars_for_process();
|
||||
if (behat_is_test_site()) {
|
||||
behat_update_vars_for_process($CFG);
|
||||
if (behat_is_test_site($CFG)) {
|
||||
$beforebehatcfg = $CFG;
|
||||
$CFG = clone($CFG);
|
||||
clearstatcache();
|
||||
behat_check_config_vars();
|
||||
behat_clean_init_config();
|
||||
behat_check_config_vars($CFG);
|
||||
behat_clean_init_config($CFG);
|
||||
$CFG->wwwroot = $CFG->behat_wwwroot;
|
||||
$CFG->dataroot = $CFG->behat_dataroot;
|
||||
// We should not access database in bootstrap.
|
||||
|
||||
@@ -147,7 +147,7 @@ class edit extends moodleform {
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function set_data($outage) {
|
||||
global $OUTPUT, $CFG;
|
||||
global $OUTPUT;
|
||||
$mform = $this->_form;
|
||||
|
||||
// Cannot change method signature, check type.
|
||||
@@ -162,15 +162,6 @@ class edit extends moodleform {
|
||||
'description' => ['text' => $outage->description, 'format' => '1'],
|
||||
]);
|
||||
|
||||
// If the default_autostart is configured in config, then force autostart to be the default value.
|
||||
if (array_key_exists('auth_outage', $CFG->forced_plugin_settings)
|
||||
&& array_key_exists('default_autostart', $CFG->forced_plugin_settings['auth_outage'])) {
|
||||
$this->_form->setDefaults([
|
||||
'autostart' => $CFG->forced_plugin_settings['auth_outage']['default_autostart']
|
||||
]);
|
||||
$mform->freeze('autostart');
|
||||
}
|
||||
|
||||
if (!empty($outage->id) && $outage->autostart && $outage->starttime < time() && $outage->stoptime > time()) {
|
||||
$warning = $mform->getElement('warningreenablemaintenancemode');
|
||||
$warning->setValue($OUTPUT->notification(get_string('warningreenablemaintenancemode', 'auth_outage'),
|
||||
|
||||
@@ -129,7 +129,7 @@ class waitforit extends clibase {
|
||||
return;
|
||||
}
|
||||
|
||||
$time = \core_date::strftime('%F %T %Z');
|
||||
$time = strftime('%F %T %Z');
|
||||
printf("[%s] %s\n", $time, $message);
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,6 @@ class outagelib {
|
||||
unset_config('maintenance_message');
|
||||
}
|
||||
set_config('maintenance_later', $outage->starttime);
|
||||
self::maintenance_config_log($outage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,18 +414,4 @@ EOT;
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logging for maintenance mode configuration.
|
||||
*
|
||||
* @param outage|null $outage Outage or null if no scheduled outage.
|
||||
*/
|
||||
private static function maintenance_config_log(outage $outage) {
|
||||
mtrace(get_string('logformaintmodeconfig', 'auth_outage'));
|
||||
$timezone = ' (Timezone ' . \core_date::get_server_timezone_object()->getName() . ')';
|
||||
mtrace('... updated at ' . date('H:i:s'));
|
||||
$time = date("Y-m-d H:i:s", $outage->starttime);
|
||||
mtrace("... enable maintenance mode at $time $timezone");
|
||||
mtrace(get_string('logformaintmodeconfigcomplete', 'auth_outage'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,8 +107,6 @@ $string['allowedipsempty'] = 'When the allowed IPs list is empty we will not blo
|
||||
$string['allowedipshasmyip'] = 'Your IP (<i>{$a->ip}</i>) is in the list and you will not be blocked out during an Outage.';
|
||||
$string['allowedipshasntmyip'] = 'Your IP (<i>{$a->ip}</i>) is not in the list and you will be blocked out during an outage.';
|
||||
$string['allowedipsnoconfig'] = 'Your config.php does not have the extra setup to allow blocking via IP.<br />Please refer to our <a href="https://github.com/catalyst/moodle-auth_outage#installation" target="_blank">README.md</a> file for more information.';
|
||||
$string['logformaintmodeconfig'] = 'Update maintenance mode configuration.';
|
||||
$string['logformaintmodeconfigcomplete'] = 'Updating maintenance mode configuration complete.';
|
||||
$string['menusettings'] = 'Settings';
|
||||
$string['menumanage'] = 'Manage outages';
|
||||
$string['messageoutagebackonline'] = 'We are back online!';
|
||||
|
||||
30
settings.php
30
settings.php
@@ -26,30 +26,25 @@
|
||||
* @var admin_settingpage $settings
|
||||
* @var bootstrap_renderer $OUTPUT
|
||||
* @var admin_root $ADMIN
|
||||
* @var moodle_page $PAGE
|
||||
*/
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
if ($hassiteconfig) {
|
||||
if ($hassiteconfig && is_enabled_auth('outage')) {
|
||||
$defaults = outagelib::get_config_defaults();
|
||||
$settings->visiblename = get_string('menusettings', 'auth_outage');
|
||||
$description = outagelib::generate_plugin_configuration_warning();
|
||||
|
||||
$settings->add(new admin_setting_heading(
|
||||
'defaults',
|
||||
get_string('settingssectiondefaults', 'auth_outage'),
|
||||
get_string('settingssectiondefaultsdescription', 'auth_outage') . $description
|
||||
));
|
||||
|
||||
get_string('settingssectiondefaultsdescription', 'auth_outage')));
|
||||
$settings->add(new admin_setting_configcheckbox(
|
||||
'auth_outage/default_autostart',
|
||||
get_string('defaultoutageautostart', 'auth_outage'),
|
||||
get_string('defaultoutageautostartdescription', 'auth_outage'),
|
||||
$defaults['default_autostart']
|
||||
));
|
||||
|
||||
$settings->add(new admin_setting_configduration(
|
||||
'auth_outage/default_warning_duration',
|
||||
get_string('defaultwarningduration', 'auth_outage'),
|
||||
@@ -101,22 +96,21 @@ if ($hassiteconfig) {
|
||||
|
||||
// Create 'Allowed IPs' settings.
|
||||
$allowedips = outagelib::get_config()->allowedips;
|
||||
$description = outagelib::generate_plugin_configuration_warning();
|
||||
if (trim($allowedips) == '') {
|
||||
$message = 'allowedipsempty';
|
||||
$type = 'notifymessage';
|
||||
} else if (remoteip_in_list($allowedips)) {
|
||||
$message = 'allowedipshasmyip';
|
||||
$type = 'notifysuccess';
|
||||
} else {
|
||||
if (remoteip_in_list($allowedips)) {
|
||||
$message = 'allowedipshasmyip';
|
||||
$type = 'notifysuccess';
|
||||
} else {
|
||||
$message = 'allowedipshasntmyip';
|
||||
$type = 'notifyerror';
|
||||
}
|
||||
$message = 'allowedipshasntmyip';
|
||||
$type = 'notifyerror';
|
||||
};
|
||||
$description = $OUTPUT->notification(get_string($message, 'auth_outage', ['ip' => getremoteaddr()]), $type);
|
||||
$description .= $OUTPUT->notification(get_string($message, 'auth_outage', ['ip' => getremoteaddr()]), $type);
|
||||
|
||||
$description .= '<p>' . get_string('ipblockersyntax', 'admin') . '</p>';
|
||||
$description .= '<p>' . get_string('ips_combine', 'auth_outage') . '</p>';
|
||||
$description .= '<p>'.get_string('ipblockersyntax', 'admin').'</p>';
|
||||
$description .= '<p>'.get_string('ips_combine', 'auth_outage').'</p>';
|
||||
|
||||
$iplist = new admin_setting_configiplist(
|
||||
'auth_outage/allowedips',
|
||||
@@ -156,7 +150,7 @@ if ($hassiteconfig) {
|
||||
new admin_externalpage(
|
||||
'auth_outage_manage',
|
||||
get_string('menumanage', 'auth_outage'),
|
||||
new moodle_url($CFG->wwwroot . '/auth/outage/manage.php')
|
||||
new moodle_url($CFG->wwwroot.'/auth/outage/manage.php')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,11 +63,7 @@ class auth_outage_installation_test extends auth_outage_base_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
ob_start();
|
||||
\auth_outage\dml\outagedb::save($outage);
|
||||
$text = trim(ob_get_contents());
|
||||
ob_end_clean();
|
||||
self::assertStringContainsString('Update maintenance mode configuration', $text);
|
||||
self::assertSame(1, $DB->count_records_select('event', "eventtype = 'auth_outage'", null));
|
||||
|
||||
// Uninstall plugin.
|
||||
|
||||
@@ -159,8 +159,8 @@ class auth_outage_create_test extends auth_outage_cli_testcase {
|
||||
$text = $this->execute($cli);
|
||||
self::assertStringContainsString('created', $text);
|
||||
// Check creted outage.
|
||||
$clioutput = explode(':', $text);
|
||||
$id = (int)end($clioutput);
|
||||
list(, $id) = explode(':', $text);
|
||||
$id = (int)$id;
|
||||
$outage = outagedb::get_by_id($id);
|
||||
self::assertSame($now, $outage->starttime);
|
||||
self::assertSame(10, $outage->get_warning_duration());
|
||||
@@ -223,8 +223,8 @@ class auth_outage_create_test extends auth_outage_cli_testcase {
|
||||
$text = $this->execute($cli);
|
||||
self::assertStringContainsString('created', $text);
|
||||
// Check creted outage.
|
||||
$clioutput = explode(':', $text);
|
||||
$id = (int)end($clioutput);
|
||||
list(, $id) = explode(':', $text);
|
||||
$id = (int)$id;
|
||||
$outage = outagedb::get_by_id($id);
|
||||
self::assertSame($now + 50, $outage->starttime, 'Wrong starttime.');
|
||||
self::assertSame($outage->starttime - 100, $outage->warntime, 'Wrong warntime.');
|
||||
|
||||
@@ -60,11 +60,7 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
|
||||
]);
|
||||
|
||||
set_config('maintenance_message', 'A message.');
|
||||
ob_start();
|
||||
outagedb::save($outage);
|
||||
$text = trim(ob_get_contents());
|
||||
ob_end_clean();
|
||||
self::assertStringContainsString('Update maintenance mode configuration', $text);
|
||||
self::assertFalse((bool)get_config('moodle', 'maintenance_message'));
|
||||
self::assertCount(2, $this->getDebuggingMessages());
|
||||
$this->resetDebugging();
|
||||
@@ -98,11 +94,7 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
ob_start();
|
||||
$outage->id = outagedb::save($outage);
|
||||
$text = trim(ob_get_contents());
|
||||
ob_end_clean();
|
||||
self::assertStringContainsString('Update maintenance mode configuration', $text);
|
||||
|
||||
outagelib::reset_injectcalled();
|
||||
// Get full header to avoid interactions with other single inject plugins.
|
||||
@@ -144,11 +136,7 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
ob_start();
|
||||
$outage->id = outagedb::save($outage);
|
||||
$text = trim(ob_get_contents());
|
||||
ob_end_clean();
|
||||
self::assertStringContainsString('Update maintenance mode configuration', $text);
|
||||
|
||||
$_GET = ['auth_outage_preview' => (string)$outage->id];
|
||||
|
||||
@@ -187,11 +175,8 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
ob_start();
|
||||
$outage->id = outagedb::save($outage);
|
||||
$text = trim(ob_get_contents());
|
||||
ob_end_clean();
|
||||
self::assertStringContainsString('Update maintenance mode configuration', $text);
|
||||
|
||||
$_GET = ['auth_outage_preview' => (string)$outage->id, 'auth_outage_delta' => '500'];
|
||||
outagelib::reset_injectcalled();
|
||||
$header = outagelib::get_inject_code();
|
||||
@@ -297,11 +282,7 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
ob_start();
|
||||
$outage->id = outagedb::save($outage);
|
||||
$text = trim(ob_get_contents());
|
||||
ob_end_clean();
|
||||
self::assertStringContainsString('Update maintenance mode configuration', $text);
|
||||
|
||||
// Pretend we are there...
|
||||
$_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test.
|
||||
@@ -360,7 +341,6 @@ EOT;
|
||||
/**
|
||||
* Test create maintenance php code without age
|
||||
*
|
||||
* @param string $configkey The key of the config.
|
||||
* @dataProvider test_createmaintenancephpcode_withoutage_provider
|
||||
*/
|
||||
public function test_createmaintenancephpcode_withoutage($configkey) {
|
||||
@@ -558,11 +538,8 @@ EOT;
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
ob_start();
|
||||
$outage->id = outagedb::save($outage);
|
||||
$text = trim(ob_get_contents());
|
||||
ob_end_clean();
|
||||
self::assertStringContainsString('Update maintenance mode configuration', $text);
|
||||
|
||||
// Pretend we are there...
|
||||
$_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test.
|
||||
$_SERVER['SCRIPT_NAME'] = '/admin/settings.php';
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->version = 2023012700; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2023012700; // Human-readable release information.
|
||||
$plugin->version = 2022051200; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2022051200; // 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, 401]; // A range of branch numbers of supported moodle versions.
|
||||
$plugin->supported = [39, 311]; // A range of branch numbers of supported moodle versions.
|
||||
|
||||
@@ -12,21 +12,12 @@ If you need to make changes here, remember to update your settings inside Moodle
|
||||
padding: 0;
|
||||
position: fixed;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
top: 0;
|
||||
transition: background 3s ease-out;
|
||||
width: 100%;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
#auth_outage_warningbar_box .auth_outage_warningbar_center {
|
||||
/* fix to prevent existing theme hacks to fix issue */
|
||||
margin-top: 0;
|
||||
position: static;
|
||||
}
|
||||
|
||||
#auth_outage_warningbar_box.auth_outage_warning_period {
|
||||
background:
|
||||
repeating-linear-gradient(
|
||||
@@ -75,10 +66,16 @@ If you need to make changes here, remember to update your settings inside Moodle
|
||||
background-color: #090;
|
||||
}
|
||||
|
||||
.auth_outage_warningbar_center {
|
||||
margin-top: -35px;
|
||||
position: relative;
|
||||
top: 50%;
|
||||
}
|
||||
|
||||
#auth_outage_warningbar_message {
|
||||
font-size: 200%;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
a.auth_outage_warningbar_box_title {
|
||||
@@ -90,7 +87,6 @@ a.auth_outage_warningbar_box_finish {
|
||||
border: 1px solid black;
|
||||
border-radius: 5px;
|
||||
color: darkgray;
|
||||
white-space: nowrap;
|
||||
font-weight: bold;
|
||||
margin-left: 10px;
|
||||
padding-left: 5px;
|
||||
@@ -130,9 +126,3 @@ body.auth_outage .layout.fullscreen {
|
||||
body.auth_outage .modal-dialog {
|
||||
margin: calc(150px + 1.75rem) auto;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
#auth_outage_warningbar_message {
|
||||
font-size: 120%;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user