Skip to content

Commit

Permalink
Add allowed ip's or networks to Maintenance Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cesargb committed Apr 25, 2018
1 parent 71729a2 commit 7d9f9c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Illuminate/Foundation/Console/DownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -50,6 +51,7 @@ protected function getDownFilePayload()
'time' => $this->currentTime(),
'message' => $this->option('message'),
'retry' => $this->getRetryTime(),
'allowed' => $this->option('allow'),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException;
use Symfony\Component\HttpFoundation\IpUtils;

class CheckForMaintenanceMode
{
Expand Down Expand Up @@ -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']);
}

Expand Down

0 comments on commit 7d9f9c7

Please sign in to comment.