Middleware to provide IP filtering
Middleware to provide IP filtering using M6Web/Firewall.
This package is installable and autoloadable via Composer as middlewares/firewall.
composer require middlewares/firewall
$dispatcher = new Dispatcher([ (new Middlewares\Firewall(['123.0.0.*'])) ->blacklist([ '22.214.171.124', '126.96.36.199', ]) ]); $response = $dispatcher->dispatch(new ServerRequest());
An array with the whitelist ips. See the ip formats allowed.
The blacklist ips. The ip format is the same than whitelist.
By default uses the
REMOTE_ADDR server parameter to get the client ip. This option allows to use a request attribute. Useful to combine with any ip detection middleware, for example client-ip:
$dispatcher = new Dispatcher([ //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') ]);
A PSR-17 factory to create
The MIT License (MIT). Please see LICENSE for more information.