commit | author | age
|
18341e
|
1 |
<?php |
T |
2 |
/* |
|
3 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
4 |
All rights reserved. |
|
5 |
|
|
6 |
Redistribution and use in source and binary forms, with or without modification, |
|
7 |
are permitted provided that the following conditions are met: |
|
8 |
|
|
9 |
* Redistributions of source code must retain the above copyright notice, |
|
10 |
this list of conditions and the following disclaimer. |
|
11 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer in the documentation |
|
13 |
and/or other materials provided with the distribution. |
|
14 |
* Neither the name of ISPConfig nor the names of its contributors |
|
15 |
may be used to endorse or promote products derived from this software without |
|
16 |
specific prior written permission. |
|
17 |
|
|
18 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
19 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
21 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
22 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
23 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
25 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
26 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
27 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
*/ |
|
29 |
|
|
30 |
|
|
31 |
/****************************************** |
|
32 |
* Begin Form configuration |
|
33 |
******************************************/ |
|
34 |
|
|
35 |
$tform_def_file = "form/web_subdomain.tform.php"; |
|
36 |
|
|
37 |
/****************************************** |
|
38 |
* End Form configuration |
|
39 |
******************************************/ |
|
40 |
|
7fe908
|
41 |
require_once '../../lib/config.inc.php'; |
MC |
42 |
require_once '../../lib/app.inc.php'; |
18341e
|
43 |
|
910093
|
44 |
//* Check permissions for module |
T |
45 |
$app->auth->check_module_permissions('sites'); |
18341e
|
46 |
|
T |
47 |
// Loading classes |
10b4c8
|
48 |
$app->uses('tpl,tform,tform_actions,tools_sites'); |
18341e
|
49 |
$app->load('tform_actions'); |
T |
50 |
|
|
51 |
class page_action extends tform_actions { |
7fe908
|
52 |
|
d4d985
|
53 |
var $parent_domain_record; |
7fe908
|
54 |
|
4fae7e
|
55 |
function onShowNew() { |
T |
56 |
global $app, $conf; |
7fe908
|
57 |
|
4fae7e
|
58 |
// we will check only users, not admins |
T |
59 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
7fe908
|
60 |
if(!$app->tform->checkClientLimit('limit_web_subdomain', "(type = 'subdomain' OR type = 'vhostsubdomain')")) { |
3cebc3
|
61 |
$app->error($app->tform->wordbook["limit_web_subdomain_txt"]); |
T |
62 |
} |
7fe908
|
63 |
if(!$app->tform->checkResellerLimit('limit_web_subdomain', "(type = 'subdomain' OR type = 'vhostsubdomain')")) { |
3cebc3
|
64 |
$app->error('Reseller: '.$app->tform->wordbook["limit_web_subdomain_txt"]); |
4fae7e
|
65 |
} |
T |
66 |
} |
7fe908
|
67 |
|
4fae7e
|
68 |
parent::onShowNew(); |
T |
69 |
} |
7fe908
|
70 |
|
18341e
|
71 |
function onShowEnd() { |
T |
72 |
global $app, $conf; |
7fe908
|
73 |
|
4e18bd
|
74 |
$app->uses('ini_parser,getconf'); |
M |
75 |
$settings = $app->getconf->get_global_config('domains'); |
|
76 |
if ($settings['use_domain_module'] == 'y') { |
|
77 |
/* |
|
78 |
* The domain-module is in use. |
|
79 |
*/ |
10b4c8
|
80 |
$domains = $app->tools_sites->getDomainModuleDomains(); |
4e18bd
|
81 |
$domain_select = ''; |
7fe908
|
82 |
$selected_domain = ''; |
4e18bd
|
83 |
if(is_array($domains) && sizeof($domains) > 0) { |
M |
84 |
/* We have domains in the list, so create the drop-down-list */ |
|
85 |
foreach( $domains as $domain) { |
|
86 |
$domain_select .= "<option value=" . $domain['domain_id'] ; |
|
87 |
if ('.' . $domain['domain'] == substr($this->dataRecord["domain"], -strlen($domain['domain']) - 1)) { |
|
88 |
$domain_select .= " selected"; |
7fe908
|
89 |
$selected_domain = $domain['domain']; |
4e18bd
|
90 |
} |
8c1761
|
91 |
$domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n"; |
4e18bd
|
92 |
} |
M |
93 |
} |
|
94 |
else { |
|
95 |
/* |
|
96 |
* We have no domains in the domain-list. This means, we can not add ANY new domain. |
|
97 |
* To avoid, that the variable "domain_option" is empty and so the user can |
|
98 |
* free enter a domain, we have to create a empty option! |
|
99 |
*/ |
|
100 |
$domain_select .= "<option value=''></option>\r\n"; |
|
101 |
} |
7fe908
|
102 |
$app->tpl->setVar("domain_option", $domain_select); |
MC |
103 |
$this->dataRecord['domain'] = substr($this->dataRecord["domain"], 0, strlen($this->dataRecord['domain']) - strlen($selected_domain) - 1); |
4e18bd
|
104 |
} else { |
7fe908
|
105 |
|
MC |
106 |
// Get the record of the parent domain |
|
107 |
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".$app->functions->intval(@$this->dataRecord["parent_domain_id"])); |
|
108 |
|
|
109 |
// remove the parent domain part of the domain name before we show it in the text field. |
|
110 |
$this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"], '', $this->dataRecord["domain"]); |
|
111 |
} |
|
112 |
$app->tpl->setVar("domain", $this->dataRecord["domain"]); |
|
113 |
|
bfcdef
|
114 |
if($_SESSION["s"]["user"]["typ"] == 'admin') { |
7fe908
|
115 |
// Directive Snippets |
bfcdef
|
116 |
$proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y'"); |
T |
117 |
$proxy_directive_snippets_txt = ''; |
|
118 |
if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){ |
|
119 |
foreach($proxy_directive_snippets as $proxy_directive_snippet){ |
|
120 |
$proxy_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$proxy_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.$proxy_directive_snippet['snippet'].'</pre></a> '; |
|
121 |
} |
|
122 |
} |
|
123 |
if($proxy_directive_snippets_txt == '') $proxy_directive_snippets_txt = '------'; |
7fe908
|
124 |
$app->tpl->setVar("proxy_directive_snippets_txt", $proxy_directive_snippets_txt); |
bfcdef
|
125 |
} |
7fe908
|
126 |
|
18341e
|
127 |
parent::onShowEnd(); |
7fe908
|
128 |
|
18341e
|
129 |
} |
T |
130 |
|
|
131 |
function onSubmit() { |
|
132 |
global $app, $conf; |
896a58
|
133 |
|
FT |
134 |
// Get the record of the parent domain |
|
135 |
if(!@$this->dataRecord["parent_domain_id"] && $this->id) { |
|
136 |
$tmp = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id)); |
|
137 |
if($tmp) $this->dataRecord["parent_domain_id"] = $tmp['parent_domain_id']; |
|
138 |
unset($tmp); |
|
139 |
} |
7fe908
|
140 |
|
MC |
141 |
// Get the record of the parent domain |
|
142 |
$parent_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval(@$this->dataRecord["parent_domain_id"]) . " AND ".$app->tform->getAuthSQL('r')); |
|
143 |
if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); |
9a02e2
|
144 |
/* check if the domain module is used - and check if the selected domain can be used! */ |
4e18bd
|
145 |
$app->uses('ini_parser,getconf'); |
M |
146 |
$settings = $app->getconf->get_global_config('domains'); |
|
147 |
if ($settings['use_domain_module'] == 'y') { |
7fe908
|
148 |
// get the record of the domain module domain |
MC |
149 |
$domain = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['sel_domain']); |
|
150 |
if(!$domain) { |
|
151 |
$app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />"; |
|
152 |
} else { |
|
153 |
$this->dataRecord['domain'] = $this->dataRecord['domain'] . '.' . $domain; |
|
154 |
} |
|
155 |
} else { |
|
156 |
$this->dataRecord["domain"] = $this->dataRecord["domain"].'.'.$parent_domain["domain"]; |
|
157 |
} |
|
158 |
|
43b345
|
159 |
// nginx: if redirect type is proxy and redirect path is no URL, display error |
7fe908
|
160 |
if($this->dataRecord["redirect_type"] == 'proxy' && substr($this->dataRecord['redirect_path'], 0, 1) == '/'){ |
43b345
|
161 |
$app->tform->errorMessage .= $app->tform->lng("error_proxy_requires_url")."<br />"; |
T |
162 |
} |
7fe908
|
163 |
|
18341e
|
164 |
// Set a few fixed values |
T |
165 |
$this->dataRecord["type"] = 'subdomain'; |
|
166 |
$this->dataRecord["server_id"] = $parent_domain["server_id"]; |
7fe908
|
167 |
|
d4d985
|
168 |
$this->parent_domain_record = $parent_domain; |
7fe908
|
169 |
|
4e18bd
|
170 |
//* make sure that the domain is lowercase |
04620b
|
171 |
if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]); |
896a58
|
172 |
|
e1b4ca
|
173 |
// Check custom PHP version |
TB |
174 |
if(isset($this->dataRecord['fastcgi_php_version']) && $this->dataRecord['fastcgi_php_version'] != '') { |
|
175 |
// Check php-fpm mode |
|
176 |
if($this->dataRecord['php'] == 'php-fpm'){ |
|
177 |
$tmp = $app->db->queryOneRecord("SELECT * FROM server_php WHERE CONCAT(name,':',php_fpm_init_script,':',php_fpm_ini_dir,':',php_fpm_pool_dir) = '".$app->db->quote($this->dataRecord['fastcgi_php_version'])."'"); |
|
178 |
if(is_array($tmp)) { |
|
179 |
$this->dataRecord['fastcgi_php_version'] = $tmp['name'].':'.$tmp['php_fpm_init_script'].':'.$tmp['php_fpm_ini_dir'].':'.$tmp['php_fpm_pool_dir']; |
|
180 |
} else { |
|
181 |
$this->dataRecord['fastcgi_php_version'] = ''; |
|
182 |
} |
|
183 |
unset($tmp); |
|
184 |
// Check fast-cgi mode |
|
185 |
} elseif($this->dataRecord['php'] == 'fast-cgi') { |
|
186 |
$tmp = $app->db->queryOneRecord("SELECT * FROM server_php WHERE CONCAT(name,':',php_fastcgi_binary,':',php_fastcgi_ini_dir) = '".$app->db->quote($this->dataRecord['fastcgi_php_version'])."'"); |
|
187 |
if(is_array($tmp)) { |
|
188 |
$this->dataRecord['fastcgi_php_version'] = $tmp['name'].':'.$tmp['php_fastcgi_binary'].':'.$tmp['php_fastcgi_ini_dir']; |
|
189 |
} else { |
|
190 |
$this->dataRecord['fastcgi_php_version'] = ''; |
|
191 |
} |
|
192 |
unset($tmp); |
|
193 |
} else { |
|
194 |
// Other PHP modes do not have custom versions, so we force the value to be empty |
|
195 |
$this->dataRecord['fastcgi_php_version'] = ''; |
|
196 |
} |
|
197 |
} |
|
198 |
|
18341e
|
199 |
parent::onSubmit(); |
T |
200 |
} |
7fe908
|
201 |
|
d4d985
|
202 |
function onAfterInsert() { |
T |
203 |
global $app, $conf; |
7fe908
|
204 |
|
65ea2e
|
205 |
$app->db->query('UPDATE web_domain SET sys_groupid = '.$app->functions->intval($this->parent_domain_record['sys_groupid']).' WHERE domain_id = '.$this->id); |
7fe908
|
206 |
|
d4d985
|
207 |
} |
7fe908
|
208 |
|
4e18bd
|
209 |
function onAfterUpdate() { |
M |
210 |
global $app, $conf; |
7fe908
|
211 |
|
4e18bd
|
212 |
//* Check if parent domain has been changed |
M |
213 |
if($this->dataRecord['parent_domain_id'] != $this->oldDataRecord['parent_domain_id']) { |
7fe908
|
214 |
|
4e18bd
|
215 |
//* Update the domain owner |
65ea2e
|
216 |
$app->db->query('UPDATE web_domain SET sys_groupid = '.$app->functions->intval($this->parent_domain_record['sys_groupid']).' WHERE domain_id = '.$this->id); |
7fe908
|
217 |
|
4e18bd
|
218 |
//* Update the old website, so that the vhost alias gets removed |
M |
219 |
//* We force the update by inserting a transaction record without changes manually. |
604c0c
|
220 |
$old_website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = '.$app->functions->intval($this->oldDataRecord['domain_id'])); |
TB |
221 |
$app->db->datalogSave('web_domain', 'UPDATE', 'domain_id', $app->functions->intval($this->oldDataRecord['parent_domain_id']), $old_website, $old_website, true); |
4e18bd
|
222 |
} |
7fe908
|
223 |
|
4e18bd
|
224 |
} |
7fe908
|
225 |
|
18341e
|
226 |
} |
T |
227 |
|
|
228 |
$page = new page_action; |
|
229 |
$page->onLoad(); |
|
230 |
|
7fe908
|
231 |
?> |