2017 © Pedro Peláez
 

library firewall

Middleware to provide IP filtering

image

middlewares/firewall

Middleware to provide IP filtering

  • Saturday, January 27, 2018
  • by oscarotero
  • Repository
  • 2 Watchers
  • 3 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 9 % Grown

The README.md

middlewares/firewall

Latest Version on Packagist ![Software License][ico-license] Testing ![Total Downloads][ico-downloads], (*1)

Middleware to provide IP filtering., (*2)

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/firewall., (*3)

composer require middlewares/firewall

Example

Dispatcher::run([
    (new Middlewares\Firewall(['123.0.0.*']))
        ->blacklist([
            '123.0.0.1',
            '123.0.0.2',
        ])
]);

Usage

The constructor accepts an array with the whitelist ips. See the ip formats allowed., (*4)

$firewall = new Middlewares\Firewall([
    '127.0.0.1',
    '198.168.0.*',
]);

Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface as the second argument to create the error response (403). If it's not defined, Middleware\Utils\Factory will be used to detect it automatically., (*5)

$responseFactory = new MyOwnResponseFactory();

$firewall = new Middlewares\Firewall($whitelist, $responseFactory);

blacklist

The blacklist ips. The ip format is the same than whitelist., (*6)

$whitelist = [
    '127.0.0.1',
    '198.168.0.*',
];
$blacklist = [
    '192.168.0.50',
];

$firewall = (new Middlewares\Firewall($whitelist))->blacklist($blacklist);

ipAttribute

By default uses the REMOTE_ADDR server parameter to get the client ip. Use this option if you want to use a request attribute. Useful to combine with any ip detection middleware, for example client-ip:, (*7)

Dispatcher::run([
    //detect the client ip and save it in client-ip attribute
    new Middlewares\ClientIP(),

    //use that attribute
    (new Middlewares\Firewall(['123.0.0.*']))
        ->ipAttribute('client-ip')
]);

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details., (*8)

The MIT License (MIT). Please see LICENSE for more information., (*9)

The Versions

27/01 2018

dev-master

9999999-dev https://github.com/middlewares/firewall

Middleware to provide IP filtering

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 filter security server http ip firewall psr-15

27/01 2018
13/11 2017
21/09 2017
26/12 2016

v0.3.0

0.3.0.0 https://github.com/middlewares/firewall

Middleware to provide IP filtering

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 filter security server http ip firewall psr-15

27/11 2016

v0.2.0

0.2.0.0 https://github.com/middlewares/firewall

Middleware to provide IP filtering

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 filter security server http ip firewall psr-15