From 7d9f9c745e1a55223acaec6b563c3d27d43a09c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Garcia?= Date: Wed, 25 Apr 2018 17:10:25 +0200 Subject: [PATCH] Add allowed ip's or networks to Maintenance Mode --- src/Illuminate/Foundation/Console/DownCommand.php | 4 +++- .../Foundation/Http/Middleware/CheckForMaintenanceMode.php | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/DownCommand.php b/src/Illuminate/Foundation/Console/DownCommand.php index 0cd685e59ee8..d7807ef6cc04 100644 --- a/src/Illuminate/Foundation/Console/DownCommand.php +++ b/src/Illuminate/Foundation/Console/DownCommand.php @@ -15,7 +15,8 @@ class DownCommand extends Command * @var string */ protected $signature = 'down {--message= : The message for the maintenance mode. } - {--retry= : The number of seconds after which the request may be retried.}'; + {--retry= : The number of seconds after which the request may be retried.} + {--allow=* : Ip or network allowed to use App in the maintenance mode.}'; /** * The console command description. @@ -50,6 +51,7 @@ protected function getDownFilePayload() 'time' => $this->currentTime(), 'message' => $this->option('message'), 'retry' => $this->getRetryTime(), + 'allowed' => $this->option('allow'), ]; } diff --git a/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php b/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php index 6de75096dbc7..7e6581c9143d 100644 --- a/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php +++ b/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php @@ -5,6 +5,7 @@ use Closure; use Illuminate\Contracts\Foundation\Application; use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException; +use Symfony\Component\HttpFoundation\IpUtils; class CheckForMaintenanceMode { @@ -40,6 +41,10 @@ public function handle($request, Closure $next) if ($this->app->isDownForMaintenance()) { $data = json_decode(file_get_contents($this->app->storagePath().'/framework/down'), true); + if (isset($data['allowed']) && IpUtils::checkIp($request->ip(), (array)$data['allowed'])) { + return $next($request); + } + throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']); }