1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* admin |
5
|
|
|
* |
6
|
|
|
* @category Tollwerk |
7
|
|
|
* @package Tollwerk\Admin |
8
|
|
|
* @subpackage Tollwerk\Admin\Infrastructure\Model |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Tollwerk\Admin\Infrastructure\Model; |
38
|
|
|
|
39
|
|
|
use Tollwerk\Admin\Infrastructure\App; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Virtual host model |
43
|
|
|
* |
44
|
|
|
* @package Tollwerk\Admin |
45
|
|
|
* @subpackage Tollwerk\Admin\Infrastructure |
46
|
|
|
* @Entity |
47
|
|
|
* @HasLifecycleCallbacks |
48
|
|
|
* @Table(name="vhost",uniqueConstraints={@UniqueConstraint(name="docroot_idx", columns={"account_id", "docroot"})}) |
49
|
|
|
*/ |
50
|
|
|
class Vhost |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* Virtual host ID |
54
|
|
|
* |
55
|
|
|
* @var integer |
56
|
|
|
* @Id @Column(type="integer") |
57
|
|
|
* @GeneratedValue |
58
|
|
|
*/ |
59
|
|
|
protected $id; |
60
|
|
|
/** |
61
|
|
|
* Active |
62
|
|
|
* |
63
|
|
|
* @var boolean |
64
|
|
|
* @Column(type="boolean") |
65
|
|
|
*/ |
66
|
|
|
protected $active; |
67
|
|
|
/** |
68
|
|
|
* Account this domain is belonging to |
69
|
|
|
* |
70
|
|
|
* @var Account |
71
|
|
|
* @ManyToOne(targetEntity="Tollwerk\Admin\Infrastructure\Model\Account", inversedBy="vhosts") |
72
|
|
|
* @JoinColumn(name="account_id", referencedColumnName="id", onDelete="CASCADE") |
73
|
|
|
*/ |
74
|
|
|
protected $account; |
75
|
|
|
/** |
76
|
|
|
* Virtual host type |
77
|
|
|
* |
78
|
|
|
* @var string |
79
|
|
|
* @Column(type="enumvhosttype") |
80
|
|
|
*/ |
81
|
|
|
protected $type; |
82
|
|
|
/** |
83
|
|
|
* Primary domain of this virtual host |
84
|
|
|
* |
85
|
|
|
* @var Domain |
86
|
|
|
*/ |
87
|
|
|
protected $primarydomain; |
88
|
|
|
/** |
89
|
|
|
* List of all associated domains |
90
|
|
|
* |
91
|
|
|
* @var Domain[] |
92
|
|
|
* @OneToMany(targetEntity="Tollwerk\Admin\Infrastructure\Model\Domain", mappedBy="vhost") |
93
|
|
|
*/ |
94
|
|
|
protected $domains = []; |
95
|
|
|
/** |
96
|
|
|
* Document root directory |
97
|
|
|
* |
98
|
|
|
* @var string |
99
|
|
|
* @Column(length=128) |
100
|
|
|
*/ |
101
|
|
|
protected $docroot; |
102
|
|
|
/** |
103
|
|
|
* List of all associated protocol / port combinations |
104
|
|
|
* |
105
|
|
|
* @var Port[] |
106
|
|
|
* @OneToMany(targetEntity="Tollwerk\Admin\Infrastructure\Model\Port", mappedBy="vhost") |
107
|
|
|
*/ |
108
|
|
|
protected $ports = []; |
109
|
|
|
/** |
110
|
|
|
* Supported PHP version |
111
|
|
|
* |
112
|
|
|
* @var float|null |
113
|
|
|
* @Column(type="decimal",precision=2,scale=1,nullable=true) |
114
|
|
|
*/ |
115
|
|
|
protected $php = null; |
116
|
|
|
/** |
117
|
|
|
* Redirect URL |
118
|
|
|
* |
119
|
|
|
* @var string |
120
|
|
|
* @Column(length=128, nullable=true) |
121
|
|
|
*/ |
122
|
|
|
protected $redirecturl = null; |
123
|
|
|
/** |
124
|
|
|
* Redirect status |
125
|
|
|
* |
126
|
|
|
* @var int |
127
|
|
|
* @Column(type="integer", nullable=false, options={"unsigned":true, "default":301}) |
128
|
|
|
*/ |
129
|
|
|
protected $redirectstatus = \Tollwerk\Admin\Domain\Vhost\Vhost::REDIRECT_DEFAULT_STATUS; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Return the vhost ID |
133
|
|
|
* |
134
|
|
|
* @return int Vhost ID |
135
|
|
|
*/ |
136
|
|
|
public function getId() |
137
|
|
|
{ |
138
|
|
|
return $this->id; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Set the vhost ID |
143
|
|
|
* |
144
|
|
|
* @param int $id Vhost ID |
145
|
|
|
* @return Vhost |
146
|
|
|
*/ |
147
|
|
|
public function setId($id) |
148
|
|
|
{ |
149
|
|
|
$this->id = $id; |
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Set whether this is an active vhost |
155
|
|
|
* |
156
|
|
|
* @param boolean $active Active vhost |
157
|
|
|
* @return Vhost |
158
|
|
|
*/ |
159
|
|
|
public function setActive($active) |
160
|
|
|
{ |
161
|
|
|
$this->active = $active; |
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Return whether the vhost is ative |
167
|
|
|
* |
168
|
|
|
* @return boolean Active vhost |
169
|
|
|
*/ |
170
|
|
|
public function isActive() |
171
|
|
|
{ |
172
|
|
|
return $this->active; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Return the account this virtual host is belonging to |
177
|
|
|
* |
178
|
|
|
* @return Account Account |
179
|
|
|
*/ |
180
|
|
|
public function getAccount() |
181
|
|
|
{ |
182
|
|
|
return $this->account; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Set the account this virtual host is belonging tp |
187
|
|
|
* |
188
|
|
|
* @param Account $account Account |
189
|
|
|
* @return Vhost Self reference |
190
|
|
|
*/ |
191
|
|
|
public function setAccount($account) |
192
|
|
|
{ |
193
|
|
|
$this->account = $account; |
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Return the virtual host type |
199
|
|
|
* |
200
|
|
|
* @return string Virtual host type |
201
|
|
|
*/ |
202
|
|
|
public function getType() |
203
|
|
|
{ |
204
|
|
|
return $this->type; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Set the virtual host type |
209
|
|
|
* |
210
|
|
|
* @param string $type Virtual host type |
211
|
|
|
* @return Vhost Self reference |
212
|
|
|
*/ |
213
|
|
|
public function setType($type) |
214
|
|
|
{ |
215
|
|
|
$this->type = $type; |
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Return the associated domains |
221
|
|
|
* |
222
|
|
|
* @return Domain[] Associated domains |
223
|
|
|
*/ |
224
|
|
|
public function getDomains() |
225
|
|
|
{ |
226
|
|
|
return $this->domains; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Set the associated domains |
231
|
|
|
* |
232
|
|
|
* @param Domain[] $domains Associated domains |
233
|
|
|
* @return Vhost Self reference |
234
|
|
|
*/ |
235
|
|
|
public function setDomains(array $domains) |
236
|
|
|
{ |
237
|
|
|
$this->domains = $domains; |
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Return the primary domain of this virtual host |
243
|
|
|
* |
244
|
|
|
* @return Domain Primary domain |
245
|
|
|
*/ |
246
|
|
|
public function getPrimarydomain() |
247
|
|
|
{ |
248
|
|
|
if ($this->primarydomain === null) { |
249
|
|
|
$entityManager = App::getEntityManager(); |
250
|
|
|
$domainRepository = $entityManager->getRepository(Domain::class); |
251
|
|
|
$this->primarydomain = $domainRepository->findOneBy(['vhost' => $this->getId(), 'primarydomain' => 1]); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
return $this->primarydomain; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Set the primary domain of this virtual host |
259
|
|
|
* |
260
|
|
|
* @param Domain $primarydomain Primary domain |
261
|
|
|
* @return Vhost Self reference |
262
|
|
|
*/ |
263
|
|
|
public function setPrimarydomain($primarydomain) |
264
|
|
|
{ |
265
|
|
|
$this->primarydomain = $primarydomain; |
266
|
|
|
return $this; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Return the document root |
271
|
|
|
* |
272
|
|
|
* @return string Document root |
273
|
|
|
*/ |
274
|
|
|
public function getDocroot() |
275
|
|
|
{ |
276
|
|
|
return $this->docroot; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Set the document root |
281
|
|
|
* |
282
|
|
|
* @param string $docroot Document root |
283
|
|
|
* @return Vhost Self reference |
284
|
|
|
*/ |
285
|
|
|
public function setDocroot($docroot) |
286
|
|
|
{ |
287
|
|
|
$this->docroot = $docroot; |
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Return the associated protocols / port |
293
|
|
|
* |
294
|
|
|
* @return Port[] Associated protocols / port |
295
|
|
|
*/ |
296
|
|
|
public function getPorts() |
297
|
|
|
{ |
298
|
|
|
return $this->ports; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Set the associated protocols / port |
303
|
|
|
* |
304
|
|
|
* @param Port[] $ports Associated protocols / port |
305
|
|
|
* @return Vhost Self reference |
306
|
|
|
*/ |
307
|
|
|
public function setPorts(array $ports) |
308
|
|
|
{ |
309
|
|
|
$this->ports = $ports; |
310
|
|
|
return $this; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Return the supported PHP version |
315
|
|
|
* |
316
|
|
|
* @return float|null Supported PHP version |
317
|
|
|
*/ |
318
|
|
|
public function getPhp() |
319
|
|
|
{ |
320
|
|
|
return $this->php; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Set the supported PHP version |
325
|
|
|
* |
326
|
|
|
* @param float|null $php Supported PHP version |
327
|
|
|
* @return Vhost Self reference |
328
|
|
|
*/ |
329
|
|
|
public function setPhp($php) |
330
|
|
|
{ |
331
|
|
|
$this->php = $php; |
332
|
|
|
return $this; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Return the redirect URL |
337
|
|
|
* |
338
|
|
|
* @return string Redirect URL |
339
|
|
|
*/ |
340
|
|
|
public function getRedirecturl() |
341
|
|
|
{ |
342
|
|
|
return $this->redirecturl; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Set the redirect URL |
347
|
|
|
* |
348
|
|
|
* @param string $redirecturl Redirect URL |
349
|
|
|
* @return Vhost Self reference |
350
|
|
|
*/ |
351
|
|
|
public function setRedirecturl($redirecturl) |
352
|
|
|
{ |
353
|
|
|
$this->redirecturl = $redirecturl; |
354
|
|
|
return $this; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Return the redirect status |
359
|
|
|
* |
360
|
|
|
* @return int Redirect status |
361
|
|
|
*/ |
362
|
|
|
public function getRedirectstatus() |
363
|
|
|
{ |
364
|
|
|
return $this->redirectstatus; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Set the redirect status |
369
|
|
|
* |
370
|
|
|
* @param int $redirectstatus Redirect status |
371
|
|
|
* @return Vhost Self reference |
372
|
|
|
*/ |
373
|
|
|
public function setRedirectstatus($redirectstatus) |
374
|
|
|
{ |
375
|
|
|
$this->redirectstatus = $redirectstatus; |
376
|
|
|
return $this; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* Release the primary domain on deletion of this virtual host |
381
|
|
|
* |
382
|
|
|
* @PreRemove |
383
|
|
|
*/ |
384
|
|
|
public function releasePrimaryDomain() |
385
|
|
|
{ |
386
|
|
|
$this->getPrimarydomain()->setPrimarydomain(false); |
387
|
|
|
App::getEntityManager()->persist($this->getPrimarydomain()); |
388
|
|
|
App::getEntityManager()->flush(); |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|