项目作者: maxodrom

项目描述 :
Yii2 Redis IP ban filter action.
高级语言: PHP
项目地址: git://github.com/maxodrom/yii2-redis-ipban.git
创建时间: 2017-03-05T14:34:29Z
项目社区:https://github.com/maxodrom/yii2-redis-ipban

开源协议:MIT License

下载


yii2-redis-ipban

Yii2 Redis IP ban

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

  1. "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:

  1. return [
  2. //....
  3. 'components' => [
  4. 'redis' => [
  5. 'class' => 'yii\redis\Connection',
  6. 'hostname' => 'localhost',
  7. 'port' => 6379,
  8. 'database' => 0,
  9. ],
  10. ]
  11. ];

Also add the following to your application modules config:

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

In your Controller you should use:

  1. /**
  2. * @inheritdoc
  3. */
  4. public function behaviors()
  5. {
  6. return [
  7. ...,
  8. 'ipban' => [
  9. 'class' => \maxodrom\redis\ipban\filters\RedisIpBan::className(),
  10. 'redis' => Yii::$app->redis,
  11. ],
  12. ];
  13. }