mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Compare commits
19 Commits
MOODLE_38_
...
totara-10
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1cff274fe | ||
|
|
b9baa58252 | ||
|
|
1eb509d458 | ||
|
|
03d33cb5c3 | ||
|
|
ee94917bf4 | ||
|
|
76f6523577 | ||
|
|
ab26bae579 | ||
|
|
be259f6ee5 | ||
|
|
186c75b00b | ||
|
|
c56025bcdd | ||
|
|
3375ef6fea | ||
|
|
c234a70476 | ||
|
|
21ff2fbd3b | ||
|
|
4cf8d12aa4 | ||
|
|
c8f99a7bf3 | ||
|
|
f72a03aa5a | ||
|
|
a42ad4141a | ||
|
|
4ce9f05ebf | ||
|
|
bdf158a677 |
20
.travis.yml
20
.travis.yml
@@ -1,37 +1,29 @@
|
||||
language: php
|
||||
|
||||
notifications:
|
||||
email:
|
||||
recipients:
|
||||
- daniel.roperto@catalyst-au.net
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
addons:
|
||||
postgresql: "9.3"
|
||||
postgresql: "9.5"
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
|
||||
services:
|
||||
- mysql
|
||||
|
||||
env:
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_32_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE
|
||||
- DB=pgsql MOODLE_BRANCH=master
|
||||
- DB=mysqli MOODLE_BRANCH=master
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.5
|
||||
- php: 5.6
|
||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
|
||||
- php: 5.5
|
||||
- php: 5.6
|
||||
env: DB=mysqli MOODLE_BRANCH=MOODLE_30_STABLE
|
||||
- php: 7.1
|
||||
env: DB=pgsql MOODLE_BRANCH=master
|
||||
|
||||
|
||||
before_install:
|
||||
- phpenv config-rm xdebug.ini
|
||||
|
||||
12
README.md
12
README.md
@@ -39,6 +39,16 @@ 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 to 3.9 | MOODLE_39_STABLE | 7.0+ |
|
||||
| Totara 11 to 12 | MOODLE_39_STABLE | 7.0+ |
|
||||
| Moodle 3.10 | master | 7.2+ |
|
||||
| Totara 13+ | master | 7.2+ |
|
||||
|
||||
Screenshots
|
||||
-----------
|
||||
@@ -99,7 +109,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.
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -58,8 +58,8 @@ class outagelib {
|
||||
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, 1); // It is localhost, time to connect is enough.
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 5); // It is localhost, time to fetch index is enough.
|
||||
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);
|
||||
@@ -253,6 +253,7 @@ class outagelib {
|
||||
if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
define('MOODLE_INTERNAL', true);
|
||||
require_once($CFG->dirroot.'/lib/moodlelib.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');
|
||||
|
||||
@@ -36,10 +36,10 @@ $PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
|
||||
$mform = new delete();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
outagedb::delete($fromform->id);
|
||||
redirect('/auth/outage/manage.php');
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
|
||||
4
edit.php
4
edit.php
@@ -39,10 +39,10 @@ $PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
$mform = new edit();
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
} else if ($outage = $mform->get_data()) {
|
||||
$id = outagedb::save($outage);
|
||||
redirect('/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
redirect($CFG->wwwroot. '/auth/outage/manage.php#auth_outage_id_'.$id);
|
||||
}
|
||||
|
||||
$clone = optional_param('clone', 0, PARAM_INT);
|
||||
|
||||
@@ -36,10 +36,10 @@ $PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
|
||||
$mform = new finish();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect('/auth/outage/manage.php');
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
outagedb::finish($fromform->id);
|
||||
redirect('/auth/outage/manage.php');
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
}
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
|
||||
@@ -34,7 +34,7 @@ $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.';
|
||||
|
||||
2
lib.php
2
lib.php
@@ -75,7 +75,7 @@ function auth_outage_get_climaintenance_resource_file($file) {
|
||||
|
||||
// Protect against path traversal attacks.
|
||||
$basename = basename($file);
|
||||
if ($basename !== $file) {
|
||||
if ($basename !== $file && $file !== 'preview/' . $basename) {
|
||||
// @codingStandardsIgnoreStart
|
||||
if (!PHPUNIT_TEST) {
|
||||
error_log('Possible attempt for Path Traversal Attack (only filename expected): '.$file);
|
||||
|
||||
@@ -69,9 +69,10 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
|
||||
|
||||
parent::setUp();
|
||||
$this->resetAfterTest(true);
|
||||
}
|
||||
|
||||
// Do not use https.
|
||||
$CFG->wwwroot = 'http://www.example.com/moodle';
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
public function tearDown() {
|
||||
global $DB;
|
||||
$DB->delete_records('auth_outage');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -87,7 +87,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
'<body>Content<link rel="stylesheet" href="'.$externalcsslink.'"></body></html>';
|
||||
$generated = $this->generated_page_html($html);
|
||||
|
||||
self::assertContains('http://www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
self::assertNotContains($localcsslink, $generated);
|
||||
self::assertContains($externalcsslink, $generated);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
'<body><img src="'.$localimglink.'">Content<img src="'.$externalimglink.'" /></body></html>';
|
||||
$generated = $this->generated_page_html($html);
|
||||
|
||||
self::assertContains('http://www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
self::assertNotContains($localimglink, $generated);
|
||||
self::assertContains($externalimglink, $generated);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
$generated = $this->generated_page_html($html);
|
||||
|
||||
self::assertNotContains($link, $generated);
|
||||
self::assertContains('http://www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
}
|
||||
|
||||
public function test_previewpath() {
|
||||
@@ -172,7 +172,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
$generated = trim(file_get_contents($page->get_io()->get_template_file()));
|
||||
|
||||
self::assertNotContains($link, $generated);
|
||||
self::assertContains('http://www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
|
||||
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,7 +256,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
|
||||
|
||||
public function test_get_url_for_file() {
|
||||
$io = new maintenance_static_page_io();
|
||||
self::assertSame('http://www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
|
||||
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() {
|
||||
|
||||
@@ -31,7 +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 +41,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.
|
||||
*/
|
||||
@@ -293,6 +293,7 @@ class outagelib_test extends advanced_testcase {
|
||||
if ((time() >= 123) && (time() < 456)) {
|
||||
define('MOODLE_INTERNAL', true);
|
||||
require_once($CFG->dirroot.'/lib/moodlelib.php');
|
||||
require_once($CFG->dirroot.'/lib/classes/ip_utils.php');
|
||||
if (!remoteip_in_list('heyyou
|
||||
a.b.c.d
|
||||
e.e.e.e/20')) {
|
||||
@@ -333,6 +334,7 @@ EOT;
|
||||
if ((time() >= 123) && (time() < 456)) {
|
||||
define('MOODLE_INTERNAL', true);
|
||||
require_once($CFG->dirroot.'/lib/moodlelib.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');
|
||||
|
||||
Reference in New Issue
Block a user