mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-09-07 08:11:07 +02:00
Compare commits
45
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bc716aeba | ||
|
|
0da0542663 | ||
|
|
a093165caf | ||
|
|
85d0657563 | ||
|
|
88667c51e4 | ||
|
|
5dd73b0909 | ||
|
|
1a94b8e635 | ||
|
|
40fccef237 | ||
|
|
dbc8e75092 | ||
|
|
54eca9e3a1 | ||
|
|
e4be98f482 | ||
|
|
2e2692facd | ||
|
|
e653bc4365 | ||
|
|
74de81ef7c | ||
|
|
990152f439 | ||
|
|
5e0a3c015d | ||
|
|
bf51ff6de9 | ||
|
|
6ca7cb6d7e | ||
|
|
83cb36660b | ||
|
|
2a7556eb75 | ||
|
|
425ef963fb | ||
|
|
b63af0465e | ||
|
|
a8d496121f | ||
|
|
fdd5569324 | ||
|
|
a32c923aaa | ||
|
|
a96035be92 | ||
|
|
0105891b2e | ||
|
|
3fca6fe0af | ||
|
|
79b7a0fa59 | ||
|
|
59b6c63252 | ||
|
|
8a204a9b25 | ||
|
|
245bc347d4 | ||
|
|
cc09171e82 | ||
|
|
c0ea1c1261 | ||
|
|
2c25292a40 | ||
|
|
2b30fca670 | ||
|
|
1183420b3b | ||
|
|
845a370d6f | ||
|
|
329c635b3a | ||
|
|
b932792cb0 | ||
|
|
8bdfa9e222 | ||
|
|
77ee908aed | ||
|
|
1e40a209b0 | ||
|
|
361250ed49 | ||
|
|
0fd6a20e8e |
@@ -1,4 +1,4 @@
|
||||
[](https://github.com/catalyst/moodle-auth_outage/actions/workflows/ci.yml?branch=MOODLE_39_STABLE)
|
||||
[](https://github.com/catalyst/moodle-auth_outage/actions/workflows/ci.yml?branch=MOODLE_501_STABLE)
|
||||
|
||||
# Moodle Outage manager plugin
|
||||
- [Moodle Outage manager plugin](#moodle-outage-manager-plugin)
|
||||
@@ -42,9 +42,10 @@ need to manually add one extra plugin, please check:
|
||||
|
||||
Moodle supported branches
|
||||
--------
|
||||
| Version | Branch | PHP |
|
||||
|-------------|-------------------|------|
|
||||
| Moodle 3.9+ | MOODLE_39_STABLE | 7.2+ |
|
||||
| Version | Branch | PHP |
|
||||
|----------------|---------------------|------|
|
||||
| Moodle 5.1 | MOODLE_501_STABLE | 8.2 |
|
||||
| Moodle 3.9-5.0 | MOODLE_39_STABLE | 7.2+ |
|
||||
|
||||
Totara supported branches
|
||||
--------
|
||||
|
||||
@@ -53,10 +53,14 @@ class infopage {
|
||||
$CFG->svgicons = true;
|
||||
|
||||
if (is_null($params)) {
|
||||
$id = optional_param('id', null, PARAM_INT);
|
||||
$params = [
|
||||
'id' => optional_param('id', null, PARAM_INT),
|
||||
'id' => $id,
|
||||
'outage' => null,
|
||||
'static' => optional_param('static', false, PARAM_BOOL),
|
||||
'static' => !is_null($id) && hash_equals(
|
||||
self::statickey($id),
|
||||
optional_param('statickey', '', PARAM_ALPHANUM)
|
||||
),
|
||||
];
|
||||
} else {
|
||||
$defaults = [
|
||||
@@ -152,4 +156,21 @@ class infopage {
|
||||
$this->outage = $params['outage'];
|
||||
$this->static = $params['static'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the secret token that proves a request to view an outage's static
|
||||
* rendering came from this plugin's own static-page generator, not an external
|
||||
* client forging the request. Used to gate the 'static' flag (see constructor).
|
||||
*
|
||||
* @param int $outageid
|
||||
* @return string
|
||||
*/
|
||||
public static function statickey($outageid) {
|
||||
$secret = get_config('auth_outage', 'staticsecret');
|
||||
if (empty($secret)) {
|
||||
$secret = random_string(64);
|
||||
set_config('staticsecret', $secret, 'auth_outage');
|
||||
}
|
||||
return hash_hmac('sha256', (string)$outageid, $secret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@ class maintenance_static_page {
|
||||
header('X-Outage-EndTime: ' . $outage->stoptime);
|
||||
}
|
||||
$data = maintenance_static_page_io::file_get_data(
|
||||
$CFG->wwwroot . '/auth/outage/info.php?auth_outage_hide_warning=1&static=1&id=' . $outage->id
|
||||
$CFG->wwwroot . '/auth/outage/info.php?auth_outage_hide_warning=1&id=' . $outage->id
|
||||
. '&statickey=' . infopage::statickey($outage->id)
|
||||
);
|
||||
$html = $data['contents'];
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class outagelib {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
$curl = new curl(['ignoresecurity' => true]);
|
||||
$curl = new curl();
|
||||
$contents = $curl->get($file);
|
||||
$info = $curl->get_info();
|
||||
if (!empty($info['content_type'])) {
|
||||
@@ -253,7 +253,7 @@ class outagelib {
|
||||
* @param int $stoptime Outage stop time.
|
||||
* @param string $allowedips List of IPs allowed.
|
||||
* @param string|null $accesskey access key, or null if no access key set.
|
||||
* @param string|null $metadata metadata to be added to the outage headers, or null if none.
|
||||
* @param string|null $metadata Metadata to set in headers, or null if none.
|
||||
*
|
||||
* @return string
|
||||
* @throws invalid_parameter_exception
|
||||
@@ -267,6 +267,10 @@ class outagelib {
|
||||
// single-quotes (and double for the sake of it) are present otherwise it would break the code.
|
||||
$allowedips = addslashes($allowedips);
|
||||
|
||||
// Escape the access key before substitution into the PHP literal to prevent
|
||||
// code injection via a maliciously crafted access key value.
|
||||
$accesskey = addslashes((string)$accesskey);
|
||||
|
||||
$cookiesecure = is_moodle_cookie_secure();
|
||||
|
||||
// Since Moodle 4.3 cookiehttponly is default to true and this CFG is not set.
|
||||
@@ -345,9 +349,17 @@ EOT;
|
||||
$search = ['{{STARTTIME}}', '{{STOPTIME}}', '{{USEALLOWEDIPS}}', '{{ALLOWEDIPS}}', '{{USEACCESSKEY}}', '{{ACCESSKEY}}',
|
||||
'{{YOURIP}}', '{{COOKIESECURE}}', '{{COOKIEHTTPONLY}}', '{{METADATA}}'];
|
||||
// Note that var_export is required because (string) false == '', not 'false'.
|
||||
$replace = [$starttime, $stoptime, var_export(!empty($allowedips), true), $allowedips, var_export(!empty($accesskey), true),
|
||||
$accesskey, getremoteaddr('n/a'), var_export($cookiesecure, true),
|
||||
var_export($cookiehttponly, true), var_export($metadata, true)];
|
||||
$replace = [
|
||||
$starttime,
|
||||
$stoptime,
|
||||
var_export(!empty($allowedips), true),
|
||||
$allowedips,
|
||||
var_export(!empty($accesskey), true),
|
||||
$accesskey,
|
||||
getremoteaddr('n/a'),
|
||||
var_export($cookiesecure, true),
|
||||
var_export($cookiehttponly, true),
|
||||
var_export($metadata, true)];
|
||||
return str_replace($search, $replace, $code);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -61,7 +61,7 @@ function xmldb_auth_outage_upgrade($oldversion) {
|
||||
upgrade_plugin_savepoint(true, 2024081900, 'auth', 'outage');
|
||||
}
|
||||
|
||||
if ($oldversion < 2024081901) {
|
||||
if ($oldversion < 2026011301) {
|
||||
// Define field metadata to be added to auth_outage.
|
||||
$table = new xmldb_table('auth_outage');
|
||||
$field = new xmldb_field('metadata', XMLDB_TYPE_TEXT, null, null, null, null, null, 'accesskey');
|
||||
@@ -72,10 +72,10 @@ function xmldb_auth_outage_upgrade($oldversion) {
|
||||
}
|
||||
|
||||
// Outage savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2024081901, 'auth', 'outage');
|
||||
upgrade_plugin_savepoint(true, 2026011301, 'auth', 'outage');
|
||||
}
|
||||
|
||||
if ($oldversion < 2024081902) {
|
||||
if ($oldversion < 2026011302) {
|
||||
// Getting the table auth_outage and target field to remove from the table.
|
||||
$table = new xmldb_table('auth_outage');
|
||||
$field = new xmldb_field('autostart');
|
||||
@@ -89,7 +89,7 @@ function xmldb_auth_outage_upgrade($oldversion) {
|
||||
unset_config('default_autostart', 'auth_outage');
|
||||
|
||||
// Outage savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2024081902, 'auth', 'outage');
|
||||
upgrade_plugin_savepoint(true, 2026011302, 'auth', 'outage');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -28,7 +28,6 @@ use auth_outage\form\outage\edit;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
|
||||
require_once(__DIR__ . '/../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
|
||||
@@ -141,6 +141,7 @@ $string['outagefinishwarning'] = 'You are about to mark this outage as finished.
|
||||
$string['outageslistfuture'] = 'Planned outages';
|
||||
$string['outageslistpast'] = 'Outage history';
|
||||
$string['pluginname'] = 'Outage manager';
|
||||
$string["privacy:no_data_reason"] = "The Outage authentication plugin does not store any personal data.";
|
||||
$string['removeselectors'] = 'Remove selectors';
|
||||
$string['removeselectorsdescription'] = 'CSS selectors to remove when rendering a static themed maintenance page. One selector per line.';
|
||||
$string['settingssectiondefaults'] = 'Default Outage Parameters';
|
||||
@@ -172,8 +173,3 @@ $string['warningduration'] = 'Warning duration';
|
||||
$string['warningduration_help'] = 'How long before the start of the outage should the warning be displayed.';
|
||||
$string['warningdurationerrorinvalid'] = 'Warning duration must be positive.';
|
||||
$string['warningreenablemaintenancemode'] = 'Please note that saving this outage will re-enable maintenance mode.<br />Untick "Auto start maintenance mode" if you want to prevent this.';
|
||||
|
||||
/*
|
||||
* Privacy provider (GDPR)
|
||||
*/
|
||||
$string["privacy:no_data_reason"] = "The Outage authentication plugin does not store any personal data.";
|
||||
|
||||
@@ -30,7 +30,11 @@ use auth_outage\local\controllers\maintenance_static_page;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
|
||||
$id = optional_param('id', null, PARAM_INT);
|
||||
$outage = is_null($id) ? outagedb::get_next_starting() : outagedb::get_by_id($id);
|
||||
if (is_null($outage)) {
|
||||
|
||||
@@ -95,6 +95,9 @@ abstract class base_testcase extends \advanced_testcase {
|
||||
|
||||
parent::setUp();
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// These tests rely on force login being disabled, but Moodle 5.2 enables it by default (MDL-87523).
|
||||
set_config('forcelogin', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -158,7 +158,7 @@ final class waitforit_test extends cli_testcase {
|
||||
/**
|
||||
* Tests the countdown.
|
||||
*/
|
||||
public function test_countdown() {
|
||||
public function test_countdown(): void {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
outagedb::save(new outage([
|
||||
@@ -186,7 +186,7 @@ final class waitforit_test extends cli_testcase {
|
||||
/**
|
||||
* Tests if the outage changed while waiting.
|
||||
*/
|
||||
public function test_outagechanged() {
|
||||
public function test_outagechanged(): void {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$id = outagedb::save(new outage([
|
||||
|
||||
@@ -431,39 +431,6 @@ final class maintenance_static_page_test extends \auth_outage\base_testcase {
|
||||
maintenance_static_page_io::file_get_data(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test file_get_data with curlsecurityblockedhosts.
|
||||
* We will use an external URL to test passing ignoresecurity inside of file_get_data works,
|
||||
* ideally in real code we should only be calling file_get_data with internal URLs.
|
||||
*/
|
||||
public function test_file_get_data_curlsecurityblockedhosts(): void {
|
||||
global $CFG, $USER;
|
||||
|
||||
$testhtml = $this->getExternalTestFileUrl('/test.html');
|
||||
$url = new \moodle_url($testhtml);
|
||||
$host = $url->get_host();
|
||||
set_config('curlsecurityblockedhosts', $host); // Blocks $host.
|
||||
|
||||
// Test a regular curl with the default security enabled does in fact get blocked.
|
||||
$curl = new \curl();
|
||||
$contents = $curl->get($testhtml);
|
||||
$expected = $curl->get_security()->get_blocked_url_string();
|
||||
self::assertSame($expected, $contents);
|
||||
self::assertSame(0, $curl->get_errno());
|
||||
if ($CFG->branch >= 403) {
|
||||
self::assertDebuggingCalled(
|
||||
"Blocked $testhtml: The URL is blocked. [user {$USER->id}]",
|
||||
DEBUG_NONE
|
||||
);
|
||||
}
|
||||
|
||||
// Test file_get_data does return the page and isn't blocked by security.
|
||||
$found = maintenance_static_page_io::file_get_data($url->out());
|
||||
$expected = '47250a973d1b88d9445f94db4ef2c97a';
|
||||
self::assertSame($expected, md5($found['contents']));
|
||||
self::assertSame('text/html', $found['mime']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove css selector.
|
||||
*/
|
||||
@@ -583,7 +550,7 @@ final class maintenance_static_page_test extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Test meta refresh maximum 5 minutes.
|
||||
*/
|
||||
public function test_meta_refresh_maximum_5seconds() {
|
||||
public function test_meta_refresh_maximum_5seconds(): void {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n" .
|
||||
'<html><head><title>Title</title></head>' .
|
||||
@@ -593,7 +560,6 @@ final class maintenance_static_page_test extends \auth_outage\base_testcase {
|
||||
$page->set_max_refresh_time(5);
|
||||
$page->generate();
|
||||
$generated = trim(file_get_contents($page->get_io()->get_template_file()));
|
||||
return $generated;
|
||||
|
||||
self::assertStringContainsString('<meta http-equiv="refresh" content="5">', $generated);
|
||||
}
|
||||
|
||||
+5
-6
@@ -28,9 +28,8 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->version = 2024081903; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2024081903; // 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, 405]; // A range of branch numbers of supported moodle versions.
|
||||
$plugin->incompatible = 501;
|
||||
$plugin->version = 2026011308; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2026011308; // Human-readable release information.
|
||||
$plugin->requires = 2025100600; // Moodle 5.1.
|
||||
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!
|
||||
$plugin->supported = [501, 501]; // A range of branch numbers of supported moodle versions.
|
||||
|
||||
+12
-5
@@ -39,19 +39,26 @@ defined('MOODLE_INTERNAL') || die();
|
||||
<b><?php echo get_string('infountil', 'auth_outage'); ?></b>
|
||||
<?php echo userdate($viewbag['outage']->stoptime, get_string('datetimeformat', 'auth_outage')); ?>
|
||||
</div>
|
||||
<div class="auth_outage_info_description"><?php echo $viewbag['outage']->get_description(); ?></div>
|
||||
<div class="auth_outage_info_description">
|
||||
<?php
|
||||
echo format_text(
|
||||
$viewbag['outage']->get_description(),
|
||||
FORMAT_HTML,
|
||||
['context' => context_system::instance()]
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php if ($viewbag['admin']) : ?>
|
||||
<?php
|
||||
$adminlinks = [];
|
||||
foreach (
|
||||
[
|
||||
$params = [
|
||||
'startofwarning' => -$viewbag['outage']->get_warning_duration(),
|
||||
'15secondsbefore' => -15,
|
||||
'start' => 0,
|
||||
'endofoutage' => $viewbag['outage']->get_duration_planned() - 1,
|
||||
] as $title => $delta
|
||||
) {
|
||||
];
|
||||
foreach ($params as $title => $delta) {
|
||||
$adminlinks[] = html_writer::link(
|
||||
new moodle_url(
|
||||
'/auth/outage/info.php',
|
||||
|
||||
Reference in New Issue
Block a user