Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
12 changes: 12 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''),

];
6 changes: 5 additions & 1 deletion providers/MaintenanceServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"