├── ip-blocker.jpg ├── src ├── IPBlocker.php ├── Middlewares │ └── IPBlocking.php ├── Models │ └── IPBlocker.php ├── Migrations │ └── 2020_07_22_180122_create_ipblockers_table.php └── IPBlockerServicesProvider.php ├── tests └── TestCase.php ├── composer.json ├── phpunit.xml └── README.md /ip-blocker.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mahmoud-Italy/Larasecure-ipblocker/HEAD/ip-blocker.jpg -------------------------------------------------------------------------------- /src/IPBlocker.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 13 | } 14 | } -------------------------------------------------------------------------------- /src/Middlewares/IPBlocking.php: -------------------------------------------------------------------------------- 1 | \Request::ip(), 'status' => true])->count()) { 25 | $obj = true; 26 | } 27 | return $obj; 28 | } 29 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "larasecure/ip-blocker", 3 | "description": "Restrict access to the web by preventing IP Addresses", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Mahmoud.Ahmed", 9 | "email": "mahmoud.italy@outlook.com" 10 | } 11 | ], 12 | "minimum-stability": "dev", 13 | "prefer-stable": true, 14 | "require": { 15 | "php": "^7.2" 16 | }, 17 | "extra": { 18 | "laravel": { 19 | "providers": [ 20 | "Larasecure\\IPBlocker\\IPBlockerServiceProvider" 21 | ] 22 | } 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "Larasecure\\IPBlocker\\": "src/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./src/ 14 | 15 | 16 | 17 | 18 | ./tests/ 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Migrations/2020_07_22_180122_create_ipblockers_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | $table->string('ip_address', 45); 19 | $table->boolean('status')->default(false); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::dropIfExists('ipblockers'); 32 | } 33 | } -------------------------------------------------------------------------------- /src/IPBlockerServicesProvider.php: -------------------------------------------------------------------------------- 1 | publishMiddleware(); 27 | $this->publishMigrations(); 28 | $this->publishModels(); 29 | } 30 | 31 | 32 | private function publishMiddleware() 33 | { 34 | $path = $this->getMiddlwarePath(); 35 | $this->publishes([$path => app_path('/Http/Middleware/IPBlocking.php')], 'ipblocker'); 36 | } 37 | 38 | private function publishMigrations() 39 | { 40 | $path = $this->getMigrationsPath(); 41 | $this->publishes([$path => database_path('migrations')], 'ipblocker'); 42 | } 43 | 44 | private function publishModels() 45 | { 46 | $path = $this->getModelPath(); 47 | $this->publishes([$path => app_path('IPBlocker.php')], 'ipblocker'); 48 | } 49 | 50 | private function getMiddlwarePath() 51 | { 52 | return __DIR__ . '/Middlewares/IPBlocking.php'; 53 | } 54 | 55 | private function getMigrationsPath() 56 | { 57 | return __DIR__ . '/Migrations/'; 58 | } 59 | 60 | private function getModelPath() 61 | { 62 | return __DIR__ . '/Models/IPBlocker.php'; 63 | } 64 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IP Blocker 2 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Mahmoud-Italy/LaraSecure-IPBlocker/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Mahmoud-Italy/LaraSecure-IPBlocker/?branch=master) 3 | [![Code Intelligence Status](https://scrutinizer-ci.com/g/Mahmoud-Italy/LaraSecure-IPBlocker/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/code-intelligence) 4 | Total Downloads 5 | 6 | ![ib-blocker](ip-blocker.jpg) 7 | 8 | A Laravel Package to increase the security of your websites by preventing access for users having blocked IP Addresses. 9 | 10 | However, you can add IP Addresses as many as you want into table called ipblockers which you want to disallow access to your site from spam etc. 11 | 12 | # Installation 13 |
composer require larasecure/ip-blocker
14 | 15 | # Then publish the config 16 |
php artisan vendor:publish --tag=ipblocker
17 |
php artisan migrate
18 | 19 | 20 | # Usage 21 | Add this middleware in Kernel.php $routeMiddleware to restrict IP Addresses 22 | 23 |
'IPBlocking' => \Larasecure\IPBlocker\Middlewares\IPBlocking::class
24 | 25 | Add IPBlocking middleware to route group for which you want to restrict access. 26 |
27 |   Route::group(['middleware' => 'IPBlocking'], function(){
28 |     // you routes..
29 |   });
30 | 
31 | or you can injected in RouteServiceProvider.php 32 |
33 |   protected function mapApiRoutes()
34 |     {
35 |         Route::prefix('api')
36 |             ->middleware(['api', 'IPBlocking'])
37 |             ->namespace($this->namespace)
38 |             ->group(base_path('routes/api.php'));
39 |     }
40 | 
41 | 42 | or just add middleware to single route 43 |
44 |   Route::get('/', function () {
45 |     //
46 |   })->middleware('IPBlocking');
47 | 
48 |
49 | Users will be redirect to "403 | Forbidden" page if their IP exist on ipblockers table. 50 | 51 | # Credits 52 | 53 | 57 | 58 | # License 59 | The MIT License (MIT). Please see License File for more information. --------------------------------------------------------------------------------