From 538d00e0ad4a120a9172d809c15261223e01bd74 Mon Sep 17 00:00:00 2001 From: Dan Langille Date: Mon, 1 Oct 2018 02:26:37 +0000 Subject: [PATCH] Add Maintenance mode Sometimes we don't want users changing stuff. We might be upgrading to a newwer version of PostgreSQL by dumping and loading into another server. Setting IN_MAINTANCE_MODE to true, in include/constants.local.php will enter maintenance mode If you attempt to visit any of these pages, you will be redirected to now-in-maintenance-mode.php: * bouncing.php * customize.php * committer-opt-in.php * filter-setup.php * forgotten-password.php * new-user.php * password-reset-via-token.php * pkg_upload.php * port-watch.php * report-subscriptions.php * watch-categories.php * watch-list-maintenance.php * watch-list.php Once at now-in-maintenance-mode.php, the page will reload every MAINTENANCE_MODE_RERESH_TIME_SECONDS seconds, as defined in include/constants.php --- include/constants.local.php.sample | 19 ++++++++ include/constants.php | 3 ++ www/bouncing.php | 4 ++ www/committer-opt-in.php | 4 ++ www/customize.php | 4 ++ www/filter-setup.php | 4 ++ www/forgotten-password.php | 4 ++ www/new-user.php | 4 ++ www/now-in-maintenance-mode.php | 75 ++++++++++++++++++++++++++++++ www/password-reset-via-token.php | 4 ++ www/pkg_upload.php | 4 ++ www/port-watch.php | 4 ++ www/report-subscriptions.php | 4 ++ www/watch-categories.php | 4 ++ www/watch-list-maintenance.php | 4 ++ www/watch-list.php | 4 ++ 16 files changed, 149 insertions(+) create mode 100644 www/now-in-maintenance-mode.php diff --git a/include/constants.local.php.sample b/include/constants.local.php.sample index e2e268cb..fe573543 100644 --- a/include/constants.local.php.sample +++ b/include/constants.local.php.sample @@ -8,3 +8,22 @@ # constants which #define('PATH_TO_PORTSDIR', '/usr/local/'); // must have a trailing / + +#define('NO_LOGIN', false); + +# set this to true to display the now-in-maintenance-mode.php page +# users get redirected there if visit the following pages: +# * bouncing.php +# * customize.php +# * committer-opt-in.php +# * filter-setup.php +# * forgotten-password.php +# * new-user.php +# * password-reset-via-token.php +# * pkg_upload.php +# * port-watch.php +# * report-subscriptions.php +# * watch-categories.php +# * watch-list-maintenance.php +# * watch-list.php +define('IN_MAINTENCE_MODE', true); diff --git a/include/constants.php b/include/constants.php index efe23ad6..affd64f8 100644 --- a/include/constants.php +++ b/include/constants.php @@ -115,3 +115,6 @@ # number of seconds a newsfeed will remain before refreshed. define('NEWSFEED_REFRESH_SECONDS', 3600); + +define('MAINTENANCE_PAGE', 'now-in-maintenance-mode.php'); +define('MAINTENANCE_MODE_RERESH_TIME_SECONDS', 180); diff --git a/www/bouncing.php b/www/bouncing.php index 07d46656..44bd4df2 100644 --- a/www/bouncing.php +++ b/www/bouncing.php @@ -10,6 +10,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/databaselogin.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + $Debug = 0; $origin = $_GET["origin"]; diff --git a/www/committer-opt-in.php b/www/committer-opt-in.php index 2f3bba38..cc6f554b 100644 --- a/www/committer-opt-in.php +++ b/www/committer-opt-in.php @@ -10,6 +10,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/databaselogin.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + freshports_Start('Committer opt-in', 'freshports - new ports, applications', 'FreeBSD, index, applications, ports'); diff --git a/www/customize.php b/www/customize.php index bf382ebe..10a41bf8 100644 --- a/www/customize.php +++ b/www/customize.php @@ -10,6 +10,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/databaselogin.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/htmlify.php'); + + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } GLOBAL $User; diff --git a/www/filter-setup.php b/www/filter-setup.php index 31d6b7c8..5a417b5f 100644 --- a/www/filter-setup.php +++ b/www/filter-setup.php @@ -12,6 +12,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/watch-lists.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/watch_list_element.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + // if we don't know who they are, we'll make sure they login first if (!$visitor) { header("Location: /login.php?origin=" . $_SERVER["PHP_SELF"]); /* Redirect browser to PHP web site */ diff --git a/www/forgotten-password.php b/www/forgotten-password.php index da3257ba..4655e4cd 100644 --- a/www/forgotten-password.php +++ b/www/forgotten-password.php @@ -9,6 +9,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/freshports.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/databaselogin.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + $Debug = 0; diff --git a/www/new-user.php b/www/new-user.php index f31f3e4e..2ca7928b 100644 --- a/www/new-user.php +++ b/www/new-user.php @@ -5,6 +5,10 @@ # Copyright (c) 1998-2004 DVL Software Limited # + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + # for captcha session_start(); diff --git a/www/now-in-maintenance-mode.php b/www/now-in-maintenance-mode.php new file mode 100644 index 00000000..fa3e0e13 --- /dev/null +++ b/www/now-in-maintenance-mode.php @@ -0,0 +1,75 @@ + + + + + + + + + + + + + +

+The website is now in maintenance mode. No updates are allowed during this process. +

+ +

+This page will reload every seconds. When maintence mode finishes, this page will be redirect to the home page. +

+ +

+work in progress +

+ + + + + + + + + + + + + + + + + + diff --git a/www/password-reset-via-token.php b/www/password-reset-via-token.php index e38ac042..62f6c67f 100644 --- a/www/password-reset-via-token.php +++ b/www/password-reset-via-token.php @@ -11,6 +11,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/htmlify.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + GLOBAL $User; $origin = '/'; diff --git a/www/pkg_upload.php b/www/pkg_upload.php index c7d2510f..39d23d98 100644 --- a/www/pkg_upload.php +++ b/www/pkg_upload.php @@ -12,6 +12,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/watch-lists.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + freshports_Start('Uploading pkg_info', $FreshPortsName . ' - new ports, applications', 'FreeBSD, index, applications, ports'); diff --git a/www/port-watch.php b/www/port-watch.php index 84bba756..9a2c153a 100644 --- a/www/port-watch.php +++ b/www/port-watch.php @@ -15,6 +15,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/watch_list.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/watch_list_element.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + $Debug = 0; $submit = 0; $HTML = ''; diff --git a/www/report-subscriptions.php b/www/report-subscriptions.php index c00a7936..9162eb3e 100644 --- a/www/report-subscriptions.php +++ b/www/report-subscriptions.php @@ -16,6 +16,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + $ArticleTitle = 'Report subscriptions'; freshports_Start( $ArticleTitle, diff --git a/www/watch-categories.php b/www/watch-categories.php index 46d91fe3..874692b4 100644 --- a/www/watch-categories.php +++ b/www/watch-categories.php @@ -11,6 +11,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/watch-lists.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + // if we don't know who they are, we'll make sure they login first if (!$visitor) { header("Location: /login.php?origin=" . $_SERVER["PHP_SELF"]); /* Redirect browser to PHP web site */ diff --git a/www/watch-list-maintenance.php b/www/watch-list-maintenance.php index 2f2cc1c6..8d3d7207 100755 --- a/www/watch-list-maintenance.php +++ b/www/watch-list-maintenance.php @@ -11,6 +11,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/watch-lists.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + $visitor = $_COOKIE['visitor']; unset($add_name); diff --git a/www/watch-list.php b/www/watch-list.php index 41dbf040..3074dc45 100644 --- a/www/watch-list.php +++ b/www/watch-list.php @@ -11,6 +11,10 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/../include/getvalues.php'); require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/watch_list_element.php'); + if (IN_MAINTENCE_MODE) { + header('Location: /' . MAINTENANCE_PAGE, TRUE, 307); + } + $Debug = 0; if ($_POST["Origin"]) {