mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-09-07 00:06:01 +02:00
Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a55678d2cb | ||
|
|
be740fd139 | ||
|
|
9bab491666 | ||
|
|
20fef09b03 | ||
|
|
f2b7d1c7dd | ||
|
|
f0f3112ea1 | ||
|
|
0ac6b14ed1 | ||
|
|
b2c3fbd7b2 | ||
|
|
840d2c39d9 | ||
|
|
ddd56cd93f | ||
|
|
7d779f8fe9 | ||
|
|
ac29a02402 | ||
|
|
ffda33329c | ||
|
|
0bff6f5145 | ||
|
|
bffd5f39f9 | ||
|
|
fcb2a681e7 | ||
|
|
59a62c4aa4 | ||
|
|
073a682b01 | ||
|
|
da18e31dab | ||
|
|
1ef47a6233 | ||
|
|
551a97142c | ||
|
|
ceee32d889 | ||
|
|
149223d10f | ||
|
|
42b6ec3c87 | ||
|
|
6792b03ab0 | ||
|
|
7f968b2365 | ||
|
|
42dbec5b4d | ||
|
|
5d064a0bec | ||
|
|
d16ae47a5f | ||
|
|
1e3572be9f |
@@ -1,4 +1,4 @@
|
||||
[](https://github.com/catalyst/moodle-auth_outage/actions/workflows/ci.yml?branch=MOODLE_501_STABLE)
|
||||
[](https://github.com/catalyst/moodle-auth_outage/actions/workflows/ci.yml?branch=MOODLE_39_STABLE)
|
||||
|
||||
# Moodle Outage manager plugin
|
||||
- [Moodle Outage manager plugin](#moodle-outage-manager-plugin)
|
||||
@@ -42,10 +42,9 @@ need to manually add one extra plugin, please check:
|
||||
|
||||
Moodle supported branches
|
||||
--------
|
||||
| Version | Branch | PHP |
|
||||
|----------------|---------------------|------|
|
||||
| Moodle 5.1 | MOODLE_501_STABLE | 8.2 |
|
||||
| Moodle 3.9-5.0 | MOODLE_39_STABLE | 7.2+ |
|
||||
| Version | Branch | PHP |
|
||||
|-------------|-------------------|------|
|
||||
| Moodle 3.9+ | MOODLE_39_STABLE | 7.2+ |
|
||||
|
||||
Totara supported branches
|
||||
--------
|
||||
|
||||
@@ -69,7 +69,6 @@ if (is_callable('auth_outage_bootstrap_callback')) {
|
||||
}
|
||||
|
||||
// 3) Check for allowed scripts or IPs during outages.
|
||||
$outageinfo = false;
|
||||
if (!empty($_SERVER['REQUEST_URI'])) {
|
||||
$rooturl = parse_url($CFG->wwwroot);
|
||||
$path = '';
|
||||
|
||||
@@ -40,18 +40,16 @@ class calendar {
|
||||
/**
|
||||
* Create an event on the calendar for this outage.
|
||||
* @param outage $outage Outage to be added to the calendar.
|
||||
* @return void
|
||||
*/
|
||||
public static function create(outage $outage): void {
|
||||
public static function create(outage $outage) {
|
||||
calendar_event::create(self::create_data($outage));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an event on the calendar based on this outage.
|
||||
* @param outage $outage Outage to be updated in the calendar.
|
||||
* @return void
|
||||
*/
|
||||
public static function update(outage $outage): void {
|
||||
public static function update(outage $outage) {
|
||||
$event = self::load($outage->id);
|
||||
|
||||
if (is_null($event)) {
|
||||
@@ -65,9 +63,8 @@ class calendar {
|
||||
/**
|
||||
* Removes an event from the calendar related to this outage.
|
||||
* @param int $outageid Id of outage to be deleted from the calendar.
|
||||
* @return void
|
||||
*/
|
||||
public static function delete(int $outageid): void {
|
||||
public static function delete($outageid) {
|
||||
$event = self::load($outageid);
|
||||
|
||||
// If not found (was not created before) ignore it.
|
||||
|
||||
@@ -48,7 +48,6 @@ class outagedb {
|
||||
|
||||
/**
|
||||
* Gets all outage entries.
|
||||
* @return outage[]
|
||||
*/
|
||||
public static function get_all() {
|
||||
global $DB;
|
||||
@@ -362,7 +361,7 @@ class outagedb {
|
||||
$data = $DB->get_records_select(
|
||||
'auth_outage',
|
||||
'starttime <= :datetime1 AND :datetime2 <= stoptime AND finished IS NULL',
|
||||
['datetime1' => $time, 'datetime2' => $time],
|
||||
['datetime1' => $time, 'datetime2' => $time, 'datetime3' => $time],
|
||||
'starttime ASC, stoptime DESC, title ASC',
|
||||
'*',
|
||||
0,
|
||||
|
||||
@@ -67,7 +67,6 @@ class edit extends moodleform {
|
||||
$mform->addHelpButton('title', 'title', 'auth_outage');
|
||||
|
||||
$mform->addElement('editor', 'description', get_string('description', 'auth_outage'));
|
||||
$mform->setType('description[text]', PARAM_RAW);
|
||||
$mform->addHelpButton('description', 'description', 'auth_outage');
|
||||
|
||||
$mform->addElement('static', 'usagehints', '', get_string('textplaceholdershint', 'auth_outage'));
|
||||
@@ -80,7 +79,6 @@ class edit extends moodleform {
|
||||
get_string('useaccesskey:desc', 'auth_outage'),
|
||||
0
|
||||
);
|
||||
$mform->setType('useaccesskey', PARAM_BOOL);
|
||||
|
||||
$mform->addElement('text', 'accesskey', get_string('accesskey', 'auth_outage'));
|
||||
$mform->setType('accesskey', PARAM_TEXT);
|
||||
|
||||
@@ -79,6 +79,6 @@ class cli_exception extends Exception {
|
||||
* @param Exception|null $previous Another exception as reference or null.
|
||||
*/
|
||||
public function __construct($message, $code = 1, ?Exception $previous = null) {
|
||||
parent::__construct('*ERROR* ' . $message, $code, $previous);
|
||||
parent::__construct('*ERROR* ' . $message, $code, $previous = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ abstract class clibase {
|
||||
* Change session to admin user.
|
||||
*/
|
||||
protected function become_admin_user() {
|
||||
global $DB;
|
||||
$user = get_admin();
|
||||
unset($user->description);
|
||||
unset($user->access);
|
||||
|
||||
@@ -28,7 +28,8 @@ use coding_exception;
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class create extends clibase {
|
||||
class create extends clibase
|
||||
{
|
||||
/**
|
||||
* @var mixed[] Defaults to use if given option is null.
|
||||
*/
|
||||
@@ -98,7 +99,6 @@ class create extends clibase {
|
||||
|
||||
/**
|
||||
* Executes the CLI.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
public function execute() {
|
||||
// Help always overrides any other parameter.
|
||||
@@ -269,4 +269,32 @@ class create extends clibase {
|
||||
}
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the given option is or can be converted to a bool.
|
||||
* @param mixed $option The parameter to check.
|
||||
* @param string $param Name of that parameter.
|
||||
* @return bool The converted parameter.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
private function merge_options_check_parameters_bool($option, $param) {
|
||||
if (is_bool($option)) {
|
||||
return $option;
|
||||
}
|
||||
|
||||
if (is_string($option)) {
|
||||
$option = strtoupper($option);
|
||||
if (in_array($option, ['0', 'FALSE', 'NO', 'N'])) {
|
||||
return false;
|
||||
}
|
||||
if (in_array($option, ['1', 'TRUE', 'YES', 'Y'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
throw new cli_exception(
|
||||
get_string('clierrorinvalidvaluenotbool', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ class finish extends clibase {
|
||||
|
||||
/**
|
||||
* Executes the CLI.
|
||||
* @throws cli_exception
|
||||
*/
|
||||
public function execute() {
|
||||
// Help always overrides any other parameter.
|
||||
|
||||
@@ -101,7 +101,6 @@ class waitforit extends clibase {
|
||||
$outage = $this->get_outage();
|
||||
|
||||
while ($sleep = $this->wait_for_outage_to_start($outage)) {
|
||||
$sleep = max(1, $sleep);
|
||||
if (is_null($this->sleepcallback)) {
|
||||
$this->verbose('Sleeping for ' . $sleep . ' second(s).');
|
||||
sleep($sleep);
|
||||
|
||||
@@ -47,6 +47,11 @@ class infopage {
|
||||
* @param array|null $params Parameters to use or null to get from Moodle API (request).
|
||||
*/
|
||||
public function __construct(?array $params = null) {
|
||||
global $CFG;
|
||||
// Enable SVG support here to make sure all SVG files
|
||||
// used in the current theme are served properly.
|
||||
$CFG->svgicons = true;
|
||||
|
||||
if (is_null($params)) {
|
||||
$params = [
|
||||
'id' => optional_param('id', null, PARAM_INT),
|
||||
@@ -96,29 +101,21 @@ class infopage {
|
||||
if (!$this->static && !has_capability('auth/outage:viewinfo', context_system::instance())) {
|
||||
redirect(new moodle_url('/'));
|
||||
}
|
||||
|
||||
// Enable SVG support here to make sure all SVG files
|
||||
// used in the current theme are served properly.
|
||||
$previoussvg = $CFG->svgicons ?? null;
|
||||
$CFG->svgicons = true;
|
||||
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_title($this->outage->get_title());
|
||||
$PAGE->set_heading($this->outage->get_title());
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/info.php'));
|
||||
|
||||
// Inject metadata into the header before any output starts, otherwise header() will
|
||||
// fail once outagelib::get_inject_code() below has echoed anything.
|
||||
// No hooks injecting into this page, do it manually.
|
||||
echo outagelib::get_inject_code();
|
||||
|
||||
// Inject metadata into the header before output.
|
||||
if (!empty($this->outage->metadata)) {
|
||||
$safemeta = str_replace(["\r", "\n"], '', $this->outage->metadata);
|
||||
header('X-Outage-Metadata: ' . $safemeta);
|
||||
header('X-Outage-Metadata: ' . $this->outage->metadata);
|
||||
header('X-Outage-StartTime: ' . $this->outage->starttime);
|
||||
header('X-Outage-EndTime: ' . $this->outage->stoptime);
|
||||
}
|
||||
|
||||
// No hooks injecting into this page, do it manually.
|
||||
echo outagelib::get_inject_code();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
$viewbag = [
|
||||
'admin' => is_siteadmin(),
|
||||
@@ -126,8 +123,10 @@ class infopage {
|
||||
];
|
||||
require($CFG->dirroot . '/auth/outage/views/info/content.php');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
$CFG->svgicons = $previoussvg;
|
||||
// Moodle 2.7 did not check for CLI mode, which was fixed later.
|
||||
if (!($CFG->branch == '27' && CLI_SCRIPT)) {
|
||||
echo $OUTPUT->footer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,8 +51,7 @@ class maintenance_static_page {
|
||||
} else {
|
||||
// Inject metadata into the header before output.
|
||||
if (!empty($outage->metadata)) {
|
||||
$safemeta = str_replace(["\r", "\n"], '', $outage->metadata);
|
||||
header('X-Outage-Metadata: ' . $safemeta);
|
||||
header('X-Outage-Metadata: ' . $outage->metadata);
|
||||
header('X-Outage-StartTime: ' . $outage->starttime);
|
||||
header('X-Outage-EndTime: ' . $outage->stoptime);
|
||||
}
|
||||
|
||||
+10
-19
@@ -51,7 +51,6 @@ class outagelib {
|
||||
/**
|
||||
* Fetches page.
|
||||
* @param string $file file to be fetched
|
||||
* @return array{contents: string|false, mime: string}
|
||||
*/
|
||||
public static function fetch_page($file) {
|
||||
global $CFG;
|
||||
@@ -70,7 +69,6 @@ class outagelib {
|
||||
|
||||
/**
|
||||
* Resets inject called to allow the code to be regenerated.
|
||||
* @return void
|
||||
*/
|
||||
public static function reset_injectcalled() {
|
||||
self::$injectcalled = false;
|
||||
@@ -79,7 +77,6 @@ class outagelib {
|
||||
/**
|
||||
* Given a time, usually now, when is the next outage window?
|
||||
* @param int $time time for next window
|
||||
* @return int
|
||||
*/
|
||||
public static function get_next_window($time = null) {
|
||||
|
||||
@@ -180,7 +177,6 @@ class outagelib {
|
||||
'default_warning_duration' => (string)(60 * 60),
|
||||
'default_title' => get_string('defaulttitlevalue', 'auth_outage'),
|
||||
'default_description' => get_string('defaultdescriptionvalue', 'auth_outage'),
|
||||
'default_metadata' => '',
|
||||
'remove_selectors' => ".usermenu\n.logininfo\n.homelink",
|
||||
];
|
||||
}
|
||||
@@ -257,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 set in headers, or null if none.
|
||||
* @param string|null $metadata metadata to be added to the outage headers, or null if none.
|
||||
*
|
||||
* @return string
|
||||
* @throws invalid_parameter_exception
|
||||
@@ -271,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.
|
||||
@@ -288,7 +288,7 @@ if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
|
||||
}
|
||||
// Put access key as a cookie if given. This stops the need to put it as a url param on every request.
|
||||
$urlaccesskey = optional_param('accesskey', null, PARAM_ALPHANUM);
|
||||
$urlaccesskey = optional_param('accesskey', null, PARAM_TEXT);
|
||||
$isphpunit = defined('PHPUNIT_TEST');
|
||||
|
||||
if (!empty($urlaccesskey) && !$isphpunit) {
|
||||
@@ -332,8 +332,7 @@ if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
}
|
||||
|
||||
if ({{USEACCESSKEY}} && $accesskeyblocked) {
|
||||
$safeaccesskey = htmlspecialchars($useraccesskey ?? '', ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: ' . $safeaccesskey . ' -->';
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
}
|
||||
|
||||
if (!$isphpunit) {
|
||||
@@ -350,17 +349,9 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,41 @@ class base_table extends flexible_table {
|
||||
$this->set_attribute('class', 'generaltable admintable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a user by their fullname with a link to a profile.
|
||||
* @param int $userid
|
||||
* @return string HTML link to user profile
|
||||
*/
|
||||
private function format_user(int $userid): string {
|
||||
if ($userid == 0 || !$user = \core_user::get_user($userid)) {
|
||||
return get_string('na', 'auth_outage');
|
||||
}
|
||||
$url = new moodle_url('/user/profile.php', ['id' => $userid]);
|
||||
return html_writer::link($url, fullname($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats created by column.
|
||||
* @param outage $outage
|
||||
* @return string The user who created the outage.
|
||||
*/
|
||||
protected function format_created(outage $outage): string {
|
||||
return $this->format_user($outage->createdby);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats modified by column.
|
||||
* @param outage $outage
|
||||
* @return string The user who last modiifed the outage and the last modified time.
|
||||
*/
|
||||
protected function format_modified(outage $outage): string {
|
||||
$timestamp = html_writer::div(
|
||||
userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage')),
|
||||
'small text-muted'
|
||||
);
|
||||
return $this->format_user($outage->modifiedby) . $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the action buttons HTML code for a specific outage.
|
||||
* @param outage $outage The outage to generate the buttons.
|
||||
|
||||
@@ -36,7 +36,7 @@ class history_table extends base_table {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->define_columns(['warning', 'starts', 'durationplanned', 'durationactual', 'title', 'actions']);
|
||||
$this->define_columns(['warning', 'starts', 'duration', 'durationactual', 'title', 'created', 'modified', 'actions']);
|
||||
|
||||
$this->define_headers([
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
@@ -44,6 +44,8 @@ class history_table extends base_table {
|
||||
get_string('tableheaderdurationplanned', 'auth_outage'),
|
||||
get_string('tableheaderdurationactual', 'auth_outage'),
|
||||
get_string('tableheadertitle', 'auth_outage'),
|
||||
get_string('tableheadercreatedby', 'auth_outage'),
|
||||
get_string('tableheadermodifiedby', 'auth_outage'),
|
||||
get_string('actions'),
|
||||
]);
|
||||
|
||||
@@ -64,6 +66,8 @@ class history_table extends base_table {
|
||||
format_time($outage->get_duration_planned()),
|
||||
$finished,
|
||||
$outage->get_title(),
|
||||
$this->format_created($outage),
|
||||
$this->format_modified($outage),
|
||||
$this->create_data_buttons($outage, false),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -38,13 +38,15 @@ class planned_table extends base_table {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->define_columns(['warning', 'starts', 'duration', 'title', 'actions']);
|
||||
$this->define_columns(['warning', 'starts', 'duration', 'title', 'created', 'modified', 'actions']);
|
||||
|
||||
$this->define_headers([
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
get_string('tableheaderstarttime', 'auth_outage'),
|
||||
get_string('tableheaderduration', 'auth_outage'),
|
||||
get_string('tableheadertitle', 'auth_outage'),
|
||||
get_string('tableheadercreatedby', 'auth_outage'),
|
||||
get_string('tableheadermodifiedby', 'auth_outage'),
|
||||
get_string('actions'),
|
||||
]);
|
||||
|
||||
@@ -68,6 +70,8 @@ class planned_table extends base_table {
|
||||
self::create_starttime_string($outage->starttime),
|
||||
format_time($outage->get_duration_planned()),
|
||||
$title,
|
||||
$this->format_created($outage),
|
||||
$this->format_modified($outage),
|
||||
$this->create_data_buttons($outage, true),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -187,8 +187,8 @@ class renderer extends plugin_renderer_base {
|
||||
$outagehtml = html_writer::div(
|
||||
html_writer::tag(
|
||||
'blockquote',
|
||||
html_writer::div(html_writer::tag('b', format_string($outage->get_title()), ['data-id' => $outage->id])) .
|
||||
html_writer::div(html_writer::tag('i', format_text($outage->get_description(), FORMAT_HTML))) .
|
||||
html_writer::div(html_writer::tag('b', $outage->get_title(), ['data-id' => $outage->id])) .
|
||||
html_writer::div(html_writer::tag('i', $outage->get_description())) .
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderwarnbefore', 'auth_outage') . ': ') .
|
||||
format_time($outage->get_warning_duration())
|
||||
|
||||
@@ -37,10 +37,7 @@ class update_static_page extends scheduled_task {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the task: regenerates the maintenance static page for the next scheduled outage.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @throws \file_exception
|
||||
* Executes the event.
|
||||
*/
|
||||
public function execute() {
|
||||
outagelib::prepare_next_outage();
|
||||
|
||||
@@ -21,14 +21,9 @@
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="fk_createdby" TYPE="foreign" FIELDS="createdby" REFTABLE="user" REFFIELDS="id"/>
|
||||
<KEY NAME="fk_modifiedby" TYPE="foreign" FIELDS="modifiedby" REFTABLE="user" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="start_stop_title" UNIQUE="false" FIELDS="starttime, stoptime, title"/>
|
||||
<INDEX NAME="ix_stoptime_finished" UNIQUE="false" FIELDS="stoptime, finished"/>
|
||||
<INDEX NAME="ix_createdby" UNIQUE="false" FIELDS="createdby"/>
|
||||
<INDEX NAME="ix_modifiedby" UNIQUE="false" FIELDS="modifiedby"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
|
||||
+4
-4
@@ -61,7 +61,7 @@ function xmldb_auth_outage_upgrade($oldversion) {
|
||||
upgrade_plugin_savepoint(true, 2024081900, 'auth', 'outage');
|
||||
}
|
||||
|
||||
if ($oldversion < 2026011301) {
|
||||
if ($oldversion < 2024081901) {
|
||||
// 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, 2026011301, 'auth', 'outage');
|
||||
upgrade_plugin_savepoint(true, 2024081901, 'auth', 'outage');
|
||||
}
|
||||
|
||||
if ($oldversion < 2026011302) {
|
||||
if ($oldversion < 2024081902) {
|
||||
// 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, 2026011302, 'auth', 'outage');
|
||||
upgrade_plugin_savepoint(true, 2024081902, 'auth', 'outage');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -28,6 +28,7 @@ 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');
|
||||
|
||||
@@ -37,31 +37,14 @@ if (!isset($_GET['file'])) {
|
||||
die('Missing file parameter.');
|
||||
}
|
||||
|
||||
$rawfile = $_GET['file'];
|
||||
if (!preg_match('/^[a-zA-Z0-9_\-\.\/]+$/', $rawfile)) {
|
||||
http_response_code(400);
|
||||
die('Invalid file parameter.');
|
||||
}
|
||||
|
||||
$parts = explode('.', $rawfile);
|
||||
$parts = explode('.', $_GET['file']);
|
||||
if (count($parts) != 2) {
|
||||
http_response_code(400);
|
||||
die('Invalid file requested.');
|
||||
}
|
||||
$extension = strtolower(pathinfo($parts[0], PATHINFO_EXTENSION));
|
||||
$allowedmimes = [
|
||||
'css' => 'text/css',
|
||||
'png' => 'image/png',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'gif' => 'image/gif',
|
||||
];
|
||||
if (!array_key_exists($extension, $allowedmimes)) {
|
||||
http_response_code(400);
|
||||
die('Unsupported file type.');
|
||||
}
|
||||
$mime = $allowedmimes[$extension];
|
||||
$mime = base64_decode($parts[1]);
|
||||
|
||||
// Detect type, we only support css or PNG images.
|
||||
header('Content-Type: ' . $mime);
|
||||
|
||||
// Use cache.
|
||||
|
||||
@@ -141,7 +141,6 @@ $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';
|
||||
@@ -150,9 +149,11 @@ $string['settingssectionplugin'] = 'Plugin Configuration';
|
||||
$string['settingssectionplugindescription'] = 'General outage management plugin settings.';
|
||||
$string['starttime'] = 'Start date and time';
|
||||
$string['starttime_help'] = 'At which date and time the outage starts, preventing general access to the system.';
|
||||
$string['tableheadercreatedby'] = 'Created by';
|
||||
$string['tableheaderduration'] = 'Duration';
|
||||
$string['tableheaderdurationactual'] = 'Actual duration';
|
||||
$string['tableheaderdurationplanned'] = 'Planned duration';
|
||||
$string['tableheadermodifiedby'] = 'Last modified by';
|
||||
$string['tableheaderstartedtime'] = 'Started on';
|
||||
$string['tableheaderstarttime'] = 'Starts on';
|
||||
$string['tableheadertitle'] = 'Title';
|
||||
@@ -171,3 +172,8 @@ $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.";
|
||||
|
||||
@@ -31,8 +31,6 @@ use auth_outage\local\controllers\maintenance_static_page;
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
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)) {
|
||||
|
||||
@@ -158,7 +158,7 @@ final class waitforit_test extends cli_testcase {
|
||||
/**
|
||||
* Tests the countdown.
|
||||
*/
|
||||
public function test_countdown(): void {
|
||||
public function test_countdown() {
|
||||
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(): void {
|
||||
public function test_outagechanged() {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$id = outagedb::save(new outage([
|
||||
|
||||
@@ -154,23 +154,15 @@ final class infopage_test extends \auth_outage\base_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that rendering the page enables SVG support and restores the previous value afterwards.
|
||||
* Tests the constructor enables SVG support.
|
||||
*/
|
||||
public function test_svgicons_is_restored_after_output(): void {
|
||||
public function test_svgicons_is_true(): void {
|
||||
global $CFG;
|
||||
|
||||
$this->assertTrue(has_capability('auth/outage:viewinfo', context_system::instance()));
|
||||
|
||||
$outage = $this->get_dummy_outage();
|
||||
$CFG->svgicons = false;
|
||||
|
||||
$info = new infopage(['outage' => $outage, 'static' => false]);
|
||||
// Constructing the page should not touch $CFG->svgicons.
|
||||
self::assertFalse($CFG->svgicons);
|
||||
|
||||
$info->get_output();
|
||||
|
||||
// Svgicons should be restored to its original value once rendering has finished.
|
||||
self::assertFalse($CFG->svgicons);
|
||||
new infopage();
|
||||
self::assertTrue($CFG->svgicons);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,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(): void {
|
||||
public function test_meta_refresh_maximum_5seconds() {
|
||||
$this->resetAfterTest(true);
|
||||
$html = "<!DOCTYPE html>\n" .
|
||||
'<html><head><title>Title</title></head>' .
|
||||
@@ -560,6 +560,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ if ((time() >= 123) && (time() < 456)) {
|
||||
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
|
||||
}
|
||||
// Put access key as a cookie if given. This stops the need to put it as a url param on every request.
|
||||
$urlaccesskey = optional_param('accesskey', null, PARAM_ALPHANUM);
|
||||
$urlaccesskey = optional_param('accesskey', null, PARAM_TEXT);
|
||||
$isphpunit = defined('PHPUNIT_TEST');
|
||||
|
||||
if (!empty($urlaccesskey) && !$isphpunit) {
|
||||
@@ -318,8 +318,7 @@ e.e.e.e/20');
|
||||
}
|
||||
|
||||
if (true && $accesskeyblocked) {
|
||||
$safeaccesskey = htmlspecialchars($useraccesskey ?? '', ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: ' . $safeaccesskey . ' -->';
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
}
|
||||
|
||||
if (!$isphpunit) {
|
||||
@@ -359,7 +358,7 @@ if ((time() >= 123) && (time() < 456)) {
|
||||
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
|
||||
}
|
||||
// Put access key as a cookie if given. This stops the need to put it as a url param on every request.
|
||||
$urlaccesskey = optional_param('accesskey', null, PARAM_ALPHANUM);
|
||||
$urlaccesskey = optional_param('accesskey', null, PARAM_TEXT);
|
||||
$isphpunit = defined('PHPUNIT_TEST');
|
||||
|
||||
if (!empty($urlaccesskey) && !$isphpunit) {
|
||||
@@ -403,8 +402,7 @@ if ((time() >= 123) && (time() < 456)) {
|
||||
}
|
||||
|
||||
if (true && $accesskeyblocked) {
|
||||
$safeaccesskey = htmlspecialchars($useraccesskey ?? '', ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: ' . $safeaccesskey . ' -->';
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
}
|
||||
|
||||
if (!$isphpunit) {
|
||||
|
||||
+6
-5
@@ -28,8 +28,9 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->version = 2026011305; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2026011305; // 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.
|
||||
$plugin->version = 2024081906; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2024081906; // 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;
|
||||
|
||||
@@ -39,18 +39,19 @@ 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 format_text($viewbag['outage']->get_description(), FORMAT_HTML); ?></div>
|
||||
<div class="auth_outage_info_description"><?php echo $viewbag['outage']->get_description(); ?></div>
|
||||
|
||||
<?php if ($viewbag['admin']) : ?>
|
||||
<?php
|
||||
$adminlinks = [];
|
||||
$params = [
|
||||
foreach (
|
||||
[
|
||||
'startofwarning' => -$viewbag['outage']->get_warning_duration(),
|
||||
'15secondsbefore' => -15,
|
||||
'start' => 0,
|
||||
'endofoutage' => $viewbag['outage']->get_duration_planned() - 1,
|
||||
];
|
||||
foreach ($params as $title => $delta) {
|
||||
] as $title => $delta
|
||||
) {
|
||||
$adminlinks[] = html_writer::link(
|
||||
new moodle_url(
|
||||
'/auth/outage/info.php',
|
||||
|
||||
@@ -68,7 +68,7 @@ if (!$viewbag['static']) {
|
||||
<style>
|
||||
<?php
|
||||
readfile($CFG->dirroot . '/auth/outage/views/warningbar/warningbar.css');
|
||||
echo preg_replace('/<\s*\/\s*style\s*>/i', '', outagelib::get_config()->css);
|
||||
echo outagelib::get_config()->css;
|
||||
?>
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user