22 Commits

Author SHA1 Message Date
ScottVerbeek
f1cff274fe Updated README.md with new branch 2021-01-07 10:59:53 +10:00
Dan Marsden
b9baa58252 update readme to cover branch versions. 2021-01-07 09:36:59 +10:00
Brendan Heywood
1eb509d458 Merge pull request #199 from ledship/totara-10-time
Accept unix time for --start CLI option to totara-10 branch
2020-07-24 09:59:24 +10:00
Dan Marsden
03d33cb5c3 Remove incorrect usage of example.com in tests.
remove http part of test - site might be https.
2020-07-15 20:29:55 +12:00
Alexander
ee94917bf4 Accept unix time for --start CLI option 2020-07-07 10:12:03 +12:00
kristian-94
76f6523577 Merge pull request #202 from catalyst/WR336891
Issue 189 Unable to find Class 'core\ip_utils'
2020-07-03 13:43:40 +10:00
Heena Agheda
ab26bae579 Add services: mysql 2020-07-03 10:41:01 +10:00
Heena Agheda
be259f6ee5 Upgrade PHP version 2020-07-03 10:19:26 +10:00
Heena Agheda
186c75b00b Fix failing tests 2020-07-03 09:47:21 +10:00
Heena Agheda
c56025bcdd Upgrade postgresql version 2020-07-02 15:03:58 +10:00
katcher
3375ef6fea Issue 189 Unable to find Class 'core\ip_utils'
Following upgrade of moodle to 3.5.11, error above prevented moodle from
displaying on the web.  The class ip_utils was for somereason not loaded
and through an error preventing the site from displaying when in
maintenance mod.  Adding the require class appears to have fixed the
issue.
2020-07-02 11:14:14 +10:00
Nathan Nguyen
c234a70476 Fix problem with loading stylesheet in preview mode 2019-10-16 12:01:51 +11:00
Dan Marsden
21ff2fbd3b Fix resetAfterTest(false) in events_test file for Totara tests. 2019-07-22 10:41:44 +12:00
Dan Marsden
4cf8d12aa4 Fix #161 - make unit tests distinct. 2019-07-22 10:41:34 +12:00
Kristian Ringer
c8f99a7bf3 Fix unit tests in totara 10
- Change outagelib_test to use the auth_outage_base_testcase base class
  - Remove outages from test table in tearDown function after each test.
2019-05-08 13:30:08 +10:00
Ilya Tregubov
f72a03aa5a Incease timeout to prevent settings page throwing error (from time to time) 2018-10-11 11:56:40 +11:00
Dan Marsden
a42ad4141a Fix #120 increase timeout values to prevent ci failures. 2018-10-05 10:21:28 +13:00
Dan Marsden
4ce9f05ebf Fix #124 use correct urls in redirects. 2018-10-03 15:17:21 +13:00
Dan Marsden
bdf158a677 Update travis config for 3.2 and lower branch. 2018-10-03 15:05:09 +13:00
SECRET Olivier
62bf9f38ef Merge pull request #133 from catalyst/oliviersecret2
add privacy provider
2018-07-25 10:34:00 +10:00
SECRET Olivier
cbebb4a839 Fix lang String 2018-07-02 12:48:25 +10:00
Olivier SECRET
aee5ae8adb add privacy provider
to fix unit test failure
2018-06-25 11:48:15 +10:00
16 changed files with 164 additions and 44 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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'],

View File

@@ -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');

View File

@@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for auth_outage.
*
* @package auth_outage
* @copyright 2018 Olivier SECRET <olivier.secret@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_outage\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\legacy_polyfill;
/**
* Privacy provider for the authentication manual.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\null_provider {
use legacy_polyfill;
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* This function is compatible with old php version. (Diff is the underscore '_' in the beginning)
* But the get_reason is still available because of the trait legacy_polyfill.
*
* @return string
*/
public static function _get_reason() {
return 'privacy:no_data_reason';
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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.';
@@ -143,3 +143,8 @@ $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.';
/*
* Privacy provider (GDPR)
*/
$string["privacy:no_data_reason"] = "The Outage authentication plugin does not store any personal data.";

View File

@@ -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);

View 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');
}
}

View File

@@ -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();

View File

@@ -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.

View File

@@ -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() {

View File

@@ -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');

View File

@@ -28,7 +28,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$plugin->version = 2017071300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2018062500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0.9'; // Human-readable release information.
$plugin->requires = 2014051200; // Requires Moodle 2.7 or later. Moodle 3.0 or later recommended.
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!