Skip to content

Commit 7d9f9c7

Browse files
committed
Add allowed ip's or networks to Maintenance Mode
1 parent 71729a2 commit 7d9f9c7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Illuminate/Foundation/Console/DownCommand.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class DownCommand extends Command
1515
* @var string
1616
*/
1717
protected $signature = 'down {--message= : The message for the maintenance mode. }
18-
{--retry= : The number of seconds after which the request may be retried.}';
18+
{--retry= : The number of seconds after which the request may be retried.}
19+
{--allow=* : Ip or network allowed to use App in the maintenance mode.}';
1920

2021
/**
2122
* The console command description.
@@ -50,6 +51,7 @@ protected function getDownFilePayload()
5051
'time' => $this->currentTime(),
5152
'message' => $this->option('message'),
5253
'retry' => $this->getRetryTime(),
54+
'allowed' => $this->option('allow'),
5355
];
5456
}
5557

src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Closure;
66
use Illuminate\Contracts\Foundation\Application;
77
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException;
8+
use Symfony\Component\HttpFoundation\IpUtils;
89

910
class CheckForMaintenanceMode
1011
{
@@ -40,6 +41,10 @@ public function handle($request, Closure $next)
4041
if ($this->app->isDownForMaintenance()) {
4142
$data = json_decode(file_get_contents($this->app->storagePath().'/framework/down'), true);
4243

44+
if (isset($data['allowed']) && IpUtils::checkIp($request->ip(), (array)$data['allowed'])) {
45+
return $next($request);
46+
}
47+
4348
throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
4449
}
4550

0 commit comments

Comments
 (0)