定制 middlewares/firewall 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

middlewares/firewall

最新稳定版本:v2.1.0

Composer 安装命令:

composer require middlewares/firewall

包简介

Middleware to provide IP filtering

README 文档

README

Latest Version on Packagist Software License Testing Total Downloads

Middleware to provide IP filtering.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/firewall.

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.

$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.

$responseFactory = new MyOwnResponseFactory();

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

blacklist

The blacklist ips. The ip format is the same than whitelist.

$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:

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.

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

统计信息

  • 总下载量: 316.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-10