-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dea4e0b
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "ilhamdev/ipwhitelist", | ||
"description": "Simple Ip White List", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "M Ilham Sabar", | ||
"email": "ilhamsabar@gmail.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"ilhamdev\\ipwhitelist\\" : "src" | ||
} | ||
}, | ||
"require": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## 👽 Simple IP White List | ||
|
||
## How To Install | ||
composer require ilhamdev/ipwhitelist | ||
|
||
## How To Use | ||
### Add This Package in app/Http/Kernel.php | ||
protected $routeMiddleware = [ | ||
'ipwhitelist' => \ilhamdev\ipwhitelist\middleware\CheckIpMiddleware::class, | ||
]; | ||
|
||
### In Your .env add your Ip | ||
APP_IP_WHITELIST=127.0.0.1,192.168.1.1 | ||
|
||
### In Your Controller | ||
public function __construct() | ||
{ | ||
$this->middleware('ipwhitelist'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace ilhamdev\ipwhitelist\middleware; | ||
use Closure; | ||
|
||
class CheckIpMiddleware | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
if (!in_array($request->ip(), explode(',',env('APP_IP_WHITELIST')))) { | ||
return response('Access Denied',500); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |