maxodrom/yii2-redis-ipban

Yii 2 Redis IP ban filter action.

Installs: 47

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

1.4.2 2017-05-08 16:09 UTC

This package is not auto-updated.

Last update: 2024-04-13 18:07:57 UTC


README

Yii2 Redis IP ban

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist maxodrom/yii2-redis-ipban

or add

"maxodrom/yii2-redis-ipban": "~1.0"

to the require section of your composer.json.

Configuration & Usage

To use this extension, you have to configure the Connection class in your application configuration:

return [
    //....
    'components' => [
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 0,
        ],
    ]
];

Also add the following to your application modules config:

'modules' => [
    'redis-ip-ban' => [
        'class' => 'maxodrom\redis\ipban\Module',
        'redis' => 'redis',
        'allowedIPs' => [], // dont't check IPs, otherwise you can use for example this array ['127.0.0.1', '::1']
        'allowedRoles' => ['SuperAdmin'], // but check RBAC roles!
    ],
    ...
]

In your Controller you should use:

/**
 * @inheritdoc
 */
public function behaviors()
{
    return [
        ...,
        'ipban' => [
            'class' => \maxodrom\redis\ipban\filters\RedisIpBan::className(),
            'redis' => Yii::$app->redis,
        ],
    ];
}