2017 © Pedro PelĂĄez
 

library laravel-route-blocker

Block routes by IP

image

skydiver/laravel-route-blocker

Block routes by IP

  • Thursday, February 15, 2018
  • by skydiver
  • Repository
  • 2 Watchers
  • 30 Stars
  • 4,688 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 2 Open issues
  • 6 Versions
  • 30 % Grown

The README.md

Laravel Route Blocker

Block routes by IP, (*1)

(inspired on Laravel Firewall), (*2)


Requirements

Laravel 5.x, 6.x, 7.x and 8.x, (*3)


Installation

1) To install through composer, run the following command from terminal:, (*4)

```bash
$ composer require skydiver/laravel-route-blocker
```

3) Publish the config file:, (*5)

Run the following command to publish the package config file:

```bash
$ php artisan vendor:publish --tag=LaravelRouteBlocker
```

Still using Laravel 5.4 or below?
, (*6)

Please add service provider to your config/app.php providers array:, (*7)

'providers' => [
    ...
    Skydiver\LaravelRouteBlocker\LaravelRouteBlockerServiceProvider::class,
]

, (*8)


Usage

1) Register middlewares in app/Http/Kernel.php on $routeMiddleware array: 'blacklist' => \Skydiver\LaravelRouteBlocker\Middleware\BlacklistMiddleware::class, 'whitelist' => \Skydiver\LaravelRouteBlocker\Middleware\WhitelistMiddleware::class, * Blacklist allows all traffic except matching rules. * Whitelist blocks all traffic except matching rules. * You can register both or just a single middleware., (*9)

2) Create a config group on config/laravel-route-blocker.php and insert your allowed/blocked IPs: 'whitelist' => [ 'my_group' => [ '127.0.0.1', '192.168.17.0', '10.0.1.*' ], 'another_group' => [ '8.8.8.*' ], ], 'blacklist' => [ 'blocked_ips' => [ '127.0.0.1', '192.168.100.0', ], 'blocked_ips2' => [ '8.8.8.8', ], ],, (*10)

* You can create as many blacklist/whitelists groups as you wish and protect differents set of routes with differents IPs

Also, you can configure to throw an HTTP status code or redirect to a custom URL:
```
'redirect_to'      => '',   // URL TO REDIRECT IF BLOCKED (LEAVE BLANK TO THROW STATUS)
'response_status'  => 403,  // STATUS CODE (403, 404 ...)
'response_message' => ''    // MESSAGE (COMBINED WITH STATUS CODE)
```

3) Put your protected routes inside a group and specify the whitelist parameter: ``` // Only IPs matched on "my_group" will be allowed to access route Route::group(['middleware' => 'whitelist:my_group'], function() {, (*11)

        Route::get('/demo', function () {
            return "DEMO";
        });

    });

    // Only IPs matched on "my_group" will be blocked to access route
    Route::group(['middleware' => 'blacklist:blocked_ips'], function() {

        Route::get('/private', function () {
            return "Private Page";
        });

    });
```

Artisan Commands

  • To get a list of current IPs groups run:, (*12)

        $ php artisan route:blocks:groups
    
        +-----------------+--------------+-----------+
        | Group           | IP           | Type      |
        +-----------------+--------------+-----------+
        | allowed_group_1 | 127.0.0.1    | whitelist |
        | allowed_group_1 | 127.0.0.2    | whitelist |
        | allowed_group_1 | 192.168.17.0 | whitelist |
        | allowed_group_1 | 10.0.0.*     | whitelist |
        | allowed_group_2 | 8.8.8.8      | whitelist |
        | allowed_group_2 | 8.8.8.*      | whitelist |
        | allowed_group_2 | 8.8.4.4      | whitelist |
        | blocked_ips_1   | 127.0.0.1    | blacklist |
        | blocked_ips_1   | 127.0.0.2    | blacklist |
        | blocked_ips_1   | 192.168.17.0 | blacklist |
        | blocked_ips_1   | 10.0.0.*     | blacklist |
        | blocked_ips_2   | 8.8.8.8      | blacklist |
        | blocked_ips_2   | 8.8.8.*      | blacklist |
        | blocked_ips_2   | 8.8.4.4      | blacklist |
        +-----------------+--------------+-----------+
    

Testing

To manually run test suite:, (*13)

vendor/bin/phpunit --verbose

Test files inside tests/Feature should be run by GitHub action only., (*14)

The Versions

15/02 2018

dev-master

9999999-dev https://github.com/skydiver/laravel-route-blocker

Block routes by IP

  Sources   Download

MIT

The Requires

 

laravel php security block routes

15/02 2018

1.2.1

1.2.1.0 https://github.com/skydiver/laravel-route-blocker

Block routes by IP

  Sources   Download

MIT

The Requires

 

laravel php security block routes

14/02 2018

1.2.0

1.2.0.0 https://github.com/skydiver/laravel-route-blocker

Block routes by IP

  Sources   Download

MIT

The Requires

 

laravel php security block routes

30/08 2017

1.1.1

1.1.1.0 https://github.com/skydiver/laravel-route-blocker

Block routes by IP

  Sources   Download

MIT

The Requires

 

laravel php security block routes

24/02 2017

1.1.0

1.1.0.0 https://github.com/skydiver/laravel-route-blocker

Block routes by IP

  Sources   Download

MIT

The Requires

 

laravel php security block routes

18/02 2017

1.0.0

1.0.0.0 https://github.com/skydiver/laravel-route-blocker

Block routes by IP

  Sources   Download

MIT

The Requires

 

laravel php security block routes