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