1fe43b8d7a
git-svn-id: file:///home/shish/svn/shimmie2/trunk@148 7f39781d-f577-437e-ae19-be835c7a54ca
58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
class Downtime extends Extension {
|
|
// event handler {{{
|
|
public function receive_event($event) {
|
|
$this->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", "<br>");
|
|
$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", "<span style='font-size: 1.5em'><b>DOWNTIME MODE IS ON!</b></span>"), 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 <<<EOD
|
|
<html>
|
|
<head>
|
|
<title>Downtime</title>
|
|
</head>
|
|
<body>
|
|
$msg
|
|
</body>
|
|
</html>
|
|
EOD;
|
|
exit;
|
|
}
|
|
}
|
|
|
|
private function is_safe_page($event) {
|
|
if($event->page == "user" && $event->get_arg(0) == "login") return true;
|
|
else return false;
|
|
}
|
|
// }}}
|
|
}
|
|
add_event_listener(new Downtime(), 10);
|
|
?>
|