karolkrupa / fail2ban-bundle
Fail2BanBundle 类似于 Linux 中的 fail2ban
dev-master
2020-07-15 16:46 UTC
Requires
- php: ^7.1.3
- doctrine/doctrine-bundle: 2.*
- symfony/framework-bundle: 4.4.*
- symfony/orm-pack: ^1.0
- symfony/security-bundle: 4.4.*
This package is auto-updated.
Last update: 2024-09-16 01:58:35 UTC
README
Symfony Fail2banBundle 类似于 Linux fail2ban
安装
$ composer require karolkrupa/fail2ban-bundle
配置
# config/packages/fail2ban.yaml fail2ban: enabled: false block_for: '30 seconds' allowed_attempts_count: 2 #config_provider: App\Service\Fail2BanConfigProvider
配置提供者
配置提供者是一个可以提供包配置变量的类。多亏了它,你可以轻松地将配置存储在数据库中。
配置提供者实现
要创建一个配置提供者,你需要创建自己的服务,该服务实现 ConfigProvider 接口,并将其分配给 config_provider
包配置键。
示例实现
<?php namespace App\Service; use KarolKrupa\Fail2banBundle\ConfigProvider; class Fail2BanConfigProvider implements ConfigProvider { private $systemSettings; public function __construct(SystemSettings $systemSettings) { $this->systemSettings = $systemSettings; } public function get($name) { if($name == 'enabled') { return boolval($this->systemSettings->get('fail2ban.enabled', false)); } if($name == 'block_for') { return $this->systemSettings->get('fail2ban.block_for', null); } if($name == 'allowed_attempts_count') { return intval($this->systemSettings->get('fail2ban.attempts_count', 3)); } return false; } }