store enabled exts in a config file, rather than moving directories around
This commit is contained in:
43
ext/downtime/main.php
Normal file
43
ext/downtime/main.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* Name: Downtime
|
||||
* Author: Shish <webmaster@shishnet.org>
|
||||
* Link: http://code.shishnet.org/shimmie2/
|
||||
* License: GPLv2
|
||||
* Description: Show a "down for maintenance" page
|
||||
* 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.
|
||||
*/
|
||||
|
||||
class Downtime extends Extension {
|
||||
public function get_priority() {return 10;}
|
||||
|
||||
public function onSetupBuilding(SetupBuildingEvent $event) {
|
||||
$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);
|
||||
}
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event) {
|
||||
global $config, $page, $user;
|
||||
|
||||
if($config->get_bool("downtime")) {
|
||||
if(!$user->can("ignore_downtime") && !$this->is_safe_page($event)) {
|
||||
$msg = $config->get_string("downtime_message");
|
||||
$this->theme->display_message($msg);
|
||||
exit;
|
||||
}
|
||||
$this->theme->display_notification($page);
|
||||
}
|
||||
}
|
||||
|
||||
private function is_safe_page(PageRequestEvent $event) {
|
||||
if($event->page_matches("user_admin/login")) return true;
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
?>
|
10
ext/downtime/style.css
Normal file
10
ext/downtime/style.css
Normal file
@@ -0,0 +1,10 @@
|
||||
#downtime #message, #downtime #login {
|
||||
text-align: center;
|
||||
}
|
||||
#downtime H3 {
|
||||
margin-top: 32px;
|
||||
}
|
||||
#downtime #login_table {
|
||||
margin: auto;
|
||||
}
|
||||
|
23
ext/downtime/test.php
Normal file
23
ext/downtime/test.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
class DowntimeTest extends SCoreWebTestCase {
|
||||
function testDowntime() {
|
||||
$this->log_in_as_admin();
|
||||
$this->get_page("setup");
|
||||
$this->set_field("_config_downtime", true);
|
||||
$this->set_field("_config_downtime_message", "brb, unit testing");
|
||||
$this->click("Save Settings");
|
||||
$this->assert_text("DOWNTIME MODE IS ON!");
|
||||
$this->log_out();
|
||||
|
||||
$this->get_page("post/list");
|
||||
$this->assert_text("brb, unit testing");
|
||||
|
||||
$this->log_in_as_admin();
|
||||
$this->get_page("setup");
|
||||
$this->set_field("_config_downtime", false);
|
||||
$this->click("Save Settings");
|
||||
$this->assert_no_text("DOWNTIME MODE IS ON!");
|
||||
$this->log_out();
|
||||
}
|
||||
}
|
||||
?>
|
58
ext/downtime/theme.php
Normal file
58
ext/downtime/theme.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
class DowntimeTheme extends Themelet {
|
||||
/**
|
||||
* Show the admin that downtime mode is enabled
|
||||
*/
|
||||
public function display_notification(Page $page) {
|
||||
$page->add_block(new Block("Downtime",
|
||||
"<span style='font-size: 1.5em'><b><center>DOWNTIME MODE IS ON!</center></b></span>", "left", 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display $message and exit
|
||||
*/
|
||||
public function display_message(/*string*/ $message) {
|
||||
global $config, $user;
|
||||
$theme_name = $config->get_string('theme');
|
||||
$data_href = get_base_href();
|
||||
$login_link = make_link("user_admin/login");
|
||||
header("HTTP/1.0 503 Service Temporarily Unavailable");
|
||||
|
||||
$auth = $user->get_auth_html();
|
||||
print <<<EOD
|
||||
<html>
|
||||
<head>
|
||||
<title>Downtime</title>
|
||||
<link rel="stylesheet" href="$data_href/themes/$theme_name/style.css" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="downtime">
|
||||
<h1><center>Down for Maintenance</center></h1>
|
||||
<div id="message">
|
||||
$message
|
||||
</div>
|
||||
<h3>Admin Login</h3>
|
||||
<div id="login">
|
||||
<form action="$login_link" method="POST">
|
||||
$auth
|
||||
<table id="login_table" summary="Login Form">
|
||||
<tr>
|
||||
<td width="70"><label for="user">Name</label></td>
|
||||
<td width="70"><input id="user" type="text" name="user"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="pass">Password</label></td>
|
||||
<td><input id="pass" type="password" name="pass"></td>
|
||||
</tr>
|
||||
<tr><td colspan="2"><input type="submit" value="Log In"></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user