Allowed IPs Added
This commit is contained in:
parent
d68e765243
commit
6f0151806d
|
|
@ -14,7 +14,7 @@ class Kernel extends HttpKernel
|
|||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Webkul\Core\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Admin\Listeners;
|
||||
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class ChannelSettingsChange
|
||||
{
|
||||
/**
|
||||
* Check for maintenance mode and set according to settings.
|
||||
*
|
||||
* @param \Webkul\Core\Models\Channel $channel
|
||||
* @return void
|
||||
*/
|
||||
public function checkForMaintenaceMode($channel)
|
||||
{
|
||||
if ((bool) $channel->is_maintenance_on) {
|
||||
Artisan::call('down');
|
||||
} else {
|
||||
Artisan::call('up');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,5 +27,7 @@ class EventServiceProvider extends ServiceProvider
|
|||
Event::listen('sales.refund.save.after','Webkul\Admin\Listeners\Order@sendNewRefundMail');
|
||||
|
||||
Event::listen('sales.order.comment.create.after','Webkul\Admin\Listeners\Order@sendOrderCommentMail');
|
||||
|
||||
Event::listen('core.channel.update.after','Webkul\Admin\Listeners\ChannelSettingsChange@checkForMaintenaceMode');
|
||||
}
|
||||
}
|
||||
|
|
@ -805,7 +805,8 @@ return [
|
|||
'seo-title' => 'Meta title',
|
||||
'seo-description' => 'Meta description',
|
||||
'seo-keywords' => 'Meta keywords',
|
||||
'maintenance-mode' => 'Maintenance Mode'
|
||||
'maintenance-mode' => 'Maintenance Mode',
|
||||
'allowed-ips' => 'Allowed IPs'
|
||||
],
|
||||
|
||||
'sliders' => [
|
||||
|
|
|
|||
|
|
@ -232,6 +232,11 @@
|
|||
<span class="slider round"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label for="allowed-ips" class="required">{{ __('admin::app.settings.channels.allowed-ips') }}</label>
|
||||
<input class="control" id="allowed-ips" name="allowed_ips" value="{{ old('allowed_ips') ?: $channel->allowed_ips }}"/>
|
||||
</div>
|
||||
</div>
|
||||
</accordian>
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class AddColumnsInChannelsTable extends Migration
|
|||
{
|
||||
Schema::table('channels', function (Blueprint $table) {
|
||||
$table->boolean('is_maintenance_on')->after('footer_content')->default(0);
|
||||
$table->text('allowed_ips')->after('is_maintenance_on')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +27,8 @@ class AddColumnsInChannelsTable extends Migration
|
|||
public function down()
|
||||
{
|
||||
Schema::table('channels', function (Blueprint $table) {
|
||||
//
|
||||
$table->removeColumn('is_maintenance_on');
|
||||
$table->removeColumn('allowed_ips');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Original;
|
||||
|
||||
class CheckForMaintenanceMode extends Original
|
||||
{
|
||||
/**
|
||||
* The application implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Foundation\Application
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* Current channel.
|
||||
*
|
||||
* @var \Webkul\Core\Models\Channel
|
||||
*/
|
||||
protected $channel;
|
||||
|
||||
/**
|
||||
* Exclude route names.
|
||||
*/
|
||||
protected $excludedNames = [];
|
||||
|
||||
/**
|
||||
* Exclude route uris.
|
||||
*/
|
||||
protected $except = [];
|
||||
|
||||
/**
|
||||
* Exclude ips.
|
||||
*/
|
||||
protected $excludedIPs = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
*/
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
/* application */
|
||||
$this->app = $app;
|
||||
|
||||
/* current channel */
|
||||
$this->channel = core()->getCurrentChannel();
|
||||
|
||||
/* adding exception for admin routes */
|
||||
$this->except[] = env('APP_ADMIN_URL', 'admin') . '*';
|
||||
|
||||
/* adding exception for ips */
|
||||
$this->excludedIPs = array_map('trim', explode(',', $this->channel->allowed_ips));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for the except routes.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return boolean
|
||||
*/
|
||||
protected function shouldPassThrough($request)
|
||||
{
|
||||
foreach ($this->except as $except) {
|
||||
if ($except !== '/') {
|
||||
$except = trim($except, '/');
|
||||
}
|
||||
|
||||
if ($request->is($except)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($this->app->isDownForMaintenance()) {
|
||||
$response = $next($request);
|
||||
|
||||
if (in_array($request->ip(), $this->excludedIPs)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$route = $request->route();
|
||||
|
||||
if ($route instanceof Route) {
|
||||
if (in_array($route->getName(), $this->excludedNames)) {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->shouldPassThrough($request))
|
||||
{
|
||||
return $response;
|
||||
}
|
||||
|
||||
throw new HttpException(503);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,8 @@ class Channel extends Model implements ChannelContract
|
|||
'base_currency_id',
|
||||
'root_category_id',
|
||||
'home_seo',
|
||||
'is_maintenance_on'
|
||||
'is_maintenance_on',
|
||||
'allowed_ips'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,23 +2,23 @@
|
|||
|
||||
namespace Webkul\Core\Providers;
|
||||
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Theme\ViewRenderEventManager;
|
||||
use Webkul\Core\View\Compilers\BladeCompiler;
|
||||
use Webkul\Core\Console\Commands\BookingCron;
|
||||
use Webkul\Core\Core;
|
||||
use Webkul\Core\Exceptions\Handler;
|
||||
use Webkul\Core\Facades\Core as CoreFacade;
|
||||
use Webkul\Core\Models\SliderProxy;
|
||||
use Webkul\Core\Observers\SliderObserver;
|
||||
use Webkul\Core\Console\Commands\BagistoVersion;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Webkul\Theme\ViewRenderEventManager;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Webkul\Core\Console\Commands\Install;
|
||||
use Webkul\Core\Observers\SliderObserver;
|
||||
use Webkul\Core\Facades\Core as CoreFacade;
|
||||
use Webkul\Core\Console\Commands\BookingCron;
|
||||
use Webkul\Core\View\Compilers\BladeCompiler;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Webkul\Core\Console\Commands\BagistoVersion;
|
||||
use Webkul\Core\Console\Commands\ExchangeRateUpdate;
|
||||
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
||||
|
||||
class CoreServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue