2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2009-08-20 22:37:17 +00:00
|
|
|
/*
|
2008-04-11 06:12:07 +00:00
|
|
|
* Name: Downtime
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
2012-02-10 04:04:37 +00:00
|
|
|
* Link: http://code.shishnet.org/shimmie2/
|
2008-04-11 06:12:07 +00:00
|
|
|
* License: GPLv2
|
|
|
|
* Description: Show a "down for maintenance" page
|
2009-08-20 22:37:17 +00:00
|
|
|
* Documentation:
|
|
|
|
* Once installed there will be some more options on the config page --
|
|
|
|
* Ticking "disable non-admin access" will mean that regular and anonymous
|
|
|
|
* users will be blocked from accessing the site, only able to view the
|
|
|
|
* message specified in the box.
|
2008-04-11 06:12:07 +00:00
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2012-02-08 12:07:01 +00:00
|
|
|
class Downtime extends Extension {
|
2012-01-27 18:16:46 +00:00
|
|
|
public function get_priority() {return 10;}
|
|
|
|
|
2012-02-10 04:04:37 +00:00
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event) {
|
2012-01-30 02:24:17 +00:00
|
|
|
$sb = new SetupBlock("Downtime");
|
|
|
|
$sb->add_bool_option("downtime", "Disable non-admin access: ");
|
|
|
|
$sb->add_longtext_option("downtime_message", "<br>");
|
|
|
|
$event->panel->add_block($sb);
|
|
|
|
}
|
2007-06-30 01:19:11 +00:00
|
|
|
|
2012-02-10 04:04:37 +00:00
|
|
|
public function onPageRequest(PageRequestEvent $event) {
|
2012-01-30 02:24:17 +00:00
|
|
|
global $config, $page, $user;
|
2007-08-24 22:29:34 +00:00
|
|
|
|
2012-01-30 02:24:17 +00:00
|
|
|
if($config->get_bool("downtime")) {
|
2012-03-31 11:28:34 +00:00
|
|
|
if(!$user->can("ignore_downtime") && !$this->is_safe_page($event)) {
|
2012-01-30 02:24:17 +00:00
|
|
|
$msg = $config->get_string("downtime_message");
|
|
|
|
$this->theme->display_message($msg);
|
2015-08-23 15:09:52 +00:00
|
|
|
if(!defined("UNITTEST")) { // hax D:
|
|
|
|
header("HTTP/1.0 {$page->code} Downtime");
|
|
|
|
print($page->data);
|
|
|
|
exit;
|
|
|
|
}
|
2007-04-21 13:55:11 +00:00
|
|
|
}
|
2012-01-30 02:24:17 +00:00
|
|
|
$this->theme->display_notification($page);
|
2007-04-21 13:55:11 +00:00
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-06-30 01:19:11 +00:00
|
|
|
|
2009-01-04 16:30:46 +00:00
|
|
|
private function is_safe_page(PageRequestEvent $event) {
|
2008-09-06 17:48:03 +00:00
|
|
|
if($event->page_matches("user_admin/login")) return true;
|
2007-04-16 11:58:25 +00:00
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|