定制 karelwintersky/arris.toolkit.firewall 二次开发

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

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

karelwintersky/arris.toolkit.firewall

Composer 安装命令:

composer require karelwintersky/arris.toolkit.firewall

包简介

Library providing IP filtering features

README 文档

README

Readme in Russian - README.RU.md

Library providing IP filtering features

Type Syntax Details
IPV4 192.168.0.1
Range 192.168.0.0-192.168.1.60 Includes all IPs from 192.168.0.0 to 192.168.0.255
and from 192.168.1.0 to 198.168.1.60
Wild card 192.168.0.* IPs starting with 192.168.0
Same as IP Range 192.168.0.0-192.168.0.255
CIDR Mask 192.168.0.0/24 IPs starting with 192.168.0
Same as 192.168.0.0-192.168.0.255 and 192.168.0.*
and 192.168.0.0/255.255.255.0

NB! Range like 192.168.0.0/255.255.255.0 with subnet mask not supported (as deprecated)!

Basic usage

Use composer:

composer require karelwintersky/arris.toolkit.firewall
use Arris\Toolkit\FireWall;

$whiteList = [
    '127.0.0.1',
    '192.168.0.*',
];

$blackList = [
    '192.168.0.50',
];

$firewall = new FireWall(
    defaultState: false,
    deferred_range_sorting: true 
);

$connAllowed = $firewall
    ->addWhiteList($whiteList)
    ->addBlackList($blackList)
    ->validate('195.88.195.146')
    ->isAllowed()
;

if (!$connAllowed) {
    http_response_code(403); // Forbidden
    exit();
}

Constructor

$firewall = new FireWall(
    defaultState: false,
    deferred_range_sorting: true 
);
  • defaultState - rule for range *.*.*.*. Default false, i.e. FORBIDDEN. Allowed options:
    • null (equal to false)
    • true|false
    • FireWallState::FORBIDDEN или FireWallState::ALLOWED
  • deferred_range_sorting - use lazy range sorting:
    • true: at validate() call; use it if you test only one IP at once, most cases)
    • false: at addAnyList() call; use it if you test a lot if IPs with one ruleset

Add ranges

  • addWhiteList() - add range to White list (Allowed), alias of addAllowed()
  • addBlackList() - add range to Black List (Forbidden), alias of addDenied()

Argument is string or array of strings

  • 192.168.0.1 - alone IP
  • 192.168.0.0-192.168.1.60 - range
  • 192.168.0.* - wildcard range (allowed range *, that is equal to *.*.*.*)
  • 192.168.0.0/24 - CIDR range

Range 192.168.0.0/255.255.255.0 not supported now.

  • addRange(range, type) - type is FireWallState enum value

Сomplex and redundant example

$firewall = new FireWall();
$i = $firewall
    ->addBlackList('192.168.0.0/16')            // 192.168.0.0 - 192.168.255.255
    ->addWhiteList('192.168.0.0/24')            // + 0-255
    ->addBlackList('192.168.0.10-192.168.0.80') // - 10-80
    ->addBlackList('192.168.0.100-192.168.0.121') // - 100-121
    ->addWhiteList('192.168.0.42')  // + 42
    ->addWhiteList('192.168.0.120') // + 120
    ->addBlackList('192.168.0.5')   // - 5

$equals = [
    '192.168.0.0'   =>  true,
    '192.168.0.1'   =>  true,
    '192.168.0.10'  =>  false,
    '192.168.0.42'  =>  true,
    '192.168.0.99'  =>  true,
    '192.168.0.100' =>  false,
    '192.168.0.5'   =>  false,
    '192.168.0.200' =>  true,
    '192.168.0.70'  =>  false
];

Nuances

  • when ranges overlap, the one with the lower power is "stronger"
  • when ranges of equal power overlap, the result is not defined (most likely, the one that was declared earlier will be used)

How does it work?

  • We set IP ranges (white and black)
  • Whether the full range (*.*.*.*) belongs to the black/white list depends on the settings
  • Range powers are calculated
  • Ranges are sorted by power
  • The shortest range is found that includes the tested IP
  • The type of this range is the state for the IP - ALLOWED or FORBIDDEN

License

Firewall is licensed under the MIT license.

karelwintersky/arris.toolkit.firewall 适用场景与选型建议

karelwintersky/arris.toolkit.firewall 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 268 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「firewall」 「IP」 「filtering」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 karelwintersky/arris.toolkit.firewall 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 karelwintersky/arris.toolkit.firewall 我们能提供哪些服务?
定制开发 / 二次开发

基于 karelwintersky/arris.toolkit.firewall 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 268
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-08