From 2659e94ddd98d4bb046fef0d0b7c68785974b812 Mon Sep 17 00:00:00 2001 From: Martin Krikken Date: Fri, 21 Jun 2024 10:45:06 +0200 Subject: [PATCH] Add support for whitelisting IPs --- CHANGELOG.md | 4 ++++ README.md | 8 ++++++++ config.php | 12 ++++++++++++ providers/MaintenanceServiceProvider.php | 6 +++++- updates/version.yaml | 1 + 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d15a0a1..a50ba8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.2.2] - UNRELEASED + +- Add configuration option `whitelisted_ips` to allow IP-based bypass for maintenance mode. + ## [2.2.1] - 2023-06-12 - Maintenance release. diff --git a/README.md b/README.md index 906b9ad..9e41f68 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,14 @@ To bring October CMS up: php artisan up ``` +To bring October CMS down with whitelist-based bypass: + +``` +php artisan down --secret="{secret_string}" +``` + +This will make the system available for all requests coming from the IP addresses listed in the `whitelisted_ips` configuration option when the request path equals the secret string. + ## Installation ``` diff --git a/config.php b/config.php index 8d44246..bb9fc74 100644 --- a/config.php +++ b/config.php @@ -38,4 +38,16 @@ 'http_status_code_ajax' => 503, + /* + |-------------------------------------------------------------------------- + | Whitelisted IP addresses during maintenance mode + |-------------------------------------------------------------------------- + | + | Configure a list of IP addresses that are allowed to access the site + | during maintenance mode. Separate multiple IP addresses with a comma. + | + */ + + 'whitelisted_ips' => env('MAINTENANCE_WHITELIST_IPS', ''), + ]; diff --git a/providers/MaintenanceServiceProvider.php b/providers/MaintenanceServiceProvider.php index 9abf0fb..14ccd7e 100644 --- a/providers/MaintenanceServiceProvider.php +++ b/providers/MaintenanceServiceProvider.php @@ -4,8 +4,10 @@ namespace Vdlp\Maintenance\Providers; +use Config; use Illuminate\Foundation\Application; use Illuminate\Support\ServiceProvider; +use Request; use Vdlp\Maintenance\Classes\Contracts\ResponseMaker; use Vdlp\Maintenance\Classes\MaintenanceResponder; @@ -30,7 +32,9 @@ public function register(): void private function registerMaintenanceHandler(): void { $this->app->booting(static function (Application $app): void { - if ($app->isDownForMaintenance() && !$app->runningInConsole()) { + $whitelist = explode(',', Config::get('vdlp_maintenance.whitelisted_ips', '')); + $whitelisted = in_array(Request::ip(), $whitelist, true); + if ($app->isDownForMaintenance() && !$app->runningInConsole() && !$whitelisted) { /** @var ResponseMaker $responder */ $responder = $app->make(ResponseMaker::class); $responder->getResponse()->send(); diff --git a/updates/version.yaml b/updates/version.yaml index 000113d..3ad5416 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -9,3 +9,4 @@ v2.1.1: "Add configuration option `use_preferred_locale` (see CHANGELOG.md)" v2.1.2: "Add .gitattributes file to plugin repository" v2.2.0: "Maintenance release (see CHANGELOG.md)" v2.2.1: "Maintenance release (see CHANGELOG.md)" +v2.2.2: "Add configuration option 'whitelisted_ips' (see CHANGELOG.md)"