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([ '220.127.116.11', '18.104.22.168', ]) ]); $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.