minor enhancement of debugger.

This commit is contained in:
Qiang Xue
2013-08-10 07:33:55 -04:00
parent bc21de98bd
commit 1f63bf0040
6 changed files with 36 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ namespace yii\debug;
use Yii;
use yii\base\View;
use yii\web\HttpException;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
@@ -64,17 +65,20 @@ class Module extends \yii\base\Module
unset(Yii::$app->getLog()->targets['debug']);
$this->logTarget = null;
$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);
}
if ($this->checkAccess($action)) {
return true;
} elseif ($action->id === 'toolbar') {
return false;
} else {
throw new HttpException(403, 'You are not allowed to access this page.');
}
return false;
}
public function renderToolbar($event)
{
if (!$this->checkAccess()) {
return;
}
$url = Yii::$app->getUrlManager()->createUrl($this->id . '/default/toolbar', array(
'tag' => $this->logTarget->tag,
));
@@ -85,6 +89,17 @@ class Module extends \yii\base\Module
echo '<script>' . $view->renderPhpFile(__DIR__ . '/views/default/toolbar.js') . '</script>';
}
protected function checkAccess()
{
$ip = Yii::$app->getRequest()->getUserIP();
foreach ($this->allowedIPs as $filter) {
if ($filter === '*' || $filter === $ip || (($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos))) {
return true;
}
}
return false;
}
protected function corePanels()
{
return array(