Gii: Control access also by the hostname

close #7655
This commit is contained in:
Thiago Talma
2015-03-10 12:45:19 -03:00
committed by Carsten Brandt
parent 5f32d3af15
commit 127aae1e14
2 changed files with 14 additions and 1 deletions

View File

@ -4,7 +4,7 @@ Yii Framework 2 debug extension Change Log
2.0.4 under development
-----------------------
- no changes in this release.
- Enh #7655: Added ability to filter access by hostname (thiagotalma)
2.0.3 March 01, 2015

View File

@ -30,6 +30,13 @@ class Module extends \yii\base\Module implements BootstrapInterface
* by localhost.
*/
public $allowedIPs = ['127.0.0.1', '::1'];
/**
* @var array the list of hosts that are allowed to access this module.
* Each array element is a hostname that will be resolved to an IP address that is compared
* with the IP address of the user. A use case is to use a dynamic DNS (DDNS) to allow access.
* The default value is `[]`.
*/
public $allowedHosts = [];
/**
* @inheritdoc
*/
@ -197,6 +204,12 @@ class Module extends \yii\base\Module implements BootstrapInterface
return true;
}
}
foreach ($this->allowedHosts as $hostname) {
$filter = gethostbyname($hostname);
if ($filter === $ip) {
return true;
}
}
Yii::warning('Access to debugger is denied due to IP address restriction. The requesting IP address is ' . $ip, __METHOD__);
return false;
}