2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2008-04-11 06:12:07 +00:00
|
|
|
/**
|
|
|
|
* Name: Downtime
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* License: GPLv2
|
|
|
|
* Description: Show a "down for maintenance" page
|
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
|
|
|
|
class Downtime extends Extension {
|
2007-06-30 01:19:11 +00:00
|
|
|
var $theme;
|
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
public function receive_event($event) {
|
2007-06-30 01:19:11 +00:00
|
|
|
if(is_null($this->theme)) $this->theme = get_theme_object("downtime", "DowntimeTheme");
|
|
|
|
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof SetupBuildingEvent) {
|
2007-04-16 11:58:25 +00:00
|
|
|
$sb = new SetupBlock("Downtime");
|
2007-05-08 20:36:02 +00:00
|
|
|
$sb->add_bool_option("downtime", "Disable non-admin access: ");
|
|
|
|
$sb->add_longtext_option("downtime_message", "<br>");
|
2007-06-30 01:19:11 +00:00
|
|
|
$event->panel->add_block($sb);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-08-24 22:29:34 +00:00
|
|
|
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof PageRequestEvent) {
|
2007-04-21 13:55:11 +00:00
|
|
|
global $config;
|
|
|
|
if($config->get_bool("downtime")) {
|
2007-08-27 23:43:20 +00:00
|
|
|
$this->check_downtime($event);
|
2007-07-17 07:45:35 +00:00
|
|
|
$this->theme->display_notification($event->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
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
private function check_downtime($event) {
|
|
|
|
global $user;
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if($config->get_bool("downtime") && !$user->is_admin() &&
|
2008-08-22 09:41:30 +00:00
|
|
|
($event instanceof PageRequestEvent) && !$this->is_safe_page($event)) {
|
2007-04-16 11:58:25 +00:00
|
|
|
$msg = $config->get_string("downtime_message");
|
2007-06-30 01:19:11 +00:00
|
|
|
$this->theme->display_message($msg);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function is_safe_page($event) {
|
2007-07-27 13:05:48 +00:00
|
|
|
if($event->page_name == "user_admin" && $event->get_arg(0) == "login") return true;
|
2007-04-16 11:58:25 +00:00
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_event_listener(new Downtime(), 10);
|
|
|
|
?>
|