karolkrupa / fail2ban-bundle

Fail2BanBundle 类似于 Linux 中的 fail2ban

安装: 42

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

公开问题: 0

类型:symfony-bundle

dev-master 2020-07-15 16:46 UTC

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;
    }
}