-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
70 lines (56 loc) · 1.95 KB
/
Copy pathModule.php
File metadata and controls
70 lines (56 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* 邢帅教育
* 本源代码由邢帅教育及其作者共同所有,未经版权持有者的事先书面授权,
* 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
* @copyright Copyright (c) 2013 xsteach.com all rights reserved.
*/
namespace choate\vsftpd;
use Yii;
use yii\base\Application;
use yii\base\BootstrapInterface;
use yii\base\InvalidConfigException;
use yii\web\ForbiddenHttpException;
/**
* Class Module
* @package choate\vsftpd
* @author Choate <[email protected]>
*/
class Module extends \yii\base\Module
{
public $layout = 'main';
public $allowedIPs = ['127.0.0.1', '::1'];
public $controllerNamespace = 'choate\vsftpd\controllers';
public $vsftpdUserConfigPath = '/tmp';
public $vsftpdLocalRoot = '';
public $vsftpdUser = '';
public $newFileMode = 0666;
public function init() {
parent::init();
if (!is_writeable($this->vsftpdUserConfigPath)) {
throw new InvalidConfigException('vsftpdUserConfigPath');
}
if (empty($this->vsftpdUser)) {
throw new InvalidConfigException('vsftpdUser');
}
}
public function beforeAction($action) {
if (!parent::beforeAction($action)) {
return false;
}
if (Yii::$app instanceof \yii\web\Application && !$this->checkAccess()) {
throw new ForbiddenHttpException('You are not allowed to access this page.');
}
return true;
}
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;
}
}
Yii::warning('Access to Gii is denied due to IP address restriction. The requested IP is ' . $ip, __METHOD__);
return false;
}
}