151 Commits

Author SHA1 Message Date
Jerome Charaoui
c4fc4b4396 Include filelib.php to fix class not found exception 2021-05-06 10:29:33 +12:00
Dan Marsden
e632b1c2f9 We haven't been testing postgres on 3.5 - it needs pg12
disable pg test for now, but we should think about adding it back.
2021-05-06 10:04:50 +12:00
Dan Marsden
b4d996125d Update Readme with new branch naming. 2021-05-06 10:04:24 +12:00
Dan Marsden
f8d0d658fa tidy up github action config. 2021-05-05 20:23:22 +12:00
Dan Marsden
a38deb7abf Test 3.5 and 3.8 on this branch. 2021-05-05 14:53:07 +12:00
Dan Marsden
1f03af1968 Fix order of abstract/public - coding guideline failure. 2021-05-05 13:18:11 +12:00
Dan Marsden
b29e7e914b Fix node install. 2021-05-05 13:07:59 +12:00
Dan Marsden
6255ebb311 Revert "update github actions - fix node version."
This reverts commit 18d5864cac.
2021-05-05 13:03:05 +12:00
Dan Marsden
18d5864cac update github actions - fix node version. 2021-05-05 12:55:12 +12:00
Dan Marsden
0a34a368d6 add 3.10 and 3.11 tests to github actions. 2021-05-05 12:45:05 +12:00
Brendan Heywood
bfc3c2317b Merge pull request #246 from catalyst/issue245
Fix root URL path
2021-03-30 22:03:03 +11:00
Matt P
5fef56cb2f Merge pull request #223 from catalyst/issue222
Fix banner overlap
2021-03-25 13:29:59 +11:00
Mikhail Golenkov
c55b9271c4 Fix banner overlap 2021-03-25 13:20:51 +11:00
Mikhail Golenkov
77ce63e4f9 Fix root URL path 2021-03-18 15:50:39 +11:00
Matt Porritt
47154e545f fix unit test signature to be compatible with Moodle 3.10+ 2021-03-12 03:31:06 +00:00
Matt Porritt
2d59580d36 fix unit test signature to be compatible with Moodle 3.10+ 2021-03-12 03:29:55 +00:00
Brendan Heywood
49ea2a142e Merge pull request #242 from catalyst/issue241
Fix issue #241 hide warningbar under h5p-embed
2021-03-04 14:02:34 +11:00
Tomo Tsuyuki
a6bb7f4bc2 Fix #241 Do not render if layout are from some specific ones 2021-03-04 12:22:34 +11:00
Brendan Heywood
f40f52bdc3 Merge pull request #244 from catalyst/issue243
Partially fix #243: fix codingcheck error and disable behat test
2021-03-04 12:19:38 +11:00
Tomo Tsuyuki
07a8a41ad4 Partially fix #243: fix codingcheck error and disable behat test 2021-03-04 12:02:57 +11:00
Brendan Heywood
19bc18512d Merge pull request #238 from yao9394/master-fix-233-no-outage-check
Fix #233 Add no_outage check to allow checkfinished.php to be execpt …
2021-02-26 11:49:06 +11:00
John Yao
116467429e Fix issues for phpdoc check
Get rid of ci for moodle 37,38
2021-02-16 11:12:40 +11:00
John Yao
def6e997a9 add github actions and remove travis ci 2021-02-12 16:51:14 +11:00
John Yao
c53a629bc8 Fix #233 Add no_outage check to allow checkfinished.php to be execpt from the 503 maintenance logic 2021-02-12 09:38:57 +11:00
Scott Verbeek
8f7d38f355 Merge pull request #237 from catalyst/test-envbar-interact-fix
Fixed logic for sequenced calls of outage injection to central method
2021-02-05 13:47:03 +10:00
Peter Burnett
e58f7b73b3 Fixed logic for sequenced calls of outage injection to centralised method 2021-02-05 13:42:05 +10:00
Brendan Heywood
f77c85355c Merge pull request #232 from catalyst/cache-header
Improve shared caching of the checkfinished endpoint #231
2021-01-30 11:50:29 +11:00
Brendan Heywood
56ac8aa19b Improve shared caching of the checkfinished endpoint #231 2021-01-30 11:41:36 +11:00
Brendan Heywood
c590eadb4f Merge pull request #230 from catalyst/img-replace-improvement
Issue #229: Updated DOM element matching to allow for "//" urls in images
2021-01-19 10:07:21 +11:00
Peter Burnett
7cd10ab05c Updated DOM element matching to allow for "//" urls in images 2021-01-19 08:57:16 +10:00
Brendan Heywood
ca6c48d0f3 Merge pull request #215 from catalyst/verbump
Version bump to fix missing function errors
2020-11-09 16:21:12 +11:00
Peter Burnett
1cd0b7c365 Version bump to fix missing function errors 2020-11-09 15:13:30 +10:00
Brendan Heywood
ce93854b92 Merge pull request #214 from jamie-catalyst/fix_travis_config
#213 fix unit tests
2020-11-08 20:21:53 +11:00
Jamie Stamp
aab2af04e8 Fix code style violations 2020-11-06 09:32:23 +00:00
Jamie Stamp
42babf617b Update inject method 2020-11-05 17:10:02 +00:00
Jamie Stamp
90bc928754 Fix Travis CI config 2020-11-05 17:00:26 +00:00
Brendan Heywood
e22c393681 Merge pull request #212 from jamie-catalyst/html_inject_fix
Remove all usage of $CFG->additionalhtmltopofbody #211
2020-11-05 12:32:38 +11:00
Jamie Stamp
e4dc17aae4 Remove all usage of $CFG->additionalhtmltopofbody #211 2020-11-04 17:15:05 +00:00
Brendan Heywood
5fa3ba8034 Merge pull request #208 from catalyst/issue-207-proxy
Issue #207: Use Moodle curl to honor proxy settings
2020-11-04 10:01:06 +11:00
Nicholas Hoobin
6113b48866 Issue #207: Use Moodle curl to honor proxy settings 2020-09-16 12:32:11 +10:00
Dmitrii Metelkin
01bdacc90b Merge pull request #206 from catalyst/t12-unittest-fix
WR #343135: Update tests to work with T12
2020-09-11 22:46:27 +10:00
Nicholas Hoobin
0efb9acbd1 Begin the song and dance of travis. 2020-09-11 16:04:04 +10:00
Nicholas Hoobin
2b249ac036 WR #343135: Update tests to work with T12.
For some reason, $this->resetAfterTest(true); is not resetting the outage table in T12 (probably T11/13 too)
2020-09-11 15:48:04 +10:00
Nicholas Hoobin
d9b29d2335 Merge pull request #203 from catalyst/issue201-null-key
Issue #201: Resolve unit test failures with PHP7.4
2020-07-08 10:26:52 +10:00
Nicholas Hoobin
c4f9945c21 Issue #201: Update travis to check against PHP7.4
Travis, PGSQL 9.5.
Default distro.
PHP 7.4 check added on M39/master.
2020-07-07 11:01:32 +10:00
Nicholas Hoobin
6f65ff9199 Issue #201: Resolve unit test failures with PHP7.4 2020-07-06 14:36:00 +10:00
Brendan Heywood
a62be02438 Merge pull request #197 from catalyst/bootstrap-root
Fixed bug with moodles under a subdir #196
2020-06-19 13:34:54 +10:00
Brendan Heywood
32412c2580 Fixed travis node issue 2020-06-19 13:22:37 +10:00
Brendan Heywood
5a53bf04a1 Fixed bug with moodles under a subdir #196 2020-06-19 09:17:39 +10:00
golenkovm
b2e8100c19 Merge pull request #195 from catalyst/issue194
Add SVG support when building static page
2020-04-20 11:36:15 +10:00
Mikhail Golenkov
bf242d9e65 Set CFG->svgicons to true on info page #194. 2020-04-08 16:49:47 +10:00
Brendan Heywood
981452ac27 Merge pull request #193 from catalyst/issue189-require-exists
Issue 189: Changed require statement to check file exists
2020-03-26 14:00:11 +11:00
Peter Burnett
73f283847a Changed require statement to check file exists 2020-03-26 12:04:00 +10:00
Brendan Heywood
afc81edfde Removed support for cron syntax #163 2020-03-26 01:40:06 +11:00
Brendan Heywood
9ed0b74112 Added next 3 available window button for new outages #163 2020-03-26 01:30:03 +11:00
Brendan Heywood
22b38c2838 Accept natural language start times #163 2020-03-26 00:56:17 +11:00
Brendan Heywood
0e6a8ccabb Merge pull request #192 from catalyst/crontime-163
Crontime #163
2020-03-25 22:37:20 +11:00
Brendan Heywood
3b1b1ea0e1 Allow default start time using cron syntax #163 2020-03-25 22:21:35 +11:00
Brendan Heywood
e6a63f02e6 Added missing lang string 2020-03-25 21:36:19 +11:00
Brendan Heywood
56126cd431 Merge pull request #191 from catalyst/issue189
Issue189: Unable to find Class 'core\ip_utils'
2020-03-25 17:45:56 +11:00
Peter Burnett
777e466a0a Issue #189: Updated unit tests 2020-03-25 15:15:02 +10:00
katcher
4467bea1cf 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-03-18 09:17:19 -04:00
Marcus
77b63bce75 Merge pull request #188 from catalyst/fixbootstrap
Fix url parsing when Moodle is installed without subdir
2020-03-04 12:53:20 +10:00
Mikhail Golenkov
bac83b143a Fix url parsing when Moodle is installed without subdir. 2020-03-04 13:03:44 +11:00
Dan Marsden
7d52bb9695 update readme to cover branch versions. 2020-02-24 13:37:18 +13:00
Brendan Heywood
c3a2faef08 Improved cli error messages 2020-02-13 23:02:12 +11:00
Brendan Heywood
51f6f5ef5c Fixed event db snapshot record mismatch 2020-02-13 10:50:04 +11:00
Brendan Heywood
75d872564b Bump version 2020-02-13 10:17:06 +11:00
Brendan Heywood
98b3bb38f6 Removed period from string 2020-02-13 10:16:12 +11:00
Brendan Heywood
b435a3f0a7 Improved wording and links for all 3 outage events 2020-02-13 09:39:15 +11:00
golenkovm
b428805c0e Merge pull request #184 from catalyst/version
Bump plugin version
2020-02-11 09:53:59 +11:00
Mikhail Golenkov
a722ca6965 Bump plugin version. 2020-02-11 09:52:58 +11:00
Brendan Heywood
2535d6fa4c Merge pull request #175 from catalyst/issue174
Fix maintenance static page generation
2020-02-10 15:55:47 +10:00
Mikhail Golenkov
cd21fb977b Allow outage info requests #174. 2020-02-10 16:19:01 +11:00
golenkovm
a71abed5b4 Merge pull request #183 from catalyst/issue179
Fix Issue179
2020-02-10 15:57:00 +11:00
Mikhail Golenkov
2cecb87317 Format test_get_urls_from_stylesheet_provider() #179. 2020-02-10 14:28:48 +11:00
Mikhail Golenkov
b6f5db001a Fix unit tests to support older versions of phpunit #179. 2020-02-10 12:53:52 +11:00
Mikhail Golenkov
aadd7eaeee Cover get_urls_from_stylesheet() method by unit tests #179. 2020-02-10 12:17:05 +11:00
Mikhail Golenkov
7ad82886d7 Move regexps to a separate method #179. 2020-02-10 11:12:14 +11:00
Mikhail Golenkov
26baaf9993 Fix unit tests #179. 2020-02-07 15:41:52 +11:00
Mikhail Golenkov
a361ae4008 Simplify url building for update_link_stylesheet_parse() #179. 2020-02-07 14:25:33 +11:00
Mikhail Golenkov
7a1fa1f91b Tweak regexp and exclude non-url entries #179. 2020-02-06 18:02:59 +11:00
Mikhail Golenkov
ae85c94364 Cook file url properly when Moodle is installed in a sub folder #179. 2020-02-06 18:01:39 +11:00
Mikhail Golenkov
2af15f2136 Increase timeout for cases when caches have been just purged #179. 2020-02-06 17:59:44 +11:00
Brendan Heywood
076321db60 Merge pull request #173 from catalyst/issue172
Fix events that trigger re-enabling maintenance mode
2020-02-05 13:48:57 +10:00
Mikhail Golenkov
c724e1abe4 Replace custom html button with OUTPUT->single_button #172. 2020-02-05 14:09:34 +11:00
Mikhail Golenkov
d438027a18 Reorganize warning and buttons for Edit form #172. 2020-02-05 12:51:43 +11:00
Mikhail Golenkov
587bd3a311 Fix Cancel button on Edit form. 2020-02-04 17:41:08 +11:00
Mikhail Golenkov
0137811f2b Hide Create outage button if there is an ongoing outage #172. 2020-02-04 17:03:59 +11:00
Mikhail Golenkov
a906f993f0 Add conditions before calling update_maintenance_later() #172. 2020-02-04 17:03:47 +11:00
Mikhail Golenkov
10223da351 Amend redirection url when outage is saved. 2020-02-04 17:03:35 +11:00
Mikhail Golenkov
1e7d035a9b Show warning if outage editing will trigger re-enabling maintenance mode #172. 2020-02-04 17:02:59 +11:00
Brendan Heywood
d709f39122 Merge pull request #171 from catalyst/issue170
Do not check event calendar capability when running cli/finish.php
2020-02-04 13:14:20 +10:00
Mikhail Golenkov
acda7557d1 Do not check event calendar capability when running cli/finish.php #170 2020-02-04 13:39:02 +11:00
Brendan Heywood
ecaee161bb Merge pull request #177 from catalyst/issue176
Increase postgresql version to fix Travis errors
2020-02-04 11:30:31 +10:00
Mikhail Golenkov
de958edc9f Use postgresql 9.5 for 3.8 and master branch #176. 2020-02-04 11:35:39 +11:00
Mikhail Golenkov
20258deb20 Update Travis matrix #176. 2020-02-04 11:35:39 +11:00
Brendan Heywood
d3816960f0 Merge pull request #178 from catalyst/issue178
Do not run behat tests until moodle-plugin-ci is fixed
2020-02-04 09:52:26 +10:00
Mikhail Golenkov
2a6cf91743 Do not run behat tests until moodle-plugin-ci is fixed #178. 2020-02-03 17:58:46 +11:00
Brendan Heywood
6e960e8814 Merge pull request #169 from ledship/new-time-options
Accept unix time for --start CLI option
2020-01-28 21:17:33 +10:00
Alexander
e56cdf4ed3 Accept unix time for --start CLI option 2020-01-22 10:28:07 +13:00
Brendan Heywood
34c34603b6 Added docs for themes 2019-11-14 10:41:51 +11:00
Dan Marsden
905ffa34be Merge pull request #164 from catalyst/fix161-2
Fix resetAfterTest(false) in events_test file for Totara tests.
2019-07-19 10:14:28 +12:00
Dan Marsden
f60244f62c Fix resetAfterTest(false) in events_test file for Totara tests. 2019-07-19 10:09:26 +12:00
Dan Marsden
7c77d2652f Merge pull request #162 from catalyst/fix161
Fix161
2019-07-18 13:07:33 +12:00
Dan Marsden
a2224e28da Use php 7.2 for master/default, add supported branches. 2019-07-18 09:32:51 +12:00
Dan Marsden
02524a4028 Fix #161 - make unit tests distinct. 2019-07-18 09:20:35 +12:00
Matt P
40012e84ae Merge pull request #160 from mpalimaka/fix-tests
Fix tests
2019-06-18 14:46:18 +10:00
Michael Palimaka
a56c67284f Fix tests 2019-06-18 14:33:03 +10:00
Matt Porritt
816114bd87 update travis to fix issue with Java and MySql 2019-06-18 10:40:25 +10:00
Matt P
0658733a86 Merge pull request #159 from mpalimaka/outage-header
Send custom HTTP header when in maintenance mode
2019-06-18 10:37:32 +10:00
Michael Palimaka
9c7eb1b681 Send custom HTTP header when in maintenance mode 2019-05-29 12:08:21 +10:00
Adam Riddell
de1c2cab8a Merge pull request #156 from catalyst/clean_outages
Clean up outages from additionalhtmltopofbody
2019-05-28 16:45:27 +10:00
Kristian Ringer
92ad2f5db5 Clean up outages from additionalhtmltopofbody 2019-05-24 16:56:03 +10:00
kristian-94
a3304d0bfe Merge pull request #154 from catalyst/issue-153
Issue #153: Fix test_inject_broken unit test failure
2019-05-22 13:34:56 +10:00
Kristian Ringer
36cd0517b9 Issue #153: Fix test_inject_broken unit test failure 2019-05-22 12:30:11 +10:00
Brendan Heywood
dec4c7bf53 Fixed ipwhitelist escaping issue #150 2019-03-28 14:32:20 +11:00
Dmitrii Metelkin
e94d9c94ea Merge pull request #147 from catalyst/issues#146
Add an icon map for calendar events to fix #146
2019-02-22 10:35:57 +11:00
Dmitrii Metelkin
030fec75e1 Add an icon map for calendar events to fix #146 2019-02-22 10:32:19 +11:00
tuanngocnguyen
cf85a04ddc Merge pull request #145 from catalyst/issue#144
user date
2018-12-06 16:53:17 +11:00
Nathan Nguyen
c820bb1c0b Fix day display 2018-12-06 15:42:56 +11:00
Nathan Nguyen
e1b6279437 user date 2018-12-06 15:07:58 +11:00
tuanngocnguyen
846879d2d6 Merge pull request #143 from catalyst/issue#140
#140 Turn off check_wwwroot_accessible
2018-12-03 16:24:54 +11:00
Nathan Nguyen
38f838d84e Turn off check_wwwroot_accessible on admin pages other than outage setting page 2018-12-03 14:36:54 +11:00
Nathan Nguyen
df649c8133 change relative link to absolute link 2018-11-30 10:40:43 +11:00
Dmitrii Metelkin
8f5e5dbb50 Merge pull request #139 from catalyst/StyleSheetLoadingError
Fix problem with loading stylesheet in preview mode
2018-11-16 13:36:02 +11:00
Nathan Nguyen
f4962f22a8 Fix problem with loading stylesheet in preview mode 2018-11-16 10:40:08 +11:00
Dan Marsden
1ec50dadb2 add details about version support 2018-10-11 14:01:28 +13:00
Ilya Tregubov
54045d5ce1 Incease timeout to prevent settings page throwing error (from time to time) 2018-10-11 11:15:04 +11:00
Dan Marsden
e84534f7b6 Fix #127 fix boost header when outage plugin in use. 2018-10-05 15:19:12 +13:00
Dan Marsden
ceb9e065b9 Use correct check for behat running. 2018-10-05 14:21:03 +13:00
Dan Marsden
3639883d30 Don't use curl when running behat tests to get page outage.
Behat step improvements.
2018-10-05 13:45:08 +13:00
Dan Marsden
6c69d46ebe Fix some behat steps. 2018-10-05 11:49:59 +13:00
Dan Marsden
6cea3f52c2 Fix travis config for old php versions. 2018-10-05 11:08:56 +13:00
Dan Marsden
49bdb687c3 Fix #120 increase timeout values to prevent ci failures. 2018-10-05 10:20:59 +13:00
Dan Marsden
c175333f88 Remove incorrect usage of example.com in tests.
remove http part of test - site might be https.
2018-10-03 22:55:09 +13:00
Dan Marsden
3e5446d8d1 tidy up coding guideline travis failures. 2018-10-03 22:10:39 +13:00
Dan Marsden
6c489ad20e codiing guideline improvements to css file. 2018-10-03 15:50:27 +13:00
Dan Marsden
a33e80b4aa Coding guidelines - tidy up some spacing in behat tests. 2018-10-03 15:46:11 +13:00
Dan Marsden
fa0641ec47 update travis config. 2018-10-03 15:34:13 +13:00
Dan Marsden
20df09d3e9 Revert "Temporarly disabling one scenario test, see Issue #68."
This reverts commit 42fec9e752.
2018-10-03 15:28:03 +13:00
Dan Marsden
ff59dac023 Revert "Travis is freezing with a few behat tests which creates outages. It works fine locally both manually and with selenium. Ignoring tests and opening issue #77 to deal with it later as the code works fine."
This reverts commit fc2349f312.
2018-10-03 15:27:21 +13:00
adamlynam-catalyst
5aaf0ddeda Adding check for use of ip restrictions before warning (#134)
* Adding check for use of ip restrictions before warning about bootstrap.php not being included in config.php

* Replacing reference to same class with self
2018-10-03 15:22:31 +13:00
Dan Marsden
b3917b7b63 fix postgres version used in travis. 2018-10-03 15:20:26 +13:00
Dan Marsden
882f6a1afc Fix #124 use correct urls in redirects. 2018-10-03 15:16:36 +13:00
Dan Marsden
07e26e312c Convert deprecated pix_url calls. 2018-10-03 15:10:59 +13:00
Dan Marsden
92f7ec0541 add behat tests back to master branch. 2018-10-03 15:10:33 +13:00
Dan Marsden
84b35f01fa Master branch now requires 3.3 and higher so we can merge
version specific changes.
2018-10-03 15:00:20 +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
63 changed files with 1079 additions and 435 deletions

126
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,126 @@
name: Moodle plugin CI for master
# Controls when the action will run.
on: [push, pull_request]
jobs:
citest:
name: CI test
runs-on: 'ubuntu-latest'
services:
postgres:
image: postgres
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432
mariadb:
image: mariadb
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 3
strategy:
fail-fast: false
matrix:
database: ['mariadb']
moodle-branch: ['MOODLE_35_STABLE']
node: ['14.15.1']
php: ['7.1']
include:
- {moodle-branch: 'MOODLE_38_STABLE', php: '7.1', node: '14.15.1', database: 'mariadb'}
- {moodle-branch: 'MOODLE_38_STABLE', php: '7.4', node: '14.15.1', database: 'pgsql'}
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
path: plugin
- name: Install node ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pgsql, zip, gd, xmlrpc, soap
coverage: none
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8
- name: Install Moodle
run: |
mkdir ~/.npm-global
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
moodle-plugin-ci install -vvv --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
- name: Run phplint
if: ${{ always() }}
run: moodle-plugin-ci phplint
- name: Run phpcpd
if: ${{ always() }}
run: moodle-plugin-ci phpcpd || true
- name: Run phpmd
if: ${{ always() }}
run: moodle-plugin-ci phpmd
- name: Run codechecker
if: ${{ always() }}
run: moodle-plugin-ci codechecker
- name: Run validate
if: ${{ always() }}
run: moodle-plugin-ci validate
- name: Run savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints
- name: Run mustache
if: ${{ always() }}
run: moodle-plugin-ci phpcpd
- name: Run grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt
- name: Run phpdoc
if: ${{ always() }}
run: moodle-plugin-ci phpdoc
- name: Run phpunit
if: ${{ always() }}
run: moodle-plugin-ci phpunit
# - name: Run behat
# if: ${{ always() }}
# run: moodle-plugin-ci behat --profile chrome

View File

@@ -1,55 +0,0 @@
language: php
notifications:
email:
recipients:
- daniel.roperto@catalyst-au.net
cache:
directories:
- $HOME/.composer/cache
addons:
postgresql: "9.3"
php:
- 7.0
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
env: DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
- 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
- cd ../..
- composer selfupdate
- composer create-project -n --no-dev moodlerooms/moodle-plugin-ci ci ^1
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
install:
- moodle-plugin-ci install -vvv
script:
- moodle-plugin-ci validate
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
- moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
- moodle-plugin-ci csslint
- moodle-plugin-ci shifter
- moodle-plugin-ci jshint
- moodle-plugin-ci phpunit

View File

@@ -3,11 +3,12 @@
</a>
# Moodle Outage manager plugin
* [Version Support](#version-support)
* [What is this?](#what-is-this)
* [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)
@@ -39,6 +40,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.8 | MOODLE_38_STABLE | 7.1+ |
| Totara 11 to 12 | MOODLE_38_STABLE | 7.1+ |
| Moodle 3.9+ | MOODLE_39_STABLE | 7.2+ |
| Totara 13+ | MOODLE_39_STABLE | 7.2+ |
Screenshots
-----------
@@ -83,6 +94,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
----------
@@ -99,7 +124,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

@@ -58,7 +58,6 @@ class auth_plugin_outage extends auth_plugin_base {
/**
* Always returns false (password wrong or user does not exist).
*
* @inheritdoc PHPMD will not warn about unused parameters if overriding.
* @param string $username Not used in this plugin.
* @param string $password Not used in this plugin.
* @return bool False
@@ -66,11 +65,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();
}
}

View File

@@ -30,7 +30,9 @@
*/
// This call is required by Moodle, but this script should have been called by config.php anyway.
// @codingStandardsIgnoreStart
require_once(__DIR__.'/../../config.php');
// @codingStandardsIgnoreEnd
// We need the CFG->dataroot, if not set yet this script is called too early in config.php file.
if (!isset($CFG->dataroot)) {
@@ -40,13 +42,10 @@ 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();
@@ -70,9 +69,20 @@ 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['path'];
}
$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.
|| (defined('NO_AUTH_OUTAGE') && NO_AUTH_OUTAGE); // Allow any page should not be blocked by maintenance mode.
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.
@@ -85,5 +95,4 @@ $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);
}

View File

@@ -25,6 +25,12 @@
use auth_outage\dml\outagedb;
define('NO_MOODLE_COOKIES', true);
// @codingStandardsIgnoreStart
header('Cache-Control: public, max-age=10,s-maxage=10');
// @codingStandardsIgnoreEnd
define('NO_AUTH_OUTAGE', true);
require_once(__DIR__.'/../../config.php');
$active = outagedb::get_active();

View File

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

View File

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

View File

@@ -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']]);
}
/**

View File

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

View File

@@ -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']]);
}
/**

View File

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

View File

@@ -106,18 +106,18 @@ abstract class clibase {
* Generates all options (parameters) available for the CLI command.
* @return mixed[] Options.
*/
public abstract function generate_options();
abstract public function generate_options();
/**
* Generate all short forms for the available options.
* @return string[] Short form options.
*/
public abstract function generate_shortcuts();
abstract public function generate_shortcuts();
/**
* Executes the CLI script.
*/
public abstract function execute();
abstract public function execute();
/**
* Change session to admin user.
@@ -147,5 +147,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'));
}
}

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

View File

@@ -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),
@@ -88,7 +93,6 @@ class infopage {
/**
* Generates and outputs the HTML for the info page.
* @uses redirect
* @SuppressWarnings(PHPMD.UnusedLocalVariable) $viewbag is used inside 'require'.
*/
public function output() {
global $PAGE, $CFG, $OUTPUT;
@@ -103,7 +107,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 = [

View File

@@ -57,7 +57,7 @@ class maintenance_static_page {
if (is_null($outage)) {
$html = null;
} else if (PHPUNIT_TEST) {
} else if (PHPUNIT_TEST || defined('BEHAT_SITE_RUNNING')) {
$html = '<html></html>';
} else {
$data = maintenance_static_page_io::file_get_data(
@@ -122,6 +122,7 @@ class maintenance_static_page {
}
/**
* Gets generator io.
* @return maintenance_static_page_io
*/
public function get_io() {

View File

@@ -30,6 +30,7 @@ use coding_exception;
use DOMDocument;
use DOMElement;
use invalid_state_exception;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
@@ -94,6 +95,7 @@ class maintenance_static_page_generator {
}
/**
* Gets maintenance_static_page_io.
* @return maintenance_static_page_io
*/
public function get_io() {
@@ -127,7 +129,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));
@@ -137,6 +139,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.
*
@@ -147,15 +160,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;
}
@@ -179,10 +192,12 @@ class maintenance_static_page_generator {
foreach ($links as $link) {
$rel = $link->getAttribute("rel");
$href = $link->getAttribute("href");
if (($rel != 'shortcut icon') || ($href == '')) {
continue;
if (($rel == 'shortcut icon') && ($href != '')) {
if (!maintenance_static_page_io::is_url($href)) {
$href = (string) new moodle_url($href);
}
$link->setAttribute('href', $this->io->generate_file_url($href)); // Works for most image formats.
}
$link->setAttribute('href', $this->io->generate_file_url($href)); // Works for most image formats.
}
}
@@ -194,10 +209,12 @@ class maintenance_static_page_generator {
foreach ($links as $link) {
$src = $link->getAttribute("src");
if ($src == '') {
continue;
if ($src != '') {
if (!maintenance_static_page_io::is_url($src)) {
$src = (string) new moodle_url($src);
}
$link->setAttribute('src', $this->io->generate_file_url($src)); // Works for most image formats.
}
$link->setAttribute('src', $this->io->generate_file_url($src)); // Works for most image formats.
}
}
@@ -236,7 +253,7 @@ class maintenance_static_page_generator {
/**
* Fetches all elements based on the given selector.
*
* @param $selector
* @param string $selector element selector
*
* @return DOMElement[]
*/
@@ -254,7 +271,7 @@ class maintenance_static_page_generator {
/**
* Fetch all elements which contains the given class.
*
* @param $class
* @param string $class element class
*
* @return DOMElement[]
*/
@@ -270,6 +287,9 @@ class maintenance_static_page_generator {
return $matches;
}
/**
* Adds meta refresh to head element.
*/
private function add_meta_refresh() {
$meta = $this->dom->createElement('meta');
$meta->setAttribute('http-equiv', 'refresh');
@@ -282,6 +302,7 @@ class maintenance_static_page_generator {
}
/**
* Gets refresh time.
* @return int
*/
public function get_refresh_time() {
@@ -289,6 +310,7 @@ class maintenance_static_page_generator {
}
/**
* Sets refresh time.
* @param int $refreshtime
*/
public function set_refresh_time($refreshtime) {

View File

@@ -44,11 +44,13 @@ defined('MOODLE_INTERNAL') || die();
class maintenance_static_page_io {
/**
* Checks if the given string starts with "http://" or "https://".
* @param $url
* Also checks for "//" at the start of image, which setting_file_url still uses.
*
* @param string $url url string for check
* @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));
}
/**
@@ -80,6 +82,7 @@ class maintenance_static_page_io {
protected $preview = false;
/**
* Sets preview
* @param boolean $preview
*/
public function set_preview($preview) {
@@ -213,7 +216,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;

View File

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

View File

@@ -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,72 @@ require_once(__DIR__.'/../../lib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class outagelib {
/** Outage start. */
const OUTAGE_START = '<!-- OUTAGESTART -->';
/** Outage end. */
const OUTAGE_END = '<!-- OUTAGEEND -->';
/**
* @var bool Flags in the injection function was already called.
*/
private static $injectcalled = false;
/**
* Fetches page.
* @param string $file file to be fetched
*/
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, 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);
global $CFG;
require_once($CFG->libdir . '/filelib.php');
$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?
* @param int $time time for next 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 +143,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 +179,7 @@ class outagelib {
return [
'allowedips' => '',
'css' => '',
'default_time' => '',
'default_autostart' => '0',
'default_duration' => (string)(60 * 60),
'default_warning_duration' => (string)(60 * 60),
@@ -156,18 +191,30 @@ 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);
}
}
/**
* Checks if wwwroot accessible.
*/
private static function check_wwwroot_accessible() {
global $CFG;
$result = self::fetch_page($CFG->wwwroot);
@@ -246,13 +293,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 +315,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);
}
@@ -321,16 +372,14 @@ EOT;
* Generates a warning message in case the plugin is not active and configured.
*
* @return string
*
* @internal stdClass $CFG
* @internal bootstrap_renderer $OUTPUT
*/
public static function generate_plugin_configuration_warning() {
global $CFG, $OUTPUT;
global $CFG, $OUTPUT, $PAGE;
$message = [];
if (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded) {
if (trim(self::get_config()->allowedips) != ''
&& (!isset($CFG->auth_outage_bootstrap_loaded) || !$CFG->auth_outage_bootstrap_loaded)) {
$message[] = get_string('configurationwarning', 'auth_outage');
}
@@ -338,8 +387,10 @@ EOT;
$message[] = get_string('configurationdisabled', 'auth_outage');
}
if (!self::check_wwwroot_accessible()) {
$message[] = get_string('configurationinaccessiblewwwroot', 'auth_outage', ['wwwroot' => $CFG->wwwroot]);
if ($PAGE->pagetype == "admin-setting-auth_outage" || $PAGE->pagetype == "admin-setting-authsettingoutage") {
if (!self::check_wwwroot_accessible()) {
$message[] = get_string('configurationinaccessiblewwwroot', 'auth_outage', ['wwwroot' => $CFG->wwwroot]);
}
}
if (count($message) == 0) {

View File

@@ -48,6 +48,10 @@ class base_table extends flexible_table {
*/
private static $autoid = 0;
/**
* Creates start time string.
* @param string $starttime start time
*/
protected static function create_starttime_string($starttime) {
$absolute = userdate($starttime, get_string('datetimeformat', 'auth_outage'));
$relative = $starttime - time();
@@ -84,7 +88,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/info.php', ['id' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/preview'),
'src' => $OUTPUT->image_url('t/preview'),
'alt' => get_string('view'),
'class' => 'iconsmall',
@@ -100,7 +104,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/edit.php', ['edit' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/edit'),
'src' => $OUTPUT->image_url('t/edit'),
'alt' => get_string('edit'),
'class' => 'iconsmall',
]),
@@ -112,7 +116,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/edit.php', ['clone' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/copy'),
'src' => $OUTPUT->image_url('t/copy'),
'alt' => get_string('clone', 'auth_outage'),
'class' => 'iconsmall',
@@ -125,7 +129,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/finish.php', ['id' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/check'),
'src' => $OUTPUT->image_url('t/check'),
'alt' => get_string('finish', 'auth_outage'),
'class' => 'iconsmall',
]),
@@ -138,7 +142,7 @@ class base_table extends flexible_table {
$buttons .= html_writer::link(
new moodle_url('/auth/outage/delete.php', ['id' => $outage->id]),
html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/delete'),
'src' => $OUTPUT->image_url('t/delete'),
'alt' => get_string('delete'),
'class' => 'iconsmall',
]),

View File

@@ -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.
@@ -74,6 +66,13 @@ class renderer extends plugin_renderer_base {
* @return string The rendered view code.
*/
public function render_view($view, $viewbag = []) {
// Do not render if the request are from some layouts.
$excludelayout = ['embedded', 'popup', 'secure', 'maintenance'];
if (in_array($this->page->pagelayout, $excludelayout)) {
return '';
}
ob_start();
$this->output_view($view, $viewbag);
$html = ob_get_contents();
@@ -153,8 +152,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 +175,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->pix_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->pix_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 +193,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;
}
}

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

@@ -31,7 +31,6 @@ defined('MOODLE_INTERNAL') || die();
* @return bool result
* @throws moodle_exception
*/
function xmldb_auth_outage_uninstall() {
global $DB;

View File

@@ -33,13 +33,14 @@ 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()) {
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);
@@ -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();

View File

@@ -34,19 +34,21 @@ 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();
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(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();

View File

@@ -57,7 +57,6 @@ header('Accept-Ranges: none');
/**
* Callback used in bootstrap.
* @SupressWarnings(PHPMD)
*/
function auth_outage_bootstrap_callback() {
// Not using classes as classloader has not been initialized yet. Keep it minimalist.
@@ -74,7 +73,9 @@ function auth_outage_bootstrap_callback() {
exit(0);
}
// @codingStandardsIgnoreStart
require_once(__DIR__.'/../../config.php');
// @codingStandardsIgnoreEnd
// We should never reach here if config.php and auth/outage/bootstrap.php intercepted it correctly.
// If config.php did not execute the callback function we can use the debugging function here.

View File

@@ -33,13 +33,14 @@ 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()) {
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);
@@ -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();

View File

@@ -25,7 +25,9 @@
use auth_outage\local\controllers\infopage;
// @codingStandardsIgnoreStart
require_once(__DIR__.'/../../config.php');
// @codingStandardsIgnoreEnd
$info = new infopage();
$info->output();

View File

@@ -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.';
@@ -94,7 +105,7 @@ $string['allowedipshasmyip'] = 'Your IP (<i>{$a->ip}</i>) is in the list and you
$string['allowedipshasntmyip'] = 'Your IP (<i>{$a->ip}</i>) is not in the list and you will be blocked out during an outage.';
$string['allowedipsnoconfig'] = 'Your config.php does not have the extra setup to allow blocking via IP.<br />Please refer to our <a href="https://github.com/catalyst/moodle-auth_outage#installation" target="_blank">README.md</a> file for more information.';
$string['menusettings'] = 'Settings';
$string['menumanage'] = 'Manage';
$string['menumanage'] = 'Manage outages';
$string['messageoutagebackonline'] = 'We are back online!';
$string['messageoutagebackonlinedescription'] = 'You may resume browsing safely.';
$string['messageoutageongoing'] = 'Back online at {$a->stop}.';
@@ -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,3 +155,9 @@ $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)
*/
$string["privacy:no_data_reason"] = "The Outage authentication plugin does not store any personal data.";

46
lib.php
View File

@@ -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.
*
@@ -62,7 +41,7 @@ function auth_outage_outagelib_prepare_next_outage() {
*
* To keep it minimalist it was not added to the outagelib.php class.
*
* @param $file string Filename to fetch from sitedata
* @param string $file Filename to fetch from sitedata
* @return string|null Full path to the sitedata file or null if file is not valid.
*/
function auth_outage_get_climaintenance_resource_file($file) {
@@ -75,7 +54,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);
@@ -87,3 +66,24 @@ function auth_outage_get_climaintenance_resource_file($file) {
$realpath = realpath($resourcedir.'/'.$file);
return ($realpath == false) ? null : $realpath;
}
/**
* Display required icon for the calendar events.
*
* @return array
*/
function auth_outage_get_fontawesome_icon_map() {
return [
'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();
}

View File

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

View File

@@ -28,7 +28,9 @@
use auth_outage\dml\outagedb;
use auth_outage\local\controllers\maintenance_static_page;
// @codingStandardsIgnoreStart
require_once(__DIR__.'/../../config.php');
// @codingStandardsIgnoreEnd
$id = optional_param('id', null, PARAM_INT);
$outage = is_null($id) ? outagedb::get_next_starting() : outagedb::get_by_id($id);
if (is_null($outage)) {

View File

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

View File

@@ -39,7 +39,6 @@ require_once(__DIR__.'/../../../../lib/behat/behat_base.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class behat_auth_outage extends behat_base {
/**
@@ -155,6 +154,7 @@ class behat_auth_outage extends behat_base {
}
/**
* Check if an specific action is not visible.
* @Then /^I should see an empty settings text area "([^"]*)"$/
* @param string $name
*/
@@ -163,6 +163,7 @@ class behat_auth_outage extends behat_base {
}
/**
* Check if an specific action is not visible.
* @When /^I go to the "Outage Settings" page$/
*/
public function i_go_to_the_outage_settings_page() {
@@ -321,7 +322,7 @@ class behat_auth_outage extends behat_base {
}
if ($seconds >= 0) {
$seconds++; // Give one extra second for things to happen.
$this->getSession()->wait($seconds * 1000, false);
$this->getSession()->wait($seconds * 1000);
}
}

View File

@@ -11,9 +11,8 @@ Feature: Change the default settings
Given the authentication plugin "outage" is enabled
And I am an administrator
Scenario Outline: Check if I can save the default settings.
When I navigate to "Settings" node in "Site administration > Plugins > Authentication > Outage manager"
When I navigate to "Plugins > Authentication > Outage manager > Settings" in site administration
And I set the following fields to these values:
| s_auth_outage_default_autostart | <autostart> |
| s_auth_outage_default_warning_duration[v] | <warning> |

View File

@@ -0,0 +1,48 @@
@auth @auth_outage @javascript @_file_upload @_switch_iframe
Feature: Disable warning bar in embedded layout
In order alert users about an outage
As any user
I need to view the warning bar, but not in embedded layout
Background:
Given the authentication plugin "outage" is enabled
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "activities" exist:
| activity | name | intro | introformat | course | content | contentformat | idnumber |
| page | PageName1 | PageDesc1 | 1 | C1 | H5Ptest | 1 | 1 |
And the "displayh5p" filter is "on"
Scenario: Disable warning bar in embedded h5p in book activity
Given I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I add a "File" to section "1"
And I set the following fields to these values:
| Name | ipsumFile |
And I upload "h5p/tests/fixtures/ipsums.h5p" file to "Select files" filemanager
And I press "Save and return to course"
And I follow "PageName1"
And I navigate to "Edit settings" in current page administration
And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element"
And I click on "Browse repositories..." "button" in the "Insert H5P" "dialogue"
And I click on "Server files" "link" in the ".fp-repo-area" "css_element"
And I click on "ipsumFile (File)" "link"
And I click on "ipsums.h5p" "link"
And I click on "Select this file" "button"
And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue"
And I wait until the page is ready
And I click on "Save and display" "button"
When there is the following outage:
| warnbefore | startsin |
| 0 | 0 |
And I reload the page
Then I should see "Back online at" in the warning bar
And I should not see "Lorum ipsum"
# Switch to iframe created by filter
And I switch to "h5p-iframe" class iframe
And I should not see the warning bar
# Switch to iframe created by embed.php page
And I switch to "h5p-iframe" class iframe
And I should see "Lorum ipsum"
And I should not see the warning bar

View File

@@ -8,14 +8,11 @@ Feature: IP Blocker
- An ongoing outage does not block Moodle execution, although it can trigger maintenance mode.
- Maintenance mode completely blocks Moodle and can only be deactivated using the CLI.
Background:
Given the authentication plugin "outage" is enabled
Scenario: Default IP Whitelist Settings
Given I am an administrator
And I am on homepage
When I navigate to "Settings" node in "Site administration > Plugins > Authentication > Outage manager"
When I navigate to "Plugins > Authentication > Outage manager > Settings" in site administration
Then I should see "Allowed IP list"
And I should see an empty settings text area "allowedips"

View File

@@ -11,22 +11,19 @@ Feature: Manage outages
- finished is an outage that has explicitly been marked as finished.
- stopped is an outage that has already ended but not explicitly marked as finished.
Background: Always login as admin, enable the auth_outage plugin and go to the outage management page.
Given the authentication plugin "outage" is enabled
And I log in as "admin"
And I wait "1" seconds
Scenario: Check if I can navigate to management page.
Given I am on homepage
When I navigate to "Manage" node in "Site administration > Plugins > Authentication > Outage manager"
When I navigate to "Plugins > Authentication > Outage manager > Manage outages" in site administration
Then I should see "Planned outages"
And I should see "No outages found." in the "#section_planned_outages" "css_element"
And I should see "Outage history"
And I should see "No outages found." in the "#section_outage_history" "css_element"
Scenario Outline: Planned outages should include all outages not finished or stopped.
Given there is a "<type>" outage
When I am on Outage Management Page
@@ -40,7 +37,6 @@ Feature: Manage outages
| finished | outage_history |
| stopped | outage_history |
Scenario Outline: Planned and history outages have different actions.
Given there is a "<type>" outage
When I am on Outage Management Page
@@ -59,14 +55,12 @@ Feature: Manage outages
| finished | see | see | not see | not see | not see |
| stopped | see | see | not see | not see | not see |
# Scenario: Create an outage using defaults.
# Given I am on Outage Management Page
# When I press "Create outage"
# And I press "Save changes"
# And I should not see "No outages found." in the "#section_planned_outages" "css_element"
# And I should see "No outages found." in the "#section_outage_history" "css_element"
Scenario: Create an outage using defaults.
Given I am on Outage Management Page
When I press "Create outage"
And I press "Save changes"
And I should not see "No outages found." in the "#section_planned_outages" "css_element"
And I should see "No outages found." in the "#section_outage_history" "css_element"
Scenario: View an outage which should open in a new window or tab.
Given there is a "waiting" outage
@@ -75,29 +69,26 @@ Feature: Manage outages
Then I should be in a new window
And I should see "Example of waiting outage"
Scenario: Clone an outage.
Given there is a "waiting" outage
And I am on Outage Management Page
When I click on the "Clone" action button
Then I should see "Clone outage"
And I set the field "title" to "My cloned outage"
And I press "Save changes"
Then I should see "Example of waiting outage"
And I should see "My cloned outage"
# Scenario: Clone an outage.
# Given there is a "waiting" outage
# And I am on Outage Management Page
# When I click on the "Clone" action button
# Then I should see "Clone outage"
# And I set the field "title" to "My cloned outage"
# And I press "Save changes"
# Then I should see "Example of waiting outage"
# And I should see "My cloned outage"
# Scenario: Edit an outage.
# Given there is a "warning" outage
# And I am on Outage Management Page
# And I should see "Example of warning outage"
# When I click on the "Edit" action button
# Then I should see "Edit outage"
# And I set the field "title" to "My previous warning outage"
# And I press "Save changes"
# Then I should not see "Example of warning outage"
# And I should see "My previous warning outage"
Scenario: Edit an outage.
Given there is a "warning" outage
And I am on Outage Management Page
And I should see "Example of warning outage"
When I click on the "Edit" action button
Then I should see "Edit outage"
And I set the field "title" to "My previous warning outage"
And I press "Save changes"
Then I should not see "Example of warning outage"
And I should see "My previous warning outage"
Scenario: Delete an outage
Given there is a "warning" outage
@@ -109,7 +100,6 @@ Feature: Manage outages
Then I press "Delete"
And I should not see "Example of warning outage"
Scenario: Finish an outage
Given there is a "ongoing" outage
And I am on Outage Management Page

View File

@@ -11,46 +11,45 @@ Feature: Warning bar
- finished is an outage that has explicitly been marked as finished.
- stopped is an outage that has already ended but not explicitly marked as finished.
Background:
Given the authentication plugin "outage" is enabled
# Scenario: This is how an outage should happend without maintenance mode and manual finish.
# Given there is the following outage:
# | warnbefore | startsin | stopsafter |
# | 10 | 20 | 10 |
# When I am on homepage
# Then I should not see the warning bar
# When I wait until the outage warns
# And I reload the page
# Then I should see "Shutting down in" in the warning bar
# When I wait until the outage starts
# Then I should see "Back online at" in the warning bar
# When I wait until the outage stops
# Then I should see "We are back online!" in the warning bar
# When I reload the page
# Then I should not see the warning bar
Scenario Outline: Some stages should show its own warning message.
Given there is a "<type>" outage
When I am on homepage
Then I should see "<see>" in the warning bar
Examples:
| type | see |
| warning | Shutting down in |
| ongoing | Back online at |
Scenario Outline: Some stages should not have a warning bar.
Given there is a "<type>" outage
Scenario: This is how an outage should happen without maintenance mode and manual finish.
Given there is the following outage:
| warnbefore | startsin | stopsafter |
| 10 | 20 | 10 |
When I am on homepage
Then I should not see the warning bar
Examples:
| type |
| waiting |
| finished |
| stopped |
When I wait until the outage warns
And I reload the page
Then I should see "Shutting down in" in the warning bar
When I wait until the outage starts
And I reload the page
Then I should see "Back online at" in the warning bar
When I wait until the outage stops
Then I should see "We are back online!" in the warning bar
When I reload the page
Then I should not see the warning bar
#
#
# Scenario Outline: Some stages should show its own warning message.
# Given there is a "<type>" outage
# When I am on homepage
# Then I should see "<see>" in the warning bar
#
# Examples:
# | type | see |
# | warning | Shutting down in |
# | ongoing | Back online at |
#
#
# Scenario Outline: Some stages should not have a warning bar.
# Given there is a "<type>" outage
# When I am on homepage
# Then I should not see the warning bar
#
# Examples:
# | type |
# | waiting |
# | finished |
# | stopped |

View File

@@ -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();
/**
@@ -40,7 +42,6 @@ defined('MOODLE_INTERNAL') || die();
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
abstract class auth_outage_base_testcase extends advanced_testcase {
/**
@@ -64,14 +65,24 @@ abstract class auth_outage_base_testcase extends advanced_testcase {
}
}
public function setUp() {
/**
* Setup testcase.
*/
public function setUp(): void {
global $CFG;
parent::setUp();
$this->resetAfterTest(true);
}
// Do not use https.
$CFG->wwwroot = 'http://www.example.com/moodle';
$CFG->httpswwwroot = $CFG->wwwroot;
/**
* Tear down to restore the original DB reference.
*/
public function tearDown(): void {
global $DB;
foreach (outagedb::get_all() as $i => $outage) {
$DB->delete_records('auth_outage', ['id' => $outage->id]);
}
}
}

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

@@ -36,7 +36,6 @@ require_once(__DIR__.'/../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class outagedb_test extends auth_outage_base_testcase {
/**
@@ -79,7 +78,7 @@ class outagedb_test extends auth_outage_base_testcase {
/**
* Ensure DB tests run as admin.
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->setAdminUser();
}

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

@@ -198,6 +198,10 @@ class forms_test extends auth_outage_base_testcase {
];
}
/**
* Skip tests for moodle below 30.
* @param string $reason reason to be filled
*/
private function skip_because_moodle_is_below_30($reason = '') {
global $CFG;

View File

@@ -39,7 +39,6 @@ require_once(__DIR__.'/base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class installation_test extends auth_outage_base_testcase {
/**

View File

@@ -34,9 +34,11 @@ require_once(__DIR__.'/../../lib.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class lib_test extends auth_outage_base_testcase {
/**
* Test this plugin gets climaintenance resource file.
*/
public function test_auth_outage_get_climaintenance_resource_file_resolves_a_file() {
global $CFG;
$dir = $CFG->dataroot.'/auth_outage/climaintenance';
@@ -88,6 +90,9 @@ class lib_test extends auth_outage_base_testcase {
self::assertSame($realfile, $actual);
}
/**
* Test this plugin gets climaintenance resource file and prevents path traversal attack.
*/
public function test_auth_outage_get_climaintenance_resource_file_prevent_path_traversal() {
global $CFG;

View File

@@ -36,7 +36,6 @@ require_once(__DIR__.'/cli_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class cli_test extends auth_outage_cli_testcase {
/**

View File

@@ -35,13 +35,12 @@ require_once(__DIR__.'/../../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
abstract class auth_outage_cli_testcase extends auth_outage_base_testcase {
/**
* Always enable the auth outage plugin, resets after test and set no parameters.
*/
public function setUp() {
public function setUp(): void {
global $CFG;
// PHPUnit does not load config.php file.

View File

@@ -38,7 +38,6 @@ require_once(__DIR__.'/cli_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class create_test extends auth_outage_cli_testcase {
/**

View File

@@ -38,7 +38,6 @@ require_once(__DIR__.'/cli_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class finish_test extends auth_outage_cli_testcase {
/**

View File

@@ -38,7 +38,6 @@ require_once(__DIR__.'/cli_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class waitforit_test extends auth_outage_cli_testcase {
/**

View File

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

View File

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

View File

@@ -36,7 +36,6 @@ require_once(__DIR__.'/../../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class infopagecontroller_test extends auth_outage_base_testcase {
/**
@@ -106,4 +105,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);
}
}

View File

@@ -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();
@@ -37,10 +38,11 @@ require_once(__DIR__.'/../../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
* @SuppressWarnings(methods) Allow as many methods as needed.
*/
class maintenance_static_page_test extends auth_outage_base_testcase {
/**
* Test template file.
*/
public function test_templatefile() {
global $CFG;
$page = maintenance_static_page::create_from_html('<html></html>');
@@ -50,6 +52,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
$page->get_io()->get_template_file());
}
/**
* Test resources folder.
*/
public function test_resourcesfolder() {
global $CFG;
$page = maintenance_static_page::create_from_html('<html></html>');
@@ -58,10 +63,16 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertSame($CFG->dataroot.'/auth_outage/climaintenance/preview', $page->get_io()->get_resources_folder());
}
/**
* Test create from outage.
*/
public function test_createfromoutage() {
// How to fetch a page from PHPUnit environment?
}
/**
* Test create from HTML.
*/
public function test_createfromhtml() {
$html = "<!DOCTYPE html>\n<html><head><title>Title</title></head><body>Content</body></html>";
$expected = "<!DOCTYPE html>\n<html><head><title>Title</title><meta http-equiv=\"refresh\" content=\"300\">".
@@ -69,6 +80,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertSame($expected, $this->generated_page_html($html));
}
/**
* Test remove script tags.
*/
public function test_removescripttags() {
$html = "<!DOCTYPE html>\n".
'<html><head><script type="text/javascript" src="http://xyz"></script><title>Title</title></head>'.
@@ -79,6 +93,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertNotContains('<script', $generated);
}
/**
* Test remove script tags.
*/
public function test_updatelinkstylesheet() {
$localcsslink = $this->get_fixture_path('simple.css');
$externalcsslink = 'http://google.com/coolstuff.css';
@@ -87,11 +104,14 @@ 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);
}
/**
* Test update link style sheet urls.
*/
public function test_updatelinkstylesheet_urls() {
$localcsslink = $this->get_fixture_path('withurls.css');
$html = "<!DOCTYPE html>\n".
@@ -101,12 +121,15 @@ 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');
}
/**
* Test update link style sheet urls quoted.
*/
public function test_updatelinkstylesheet_urls_quoted() {
$localcsslink = $this->get_fixture_path('withurls-quoted.css');
$html = "<!DOCTYPE html>\n".
@@ -116,12 +139,15 @@ 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');
}
/**
* Test update link style sheet urls with sub dir.
*/
public function test_updatelinkstylesheet_urls_subdir() {
$localcsslink = $this->get_fixture_path('subdir/withurls-subdir.css');
$html = "<!DOCTYPE html>\n".
@@ -137,6 +163,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertFileExists($page->get_io()->get_resources_folder().'/a02a8a442fa82d5205ffb24722d9df7f35161f56.dGV4dC9wbGFpbg');
}
/**
* Test update images to file.php style link.
*/
public function test_updateimages() {
$localimglink = $this->get_fixture_path('catalyst.png');
$externalimglink = 'http://google.com/coolstyle.css';
@@ -145,11 +174,14 @@ 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);
}
/**
* Test update favicon to file.php style link.
*/
public function test_updatelinkfavicon() {
$link = $this->get_fixture_path('catalyst.png');
$html = "<!DOCTYPE html>\n".
@@ -158,9 +190,12 @@ 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);
}
/**
* Test update preview path to file.php style link.
*/
public function test_previewpath() {
$link = $this->get_fixture_path('catalyst.png');
$html = "<!DOCTYPE html>\n".
@@ -172,7 +207,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);
}
/**
@@ -211,6 +246,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertFileNotExists($file);
}
/**
* Tests created file.
*/
public function test_createdfile() {
global $CFG;
@@ -234,7 +272,7 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
/**
* Gets a fixture file for this test case.
*
* @param $file
* @param string $file file name
*
* @return string
*/
@@ -242,30 +280,59 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
return (string)new moodle_url('/auth/outage/tests/phpunit/local/controllers/fixtures/'.$file);
}
/**
* Test saving empty string for template file.
*/
public function test_invalid_string_saving_template_empty() {
$io = new maintenance_static_page_io();
$this->set_expected_exception('coding_exception');
$io->save_template_file('');
}
/**
* Test saving non string for template file.
*/
public function test_invalid_string_saving_template_nostring() {
$io = new maintenance_static_page_io();
$this->set_expected_exception('coding_exception');
$io->save_template_file(50);
}
/**
* Test get url for file.
*/
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() {
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'));
/**
* Return array of url data provider and true or false.
*/
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']
];
}
/**
* Test if it is url
* @dataProvider is_url_dataprovider
* @param string $result expected result
* @param string $url url to be checked
*/
public function test_is_url($result, $url) {
self::assertEquals($result, maintenance_static_page_io::is_url($url));
}
/**
* Test file get_data.
*/
public function test_file_get_data() {
$file = __DIR__.'/fixtures/catalyst.png';
$found = maintenance_static_page_io::file_get_data($file);
@@ -273,6 +340,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertSame('image/png', $found['mime']);
}
/**
* Test invalid file get_data.
*/
public function test_file_get_data_invalidfile() {
$found = maintenance_static_page_io::file_get_data(__DIR__.'/fixtures/invalidfile');
self::assertSame('', $found['contents']);
@@ -281,11 +351,17 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
phpunit_util::reset_debugging();
}
/**
* Test invalid file get_data.
*/
public function test_file_get_data_invalidfilename() {
$this->set_expected_exception('coding_exception');
maintenance_static_page_io::file_get_data(200);
}
/**
* Test remove css selector.
*/
public function test_remove_css_selector() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -298,6 +374,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
* Test remove css selector id.
*/
public function test_remove_css_selector_id() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -310,6 +389,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
* Test remove css selector with multi lines.
*/
public function test_remove_css_selector_with_multiline() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -326,6 +408,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
* Test remove css selector needs trim.
*/
public function test_remove_css_selector_needing_trim() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -342,6 +427,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
* Test remove css selector with empty line.
*/
public function test_remove_css_selector_with_empty_line() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -358,6 +446,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertNotContains('Goodbye cruel world', $generated);
}
/**
* Test remove css selector with invalid id.
*/
public function test_remove_css_selector_with_invalid_id() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -370,6 +461,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertContains('Goodbye cruel world', $generated);
}
/**
* Test meta refresh 5 minutes.
*/
public function test_meta_refresh_5minutes() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -381,6 +475,9 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertContains('<meta http-equiv="refresh" content="300">', $generated);
}
/**
* Test meta refresh maximum 5 minutes.
*/
public function test_meta_refresh_maximum_5seconds() {
$this->resetAfterTest(true);
$html = "<!DOCTYPE html>\n".
@@ -395,4 +492,45 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertContains('<meta http-equiv="refresh" content="5">', $generated);
}
/**
* Data provider for test_get_urls_from_stylesheet
* @return array
*/
public function test_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 test_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]);
}
}

View File

@@ -35,7 +35,6 @@ require_once(__DIR__.'/../base_testcase.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @SuppressWarnings(public) Allow as many methods as needed.
*/
class outage_test extends auth_outage_base_testcase {
/**

View File

@@ -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.
@@ -39,9 +40,8 @@ require_once($CFG->libdir.'/adminlib.php');
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @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 +81,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,18 +95,18 @@ 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();
// Get full header to avoid interactions with other single inject plugins.
$header1 = $OUTPUT->standard_top_of_body_html();
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));
$this->resetDebugging(); // Function pix_url deprecated in Moodle 33+.
// Should not inject more than once.
$size = strlen($OUTPUT->standard_top_of_body_html());
self::assertSame($size, strlen($OUTPUT->standard_top_of_body_html()));
// Check styles aren't reinjected.
self::assertNotContains('<style>', $OUTPUT->standard_top_of_body_html());
}
/**
@@ -114,7 +114,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();
}
@@ -136,14 +137,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);
$this->resetDebugging(); // Function pix_url deprecated in Moodle 33+.
outagelib::reset_injectcalled();
$header = outagelib::get_inject_code();
self::assertContains('<style>', $header);
self::assertContains('<script>', $header);
}
/**
@@ -151,11 +151,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);
}
/**
@@ -175,18 +176,20 @@ 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();
outagelib::get_inject_code();
}
/**
@@ -276,24 +279,30 @@ 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);
}
/**
* Test create maintenance php code
*/
public function test_createmaintenancephpcode() {
$expected = <<<'EOT'
<?php
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');
@@ -307,6 +316,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);
}
@@ -324,6 +334,9 @@ EOT;
self::assertSame($expected, $found);
}
/**
* Test create maintenance php code without age
*/
public function test_createmaintenancephpcode_withoutage() {
global $CFG;
$this->resetAfterTest(true);
@@ -333,6 +346,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');
@@ -345,6 +361,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);
}
@@ -371,6 +388,9 @@ EOT;
self::assertSame($found, $expected);
}
/**
* Test create maintenance php code without IPs
*/
public function test_createmaintenancephpcode_withoutips() {
global $CFG;
$this->resetAfterTest(true);
@@ -387,6 +407,9 @@ EOT;
self::assertFileNotExists($file);
}
/**
* Test create maintenance php code without outage
*/
public function test_createmaintenancephpcode_withoutoutage() {
global $CFG;
$file = $CFG->dataroot.'/climaintenance.php';
@@ -494,19 +517,20 @@ 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);
$this->resetDebugging(); // Function pix_url deprecated in Moodle 33+.
$header = outagelib::get_inject_code();
self::assertNotEmpty($header);
}
/**
* Creates outage for tests.
*/
private function create_outage() {
$this->resetAfterTest(true);
self::setAdminUser();

View File

@@ -28,7 +28,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$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->version = 2021032500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2021032500; // Human-readable release information.
$plugin->requires = 2017051500; // Requires 3.3 and higher.
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!

View File

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

View File

@@ -7,7 +7,7 @@ If you need to make changes here, remember to update your settings inside Moodle
background-color: red;
box-sizing: content-box;
color: white;
height: 90px;
height: 100px;
left: 0;
padding: 0;
position: fixed;
@@ -19,47 +19,51 @@ If you need to make changes here, remember to update your settings inside Moodle
}
#auth_outage_warningbar_box.auth_outage_warning_period {
background: repeating-linear-gradient(
background:
repeating-linear-gradient(
-45deg,
#ff7c00,
#ff7c00 10px,
#ff6c00 10px,
#ff6c00 20px
);
);
background-color: #ff7c00;
}
#auth_outage_warningbar_box.auth_outage_imminent_period {
background: repeating-linear-gradient(
background:
repeating-linear-gradient(
-45deg,
#a000a0,
#a000a0 10px,
#800080 10px,
#800080 20px
);
);
background-color: #800080;
}
#auth_outage_warningbar_box.auth_outage_ongoing_period {
background: repeating-linear-gradient(
background:
repeating-linear-gradient(
-45deg,
#ee0000,
#ee0000 10px,
#cc0000 10px,
#cc0000 20px
);
background-color: #ee0000;
#e00,
#e00 10px,
#c00 10px,
#c00 20px
);
background-color: #e00;
}
#auth_outage_warningbar_box.auth_outage_finished_period {
background: repeating-linear-gradient(
background:
repeating-linear-gradient(
-45deg,
#00aa00,
#00aa00 10px,
#009900 10px,
#009900 20px
);
background-color: #009900;
#0a0,
#0a0 10px,
#090 10px,
#090 20px
);
background-color: #090;
}
.auth_outage_warningbar_center {
@@ -95,10 +99,30 @@ a.auth_outage_warningbar_box_finish:hover {
background-color: black;
}
.navbar.navbar-fixed-top {
top: 90px;
body.auth_outage #nav-drawer {
top: 150px;
}
.auth_outage_warningbar_spacer {
height: 80px;
body.auth_outage nav.fixed-top.navbar {
top: 100px;
}
body.auth_outage #page {
margin-top: 150px;
}
body.auth_outage.path-mod-assign [data-region="grading-navigation-panel"] {
top: 100px;
}
body.auth_outage.path-mod-assign [data-region="grade-panel"] {
top: 185px;
}
body.auth_outage .layout.fullscreen {
top: 150px;
}
body.auth_outage .modal-dialog {
margin: calc(150px + 1.75rem) auto;
}

View File

@@ -114,8 +114,10 @@ var authOutageWarningBar = {
seconds2hms: function(seconds) {
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
seconds %= 60;
minutes %= 60;
hours %= 24;
// Cross-browser simple solution for padding zeroes.
if (minutes < 10) {
minutes = "0" + minutes;
@@ -123,6 +125,15 @@ var authOutageWarningBar = {
if (seconds < 10) {
seconds = "0" + seconds;
}
return hours + ':' + minutes + ':' + seconds;
if (days > 0) {
if (days > 1) {
days = days + ' days ';
} else {
days = days + ' day ';
}
} else {
days = '';
}
return days + hours + ':' + minutes + ':' + seconds;
}
};

View File

@@ -48,7 +48,7 @@ if (!$viewbag['static']) {
if (is_siteadmin()) {
$url = new moodle_url('/auth/outage/finish.php', ['id' => $viewbag['outage']->id]);
$text = html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/check'),
'src' => $OUTPUT->image_url('t/check'),
'alt' => get_string('finish', 'auth_outage'),
'class' => 'iconsmall',
]).' '.get_string('finish', 'auth_outage');
@@ -74,8 +74,6 @@ if (!$viewbag['static']) {
</div>
</div>
<div class="auth_outage_warningbar_spacer">&nbsp;</div>
<?php if (!$viewbag['static']): ?>
<script>
document.body.className += ' auth_outage';