Download the PHP package ryudith/mezzio-block-ip without Composer
On this page you can find all versions of the php package ryudith/mezzio-block-ip. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ryudith/mezzio-block-ip
More information about ryudith/mezzio-block-ip
Files in ryudith/mezzio-block-ip
Package mezzio-block-ip
Short Description Middleware library to block IP request for Mezzio framework.
License Apache-2.0
Informations about the package mezzio-block-ip
mezzio-block-ip
Ryudith\MezzioBlockIp is middleware to block IP based on request.
Version 1.1.0 remove code auto register route when helper configuration is enable (
enable_helper) also removeenable_helperfrom configuration and add CLI helper version.
To enable helper please read enable helper below.
Installation
To install run command :
Usage
Add Ryudith\MezzioBlockIp\ConfigProvider to config/config.php
Add Ryudith\MezzioBlockIp\BlockIPMiddleware to config/pipeline.php
You can place
$app->pipe(BlockIPMiddleware::class)before$app->pipe(ErrorHandler::class)if you want.
Custom Configuration
Configuration is locate in vendor/ryudith/mezzio-block-ip/ConfigProvider.php :
Detail :
-
limit_hit
is how many request hit per limit_duration before blocked. -
limit_duration
is duration for limit_hit in second. -
request_real_ip_key
is assoc key for get IP from $_SERVER or $_ENV variable. -
ip_data_dir
is directory location to save record request IP, since the storage implementation is file system based. -
blacklist_data_dir
is directory location to save blacklist file. -
whitelist_data_dir
is directory location to save whitelist file. -
file_data_delimiter
is data delimiter inside file. -
ip_storage_class
is implementation class ofRyudith\MezzioBlockIp\Storage\StorageInterfacethat will do work to check, create, delete blacklist or whitelist data. -
ip_response_class
is implementation class ofRyudith\MezzioBlockIp\SimpleResponse\SimpleResponseInterfacethat will give response from blacklist IP. admin_whitelist_ip
is string array whitelist permanent IP for admin.
Enable Helper
To enable helper add the following items to factories configuration (usually in config/dependencies.global.php) :
Then for web helper register helper to routes.php
Make sure your
blacklist_uri_pathandwhitelist_uri_pathvalue is match to your route path.
For web helper you can change default configuration values as listed below by add array key to mezzio_block_ip configuration, also don't forget to add your IP to whitelist to be able access helper.
-
helper_url_param_op
is URL query parameter key for helper operation. Default 'op' and the option value is 'add' or 'delete'. -
helper_url_param_ip
is URL query parameter key for helper data IP, default value 'ip'. -
blacklist_uri_path
is URI path for blacklist helper operation. whitelist_uri_path
is URI path for whitelist helper operation.
Change default configuration web helper value
Create new file
config/autoload/blockip.local.phpand add :Then you can access helper with URL http://localhost:8080/blockip/blacklist?operation=add&ip=userip.168.0.12 with your whitelist IP.
For CLI helper you need to register helper command to laminas-cli commands configuration usually locate in file config/autoload/mezzio.global.php :
Change
your:commandto your own choice command.
Documentation
All versions of mezzio-block-ip with dependencies
psr/http-server-middleware Version ^1.0
psr/container Version ^1.0
laminas/laminas-diactoros Version ^2.11