Giter VIP home page Giter VIP logo

laravel-route-blocker's Introduction

#Laravel Route Blocker

Block routes by IP

(inspired on Laravel Firewall)


Requirements

Laravel 5.1. 5.2, 5.3, 5.4, 5.5


Installation

  1. Require this package in your composer.json and run composer update.
    "skydiver/laravel-route-blocker": "dev-master"
  1. After updating composer, add ServiceProvider to the providers array in config/app.php
    Skydiver\LaravelRouteBlocker\LaravelRouteBlockerServiceProvider::class,
  1. Then publish the config file:
    $ php artisan vendor:publish --tag=LaravelRouteBlocker

Usage

  1. Add middleware to app/Http/Kernel.php on $routeMiddleware array:
    'whitelist' => \Skydiver\LaravelRouteBlocker\Middleware\WhitelistMiddleware::class,
  1. Create a config group on config/laravel-route-blocker.php and insert your allowed IPs:
'whitelist' => [
    'my_group' => [
        '127.0.0.1',
        '192.168.17.0',
        '10.0.1.*'
    ],
    'another_group' => [
        '8.8.8.*'
    ],
],

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)
  1. Put your protected routes inside a group and specify the whitelist parameter:
    Route::group(['middleware' => 'whitelist:my_group'], function() {

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

    });

Artisan Commands

  • To get a list of current IPs groups run:
    $ php artisan route:blocks:groups
    +---------+--------------+
    | Group   | IP           |
    +---------+--------------+
    | group1  | 127.0.0.1    |
    | group1  | 127.0.0.2    |
    | group1  | 192.168.17.0 |
    | group1  | 10.0.0.*     |
    | group2  | 8.8.8.8      |
    | group2  | 8.8.8.*      |
    | group2  | 8.8.4.4      |
    +---------+--------------+

Notes

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.