This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/downtime/main.php

51 lines
1.3 KiB
PHP
Raw Normal View History

2021-12-14 18:32:47 +00:00
<?php
declare(strict_types=1);
namespace Shimmie2;
class Downtime extends Extension
{
2020-02-04 00:46:36 +00:00
/** @var DowntimeTheme */
2023-06-27 14:56:49 +00:00
protected Themelet $theme;
2020-02-04 00:46:36 +00:00
public function get_priority(): int
{
return 10;
}
public function onSetupBuilding(SetupBuildingEvent $event): void
{
$sb = $event->panel->create_new_block("Downtime");
$sb->add_bool_option("downtime", "Disable non-admin access: ");
$sb->add_longtext_option("downtime_message", "<br>");
}
public function onPageRequest(PageRequestEvent $event): void
{
global $config, $page, $user;
if ($config->get_bool("downtime")) {
2019-07-09 14:10:21 +00:00
if (!$user->can(Permissions::IGNORE_DOWNTIME) && !$this->is_safe_page($event)) {
$msg = $config->get_string("downtime_message");
$this->theme->display_message($msg);
if (!defined("UNITTEST")) { // hax D:
2023-02-07 13:56:44 +00:00
header("HTTP/1.1 {$page->code} Downtime");
print($page->data);
exit;
}
}
$this->theme->display_notification($page);
}
}
private function is_safe_page(PageRequestEvent $event): bool
{
if ($event->page_matches("user_admin/login")) {
return true;
} else {
return false;
}
}
}