mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Compare commits
1 Commits
totara-10
...
moodle34_b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
490029cb65 |
20
.travis.yml
20
.travis.yml
@@ -1,29 +1,37 @@
|
||||
language: php
|
||||
|
||||
notifications:
|
||||
email:
|
||||
recipients:
|
||||
- daniel.roperto@catalyst-au.net
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
addons:
|
||||
postgresql: "9.5"
|
||||
postgresql: "9.3"
|
||||
|
||||
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.6
|
||||
- php: 5.5
|
||||
env: DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
|
||||
- php: 5.6
|
||||
- php: 5.5
|
||||
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,16 +39,6 @@ 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
|
||||
-----------
|
||||
@@ -109,7 +99,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 or unix time to start outage. Required.
|
||||
-s, --start in how many seconds should this outage start. Required.
|
||||
-d, --duration how many seconds should the outage last.
|
||||
-t, --title the title of the outage.
|
||||
-e, --description the description of the outage.
|
||||
|
||||
@@ -40,10 +40,13 @@ if (!isset($CFG->dataroot)) {
|
||||
// 1) Make sure we replace the configurations for behat as we have not ran 'lib/setup.php' yet.
|
||||
if (!empty($CFG->behat_wwwroot) or !empty($CFG->behat_dataroot) or !empty($CFG->behat_prefix)) {
|
||||
require_once(__DIR__.'/../../lib/behat/lib.php');
|
||||
|
||||
// The function call below will change $CFG so let's save it and restore later if access is granted.
|
||||
$beforebehatcfg = $CFG;
|
||||
$CFG = clone($CFG);
|
||||
behat_update_vars_for_process();
|
||||
|
||||
if (behat_is_test_site()) {
|
||||
$beforebehatcfg = $CFG;
|
||||
$CFG = clone($CFG);
|
||||
clearstatcache();
|
||||
behat_check_config_vars();
|
||||
behat_clean_init_config();
|
||||
@@ -82,4 +85,5 @@ $CFG->auth_outage_bootstrap_loaded = true;
|
||||
// 5) Restore behat config as needed (let setup.php execute which is more complex than our quick-check).
|
||||
if (isset($beforebehatcfg)) {
|
||||
$CFG = $beforebehatcfg;
|
||||
unset($beforebehatcfg);
|
||||
}
|
||||
|
||||
@@ -170,9 +170,7 @@ class create extends clibase {
|
||||
$this->become_admin_user();
|
||||
|
||||
// Create the outage.
|
||||
// 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'];
|
||||
$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, 5); // It is localhost, time to connect is enough.
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 15); // It is localhost, time to fetch index is enough.
|
||||
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.
|
||||
$contents = curl_exec($curl);
|
||||
$mime = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
|
||||
curl_close($curl);
|
||||
@@ -253,7 +253,6 @@ 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');
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<?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';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,10 +36,10 @@ $PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
|
||||
|
||||
$mform = new delete();
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
outagedb::delete($fromform->id);
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
redirect('/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(new moodle_url('/auth/outage/manage.php'));
|
||||
redirect('/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('/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(new moodle_url('/auth/outage/manage.php'));
|
||||
redirect('/auth/outage/manage.php');
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
outagedb::finish($fromform->id);
|
||||
redirect(new moodle_url('/auth/outage/manage.php'));
|
||||
redirect('/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 or unix time to start outage. Required.';
|
||||
$string['clicreateparamstart'] = 'in how many seconds should this outage start. 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,8 +143,3 @@ $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.";
|
||||
|
||||
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 && $file !== 'preview/' . $basename) {
|
||||
if ($basename !== $file) {
|
||||
// @codingStandardsIgnoreStart
|
||||
if (!PHPUNIT_TEST) {
|
||||
error_log('Possible attempt for Path Traversal Attack (only filename expected): '.$file);
|
||||
|
||||
@@ -69,10 +69,9 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
|
||||
|
||||
parent::setUp();
|
||||
$this->resetAfterTest(true);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
global $DB;
|
||||
$DB->delete_records('auth_outage');
|
||||
// Do not use https.
|
||||
$CFG->wwwroot = 'http://www.example.com/moodle';
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,20 +70,8 @@ class calendar_test extends advanced_testcase {
|
||||
* Updates an outage and checks the calendar.
|
||||
*/
|
||||
public function test_update() {
|
||||
$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->resetAfterTest(false);
|
||||
|
||||
self::$outage->title = 'New Title';
|
||||
calendar::update(self::$outage);
|
||||
@@ -94,22 +82,8 @@ class calendar_test extends advanced_testcase {
|
||||
* Deletes an outage and checks the calendar.
|
||||
*/
|
||||
public function test_delete() {
|
||||
$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();
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
calendar::delete(self::$outage->id);
|
||||
self::assertNull(calendar::load(self::$outage->id));
|
||||
@@ -119,8 +93,8 @@ class calendar_test extends advanced_testcase {
|
||||
* Try to update a non existing outage.
|
||||
*/
|
||||
public function test_update_notfound() {
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$time = time();
|
||||
$outage = new outage([
|
||||
@@ -142,9 +116,8 @@ class calendar_test extends advanced_testcase {
|
||||
* Try to delete a non existing outage.
|
||||
*/
|
||||
public function test_delete_notfound() {
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
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(true);
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
// Save new outage.
|
||||
$now = time();
|
||||
@@ -90,20 +90,7 @@ class events_test extends advanced_testcase {
|
||||
global $DB;
|
||||
|
||||
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;
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
self::$outage->starttime += 10;
|
||||
outagedb::save(self::$outage);
|
||||
@@ -130,19 +117,6 @@ 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('www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
self::assertContains('http://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('www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
self::assertContains('http://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('www.example.com/moodle/auth/outage/file.php?file=', $generated);
|
||||
self::assertContains('http://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('www.example.com/moodle/auth/outage/file.php?file=preview%2F', $generated);
|
||||
self::assertContains('http://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::assertContains('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
|
||||
self::assertSame('http://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(__DIR__.'/../base_testcase.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 auth_outage_base_testcase {
|
||||
class outagelib_test extends advanced_testcase {
|
||||
/**
|
||||
* Check if maintenance message is disabled as needed.
|
||||
*/
|
||||
@@ -293,7 +293,6 @@ class outagelib_test extends auth_outage_base_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')) {
|
||||
@@ -334,7 +333,6 @@ 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');
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->version = 2018062500; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2017071300; // 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!
|
||||
|
||||
Reference in New Issue
Block a user