diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a90cc7..b397cf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to `laravel-ip-gateway` will be documented in this file. +## 2.1.0 - 2023-06-19 + +- Code refactoring - remove unnecessary conditions. + +## 2.0.0 - 2023-04-12 + +- Code refactoring and version upgrade. + ## 1.0.0 - 2018-01-10 -- First release \ No newline at end of file +- First release diff --git a/src/IpGatewayProvider.php b/src/IpGatewayProvider.php index 0f31b18..99339b9 100644 --- a/src/IpGatewayProvider.php +++ b/src/IpGatewayProvider.php @@ -20,11 +20,8 @@ class IpGatewayProvider extends ServiceProvider public function boot() { $router = $this->app['router']; - - if (config('ip-gateway')) { - foreach (config('ip-gateway.middleware') as $middlewareName) { - $router->pushMiddlewareToGroup($middlewareName, IpGatewayMiddleware::class); - } + foreach (config('ip-gateway.middleware') as $middlewareName) { + $router->pushMiddlewareToGroup($middlewareName, IpGatewayMiddleware::class); } } @@ -50,6 +47,5 @@ public function publishFiles() foreach ($publishableFiles as $storedPath => $publishPath) { $this->publishes([$storedPath => $publishPath]); } - } } diff --git a/src/Middleware/IpGatewayMiddleware.php b/src/Middleware/IpGatewayMiddleware.php index 8982ddf..b7b0b68 100644 --- a/src/Middleware/IpGatewayMiddleware.php +++ b/src/Middleware/IpGatewayMiddleware.php @@ -20,9 +20,8 @@ class IpGatewayMiddleware /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * + * @param $request + * @param Closure $next * @return mixed */ public function handle($request, Closure $next) @@ -33,7 +32,7 @@ public function handle($request, Closure $next) $enableBlacklist = config('ip-gateway.enable_blacklist') === true; $redirectRoute = config('ip-gateway.redirect_route_to'); - if (config('ip-gateway') && config('ip-gateway.enable_package') === true) { + if (config('ip-gateway.enable_package') === true) { // Check if package status is enable. foreach ($getClientIps as $ip) { if ($enableBlacklist && $this->grantIpAddress($ip)) { // Its check blacklisted ip-addresses from ip-config file. $prohibitRequest = true; @@ -43,18 +42,18 @@ public function handle($request, Closure $next) Log::warning($ip . ' IP address has tried to access.'); } } - } - if ($prohibitRequest) { - return redirect($redirectRoute != '' ? $redirectRoute : '/404'); + if ($prohibitRequest) { + return redirect($redirectRoute != '' ? $redirectRoute : '/404'); + } } return $next($request); } catch (\Exception $ex) { Log::error('Problem occurred while handle an incoming request '.$ex->getMessage()); + return redirect('/404'); } - } /** @@ -65,7 +64,6 @@ public function handle($request, Closure $next) */ protected function grantIpAddress(string $ip) : bool { - $this->ipList = config('ip-gateway.ip-list'); - return in_array($ip, $this->ipList); + return in_array($ip, config('ip-gateway.ip-list')); } }