mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-18 15:31:06 +08:00
Added IP filter.
This commit is contained in:
@@ -17,6 +17,15 @@ use yii\helpers\Html;
|
|||||||
*/
|
*/
|
||||||
class Module extends \yii\base\Module
|
class Module extends \yii\base\Module
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var array the list of IPs that are allowed to access this module.
|
||||||
|
* Each array element represents a single IP filter which can be either an IP address
|
||||||
|
* or an address with wildcard (e.g. 192.168.0.*) to represent a network segment.
|
||||||
|
* The default value is `array('127.0.0.1', '::1')`, which means the module can only be accessed
|
||||||
|
* by localhost.
|
||||||
|
*/
|
||||||
|
public $allowedIPs = array('127.0.0.1', '::1');
|
||||||
|
|
||||||
public $controllerNamespace = 'yii\debug\controllers';
|
public $controllerNamespace = 'yii\debug\controllers';
|
||||||
/**
|
/**
|
||||||
* @var array|Panel[]
|
* @var array|Panel[]
|
||||||
@@ -40,8 +49,15 @@ class Module extends \yii\base\Module
|
|||||||
{
|
{
|
||||||
Yii::$app->getView()->off(View::EVENT_END_BODY, array($this, 'renderToolbar'));
|
Yii::$app->getView()->off(View::EVENT_END_BODY, array($this, 'renderToolbar'));
|
||||||
unset(Yii::$app->getLog()->targets['debug']);
|
unset(Yii::$app->getLog()->targets['debug']);
|
||||||
|
|
||||||
|
$ip = Yii::$app->getRequest()->getUserIP();
|
||||||
|
foreach ($this->allowedIPs as $filter) {
|
||||||
|
if ($filter === '*' || $filter === $ip || (($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos))) {
|
||||||
return parent::beforeAction($action);
|
return parent::beforeAction($action);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function renderToolbar($event)
|
public function renderToolbar($event)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user