summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Http/Controllers/AdminController.php1
-rw-r--r--app/Http/Middleware/CheckForMaintenanceMode.php48
-rw-r--r--includes/session.php11
-rw-r--r--index.php5
-rw-r--r--resources/views/layouts/offline.php66
-rw-r--r--site-offline.php74
6 files changed, 121 insertions, 84 deletions
diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php
index e4ad0f118c..7aa99714cc 100644
--- a/app/Http/Controllers/AdminController.php
+++ b/app/Http/Controllers/AdminController.php
@@ -500,6 +500,7 @@ class AdminController extends AbstractBaseController {
WT_ROOT . 'reportengine.php',
WT_ROOT . 'search.php',
WT_ROOT . 'search_advanced.php',
+ WT_ROOT . 'site-offline.php',
WT_ROOT . 'site-unavailable.php',
WT_ROOT . 'sourcelist.php',
WT_ROOT . 'statistics.php',
diff --git a/app/Http/Middleware/CheckForMaintenanceMode.php b/app/Http/Middleware/CheckForMaintenanceMode.php
new file mode 100644
index 0000000000..9097a862be
--- /dev/null
+++ b/app/Http/Middleware/CheckForMaintenanceMode.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2018 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\Middleware;
+
+use Closure;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * Middleware to check whether the site is offline.
+ */
+class CheckForMaintenanceMode {
+ /**
+ * @param Request $request
+ * @param Closure $next
+ *
+ * @return Response
+ */
+ public function handle(Request $request, Closure $next): Response {
+ $file = WT_ROOT . 'data/offline.txt';
+
+ if (file_exists($file)) {
+ $html = view('layouts/offline', [
+ 'message' => file_get_contents($file),
+ 'url' => $request->getRequestUri(),
+ ]);
+
+ return new Response($html, Response::HTTP_SERVICE_UNAVAILABLE);
+ }
+
+ return $next($request);
+ }
+}
diff --git a/includes/session.php b/includes/session.php
index d7fa0a6cb7..ac60848a29 100644
--- a/includes/session.php
+++ b/includes/session.php
@@ -122,13 +122,7 @@ set_error_handler(function ($errno, $errstr, $errfile, $errline) {
DebugBar::startMeasure('init database');
// Load our configuration file, so we can connect to the database
-if (file_exists(WT_ROOT . 'data/config.ini.php')) {
- // Down for maintenance?
- if (file_exists(WT_ROOT . 'data/offline.txt')) {
- header('Location: site-offline.php');
- exit;
- }
-} else {
+if (!file_exists(WT_ROOT . 'data/config.ini.php')) {
// No config file. Set one up.
$url = Html::url('setup.php', ['route' => 'setup']);
$response = new RedirectResponse($url);
@@ -210,10 +204,9 @@ if (!Session::get('initiated')) {
DebugBar::startMeasure('init tree');
// Set the tree for the page; (1) the request, (2) the session, (3) the site default, (4) any tree
-foreach ([Filter::post('ged'), Filter::get('ged'), Session::get('GEDCOM'), Site::getPreference('DEFAULT_GEDCOM')] as $tree_name) {
+foreach ([Filter::post('ged'), Filter::get('ged'), Site::getPreference('DEFAULT_GEDCOM')] as $tree_name) {
$WT_TREE = Tree::findByName($tree_name);
if ($WT_TREE) {
- Session::put('GEDCOM', $tree_name);
break;
}
}
diff --git a/index.php b/index.php
index 6d686fe014..dc56d2a791 100644
--- a/index.php
+++ b/index.php
@@ -20,6 +20,7 @@ namespace Fisharebest\Webtrees;
use Closure;
use Fisharebest\Webtrees\Http\Controllers\ErrorController;
use Fisharebest\Webtrees\Http\Middleware\CheckCsrf;
+use Fisharebest\Webtrees\Http\Middleware\CheckForMaintenanceMode;
use Fisharebest\Webtrees\Http\Middleware\UseTransaction;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -75,7 +76,9 @@ try {
// generate the response - which includes (and stops) the timer
DebugBar::startMeasure('controller_action', $controller_action);
- $middleware_stack = [];
+ $middleware_stack = [
+ new CheckForMaintenanceMode,
+ ];
if ($method === 'POST') {
$middleware_stack[] = new UseTransaction;
diff --git a/resources/views/layouts/offline.php b/resources/views/layouts/offline.php
new file mode 100644
index 0000000000..2e03d4da53
--- /dev/null
+++ b/resources/views/layouts/offline.php
@@ -0,0 +1,66 @@
+<?php use Fisharebest\Webtrees\I18N; ?>
+<!DOCTYPE html>
+<html <?= I18N::htmlAttributes() ?>>
+ <head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+
+ <title><?= WT_WEBTREES ?></title>
+
+ <link rel="icon" href="favicon.ico" type="image/x-icon">
+ <style type="text/css">
+ body {
+ color: gray;
+ background-color: white;
+ font: 14px tahoma, arial, helvetica, sans-serif;
+ padding: 10px;
+ }
+
+ a {
+ color: #81A9CB;
+ font-weight: bold;
+ text-decoration: none;
+ }
+
+ a:hover {
+ text-decoration: underline;
+ }
+
+ h1 {
+ color: #81A9CB;
+ font-weight: normal;
+ text-align: center;
+ }
+
+ li {
+ line-height: 2;
+ }
+
+ blockquote {
+ color: red;
+ }
+
+ .content { /*margin:auto; width:800px;*/
+ border: 1px solid gray;
+ padding: 15px;
+ border-radius: 15px;
+ }
+
+ .good {
+ color: green;
+ }
+ </style>
+ </head>
+
+ <body class="container">
+ <h1><?= I18N::translate('This website is temporarily unavailable') ?></h1>
+ <div class="content">
+ <p>
+ <?= str_replace('index.php', e($url), I18N::translate('This website is down for maintenance. You should <a href="index.php">try again</a> in a few minutes.')) ?>
+ </p>
+ <p>
+ <?= $message ?>
+ </p>
+ </div>
+ </body>
+</html>
diff --git a/site-offline.php b/site-offline.php
deleted file mode 100644
index bc0b38533d..0000000000
--- a/site-offline.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-/**
- * webtrees: online genealogy
- * Copyright (C) 2018 webtrees development team
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-namespace Fisharebest\Webtrees;
-
-// This script does not load session.php.
-// session.php won’t run until a configuration file and database connection exist...
-// This next block of code is a minimal version of session.php
-define('WT_WEBTREES', 'webtrees');
-define('WT_BASE_URL', '');
-define('WT_ROOT', '');
-define('WT_DATA_DIR', realpath('data') . DIRECTORY_SEPARATOR);
-define('WT_MODULES_DIR', 'modules_v3/');
-
-require 'vendor/autoload.php';
-
-Session::start();
-
-define('WT_LOCALE', I18N::init());
-
-if (file_exists(WT_DATA_DIR . 'offline.txt')) {
- $offline_txt = file_get_contents(WT_DATA_DIR . 'offline.txt');
-} else {
- // offline.txt has gone - we're back online!
- header('Location: index.php');
-
- return;
-}
-
-http_response_code(503);
-header('Content-Type: text/html; charset=UTF-8');
-
-echo
- '<!DOCTYPE html>',
- '<html ', I18N::htmlAttributes(), '>',
- '<head>',
- '<meta charset="UTF-8">',
- '<title>', WT_WEBTREES, '</title>',
- '<meta name="robots" content="noindex,follow">',
- '<style type="text/css">
- body {color: gray; background-color: white; font: 14px tahoma, arial, helvetica, sans-serif; padding:10px; }
- a {color: #81A9CB; font-weight: bold; text-decoration: none;}
- a:hover {text-decoration: underline;}
- h1 {color: #81A9CB; font-weight:normal; text-align:center;}
- li {line-height:2;}
- blockquote {color:red;}
- .content { /*margin:auto; width:800px;*/ border:1px solid gray; padding:15px; border-radius:15px;}
- .good {color: green;}
- </style>',
- '</head><body>',
- '<h1>', I18N::translate('This website is temporarily unavailable'), '</h1>',
- '<div class="content"><p>';
-
-if ($offline_txt) {
- echo $offline_txt;
-} else {
- echo I18N::translate('This website is down for maintenance. You should <a href="index.php">try again</a> in a few minutes.');
-}
-echo '</p>';
-echo '</div>';
-echo '</body>';
-echo '</html>';