mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Compare commits
92 Commits
1.0.10
...
wr334284-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5589bb77e2 | ||
|
|
f77c85355c | ||
|
|
56ac8aa19b | ||
|
|
c590eadb4f | ||
|
|
7cd10ab05c | ||
|
|
ca6c48d0f3 | ||
|
|
1cd0b7c365 | ||
|
|
ce93854b92 | ||
|
|
aab2af04e8 | ||
|
|
42babf617b | ||
|
|
90bc928754 | ||
|
|
e22c393681 | ||
|
|
e4dc17aae4 | ||
|
|
5fa3ba8034 | ||
|
|
6113b48866 | ||
|
|
01bdacc90b | ||
|
|
0efb9acbd1 | ||
|
|
2b249ac036 | ||
|
|
d9b29d2335 | ||
|
|
c4f9945c21 | ||
|
|
6f65ff9199 | ||
|
|
a62be02438 | ||
|
|
32412c2580 | ||
|
|
5a53bf04a1 | ||
|
|
b2e8100c19 | ||
|
|
bf242d9e65 | ||
|
|
981452ac27 | ||
|
|
73f283847a | ||
|
|
afc81edfde | ||
|
|
9ed0b74112 | ||
|
|
22b38c2838 | ||
|
|
0e6a8ccabb | ||
|
|
3b1b1ea0e1 | ||
|
|
e6a63f02e6 | ||
|
|
56126cd431 | ||
|
|
777e466a0a | ||
|
|
4467bea1cf | ||
|
|
77b63bce75 | ||
|
|
bac83b143a | ||
|
|
7d52bb9695 | ||
|
|
c3a2faef08 | ||
|
|
51f6f5ef5c | ||
|
|
75d872564b | ||
|
|
98b3bb38f6 | ||
|
|
b435a3f0a7 | ||
|
|
b428805c0e | ||
|
|
a722ca6965 | ||
|
|
2535d6fa4c | ||
|
|
cd21fb977b | ||
|
|
a71abed5b4 | ||
|
|
2cecb87317 | ||
|
|
b6f5db001a | ||
|
|
aadd7eaeee | ||
|
|
7ad82886d7 | ||
|
|
26baaf9993 | ||
|
|
a361ae4008 | ||
|
|
7a1fa1f91b | ||
|
|
ae85c94364 | ||
|
|
2af15f2136 | ||
|
|
076321db60 | ||
|
|
c724e1abe4 | ||
|
|
d438027a18 | ||
|
|
587bd3a311 | ||
|
|
0137811f2b | ||
|
|
a906f993f0 | ||
|
|
10223da351 | ||
|
|
1e7d035a9b | ||
|
|
d709f39122 | ||
|
|
acda7557d1 | ||
|
|
ecaee161bb | ||
|
|
de958edc9f | ||
|
|
20258deb20 | ||
|
|
d3816960f0 | ||
|
|
2a6cf91743 | ||
|
|
6e960e8814 | ||
|
|
e56cdf4ed3 | ||
|
|
34c34603b6 | ||
|
|
905ffa34be | ||
|
|
f60244f62c | ||
|
|
7c77d2652f | ||
|
|
a2224e28da | ||
|
|
02524a4028 | ||
|
|
40012e84ae | ||
|
|
a56c67284f | ||
|
|
816114bd87 | ||
|
|
0658733a86 | ||
|
|
9c7eb1b681 | ||
|
|
de1c2cab8a | ||
|
|
92ad2f5db5 | ||
|
|
a3304d0bfe | ||
|
|
36cd0517b9 | ||
|
|
dec4c7bf53 |
57
.travis.yml
57
.travis.yml
@@ -1,14 +1,14 @@
|
||||
language: php
|
||||
|
||||
sudo: true
|
||||
services:
|
||||
- mysql
|
||||
|
||||
addons:
|
||||
firefox: "47.0.1"
|
||||
postgresql: "9.4"
|
||||
postgresql: "9.6"
|
||||
apt:
|
||||
packages:
|
||||
- oracle-java8-installer
|
||||
- oracle-java8-set-default
|
||||
- openjdk-8-jre
|
||||
|
||||
cache:
|
||||
directories:
|
||||
@@ -16,32 +16,44 @@ cache:
|
||||
- $HOME/.npm
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
- 7.2
|
||||
|
||||
env:
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=master
|
||||
- DB=mysqli MOODLE_BRANCH=master
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE NODEJS=8
|
||||
- DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE NODEJS=8
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_39_STABLE
|
||||
- DB=mysqli MOODLE_BRANCH=MOODLE_39_STABLE
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.6
|
||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE
|
||||
- php: 5.6
|
||||
env: DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
|
||||
- php: 7.1
|
||||
env: DB=pgsql MOODLE_BRANCH=master
|
||||
|
||||
- php: 7.0
|
||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE
|
||||
- php: 7.0
|
||||
env: DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE NODEJS=8
|
||||
- php: 7.2
|
||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
|
||||
- php: 7.2
|
||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
|
||||
- php: 7.4
|
||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_39_STABLE
|
||||
- php: 7.2
|
||||
env: DB=mysqli MOODLE_BRANCH=MOODLE_39_STABLE
|
||||
|
||||
before_install:
|
||||
- export MOODLE_VERSION=$(echo "$MOODLE_BRANCH" | cut -d'_' -f 2)
|
||||
- phpenv config-rm xdebug.ini
|
||||
- nvm install 8.9
|
||||
- nvm use 8.9
|
||||
- if [ "$NODEJS" = 8 ]; then
|
||||
nvm install 8.9;
|
||||
nvm use 8.9;
|
||||
else
|
||||
nvm install 14.0.0;
|
||||
nvm use 14.0.0;
|
||||
fi
|
||||
- cd ../..
|
||||
- composer selfupdate
|
||||
- composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2
|
||||
- composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3;
|
||||
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
|
||||
|
||||
install:
|
||||
@@ -57,4 +69,7 @@ script:
|
||||
- moodle-plugin-ci mustache
|
||||
- moodle-plugin-ci grunt
|
||||
- moodle-plugin-ci phpunit
|
||||
- moodle-plugin-ci behat
|
||||
# Behat tests are failing due to issue:
|
||||
# https://github.com/blackboard-open-source/moodle-plugin-ci/issues/70
|
||||
# Commenting it out until the issue is fixed.
|
||||
# - moodle-plugin-ci behat
|
||||
|
||||
30
README.md
30
README.md
@@ -8,16 +8,12 @@
|
||||
* [Moodle Requirements](#moodle-requirements)
|
||||
* [Screenshots](#screenshots)
|
||||
* [Installation](#installation)
|
||||
* [Theme configuration](#theme-configuration)
|
||||
* [How to use](#how-to-use)
|
||||
* [Quick Guide](#quick-guide)
|
||||
* [Why is it an auth plugin?](#why-it-is-an-auth-plugin)
|
||||
* [Feedback and issues](#feedback-and-issues)
|
||||
|
||||
Version Support
|
||||
-------------
|
||||
The master branch supports Moodle 3.3 and higher.
|
||||
The MOODLE_32_STABLE branch supports Moodle 2.7 -> Moodle 3.2
|
||||
|
||||
What is this?
|
||||
-------------
|
||||
|
||||
@@ -44,6 +40,14 @@ If you have an older version of Moodle you can still make it work but you will
|
||||
need to manually add one extra plugin, please check:
|
||||
* https://github.com/catalyst/moodle-local_outage
|
||||
|
||||
Branches
|
||||
--------
|
||||
| Moodle version | Branch | PHP |
|
||||
| ----------------- | ----------- | ---- |
|
||||
| Moodle 2.7 to 3.2 | MOODLE_32_STABLE | 5.5+ |
|
||||
| Totara up to 10 | TOTARA_10 | 5.5+ |
|
||||
| Moodle 3.3+ | master | 7.0+ |
|
||||
| Totara 11+ | master | 7.0+ |
|
||||
|
||||
Screenshots
|
||||
-----------
|
||||
@@ -88,6 +92,20 @@ if (file_exists(__DIR__.'/auth/outage/bootstrap.php')) {
|
||||
}
|
||||
```
|
||||
|
||||
Theme configuration
|
||||
-------------------
|
||||
|
||||
This plugin must work gracefully with your theme, but every theme can be different so it's impossible to get this right out of the box (other than with the default moodle theme Boost).
|
||||
|
||||
There is an admin setting which allows you to add or override and css to fix css issues. Typically these include properly pushing the page down when the outage notification bar is visible, including making this work with fixed headers and when the hamburger menu is open / closed and at different responsive breakpoints.
|
||||
|
||||
This can be found at:
|
||||
|
||||
`Dashboard / Site administration / Plugins / Authentication / Outage manager / Settings`
|
||||
|
||||
|
||||
|
||||
|
||||
How to use
|
||||
----------
|
||||
|
||||
@@ -104,7 +122,7 @@ Creates a new outage.
|
||||
-c, --clone clone another outage except for the start time.
|
||||
-a, --autostart must be Y or N, sets if the outage automatically triggers maintenance mode.
|
||||
-w, --warn how many seconds before it starts to display a warning.
|
||||
-s, --start in how many seconds should this outage start. Required.
|
||||
-s, --start in how many seconds should this outage start or unix time to start outage. Required.
|
||||
-d, --duration how many seconds should the outage last.
|
||||
-t, --title the title of the outage.
|
||||
-e, --description the description of the outage.
|
||||
|
||||
7
auth.php
7
auth.php
@@ -66,11 +66,4 @@ class auth_plugin_outage extends auth_plugin_base {
|
||||
public function user_login($username, $password) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Login page hook.
|
||||
*/
|
||||
public function loginpage_hook() {
|
||||
outagelib::inject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,9 +67,19 @@ if (is_callable('auth_outage_bootstrap_callback')) {
|
||||
}
|
||||
|
||||
// 3) Check for allowed scripts or IPs during outages.
|
||||
if (!empty($_SERVER['REQUEST_URI'])) {
|
||||
$rooturl = parse_url($CFG->wwwroot);
|
||||
$path = '';
|
||||
if (array_key_exists('path', $rooturl) && !empty($rooturl['path'])) {
|
||||
$path = $rooturl['url'];
|
||||
}
|
||||
$url = $path.'/auth/outage/info.php';
|
||||
$outageinfo = strpos($_SERVER['REQUEST_URI'], $url) === 0 ? true : false;
|
||||
}
|
||||
$allowed = !file_exists($CFG->dataroot.'/climaintenance.php') // Not in maintenance mode.
|
||||
|| (defined('ABORT_AFTER_CONFIG') && ABORT_AFTER_CONFIG) // Only config requested.
|
||||
|| (defined('CLI_SCRIPT') && CLI_SCRIPT); // Allow CLI scripts.
|
||||
|| (defined('CLI_SCRIPT') && CLI_SCRIPT) // Allow CLI scripts.
|
||||
|| $outageinfo; // Allow outage info requests.
|
||||
if (!$allowed) {
|
||||
// Call the climaintenance.php which will check for allowed IPs.
|
||||
$CFG->dirroot = dirname(dirname(dirname(__FILE__))); // It is not defined yet but the script below needs it.
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
|
||||
define('NO_MOODLE_COOKIES', true);
|
||||
header('Cache-Control: public, max-age=10,s-maxage=10');
|
||||
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
|
||||
$active = outagedb::get_active();
|
||||
|
||||
@@ -65,7 +65,7 @@ class calendar {
|
||||
debugging('Cannot update calendar entry for outage #'.$outage->id.', event not found. Creating it...');
|
||||
self::create($outage);
|
||||
} else {
|
||||
$event->update(self::create_data($outage));
|
||||
$event->update(self::create_data($outage), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,25 +117,40 @@ class outagedb {
|
||||
$outage->createdby = $USER->id;
|
||||
// Then create it, log it and adjust its id.
|
||||
$outage->id = $DB->insert_record('auth_outage', $outage, true);
|
||||
outage_created::create(
|
||||
['objectid' => $outage->id, 'other' => (array)$outage]
|
||||
)->trigger();
|
||||
|
||||
$other = (array) $outage;
|
||||
$other['title'] = $outage->get_title();
|
||||
$event = outage_created::create([
|
||||
'objectid' => $outage->id,
|
||||
'other' => $other,
|
||||
]);
|
||||
$event->add_record_snapshot('auth_outage', (object)(array) $outage);
|
||||
$event->trigger();
|
||||
|
||||
// Create calendar entry.
|
||||
calendar::create($outage);
|
||||
} else {
|
||||
|
||||
$other = (array) $outage;
|
||||
$other['title'] = $outage->get_title();
|
||||
$event = outage_updated::create([
|
||||
'objectid' => $outage->id,
|
||||
'other' => $other,
|
||||
]);
|
||||
|
||||
$event->add_record_snapshot('auth_outage', (object)(array) $outage);
|
||||
$event->trigger();
|
||||
|
||||
// Remove the createdby field so it does not get updated.
|
||||
unset($outage->createdby);
|
||||
$DB->update_record('auth_outage', $outage);
|
||||
// Log it.
|
||||
outage_updated::create(
|
||||
['objectid' => $outage->id, 'other' => (array)$outage]
|
||||
)->trigger();
|
||||
|
||||
// Update calendar entry.
|
||||
calendar::update($outage);
|
||||
}
|
||||
|
||||
// Trigger outages modified events.
|
||||
outagelib::prepare_next_outage();
|
||||
outagelib::prepare_next_outage(true);
|
||||
|
||||
// All done, return the id.
|
||||
return $outage->id;
|
||||
@@ -156,7 +171,16 @@ class outagedb {
|
||||
|
||||
// Log it.
|
||||
$previous = $DB->get_record('auth_outage', ['id' => $id], '*', MUST_EXIST);
|
||||
$event = outage_deleted::create(['objectid' => $id, 'other' => (array)$previous]);
|
||||
|
||||
$outage = new outage($previous);
|
||||
|
||||
$other = (array) $outage;
|
||||
$other['title'] = $outage->get_title();
|
||||
$event = outage_deleted::create([
|
||||
'objectid' => $id,
|
||||
'other' => $other,
|
||||
]);
|
||||
|
||||
$event->add_record_snapshot('auth_outage', $previous);
|
||||
$event->trigger();
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ class outage_created extends base {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' created a new outage title '{$this->other['title']}' ".
|
||||
" with id '{$this->other['id']}'.";
|
||||
return "The user with the id '{$this->userid}' created outage {$this->other['id']} '{$this->other['title']}'";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,7 @@ class outage_created extends base {
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new moodle_url('/auth/outage/list.php#auth_outage_id_'.$this->other['id']);
|
||||
return new moodle_url('/auth/outage/edit.php', ['edit' => $this->other['id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,8 +44,7 @@ class outage_deleted extends base {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' deleted the outage titled '{$this->other['title']}' ".
|
||||
"with id '{$this->other['id']}'.";
|
||||
return "The user with the id '{$this->userid}' deleted outage {$this->other['id']} '{$this->other['title']}'";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +52,7 @@ class outage_deleted extends base {
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new moodle_url('/auth/outage/list.php#auth_outage_id_'.$this->other['id']);
|
||||
return new moodle_url('/auth/outage/manage.php');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,8 +45,7 @@ class outage_updated extends base {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' updated the outage title '{$this->other['title']}' ".
|
||||
"with id '{$this->other['id']}'.";
|
||||
return "The user with the id '{$this->userid}' updated outage {$this->other['id']} '{$this->other['title']}'";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,7 @@ class outage_updated extends base {
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new moodle_url('/auth/outage/list.php');
|
||||
return new moodle_url('/auth/outage/edit.php', ['edit' => $this->other['id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,6 +82,7 @@ class edit extends moodleform {
|
||||
$mform->addHelpButton('description', 'description', 'auth_outage');
|
||||
|
||||
$mform->addElement('static', 'usagehints', '', get_string('textplaceholdershint', 'auth_outage'));
|
||||
$mform->addElement('static', 'warningreenablemaintenancemode', '');
|
||||
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
@@ -146,6 +147,9 @@ class edit extends moodleform {
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function set_data($outage) {
|
||||
global $OUTPUT;
|
||||
$mform = $this->_form;
|
||||
|
||||
// Cannot change method signature, check type.
|
||||
if ($outage instanceof outage) {
|
||||
$this->_form->setDefaults([
|
||||
@@ -157,6 +161,12 @@ class edit extends moodleform {
|
||||
'title' => $outage->title,
|
||||
'description' => ['text' => $outage->description, 'format' => '1'],
|
||||
]);
|
||||
|
||||
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'),
|
||||
'notifywarning'));
|
||||
}
|
||||
} else {
|
||||
throw new coding_exception('$outage must be an outage object.', $outage);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,15 @@ abstract class clibase {
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reference time for creating outages.
|
||||
*/
|
||||
public function get_referencetime()
|
||||
{
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates all options (parameters) available for the CLI command.
|
||||
* @return mixed[] Options.
|
||||
@@ -147,5 +156,6 @@ abstract class clibase {
|
||||
$long = '--'.$long;
|
||||
printf(" %-4s %-20s %s\n", $short, $long, $text);
|
||||
}
|
||||
printf("\n%s\n\n", get_string('cli'.$cliname.'examples', 'auth_outage'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,9 @@ class create extends clibase {
|
||||
$this->become_admin_user();
|
||||
|
||||
// Create the outage.
|
||||
$start = $this->time + $options['start'];
|
||||
// If time is above 1500000000 then it must be a unix time timestamp, otherwise they are trying to create
|
||||
// an outage 47 years in advance.
|
||||
$start = $options['start'] > 1500000000 ? $options['start'] : $this->time + $options['start'];
|
||||
$outage = new outage([
|
||||
'autostart' => $options['autostart'],
|
||||
'warntime' => $start - $options['warn'],
|
||||
@@ -198,7 +200,7 @@ class create extends clibase {
|
||||
private function clone_defaults() {
|
||||
$id = $this->options['clone'];
|
||||
if (!is_number($id) || ($id <= 0)) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => 'clone']),
|
||||
throw new cli_exception(get_string('clierrorinvalidvaluenotid', 'auth_outage', ['param' => 'clone']),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
|
||||
@@ -243,12 +245,12 @@ class create extends clibase {
|
||||
*/
|
||||
private function merge_options_check_parameters_int_nonnegative($option, $param) {
|
||||
if (!is_number($option)) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
throw new cli_exception(get_string('clierrorinvalidvaluenotnumber', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
$option = (int)$option;
|
||||
if ($option < 0) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
throw new cli_exception(get_string('clierrorinvalidvaluenegativenumber', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
return $option;
|
||||
@@ -263,12 +265,12 @@ class create extends clibase {
|
||||
*/
|
||||
private function merge_options_check_parameters_string_nonempty($option, $param) {
|
||||
if (!is_string($option)) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
throw new cli_exception(get_string('clierrorinvalidvaluenotstring', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
$option = trim($option);
|
||||
if (strlen($option) == 0) {
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
throw new cli_exception(get_string('clierrorinvalidvalueemptystring', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
return $option;
|
||||
@@ -296,7 +298,7 @@ class create extends clibase {
|
||||
}
|
||||
}
|
||||
|
||||
throw new cli_exception(get_string('clierrorinvalidvalue', 'auth_outage', ['param' => $param]),
|
||||
throw new cli_exception(get_string('clierrorinvalidvaluenotbool', 'auth_outage', ['param' => $param]),
|
||||
cli_exception::ERROR_PARAMETER_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,11 @@ class infopage {
|
||||
* @param array $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),
|
||||
@@ -103,7 +108,7 @@ class infopage {
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/info.php'));
|
||||
|
||||
// No hooks injecting into this page, do it manually.
|
||||
outagelib::inject();
|
||||
echo outagelib::get_inject_code();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
$viewbag = [
|
||||
|
||||
@@ -128,7 +128,7 @@ class maintenance_static_page_generator {
|
||||
continue;
|
||||
}
|
||||
$saved = $this->io->save_url_file($href);
|
||||
if (is_null($saved['url'])) {
|
||||
if (empty($saved['url'])) {
|
||||
$url = $href; // Skipped, use original URL.
|
||||
} else {
|
||||
$this->update_link_stylesheet_parse($saved['file'], dirname($href));
|
||||
@@ -138,6 +138,17 @@ class maintenance_static_page_generator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all URLs from file content using regular expressions.
|
||||
*
|
||||
* @param string $contents Content of the file
|
||||
* @return array Array of all matches in multi-dimensional array
|
||||
*/
|
||||
public function get_urls_from_stylesheet($contents) {
|
||||
preg_match_all('#url\([\'"]?(?!data:)([^\'"\)]+)#', $contents, $matches);
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for urls inside filename.
|
||||
*
|
||||
@@ -148,15 +159,15 @@ class maintenance_static_page_generator {
|
||||
global $CFG;
|
||||
|
||||
$contents = file_get_contents($filename);
|
||||
if (!preg_match_all('#url\([\'"]?([^\'"\)]+)#', $contents, $matches)) {
|
||||
return;
|
||||
}
|
||||
$matches = $this->get_urls_from_stylesheet($contents);
|
||||
|
||||
foreach ($matches[1] as $originalurl) {
|
||||
// Allow incomplete URLs in CSS, assume it is from moodle root.
|
||||
if (maintenance_static_page_io::is_url($originalurl)) {
|
||||
$fullurl = $originalurl;
|
||||
} else if ($originalurl[0] == '/') {
|
||||
$fullurl = $CFG->wwwroot.$originalurl;
|
||||
$rooturl = parse_url($CFG->wwwroot);
|
||||
$fullurl = $rooturl['scheme'].'://'.$rooturl['host'].$originalurl;
|
||||
} else {
|
||||
$fullurl = $baseref.'/'.$originalurl;
|
||||
}
|
||||
|
||||
@@ -44,11 +44,13 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class maintenance_static_page_io {
|
||||
/**
|
||||
* Checks if the given string starts with "http://" or "https://".
|
||||
* Also checks for "//" at the start of image, which setting_file_url still uses.
|
||||
*
|
||||
* @param $url
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_url($url) {
|
||||
return (bool)preg_match('#^http(s)?://#', $url);
|
||||
return ((bool) preg_match('#^http(s)?://#', $url) || (bool) preg_match('#^//#', $url));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,7 +215,7 @@ class maintenance_static_page_io {
|
||||
/**
|
||||
* Saves the content of the URL into a file, returning the local filename.
|
||||
* @param string $url Input URL.
|
||||
* @return string|null Output filename or null if skipped.
|
||||
* @return array|null Output an array with the filename and url or null if skipped.
|
||||
*/
|
||||
public function save_url_file($url) {
|
||||
global $CFG;
|
||||
|
||||
@@ -281,7 +281,17 @@ class outage {
|
||||
*/
|
||||
private function adjust_field_types() {
|
||||
// Adjust int fields.
|
||||
$fs = ['createdby', 'id', 'lastmodified', 'modifiedby', 'starttime', 'stoptime', 'warntime', 'finished'];
|
||||
$fs = [
|
||||
'id',
|
||||
'starttime',
|
||||
'stoptime',
|
||||
'warntime',
|
||||
'finished',
|
||||
'createdby',
|
||||
'lastmodified',
|
||||
'modifiedby',
|
||||
];
|
||||
|
||||
foreach ($fs as $f) {
|
||||
$this->$f = ($this->$f === null) ? null : (int)$this->$f;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\controllers\maintenance_static_page;
|
||||
use auth_outage\output\renderer;
|
||||
use coding_exception;
|
||||
use curl;
|
||||
use Exception;
|
||||
use file_exception;
|
||||
use invalid_parameter_exception;
|
||||
@@ -47,39 +48,62 @@ require_once(__DIR__.'/../../lib.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outagelib {
|
||||
|
||||
const OUTAGE_START = '<!-- OUTAGESTART -->';
|
||||
|
||||
const OUTAGE_END = '<!-- OUTAGEEND -->';
|
||||
|
||||
/**
|
||||
* @var bool Flags in the injection function was already called.
|
||||
*/
|
||||
private static $injectcalled = false;
|
||||
|
||||
public static function fetch_page($file) {
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $file);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); // It is localhost, time to connect is enough.
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 15); // It is localhost, time to fetch index is enough.
|
||||
$contents = curl_exec($curl);
|
||||
$mime = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
|
||||
curl_close($curl);
|
||||
$curl = new curl();
|
||||
$contents = $curl->get($file);
|
||||
$info = $curl->get_info();
|
||||
if (!empty($info['content_type'])) {
|
||||
$mime = $info['content_type'];
|
||||
} else {
|
||||
$mime = '';
|
||||
}
|
||||
return compact('contents', 'mime');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls inject even if it was already called before.
|
||||
* Resets inject called to allow the code to be regenerated.
|
||||
*/
|
||||
public static function reinject() {
|
||||
public static function reset_injectcalled() {
|
||||
self::$injectcalled = false;
|
||||
self::inject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Will check for ongoing or warning outages and will attach the message bar as required.
|
||||
* Given a time, usually now, when is the next outage window?
|
||||
*/
|
||||
public static function inject() {
|
||||
global $CFG;
|
||||
public static function get_next_window($time = null) {
|
||||
|
||||
$config = self::get_config();
|
||||
|
||||
if (!$time) {
|
||||
$time = time();
|
||||
}
|
||||
|
||||
$default = $config->default_time;
|
||||
if ($default) {
|
||||
// First try natural language parsing.
|
||||
$time = strtotime($default, $time);
|
||||
}
|
||||
return $time;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Will check for ongoing or warning outages and will return the message bar as required.
|
||||
*
|
||||
* @return string|void CSS and HTML for the warning bar if it should be displayed
|
||||
*/
|
||||
public static function get_inject_code() {
|
||||
global $PAGE;
|
||||
// Ensure we do not kill the whole website in case of an error.
|
||||
try {
|
||||
// Check if we should inject the code.
|
||||
@@ -109,8 +133,8 @@ class outagelib {
|
||||
}
|
||||
|
||||
// There is a previewing or active outage.
|
||||
$CFG->additionalhtmltopofbody = renderer::get()->render_warningbar($active, $time, false, $preview).
|
||||
$CFG->additionalhtmltopofbody;
|
||||
$renderer = $PAGE->get_renderer('auth_outage');
|
||||
return $renderer->render_warningbar($active, $time, false, $preview);
|
||||
} catch (Exception $e) {
|
||||
debugging('Exception occured while injecting our code: '.$e->getMessage());
|
||||
debugging($e->getTraceAsString(), DEBUG_DEVELOPER);
|
||||
@@ -145,6 +169,7 @@ class outagelib {
|
||||
return [
|
||||
'allowedips' => '',
|
||||
'css' => '',
|
||||
'default_time' => '',
|
||||
'default_autostart' => '0',
|
||||
'default_duration' => (string)(60 * 60),
|
||||
'default_warning_duration' => (string)(60 * 60),
|
||||
@@ -156,16 +181,25 @@ class outagelib {
|
||||
|
||||
/**
|
||||
* Executed when outages are modified (created, updated or deleted).
|
||||
*
|
||||
* @param bool $reenablemaint should we re-enable maintenance mode for ongoing outage
|
||||
* @throws coding_exception
|
||||
* @throws file_exception
|
||||
*/
|
||||
public static function prepare_next_outage() {
|
||||
public static function prepare_next_outage($reenablemaint = false) {
|
||||
// If there is an ongoing outage, prepare it instead.
|
||||
$outage = outagedb::get_ongoing();
|
||||
if (is_null($outage)) {
|
||||
$outage = outagedb::get_next_starting();
|
||||
$ongoingoutage = false;
|
||||
} else {
|
||||
$ongoingoutage = true;
|
||||
}
|
||||
maintenance_static_page::create_from_outage($outage)->generate();
|
||||
self::update_climaintenance_code($outage);
|
||||
self::update_maintenance_later($outage);
|
||||
if (!$ongoingoutage || $reenablemaint || is_null($outage)) {
|
||||
self::update_maintenance_later($outage);
|
||||
}
|
||||
}
|
||||
|
||||
private static function check_wwwroot_accessible() {
|
||||
@@ -246,13 +280,16 @@ class outagelib {
|
||||
}
|
||||
// I know Moodle validation would clean up this field, but just in case, let's ensure no
|
||||
// single-quotes (and double for the sake of it) are present otherwise it would break the code.
|
||||
$allowedips = str_replace('\'"', '', $allowedips);
|
||||
$allowedips = addslashes($allowedips);
|
||||
|
||||
$code = <<<'EOT'
|
||||
<?php
|
||||
if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
define('MOODLE_INTERNAL', true);
|
||||
require_once($CFG->dirroot.'/lib/moodlelib.php');
|
||||
if (file_exists($CFG->dirroot.'/lib/classes/ip_utils.php')) {
|
||||
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
|
||||
}
|
||||
if (!remoteip_in_list('{{ALLOWEDIPS}}')) {
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
|
||||
header('Status: 503 Moodle under maintenance');
|
||||
@@ -265,6 +302,7 @@ if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Accept-Ranges: none');
|
||||
header('X-Moodle-Maintenance: manager');
|
||||
if ((defined('AJAX_SCRIPT') && AJAX_SCRIPT) || (defined('WS_SERVER') && WS_SERVER)) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
namespace auth_outage\output;
|
||||
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagelib;
|
||||
use coding_exception;
|
||||
use core_user;
|
||||
use html_writer;
|
||||
@@ -43,15 +44,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Returns the outage renderer.
|
||||
* @return renderer The outage renderer.
|
||||
*/
|
||||
public static function get() {
|
||||
global $PAGE;
|
||||
return $PAGE->get_renderer('auth_outage');
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the view in a separate scope to avoid conflicts with variable names.
|
||||
* @param string $view View PHP file.
|
||||
@@ -153,8 +145,6 @@ class renderer extends plugin_renderer_base {
|
||||
* @return string The formatted HTML.
|
||||
*/
|
||||
private function renderoutage(outage $outage, $buttons) {
|
||||
global $OUTPUT;
|
||||
|
||||
if ($outage->createdby == 0) {
|
||||
$created = get_string('na', 'auth_outage');
|
||||
} else {
|
||||
@@ -178,14 +168,14 @@ class renderer extends plugin_renderer_base {
|
||||
$url = new moodle_url('/auth/outage/edit.php', ['edit' => $outage->id]);
|
||||
$img = html_writer::empty_tag(
|
||||
'img',
|
||||
['src' => $OUTPUT->image_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall']
|
||||
['src' => $this->output->image_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall']
|
||||
);
|
||||
$linkedit = html_writer::link($url, $img, ['title' => get_string('edit')]);
|
||||
|
||||
$url = new moodle_url('/auth/outage/delete.php', ['id' => $outage->id]);
|
||||
$img = html_writer::empty_tag(
|
||||
'img',
|
||||
['src' => $OUTPUT->image_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall']
|
||||
['src' => $this->output->image_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall']
|
||||
);
|
||||
$linkdelete = html_writer::link($url, $img, ['title' => get_string('delete')]);
|
||||
|
||||
@@ -196,35 +186,38 @@ class renderer extends plugin_renderer_base {
|
||||
$finished = userdate($finished, get_string('datetimeformat', 'auth_outage'));
|
||||
}
|
||||
|
||||
return html_writer::div(
|
||||
$start = outagelib::OUTAGE_START;
|
||||
$end = outagelib::OUTAGE_END;
|
||||
$outagehtml = html_writer::div(
|
||||
html_writer::tag('blockquote',
|
||||
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())
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderstarttime', 'auth_outage').': ').
|
||||
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'))
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage').': ').
|
||||
format_time($outage->get_duration_planned())
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage').': ').
|
||||
$finished
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('small',
|
||||
'Created by '.$created.
|
||||
', modified by '.$modified.' on '.
|
||||
userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage'))
|
||||
)
|
||||
).
|
||||
($buttons ? html_writer::div($linkedit.$linkdelete) : '')
|
||||
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())
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderstarttime', 'auth_outage').': ').
|
||||
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'))
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage').': ').
|
||||
format_time($outage->get_duration_planned())
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage').': ').
|
||||
$finished
|
||||
).
|
||||
html_writer::div(
|
||||
html_writer::tag('small',
|
||||
'Created by '.$created.
|
||||
', modified by '.$modified.' on '.
|
||||
userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage'))
|
||||
)
|
||||
).
|
||||
($buttons ? html_writer::div($linkedit.$linkdelete) : '')
|
||||
)
|
||||
);
|
||||
return $start . $outagehtml . $end;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
$output = $PAGE->get_renderer('auth_outage');
|
||||
|
||||
$mform = new delete();
|
||||
if ($mform->is_cancelled()) {
|
||||
@@ -52,10 +53,10 @@ $dataid = new stdClass();
|
||||
$dataid->id = $outage->id;
|
||||
$mform->set_data($dataid);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $output->header();
|
||||
|
||||
echo renderer::get()->renderdeleteconfirmation($outage);
|
||||
echo $output->renderdeleteconfirmation($outage);
|
||||
|
||||
$mform->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
echo $output->footer();
|
||||
|
||||
15
edit.php
15
edit.php
@@ -34,6 +34,7 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
$output = $PAGE->get_renderer('auth_outage');
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
|
||||
$mform = new edit();
|
||||
@@ -42,11 +43,12 @@ if ($mform->is_cancelled()) {
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
} else if ($outage = $mform->get_data()) {
|
||||
$id = outagedb::save($outage);
|
||||
redirect($CFG->wwwroot. '/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
}
|
||||
|
||||
$clone = optional_param('clone', 0, PARAM_INT);
|
||||
$edit = optional_param('edit', 0, PARAM_INT);
|
||||
$time = optional_param('starttime', 0, PARAM_INT);
|
||||
if ($clone && $edit) {
|
||||
throw new invalid_parameter_exception('Cannot provide both clone and edit ids.');
|
||||
}
|
||||
@@ -60,7 +62,10 @@ if ($clone) {
|
||||
$action = 'outageedit';
|
||||
} else {
|
||||
$config = outagelib::get_config();
|
||||
$time = time();
|
||||
if (empty($time)) {
|
||||
$time = outagelib::get_next_window();
|
||||
}
|
||||
|
||||
$outage = new outage([
|
||||
'autostart' => $config->default_autostart,
|
||||
'starttime' => $time,
|
||||
@@ -79,7 +84,7 @@ if ($outage == null) {
|
||||
$mform->set_data($outage);
|
||||
|
||||
$PAGE->navbar->add(get_string($action.'crumb', 'auth_outage'));
|
||||
echo $OUTPUT->header();
|
||||
echo renderer::get()->rendersubtitle($action);
|
||||
echo $output->header();
|
||||
echo $output->rendersubtitle($action);
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
echo $output->footer();
|
||||
|
||||
@@ -33,6 +33,7 @@ require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
$output = $PAGE->get_renderer('auth_outage');
|
||||
|
||||
$mform = new finish();
|
||||
if ($mform->is_cancelled()) {
|
||||
@@ -52,10 +53,10 @@ $dataid = new stdClass();
|
||||
$dataid->id = $outage->id;
|
||||
$mform->set_data($dataid);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $output->header();
|
||||
|
||||
echo renderer::get()->renderfinishconfirmation($outage);
|
||||
echo $output->renderfinishconfirmation($outage);
|
||||
|
||||
$mform->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
echo $output->footer();
|
||||
|
||||
@@ -27,6 +27,7 @@ $string['auth_outagedescription'] = 'Auxiliary plugin that warns users about a f
|
||||
$string['autostart'] = 'Auto start maintenance mode.';
|
||||
$string['autostart_help'] = 'If selected, when the outage starts it will automatically turn on Moodle maintenance mode.';
|
||||
$string['clicreatehelp'] = 'Creates a new outage.';
|
||||
$string['clicreateexamples'] = "Create an outage starting in 10 seconds\n\n> php create.php -s=10";
|
||||
$string['clicreateparamautostart'] = 'must be Y or N, sets if the outage automatically triggers maintenance mode.';
|
||||
$string['clicreateparamblock'] = 'blocks until outage starts.';
|
||||
$string['clicreateparamclone'] = 'clone another outage except for the start time.';
|
||||
@@ -34,10 +35,11 @@ $string['clicreateparamdescription'] = 'the description of the outage.';
|
||||
$string['clicreateparamduration'] = 'how many seconds should the outage last.';
|
||||
$string['clicreateparamhelp'] = 'shows parameters help.';
|
||||
$string['clicreateparamonlyid'] = 'only outputs the new outage id, useful for scripts.';
|
||||
$string['clicreateparamstart'] = 'in how many seconds should this outage start. Required.';
|
||||
$string['clicreateparamstart'] = 'in how many seconds should this outage start or unix time to start outage. Required.';
|
||||
$string['clicreateparamtitle'] = 'the title of the outage.';
|
||||
$string['clicreateparamwarn'] = 'how many seconds before it starts to display a warning.';
|
||||
$string['clifinishhelp'] = 'Finishes an ongoing outage.';
|
||||
$string['clifinishexamples'] = '';
|
||||
$string['clifinishnotongoing'] = 'Outage is not ongoing.';
|
||||
$string['clifinishparamhelp'] = 'shows parameters help.';
|
||||
$string['clifinishparamactive'] = 'finishes the currently active outage.';
|
||||
@@ -45,6 +47,7 @@ $string['clifinishparamoutageid'] = 'the id of the outage to finish.';
|
||||
$string['cliinmaintenancemode'] = 'Moodle maintenance mode is on. Use "php admin/cli/maintenance.php --disable" to disable it before finishing the outage.';
|
||||
$string['cliwaitforiterroridxoractive'] = 'You must use --outageid=# or --active parameter but not both.';
|
||||
$string['cliwaitforithelp'] = 'Waits until an outage starts.';
|
||||
$string['cliwaitforitexamples'] = '';
|
||||
$string['cliwaitforitoutagestarted'] = 'Outage started!';
|
||||
$string['cliwaitforitoutagestartingin'] = 'Outage starting in {$a->countdown}.';
|
||||
$string['cliwaitforitparamactive'] = 'wait for the currently active outage.';
|
||||
@@ -53,6 +56,12 @@ $string['cliwaitforitparamoutageid'] = 'the id of the outage to wait until it st
|
||||
$string['cliwaitforitparamsleep'] = 'maximum amount of seconds before status output.';
|
||||
$string['cliwaitforitparamverbose'] = 'enable verbose mode.';
|
||||
$string['clierrorinvalidvalue'] = 'Invalid value for parameter: {$a->param}';
|
||||
$string['clierrorinvalidvaluenotid'] = 'Param --{$a->param} must be an id number';
|
||||
$string['clierrorinvalidvaluenotbool'] = 'Param --{$a->param} must be set to either Y or N';
|
||||
$string['clierrorinvalidvaluenotnumber'] = 'Param --{$a->param} must be a number';
|
||||
$string['clierrorinvalidvaluenegativenumber'] = 'Param --{$a->param} must be a positive number';
|
||||
$string['clierrorinvalidvaluenotstring'] = 'Param --{$a->param} must be a string';
|
||||
$string['clierrorinvalidvalueemptystring'] = 'Param --{$a->param} must not be an empty string';
|
||||
$string['clierrormissingparamaters'] = 'You must specify the start time, use --help for more information.';
|
||||
$string['clierroroutagechanged'] = 'Outage was changed while waiting.';
|
||||
$string['clierroroutageended'] = 'Outage has already ended.';
|
||||
@@ -71,9 +80,11 @@ $string['defaultoutageduration'] = 'Outage duration';
|
||||
$string['defaultoutagedurationdescription'] = 'Default duration (in minutes) of an outage.';
|
||||
$string['defaultwarningduration'] = 'Warning duration';
|
||||
$string['defaultwarningdurationdescription'] = 'Default warning time (in minutes) for outages.';
|
||||
$string['defaulttime'] = 'Default time';
|
||||
$string['defaulttimedescription'] = 'The default time for the next outage, expressed in natural language eg "next Thursday 7pm". See <a target=_blank href="https://www.php.net/manual/en/datetime.formats.relative.php">PHP relative dates</a>';
|
||||
$string['defaulttitle'] = 'Title';
|
||||
$string['defaulttitledescription'] = 'Default title for outages. Use {{start}} and {{stop}} placeholders as required.';
|
||||
$string['defaulttitlevalue'] = 'System down from {{start}} for {{duration}}.';
|
||||
$string['defaulttitlevalue'] = 'System down from {{start}} for {{duration}}';
|
||||
$string['defaultdescription'] = 'Description';
|
||||
$string['defaultdescriptiondescription'] = 'Default warning message for outages. Use {{start}} and {{stop}} placeholders as required.';
|
||||
$string['defaultdescriptionvalue'] = 'There is an scheduled maintenance from {{start}} to {{stop}} and our system will not be available during that time.';
|
||||
@@ -116,6 +127,7 @@ $string['outagefinish'] = 'Finish outage';
|
||||
$string['outagefinishwarning'] = 'You are about to mark this outage as finished. The system will be immediately back online.';
|
||||
$string['outageslistfuture'] = 'Planned outages';
|
||||
$string['outageslistpast'] = 'Outage history';
|
||||
$string['outage:updatenotify'] = '';
|
||||
$string['pluginname'] = 'Outage manager';
|
||||
$string['removeselectors'] = 'Remove selectors';
|
||||
$string['removeselectorsdescription'] = 'CSS selectors to remove when rendering a static themed maintenance page. One selector per line.';
|
||||
@@ -143,6 +155,7 @@ $string['title_help'] = 'A short title to for this outage. It will be displayed
|
||||
$string['warningdurationerrorinvalid'] = 'Warning duration must be positive.';
|
||||
$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.<br />Untick "Auto start maintenance mode" if you want to prevent this.';
|
||||
|
||||
/*
|
||||
* Privacy provider (GDPR)
|
||||
|
||||
31
lib.php
31
lib.php
@@ -27,27 +27,6 @@ use auth_outage\local\outagelib;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Used in Moodle 30+ when a user is logged on.
|
||||
*/
|
||||
function auth_outage_extend_navigation_user_settings() {
|
||||
outagelib::inject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in Moodle 30+ on the frontpage.
|
||||
*/
|
||||
function auth_outage_extend_navigation_frontpage() {
|
||||
outagelib::inject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in Moodle 31+ when a user is logged on.
|
||||
*/
|
||||
function auth_outage_extend_navigation_user() {
|
||||
outagelib::inject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for adminlib::set_updatedcallback which requires a string that resolves to a function.
|
||||
*
|
||||
@@ -98,3 +77,13 @@ function auth_outage_get_fontawesome_icon_map() {
|
||||
'core:i/auth_outageevent' => 'fa-power-off',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject the warning bar into the page if there is currently an outage.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
function auth_outage_before_standard_top_of_body_html() {
|
||||
// Get code to inject.
|
||||
return outagelib::get_inject_code();
|
||||
}
|
||||
@@ -32,16 +32,17 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
$PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
$output = $PAGE->get_renderer('auth_outage');
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $output->header();
|
||||
|
||||
// Give it a consistent time so all outages are listed. Useful when debugging.
|
||||
$now = time();
|
||||
|
||||
renderer::get()->output_view('manage.php', [
|
||||
$output->output_view('manage.php', [
|
||||
'unended' => outagedb::get_all_unended($now),
|
||||
'ended' => outagedb::get_all_ended($now),
|
||||
'warning' => outagelib::generate_plugin_configuration_warning(),
|
||||
]);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
echo $output->footer();
|
||||
|
||||
@@ -59,6 +59,13 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
|
||||
$defaults['default_duration'],
|
||||
60
|
||||
));
|
||||
$settings->add(new admin_setting_configtext(
|
||||
'auth_outage/default_time',
|
||||
get_string('defaulttime', 'auth_outage'),
|
||||
get_string('defaulttimedescription', 'auth_outage'),
|
||||
'',
|
||||
PARAM_TEXT
|
||||
));
|
||||
$settings->add(new admin_setting_configtext(
|
||||
'auth_outage/default_title',
|
||||
get_string('defaulttitle', 'auth_outage'),
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
@@ -70,4 +72,12 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
|
||||
parent::setUp();
|
||||
$this->resetAfterTest(true);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
global $DB;
|
||||
|
||||
foreach (outagedb::get_all() as $i => $outage) {
|
||||
$DB->delete_records('auth_outage', ['id' => $outage->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ class calendar_test extends advanced_testcase {
|
||||
* Creates an outage and checks if its in the calendar.
|
||||
*/
|
||||
public function test_create() {
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$time = time();
|
||||
self::$outage = new outage([
|
||||
@@ -70,8 +70,20 @@ class calendar_test extends advanced_testcase {
|
||||
* Updates an outage and checks the calendar.
|
||||
*/
|
||||
public function test_update() {
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$time = time();
|
||||
self::$outage = new outage([
|
||||
'id' => 1,
|
||||
'autostart' => false,
|
||||
'warntime' => $time - 100,
|
||||
'starttime' => $time,
|
||||
'stoptime' => $time + (2 * 60 * 60),
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
calendar::create(self::$outage);
|
||||
|
||||
self::$outage->title = 'New Title';
|
||||
calendar::update(self::$outage);
|
||||
@@ -82,8 +94,22 @@ class calendar_test extends advanced_testcase {
|
||||
* Deletes an outage and checks the calendar.
|
||||
*/
|
||||
public function test_delete() {
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
|
||||
$time = time();
|
||||
self::$outage = new outage([
|
||||
'id' => 1,
|
||||
'autostart' => false,
|
||||
'warntime' => $time - 100,
|
||||
'starttime' => $time,
|
||||
'stoptime' => $time + (2 * 60 * 60),
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
calendar::create(self::$outage);
|
||||
|
||||
$this->check_calendar();
|
||||
|
||||
calendar::delete(self::$outage->id);
|
||||
self::assertNull(calendar::load(self::$outage->id));
|
||||
@@ -93,8 +119,8 @@ class calendar_test extends advanced_testcase {
|
||||
* Try to update a non existing outage.
|
||||
*/
|
||||
public function test_update_notfound() {
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
|
||||
$time = time();
|
||||
$outage = new outage([
|
||||
@@ -116,8 +142,9 @@ class calendar_test extends advanced_testcase {
|
||||
* Try to delete a non existing outage.
|
||||
*/
|
||||
public function test_delete_notfound() {
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
|
||||
calendar::delete(1);
|
||||
self::assertCount(1, phpunit_util::get_debugging_messages());
|
||||
phpunit_util::reset_debugging();
|
||||
|
||||
@@ -95,6 +95,8 @@ class outagedb_test extends auth_outage_base_testcase {
|
||||
$outage = $this->createoutage(2);
|
||||
$outage->id = $id;
|
||||
outagedb::save($outage);
|
||||
// Ensure an id was given.
|
||||
self::assertNotEquals(0, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,7 +57,7 @@ class events_test extends advanced_testcase {
|
||||
public function test_save() {
|
||||
global $DB;
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(false);
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Save new outage.
|
||||
$now = time();
|
||||
@@ -90,7 +90,20 @@ class events_test extends advanced_testcase {
|
||||
global $DB;
|
||||
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(false);
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Save new outage.
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 60,
|
||||
'starttime' => 60,
|
||||
'stoptime' => 120,
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
$outage->id = outagedb::save($outage);
|
||||
self::$outage = $outage;
|
||||
|
||||
self::$outage->starttime += 10;
|
||||
outagedb::save(self::$outage);
|
||||
@@ -117,6 +130,19 @@ class events_test extends advanced_testcase {
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Save new outage.
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 60,
|
||||
'starttime' => 60,
|
||||
'stoptime' => 120,
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
$outage->id = outagedb::save($outage);
|
||||
self::$outage = $outage;
|
||||
|
||||
outagedb::delete(self::$outage->id);
|
||||
|
||||
// Should not exist.
|
||||
|
||||
@@ -44,14 +44,16 @@ class forms_test extends auth_outage_base_testcase {
|
||||
* Create a delete form.
|
||||
*/
|
||||
public function test_delete() {
|
||||
new delete();
|
||||
$form = new delete();
|
||||
self::assertNotNull($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a finish form.
|
||||
*/
|
||||
public function test_finish() {
|
||||
new finish();
|
||||
$form = new finish();
|
||||
self::assertNotNull($form);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,6 +166,7 @@ class forms_test extends auth_outage_base_testcase {
|
||||
]);
|
||||
$edit = new edit();
|
||||
$edit->set_data($outage);
|
||||
self::assertTrue(true, "set_data did not return any error");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,8 +61,12 @@ class cli_test extends auth_outage_cli_testcase {
|
||||
*/
|
||||
public function test_setreferencetime() {
|
||||
$cli = new create(['start' => 0]);
|
||||
|
||||
$cli->set_referencetime(1);
|
||||
self::assertEquals(1, $cli->get_referencetime());
|
||||
|
||||
$cli->set_referencetime(60 * 60 * 24 * 7);
|
||||
self::assertEquals(604800, $cli->get_referencetime());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,10 +121,16 @@ class finish_test extends auth_outage_cli_testcase {
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]));
|
||||
$outage = outagedb::get_by_id($id);
|
||||
self::assertNull($outage->finished, "outage should not be finished");
|
||||
|
||||
$this->set_parameters(['-id='.$id]);
|
||||
$cli = new finish();
|
||||
$cli->set_referencetime($now);
|
||||
$this->execute($cli);
|
||||
|
||||
$outage = outagedb::get_by_id($id);
|
||||
self::assertNotNull($outage->finished, "outage should be finished");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,5 +3,5 @@ a {
|
||||
}
|
||||
|
||||
div {
|
||||
background-image: url('/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png');
|
||||
background-image: url('/moodle/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png');
|
||||
}
|
||||
@@ -3,5 +3,5 @@ a {
|
||||
}
|
||||
|
||||
div {
|
||||
background-image: url(/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png);
|
||||
background-image: url(/moodle/auth/outage/tests/phpunit/local/controllers/fixtures/catalyst.png);
|
||||
}
|
||||
@@ -43,7 +43,8 @@ class infopagecontroller_test extends auth_outage_base_testcase {
|
||||
* Tests the constructor.
|
||||
*/
|
||||
public function test_constructor() {
|
||||
new infopage();
|
||||
$infopage = new infopage();
|
||||
self::assertNotNull($infopage);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +52,8 @@ class infopagecontroller_test extends auth_outage_base_testcase {
|
||||
*/
|
||||
public function test_constructor_withparams() {
|
||||
$_GET = ['id' => 1, 'static' => 'true'];
|
||||
new infopage();
|
||||
$infopage = new infopage();
|
||||
self::assertNotNull($infopage);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,4 +108,14 @@ class infopagecontroller_test extends auth_outage_base_testcase {
|
||||
$output = $info->get_output();
|
||||
self::assertContains('auth_outage_info', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor enables SVG support.
|
||||
*/
|
||||
public function test_svgicons_is_true() {
|
||||
global $CFG;
|
||||
$CFG->svgicons = false;
|
||||
new infopage();
|
||||
self::assertTrue($CFG->svgicons);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
use auth_outage\local\controllers\maintenance_static_page;
|
||||
use auth_outage\local\controllers\maintenance_static_page_io;
|
||||
use auth_outage\local\controllers\maintenance_static_page_generator;
|
||||
use auth_outage\task\update_static_page;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -59,7 +60,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
}
|
||||
|
||||
public function test_createfromoutage() {
|
||||
// How to fetch a page from PHPUnit environment?
|
||||
self::markTestSkipped("How to fetch a page from PHPUnit environment?");
|
||||
}
|
||||
|
||||
public function test_createfromhtml() {
|
||||
@@ -101,7 +102,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
$page->generate();
|
||||
|
||||
// Check for css file.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder().'/622ef6e83acfcb274cdf37bdb3bffa0923f9a7ad.dGV4dC9wbGFpbg');
|
||||
self::assertFileExists($page->get_io()->get_resources_folder().'/d8643101d96b093e642b15544e4d1f7815b5ba55.dGV4dC9wbGFpbg');
|
||||
|
||||
// Check for catalyst.png file referenced in url(..) of css.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder().'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n');
|
||||
@@ -116,7 +117,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
$page->generate();
|
||||
|
||||
// Check for css file.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder().'/1d84b6d321fef780237f84834b7316c079221a31.dGV4dC9wbGFpbg');
|
||||
self::assertFileExists($page->get_io()->get_resources_folder().'/9fe2374b03953e1949d54ab750be2d8706891c03.dGV4dC9wbGFpbg');
|
||||
|
||||
// Check for catalyst.png file referenced in url(..) of css.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder().'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n');
|
||||
@@ -259,11 +260,22 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
|
||||
}
|
||||
|
||||
public function test_is_url() {
|
||||
self::assertTrue(maintenance_static_page_io::is_url('http://catalyst.net.nz'));
|
||||
self::assertTrue(maintenance_static_page_io::is_url('https://www.catalyst-au.net/'));
|
||||
self::assertFalse(maintenance_static_page_io::is_url('/homepage'));
|
||||
self::assertFalse(maintenance_static_page_io::is_url('file://homepage'));
|
||||
public function is_url_dataprovider() {
|
||||
return [
|
||||
[true, 'http://catalyst.net.nz'],
|
||||
[true, 'https://www.catalyst-au.net/'],
|
||||
[false, '/homepage'],
|
||||
[false, 'file://homepage'],
|
||||
[true, '//catalyst-au.net/img/test.jpg'],
|
||||
[false, '://www.catalyst-au.net/img/test.jpg']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider is_url_dataprovider
|
||||
*/
|
||||
public function test_is_url($result, $url) {
|
||||
self::assertEquals($result, maintenance_static_page_io::is_url($url));
|
||||
}
|
||||
|
||||
public function test_file_get_data() {
|
||||
@@ -391,8 +403,48 @@ 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::assertContains('<meta http-equiv="refresh" content="5">', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_get_urls_from_stylesheet
|
||||
* @return array
|
||||
*/
|
||||
public function get_urls_from_stylesheet_provider() {
|
||||
return [
|
||||
// Empty string.
|
||||
["", 0],
|
||||
// URLs that should be retrieved.
|
||||
["background:url(/theme/image.php/_s/boost/core/1581292565/t/expanded)", 1],
|
||||
["background:url('/theme/image.php/_s/boost/core/1581292565/t/expanded')", 1],
|
||||
["src:url(\"/theme/font.php/boost/core/1581292565/fontawesome-webfont.eot?#iefix&v=4.7.0\")", 1],
|
||||
["background-image:url(pix/vline-rtl.gif)", 1],
|
||||
// URLs that should not be retrieved.
|
||||
["background-image:url(data:image/gif;base64,R0lGODlhYADIAP=)", 0],
|
||||
["background-image:url('data:image/gif;base64,R0lGODlhYADIAP=')", 0],
|
||||
["background-image:url(\"data:image/svg+xml;charset=utf8,%3Csvg xmlns=\'http://www.w3.org/2000/svg\'\")", 0],
|
||||
// Combination of URLs used above.
|
||||
["background-image:url(pix/vline-rtl.gif) background:url(/theme/image.php/_s/boost/core/158/t/expanded)", 2],
|
||||
["background-image:url(data:image/gif;base64,R0lG=)src:url(\"/theme/font.php/fontawesome-webfont.eot\")", 1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests get_urls_from_stylesheet() method to get all appropriate URLS from the file.
|
||||
*
|
||||
* @dataProvider get_urls_from_stylesheet_provider
|
||||
* @param string $filecontent Content of the file
|
||||
* @param int $count Expected quantity of found URLs
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public function test_get_urls_from_stylesheet($filecontent, $count) {
|
||||
$this->resetAfterTest(true);
|
||||
$generator = new maintenance_static_page_generator(new DOMDocument(), new maintenance_static_page_io());
|
||||
$matches = $generator->get_urls_from_stylesheet($filecontent);
|
||||
|
||||
self::assertInternalType('array', $matches);
|
||||
self::assertCount(2, $matches);
|
||||
self::assertCount($count, $matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once(__DIR__.'/../base_testcase.php');
|
||||
|
||||
/**
|
||||
* outagelib_test test class.
|
||||
@@ -41,7 +42,7 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @SuppressWarnings(public) Allow as many methods as needed.
|
||||
*/
|
||||
class outagelib_test extends advanced_testcase {
|
||||
class outagelib_test extends auth_outage_base_testcase {
|
||||
/**
|
||||
* Check if maintenance message is disabled as needed.
|
||||
*/
|
||||
@@ -81,7 +82,7 @@ class outagelib_test extends advanced_testcase {
|
||||
* Check outagelib::inject() works as expected.
|
||||
*/
|
||||
public function test_inject() {
|
||||
global $CFG;
|
||||
global $OUTPUT;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
@@ -95,16 +96,15 @@ class outagelib_test extends advanced_testcase {
|
||||
'description' => 'Description',
|
||||
]);
|
||||
$outage->id = outagedb::save($outage);
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
|
||||
outagelib::reinject();
|
||||
self::assertContains('<style>', $CFG->additionalhtmltopofbody);
|
||||
self::assertContains('<script>', $CFG->additionalhtmltopofbody);
|
||||
outagelib::reset_injectcalled();
|
||||
$header1 = outagelib::get_inject_code();
|
||||
self::assertContains('<style>', $header1);
|
||||
self::assertContains('<script>', $header1);
|
||||
|
||||
// Should not inject more than once with the inject() function.
|
||||
$size = strlen($CFG->additionalhtmltopofbody);
|
||||
outagelib::inject();
|
||||
self::assertSame($size, strlen($CFG->additionalhtmltopofbody));
|
||||
// Should not inject more than once.
|
||||
$size = strlen($OUTPUT->standard_top_of_body_html());
|
||||
self::assertSame($size, strlen($OUTPUT->standard_top_of_body_html()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,8 @@ class outagelib_test extends advanced_testcase {
|
||||
*/
|
||||
public function test_inject_broken() {
|
||||
$_GET = ['auth_outage_break_code' => '1'];
|
||||
outagelib::reinject();
|
||||
outagelib::reset_injectcalled();
|
||||
$header = outagelib::get_inject_code();
|
||||
self::assertCount(2, phpunit_util::get_debugging_messages());
|
||||
phpunit_util::reset_debugging();
|
||||
}
|
||||
@@ -134,12 +135,13 @@ class outagelib_test extends advanced_testcase {
|
||||
'description' => 'Description',
|
||||
]);
|
||||
$outage->id = outagedb::save($outage);
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
|
||||
$_GET = ['auth_outage_preview' => (string)$outage->id];
|
||||
|
||||
outagelib::reinject();
|
||||
self::assertContains('<style>', $CFG->additionalhtmltopofbody);
|
||||
self::assertContains('<script>', $CFG->additionalhtmltopofbody);
|
||||
outagelib::reset_injectcalled();
|
||||
$header = outagelib::get_inject_code();
|
||||
self::assertContains('<style>', $header);
|
||||
self::assertContains('<script>', $header);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,11 +149,12 @@ class outagelib_test extends advanced_testcase {
|
||||
*/
|
||||
public function test_inject_preview_notfound() {
|
||||
global $CFG;
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
|
||||
$_GET = ['auth_outage_preview' => '1'];
|
||||
// Should not throw exception or halt anything, silently ignore it.
|
||||
outagelib::reinject();
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
outagelib::reset_injectcalled();
|
||||
$header = outagelib::get_inject_code();
|
||||
self::assertEmpty($header);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,18 +174,21 @@ class outagelib_test extends advanced_testcase {
|
||||
'description' => 'Description',
|
||||
]);
|
||||
$outage->id = outagedb::save($outage);
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
|
||||
$_GET = ['auth_outage_preview' => (string)$outage->id, 'auth_outage_delta' => '500'];
|
||||
outagelib::reinject();
|
||||
outagelib::reset_injectcalled();
|
||||
$header = outagelib::get_inject_code();
|
||||
// Still empty, delta is too high (outage ended).
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
self::assertEmpty($header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test injection without active outage.
|
||||
*/
|
||||
public function test_inject_noactive() {
|
||||
outagelib::reinject();
|
||||
outagelib::reset_injectcalled();
|
||||
$code = outagelib::get_inject_code();
|
||||
self::assertNull($code);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,15 +278,15 @@ class outagelib_test extends advanced_testcase {
|
||||
'description' => 'Description',
|
||||
]);
|
||||
$outage->id = outagedb::save($outage);
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
|
||||
// Pretend we are there...
|
||||
$_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test.
|
||||
$_SERVER['SCRIPT_NAME'] = '/admin/settings.php';
|
||||
$_GET['section'] = 'additionalhtml';
|
||||
outagelib::reinject();
|
||||
outagelib::reset_injectcalled();
|
||||
$header = outagelib::get_inject_code();
|
||||
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
self::assertEmpty($header);
|
||||
}
|
||||
|
||||
public function test_createmaintenancephpcode() {
|
||||
@@ -289,7 +295,10 @@ class outagelib_test extends advanced_testcase {
|
||||
if ((time() >= 123) && (time() < 456)) {
|
||||
define('MOODLE_INTERNAL', true);
|
||||
require_once($CFG->dirroot.'/lib/moodlelib.php');
|
||||
if (!remoteip_in_list('heyyou
|
||||
if (file_exists($CFG->dirroot.'/lib/classes/ip_utils.php')) {
|
||||
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
|
||||
}
|
||||
if (!remoteip_in_list('hey\'\"you
|
||||
a.b.c.d
|
||||
e.e.e.e/20')) {
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
|
||||
@@ -303,6 +312,7 @@ e.e.e.e/20')) {
|
||||
header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Accept-Ranges: none');
|
||||
header('X-Moodle-Maintenance: manager');
|
||||
if ((defined('AJAX_SCRIPT') && AJAX_SCRIPT) || (defined('WS_SERVER') && WS_SERVER)) {
|
||||
exit(0);
|
||||
}
|
||||
@@ -329,6 +339,9 @@ EOT;
|
||||
if ((time() >= 123) && (time() < 456)) {
|
||||
define('MOODLE_INTERNAL', true);
|
||||
require_once($CFG->dirroot.'/lib/moodlelib.php');
|
||||
if (file_exists($CFG->dirroot.'/lib/classes/ip_utils.php')) {
|
||||
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
|
||||
}
|
||||
if (!remoteip_in_list('127.0.0.1')) {
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
|
||||
header('Status: 503 Moodle under maintenance');
|
||||
@@ -341,6 +354,7 @@ if ((time() >= 123) && (time() < 456)) {
|
||||
header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Accept-Ranges: none');
|
||||
header('X-Moodle-Maintenance: manager');
|
||||
if ((defined('AJAX_SCRIPT') && AJAX_SCRIPT) || (defined('WS_SERVER') && WS_SERVER)) {
|
||||
exit(0);
|
||||
}
|
||||
@@ -490,15 +504,15 @@ EOT;
|
||||
'description' => 'Description',
|
||||
]);
|
||||
$outage->id = outagedb::save($outage);
|
||||
self::assertEmpty($CFG->additionalhtmltopofbody);
|
||||
|
||||
// Pretend we are there...
|
||||
$_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test.
|
||||
$_SERVER['SCRIPT_NAME'] = '/admin/settings.php';
|
||||
$_GET['section'] = 'notadditionalhtml';
|
||||
outagelib::reinject();
|
||||
outagelib::reset_injectcalled();
|
||||
|
||||
self::assertNotEmpty($CFG->additionalhtmltopofbody);
|
||||
$header = outagelib::get_inject_code();
|
||||
self::assertNotEmpty($header);
|
||||
}
|
||||
|
||||
private function create_outage() {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->version = 2019022200; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = '1.0.10'; // Human-readable release information.
|
||||
$plugin->requires = 2017051500; // Requires 3.3 and higher.
|
||||
$plugin->version = 2020110900; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2020110900; // Human-readable release information.
|
||||
$plugin->requires = 2017051500; // Requires 3.3 and higher.
|
||||
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!
|
||||
|
||||
@@ -26,16 +26,20 @@
|
||||
use auth_outage\output\manage\history_table;
|
||||
use auth_outage\output\manage\planned_table;
|
||||
use auth_outage\output\renderer;
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $PAGE;
|
||||
$output = $PAGE->get_renderer('auth_outage');
|
||||
$urlnew = new moodle_url('/auth/outage/edit.php');
|
||||
|
||||
echo $viewbag['warning'];
|
||||
?>
|
||||
|
||||
<section id="section_planned_outages">
|
||||
<?php echo renderer::get()->rendersubtitle('outageslistfuture'); ?>
|
||||
<?php echo $output->rendersubtitle('outageslistfuture'); ?>
|
||||
<?php if (empty($viewbag['unended'])): ?>
|
||||
<p>
|
||||
<small><?php echo get_string('notfound', 'auth_outage'); ?></small>
|
||||
@@ -47,13 +51,27 @@ echo $viewbag['warning'];
|
||||
$table->finish_output();
|
||||
?>
|
||||
<?php endif; ?>
|
||||
<input type="button" class="form-submit"
|
||||
value="<?php echo get_string('outagecreate', 'auth_outage'); ?>"
|
||||
onclick="location.href='<?php echo $urlnew; ?>';"/>
|
||||
<?php
|
||||
$outage = outagedb::get_ongoing();
|
||||
if (is_null($outage)) :
|
||||
$config = outagelib::get_config();
|
||||
$default = $config->default_time;
|
||||
$max = $default ? 3 : 1;
|
||||
$next = time();
|
||||
for ($c = 0; $c < $max; $c++) {
|
||||
echo '<p>';
|
||||
$next = outagelib::get_next_window($next);
|
||||
$urlnew->param('starttime', $next);
|
||||
echo $output->single_button($urlnew, get_string('outagecreate', 'auth_outage'));
|
||||
if ($default) {
|
||||
echo ' ' . userdate( $next, get_string('datetimeformat', 'auth_outage'));
|
||||
}
|
||||
}
|
||||
endif; ?>
|
||||
</section>
|
||||
|
||||
<section id="section_outage_history">
|
||||
<?php echo renderer::get()->rendersubtitle('outageslistpast'); ?>
|
||||
<?php echo $output->rendersubtitle('outageslistpast'); ?>
|
||||
<?php if (empty($viewbag['ended'])): ?>
|
||||
<p>
|
||||
<small><?php echo get_string('notfound', 'auth_outage'); ?></small>
|
||||
|
||||
Reference in New Issue
Block a user