check_downtime($event);
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("Downtime");
$sb->add_bool_option("downtime", "Disable non-admin access: ");
$sb->add_longtext_option("downtime_message", "
");
$event->panel->add_main_block($sb);
}
if(is_a($event, 'ConfigSaveEvent')) {
$event->config->set_bool_from_post("downtime");
$event->config->set_string_from_post("downtime_message");
}
if(is_a($event, 'PageRequestEvent')) {
global $config;
if($config->get_bool("downtime")) {
global $page;
$page->add_side_block(new Block("Downtime", "DOWNTIME MODE IS ON!"), 0);
}
}
}
// }}}
// do things {{{
private function check_downtime($event) {
global $user;
global $config;
if($config->get_bool("downtime") && !$user->is_admin() &&
is_a($event, 'PageRequestEvent') && !$this->is_safe_page($event)) {
$msg = $config->get_string("downtime_message");
header("HTTP/1.0 503 Service Temporarily Unavailable");
print <<
Downtime
$msg