Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
3669b3 1 <?php
MC 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_childdomain.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
41 require_once '../../lib/config.inc.php';
42 require_once '../../lib/app.inc.php';
43
44 //* Check permissions for module
45 $app->auth->check_module_permissions('sites');
46
47 // Loading classes
48 $app->uses('tpl,tform,tform_actions,tools_sites');
49 $app->load('tform_actions');
50
51 class page_action extends tform_actions {
52
53     var $parent_domain_record;
54     var $_childdomain_type;
55     
56     function onLoad() {
57         //* Get and set the child domain type - store in session
58         $show_type = 'aliasdomain';
59         if(isset($_GET['type']) && $_GET['type'] == 'subdomain') $show_type = 'subdomain';
60         elseif(!isset($_GET['type']) && isset($_SESSION['s']['var']['childdomain_type']) && $_SESSION['s']['var']['childdomain_type'] == 'subdomain') $show_type = 'subdomain';
61
62         $_SESSION['s']['var']['childdomain_type'] = $show_type;
63         $this->_childdomain_type = $show_type;
64         
65         parent::onLoad();
66     }
67     
68     function onShowNew() {
69         global $app, $conf;
70
71         // we will check only users, not admins
72         if($_SESSION["s"]["user"]["typ"] == 'user') {
73             if($this->_childdomain_type == 'subdomain') {
74                 if(!$app->tform->checkClientLimit('limit_web_subdomain', "(type = 'subdomain' OR type = 'vhostsubdomain')")) {
75                     $app->error($app->tform->wordbook["limit_web_subdomain_txt"]);
76                 }
77                 if(!$app->tform->checkResellerLimit('limit_web_subdomain', "(type = 'subdomain' OR type = 'vhostsubdomain')")) {
78                     $app->error('Reseller: '.$app->tform->wordbook["limit_web_subdomain_txt"]);
79                 }
80             } else {
81                 if(!$app->tform->checkClientLimit('limit_web_aliasdomain', "(type = 'alias' OR type = 'vhostalias')")) {
82                     $app->error($app->tform->wordbook["limit_web_aliasdomain_txt"]);
83                 }
e60d4c 84                 if(!$app->tform->checkResellerLimit('limit_web_aliasdomain', "(type = 'alias' OR type = 'vhostalias')")) {
3669b3 85                     $app->error('Reseller: '.$app->tform->wordbook["limit_web_aliasdomain_txt"]);
MC 86                 }
87             }
88         }
89
90         $app->tpl->setVar('childdomain_type', $this->_childdomain_type);
91
92         parent::onShowNew();
93     }
94
95     function onShowEnd() {
96         global $app, $conf;
97
98         /*
99          * Now we have to check, if we should use the domain-module to select the domain
100          * or not
101          */
102         $app->uses('ini_parser,getconf');
103         $settings = $app->getconf->get_global_config('domains');
104         if ($settings['use_domain_module'] == 'y') {
105             /*
106              * The domain-module is in use.
107             */
9ec304 108             $domains = $app->tools_sites->getDomainModuleDomains($this->_vhostdomain_type == 'subdomain' ? null : "web_domain", $this->dataRecord["domain"]);
3669b3 109             $domain_select = '';
MC 110             $selected_domain = '';
111             if(is_array($domains) && sizeof($domains) > 0) {
112                 /* We have domains in the list, so create the drop-down-list */
113                 foreach( $domains as $domain) {
114                     $domain_select .= "<option value=" . $domain['domain_id'] ;
115                     if ($this->_childdomain_type == 'subdomain' && '.' . $domain['domain'] == substr($this->dataRecord["domain"], -strlen($domain['domain']) - 1)) {
116                         $domain_select .= " selected";
117                         $selected_domain = $domain['domain'];
118                     } elseif($this->_childdomain_type == 'aliasdomain' && $domain['domain'] == $this->dataRecord["domain"]) {
119                         $domain_select .= " selected";
120                     }
121                     $domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n";
122                 }
123             }
124             else {
125                 /*
126                  * We have no domains in the domain-list. This means, we can not add ANY new domain.
127                  * To avoid, that the variable "domain_option" is empty and so the user can
128                  * free enter a domain, we have to create a empty option!
129                 */
130                 $domain_select .= "<option value=''></option>\r\n";
131             }
132             $app->tpl->setVar("domain_option", $domain_select);
133             if($this->_childdomain_type == 'subdomain') {
134                 $this->dataRecord['domain'] = substr($this->dataRecord["domain"], 0, strlen($this->dataRecord['domain']) - strlen($selected_domain) - 1);
135             }
136         } else {
137             if($this->_childdomain_type == 'subdomain') {
138                 // Get the record of the parent domain
cc7a82 139                 $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ?", @$this->dataRecord["parent_domain_id"]);
3669b3 140
MC 141                 // remove the parent domain part of the domain name before we show it in the text field.
142                 $this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"], '', $this->dataRecord["domain"]);
143             }
144         }
145         if($this->_childdomain_type == 'subdomain') $app->tpl->setVar("domain", $this->dataRecord["domain"]);
146
147         if($_SESSION["s"]["user"]["typ"] == 'admin') {
148             // Directive Snippets
149             $proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y'");
150             $proxy_directive_snippets_txt = '';
151             if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){
152                 foreach($proxy_directive_snippets as $proxy_directive_snippet){
153                     $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> ';
154                 }
155             }
156             if($proxy_directive_snippets_txt == '') $proxy_directive_snippets_txt = '------';
157             $app->tpl->setVar("proxy_directive_snippets_txt", $proxy_directive_snippets_txt);
158         }
159
160         $app->tpl->setVar('childdomain_type', $this->_childdomain_type);
161
162         parent::onShowEnd();
163
164     }
165
166     function onSubmit() {
167         global $app, $conf;
797215 168         
MC 169         // Get the record of the parent domain
170         if(!@$this->dataRecord["parent_domain_id"] && $this->id) {
cc7a82 171             $tmp = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_domain WHERE domain_id = ?", $this->id);
797215 172             if($tmp) $this->dataRecord["parent_domain_id"] = $tmp['parent_domain_id'];
MC 173             unset($tmp);
174         }
3669b3 175
MC 176         // Get the record of the parent domain
cc7a82 177         $parent_domain = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]);
3669b3 178         if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
MC 179         /* check if the domain module is used - and check if the selected domain can be used! */
180         $app->uses('ini_parser,getconf');
181         $settings = $app->getconf->get_global_config('domains');
182         if ($settings['use_domain_module'] == 'y') {
183             // get the record of the domain module domain
184             if($this->_childdomain_type == 'subdomain') {
185                 $domain = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['sel_domain']);
186                 if(!$domain) {
187                     $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
188                 } else {
189                     $this->dataRecord['domain'] = $this->dataRecord['domain'] . '.' . $domain;
190                 }
191             } else {
192                 $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['domain']);
193                 if(!$domain_check) {
194                     // invalid domain selected
195                     $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
196                 } else {
197                     $this->dataRecord['domain'] = $domain_check;
198                 }
199             }
200         } else {
201             if($this->_childdomain_type == 'subdomain') $this->dataRecord["domain"] = $this->dataRecord["domain"].'.'.$parent_domain["domain"];
202         }
203
204         // nginx: if redirect type is proxy and redirect path is no URL, display error
205         if($this->dataRecord["redirect_type"] == 'proxy' && substr($this->dataRecord['redirect_path'], 0, 1) == '/'){
206             $app->tform->errorMessage .= $app->tform->lng("error_proxy_requires_url")."<br />";
207         }
208
209         // Set a few fixed values
210         $this->dataRecord["type"] = ($this->_childdomain_type == 'subdomain' ? 'subdomain' : 'alias');
211         $this->dataRecord["server_id"] = $parent_domain["server_id"];
212
213         $this->parent_domain_record = $parent_domain;
214
215         //* make sure that the domain is lowercase
216         if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
797215 217         
3669b3 218         parent::onSubmit();
MC 219     }
220
221     function onAfterInsert() {
222         global $app, $conf;
223
224         $app->db->query('UPDATE web_domain SET sys_groupid = ? WHERE domain_id = ?', $this->parent_domain_record['sys_groupid'], $this->id);
225
226     }
227
228     function onAfterUpdate() {
229         global $app, $conf;
230
231         //* Check if parent domain has been changed
232         if($this->dataRecord['parent_domain_id'] != $this->oldDataRecord['parent_domain_id']) {
233
234             //* Update the domain owner
235             $app->db->query('UPDATE web_domain SET sys_groupid = ? WHERE domain_id = ?', $this->parent_domain_record['sys_groupid'], $this->id);
236
237             //* Update the old website, so that the vhost alias gets removed
238             //* We force the update by inserting a transaction record without changes manually.
cc7a82 239             $old_website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $this->oldDataRecord['domain_id']);
3669b3 240             $app->db->datalogSave('web_domain', 'UPDATE', 'domain_id', $app->functions->intval($this->oldDataRecord['parent_domain_id']), $old_website, $old_website, true);
MC 241         }
242
243     }
244
245 }
246
247 $page = new page_action;
248 $page->onLoad();
249
250 ?>