maxcrossan/yii_ip_blocker

将阻止并注销不在白名单中的任何用户

1.0 2018-05-23 17:06 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:49:19 UTC


README

这将阻止并注销IP地址不在白名单中的任何用户

安装

运行Composer命令以安装IPBlocker的最新稳定版本

    php composer.phar require maxcrossan/yii_ip_blocker

配置组件并在protected/config/main.php中预加载它

    'preload'=>array('ip-blocker'),
    
    'components'=>array(
        'ip-blocker' => array(
            'class' => Crossan\IPBlocker::class,
            //Expression to validate on (should return true if validation is required)
            'validateOn' => '!Yii::app()->user->isGuest',
            //{ip} will be replaced
            'blockedMessage' => "Access to this system is blocked from your IP: {ip}.",
            // Network ranges can be specified as:
            // 1. Wildcard format:     1.2.3.*
            // 2. CIDR format:         1.2.3/24  OR  1.2.3.4/255.255.255.0
            // 3. Start-End IP format: 1.2.3.0-1.2.3.255
            'whitelistedIPs' => array(
                ':1', '127.0.0.1', //
                '123.123.123.123', //Office
            ),
            'whitelistArraySupplier' => null, //Use this to grab IPs from a method somewhere in your codebase. Will override whitelistedIPs if set.
        ),
    )