1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* admin |
5
|
|
|
* |
6
|
|
|
* @category Tollwerk |
7
|
|
|
* @package Tollwerk\Admin |
8
|
|
|
* @subpackage Tollwerk\Admin\Ports\Facade |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2016 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 © 2016 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\Ports\Facade; |
38
|
|
|
|
39
|
|
|
use Tollwerk\Admin\Domain\Vhost\Vhost as DomainVhost; |
40
|
|
|
use Tollwerk\Admin\Domain\Vhost\VhostInterface; |
41
|
|
|
use Tollwerk\Admin\Infrastructure\App; |
42
|
|
|
use Tollwerk\Admin\Infrastructure\Facade\AbstractFacade; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Virtual host facade |
46
|
|
|
* |
47
|
|
|
* @package Tollwerk\Admin |
48
|
|
|
* @subpackage Tollwerk\Admin\Ports |
49
|
|
|
*/ |
50
|
|
|
class Vhost extends AbstractFacade |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* Create and add a virtual host to an account |
54
|
|
|
* |
55
|
|
|
* @param string $account Account name |
56
|
|
|
* @param string $domain Primary domain name |
57
|
|
|
* @param string $docroot Document root |
58
|
|
|
* @param string $type Virtual host type |
59
|
|
|
* @return boolean Success |
60
|
|
|
*/ |
61
|
|
|
public static function create($account, $domain, $docroot = '', $type = DomainVhost::TYPE_APACHE) |
62
|
|
|
{ |
63
|
|
|
// Get the account to operate on |
64
|
|
|
$account = self::loadAccount($account); |
65
|
|
|
|
66
|
|
|
// Load the primary domain |
67
|
|
|
$domain = App::getDomainService()->loadUnassigned($domain, $account); |
68
|
|
|
|
69
|
|
|
return App::getVirtualHostService()->create($account, $domain, $docroot, $type) instanceof VhostInterface; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Delete and remove a virtual host from an account |
74
|
|
|
* |
75
|
|
|
* @param string $account Account name |
76
|
|
|
* @param string $docroot Document root |
77
|
|
|
* @return boolean Success |
78
|
|
|
*/ |
79
|
|
|
public static function delete($account, $docroot = '') |
80
|
|
|
{ |
81
|
|
|
// Get the account to operate on |
82
|
|
|
$account = self::loadAccount($account); |
83
|
|
|
|
84
|
|
|
return App::getVirtualHostService()->delete($account, $docroot) instanceof VhostInterface; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Enable a virtual host |
89
|
|
|
* |
90
|
|
|
* @param string $account Account name |
91
|
|
|
* @param string $docroot Document root |
92
|
|
|
* @return bool Success |
93
|
|
|
*/ |
94
|
|
|
public static function enable($account, $docroot = '') |
95
|
|
|
{ |
96
|
|
|
// Get the account to operate on |
97
|
|
|
$account = self::loadAccount($account); |
98
|
|
|
|
99
|
|
|
return App::getVirtualHostService()->enable($account, $docroot) instanceof VhostInterface; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Disable a virtual host |
104
|
|
|
* |
105
|
|
|
* @param string $account Account name |
106
|
|
|
* @param string $docroot Document root |
107
|
|
|
* @return bool Success |
108
|
|
|
*/ |
109
|
|
|
public static function disable($account, $docroot = '') |
110
|
|
|
{ |
111
|
|
|
// Get the account to operate on |
112
|
|
|
$account = self::loadAccount($account); |
113
|
|
|
|
114
|
|
|
return App::getVirtualHostService()->disable($account, $docroot) instanceof VhostInterface; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Redirect a virtual host |
119
|
|
|
* |
120
|
|
|
* @param string $account Account name |
121
|
|
|
* @param string $docroot Document root |
122
|
|
|
* @param string $url Redirect URL |
123
|
|
|
* @param int $status Redirect HTTP status |
124
|
|
|
* @return bool Success |
125
|
|
|
*/ |
126
|
|
|
public static function redirect($account, $docroot = '', $url = '', $status = DomainVhost::REDIRECT_DEFAULT_STATUS) |
127
|
|
|
{ |
128
|
|
|
// Get the account to operate on |
129
|
|
|
$account = self::loadAccount($account); |
130
|
|
|
|
131
|
|
|
return App::getVirtualHostService() |
132
|
|
|
->redirect($account, $docroot, $url, intval($status)) instanceof VhostInterface; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Configure the PHP version of a virtual host |
137
|
|
|
* |
138
|
|
|
* @param string $account Account name |
139
|
|
|
* @param string $docroot Document root |
140
|
|
|
* @param string|null $php PHP version |
141
|
|
|
* @return bool Success |
142
|
|
|
*/ |
143
|
|
|
public static function php($account, $docroot = '', $php = null) |
144
|
|
|
{ |
145
|
|
|
// Get the account to operate on |
146
|
|
|
$account = self::loadAccount($account); |
147
|
|
|
|
148
|
|
|
return App::getVirtualHostService()->php($account, $docroot, $php) instanceof VhostInterface; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Configure a protocol based port for a virtual host |
153
|
|
|
* |
154
|
|
|
* @param string $account Account name |
155
|
|
|
* @param string $docroot Document root |
156
|
|
|
* @param int $protocol Protocol |
157
|
|
|
* @param int|null $port Port |
158
|
|
|
* @return bool Success |
159
|
|
|
*/ |
160
|
|
|
public static function port( |
161
|
|
|
$account, |
162
|
|
|
$docroot = '', |
163
|
|
|
$protocol = \Tollwerk\Admin\Domain\Vhost\Vhost::PROTOCOL_HTTP, |
164
|
|
|
$port = null |
165
|
|
|
) { |
166
|
|
|
// Get the account to operate on |
167
|
|
|
$account = self::loadAccount($account); |
168
|
|
|
|
169
|
|
|
return App::getVirtualHostService()->port($account, $docroot, $protocol, $port) instanceof VhostInterface; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Add a secondary domain to a virtual host |
174
|
|
|
* |
175
|
|
|
* @param string $account Account name |
176
|
|
|
* @param string $domain Domain |
177
|
|
|
* @param string $docroot Document root |
178
|
|
|
* @return bool Success |
179
|
|
|
*/ |
180
|
|
|
public static function addDomain($account, $domain, $docroot = '') |
181
|
|
|
{ |
182
|
|
|
// Get the account to operate on |
183
|
|
|
$account = self::loadAccount($account); |
184
|
|
|
|
185
|
|
|
// Load the primary domain |
186
|
|
|
$domain = App::getDomainService()->loadUnassigned($domain, $account); |
187
|
|
|
|
188
|
|
|
return App::getVirtualHostService()->addDomain($account, $domain, $docroot) instanceof VhostInterface; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Remove a secondary domain from a virtual host |
193
|
|
|
* |
194
|
|
|
* @param string $account Account name |
195
|
|
|
* @param string $domain Domain |
196
|
|
|
* @param string $docroot Document root |
197
|
|
|
* @return bool Success |
198
|
|
|
*/ |
199
|
|
|
public static function removeDomain($account, $domain, $docroot = '') |
200
|
|
|
{ |
201
|
|
|
// Get the account to operate on |
202
|
|
|
$account = self::loadAccount($account); |
203
|
|
|
|
204
|
|
|
// Load the primary domain |
205
|
|
|
$domain = App::getDomainService()->loadAssigned($domain, $account, $docroot); |
206
|
|
|
|
207
|
|
|
return App::getVirtualHostService()->removeDomain($account, $domain, $docroot) instanceof VhostInterface; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|