1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Hosting Plugin for HiPanel |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hipanel-module-hosting |
7
|
|
|
* @package hipanel-module-hosting |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\modules\hosting\models; |
13
|
|
|
|
14
|
|
|
use hipanel\modules\client\validators\LoginValidator as ClientLoginValidator; |
15
|
|
|
use hipanel\modules\hosting\validators\LoginValidator as AccountLoginValidator; |
16
|
|
|
use hipanel\validators\DomainValidator; |
17
|
|
|
use Yii; |
18
|
|
|
use yii\web\JsExpression; |
19
|
|
|
|
20
|
|
|
class Hdomain extends \hipanel\base\Model |
21
|
|
|
{ |
22
|
|
|
use \hipanel\base\ModelTrait; |
23
|
|
|
|
24
|
|
|
const STATE_OK = 'ok'; |
25
|
|
|
const STATE_BLOCKED = 'blocked'; |
26
|
|
|
const STATE_DELETED = 'deleted'; |
27
|
|
|
const STATE_DISABLED = 'disabled'; |
28
|
|
|
const STATE_TEMPORARY = 'temporary'; |
29
|
|
|
|
30
|
|
|
public function init() |
31
|
|
|
{ |
32
|
|
|
$this->on(self::EVENT_AFTER_FIND, function ($event) { |
|
|
|
|
33
|
|
|
$this->setAttributes([ |
34
|
|
|
'ip' => $this->getAttribute('vhost')['ip'], |
35
|
|
|
'backend_ip' => $this->getAttribute('vhost')['backend']['ip'], |
36
|
|
|
'proxy_enabled' => $this->getIsProxied(), |
37
|
|
|
]); |
38
|
|
|
}); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array Stores array of additional info for vhost of hdomain |
43
|
|
|
*/ |
44
|
|
|
public $vhost; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var array Stores array of aliases of hdomain |
48
|
|
|
*/ |
49
|
|
|
public $aliases; |
50
|
|
|
|
51
|
|
|
/** @inheritdoc */ |
52
|
|
|
public function rules() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
[ |
56
|
|
|
[ |
57
|
|
|
'id', |
58
|
|
|
'server_id', |
59
|
|
|
'client_id', |
60
|
|
|
'seller_id', |
61
|
|
|
'account_id', |
62
|
|
|
'hdomain_id', |
63
|
|
|
'state_id', |
64
|
|
|
'type_id', |
65
|
|
|
'vhost_id', |
66
|
|
|
'device_id', |
67
|
|
|
'dns_hdomain_id', |
68
|
|
|
], |
69
|
|
|
'integer' |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
[ |
73
|
|
|
'server', |
74
|
|
|
'device', |
75
|
|
|
'state', |
76
|
|
|
'type', |
77
|
|
|
'backuping_type', |
78
|
|
|
'state_label', |
79
|
|
|
'alias_type', |
80
|
|
|
'proxy_enabled', |
81
|
|
|
'dns_hdomain_domain', |
82
|
|
|
], |
83
|
|
|
'safe' |
84
|
|
|
], |
85
|
|
|
[['client', 'seller'], ClientLoginValidator::class], |
86
|
|
|
[['account'], AccountLoginValidator::class], |
87
|
|
|
[['with_www'], 'boolean', 'on' => ['create-alias']], |
88
|
|
|
[['dns_on', 'with_www', 'proxy_enable'], 'boolean', 'on' => ['create']], |
89
|
|
|
[['domain', 'alias'], DomainValidator::class], |
90
|
|
|
[['ip', 'backend_ip'], 'ip'], |
91
|
|
|
[['ip'], 'required', 'on' => ['create']], |
92
|
|
|
[['domain', 'id'], 'safe', 'on' => ['enable-paid-feature-autorenewal', 'disable-paid-feature-autorenewal']], |
93
|
|
|
[ |
94
|
|
|
[ |
95
|
|
|
'server', |
96
|
|
|
'account', |
97
|
|
|
'domain', |
98
|
|
|
'path', |
99
|
|
|
'ip', |
100
|
|
|
], |
101
|
|
|
'required', |
102
|
|
|
'on' => ['create'] |
103
|
|
|
], |
104
|
|
|
[ |
105
|
|
|
['subdomain'], |
106
|
|
|
'match', |
107
|
|
|
'pattern' => '/^(\*|[a-z0-9][a-z0-9-]*)$/i', |
108
|
|
|
'message' => \Yii::t('app', '{attribute} does not look like a domain part'), |
109
|
|
|
'on' => ['create-alias'] |
110
|
|
|
], |
111
|
|
|
[ |
112
|
|
|
[ |
113
|
|
|
'server', |
114
|
|
|
'account', |
115
|
|
|
'vhost_id', |
116
|
|
|
], |
117
|
|
|
'required', |
118
|
|
|
'on' => ['create-alias'] |
119
|
|
|
], |
120
|
|
|
[ |
121
|
|
|
[ |
122
|
|
|
'domain', |
123
|
|
|
], |
124
|
|
|
'required', |
125
|
|
|
'when' => function ($model) { |
126
|
|
|
return $model->alias_type === 'new'; |
127
|
|
|
}, |
128
|
|
|
'whenClient' => new JsExpression("function (attribute, value) { |
129
|
|
|
return false; |
130
|
|
|
}"), |
131
|
|
|
'on' => ['create-alias'] |
132
|
|
|
], |
133
|
|
|
[ |
134
|
|
|
['id'], |
135
|
|
|
'required', |
136
|
|
|
'on' => ['manage-proxy', 'delete'] |
137
|
|
|
], |
138
|
|
|
[['type', 'comment'], 'required', 'on' => ['enable-block']], |
139
|
|
|
[['comment'], 'safe', 'on' => ['disable-block']], |
140
|
|
|
[['id', 'dns_on'], 'safe', 'on' => ['set-dns-on']], |
141
|
|
|
]; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function getIsProxied() |
145
|
|
|
{ |
146
|
|
|
return isset($this->getAttribute('vhost')['backend']); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** @inheritdoc */ |
150
|
|
|
public function attributeLabels() |
151
|
|
|
{ |
152
|
|
|
return $this->mergeAttributeLabels([ |
153
|
|
|
'domain' => Yii::t('app', 'Domain Name'), |
154
|
|
|
'backend_ip' => Yii::t('app', 'Backend IP'), |
155
|
|
|
'with_www' => Yii::t('app', 'Create www alias'), |
156
|
|
|
'proxy_enable' => Yii::t('app', 'Enable proxy (NEED MANUAL)'), |
157
|
|
|
'backuping_type' => Yii::t('app', 'Backup periodicity'), |
158
|
|
|
'dns_on' => Yii::t('hipanel/hosting', 'DNS'), |
159
|
|
|
'vhost_id' => Yii::t('app', 'Alias for'), |
160
|
|
|
'comment' => Yii::t('app', 'Comment'), |
161
|
|
|
'proxy_enabled' => Yii::t('hipanel/hosting', 'Proxy enabled'), |
162
|
|
|
'path' => Yii::t('hipanel/hosting', 'Path'), |
163
|
|
|
]); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function getIsBlocked() |
167
|
|
|
{ |
168
|
|
|
return $this->state === static::STATE_BLOCKED; |
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function getDnsId() |
172
|
|
|
{ |
173
|
|
|
return $this->dns_hdomain_id ?: $this->id; |
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function isAlias() |
177
|
|
|
{ |
178
|
|
|
return isset($this->vhost_id); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function scenarioCommands() |
182
|
|
|
{ |
183
|
|
|
$result = []; |
184
|
|
|
|
185
|
|
|
if (in_array($this->scenario, ['create', 'update'], true)) { |
186
|
|
|
$result['create'] = ['vhosts', ucfirst($this->scenario)]; // Create must be sent to vhost module |
187
|
|
|
} |
188
|
|
|
$result['create-alias'] = 'create'; |
189
|
|
|
$result['set-dns-on'] = 'update'; |
190
|
|
|
return $result; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.