Marius Cramer
2014-08-13 42539643c396f9d8865dcf9a51b13dc869709d16
commit | author | age
146783 1 <?php
MC 2 /*
3 Copyright (c) 2007 - 2009, 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_domain.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';
146783 43
MC 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     //* Returna a "3/2/1" path hash from a numeric id '123'
7fe908 54     function id_hash($id, $levels) {
146783 55         $hash = "" . $id % 10 ;
MC 56         $id /= 10 ;
57         $levels -- ;
58         while ( $levels > 0 ) {
59             $hash .= "/" . $id % 10 ;
60             $id /= 10 ;
61             $levels-- ;
62         }
63         return $hash;
64     }
7fe908 65
146783 66     function onShowNew() {
MC 67         global $app, $conf;
68
69         // we will check only users, not admins
70         if($_SESSION["s"]["user"]["typ"] == 'user') {
7fe908 71             if(!$app->tform->checkClientLimit('limit_web_domain', "type = 'vhost'")) {
146783 72                 $app->error($app->tform->wordbook["limit_web_domain_txt"]);
MC 73             }
7fe908 74             if(!$app->tform->checkResellerLimit('limit_web_domain', "type = 'vhost'")) {
146783 75                 $app->error('Reseller: '.$app->tform->wordbook["limit_web_domain_txt"]);
MC 76             }
7fe908 77
146783 78             // Get the limits of the client
604c0c 79             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
146783 80             $client = $app->db->queryOneRecord("SELECT client.default_webserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
MC 81             $app->tpl->setVar("server_id_value", $client['default_webserver']);
82         }
7fe908 83         $app->tform->formDef['tabs']['domain']['readonly'] = false;
146783 84
MC 85         parent::onShowNew();
86     }
87
88     function onShowEnd() {
89         global $app, $conf;
7fe908 90
146783 91         $app->uses('ini_parser,getconf');
MC 92
7fe908 93         $read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl');
146783 94
MC 95         //* Client: If the logged in user is not admin and has no sub clients (no reseller)
96         if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
97
98             // Get the limits of the client
604c0c 99             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
146783 100             $client = $app->db->queryOneRecord("SELECT client.limit_web_domain, client.default_webserver, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
7fe908 101
146783 102             //* Get global web config
MC 103             $web_config = $app->getconf->get_server_config($client['default_webserver'], 'web');
7fe908 104
146783 105             // Set the webserver to the default server of the client
MC 106             $tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".intval($client['default_webserver']));
7fe908 107             $app->tpl->setVar("server_id", "<option value='$client[default_webserver]'>$tmp[server_name]</option>");
146783 108             unset($tmp);
MC 109
30848e 110             //* Fill the IPv4 select field with the IP addresses that are allowed for this client; if website was created on a different server (e.g. by admin), display IP addresses from that server - otherwise IP will be changed to * if user changes the tab
FT 111             $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".($app->functions->intval($this->dataRecord["server_id"]) > 0 && $app->functions->intval($this->dataRecord["server_id"]) != $app->functions->intval($client['default_webserver'])? $app->functions->intval($this->dataRecord["server_id"]) : $app->functions->intval($client['default_webserver']))." AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")";
146783 112             $ips = $app->db->queryAllRecords($sql);
MC 113             $ip_select = ($web_config['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
30848e 114             //if(!in_array($this->dataRecord["ip_address"], $ips)) $ip_select .= "<option value='".$this->dataRecord["ip_address"]."' SELECTED>".$this->dataRecord["ip_address"]."</option>\r\n";
146783 115             //$ip_select = "";
MC 116             if(is_array($ips)) {
117                 foreach( $ips as $ip) {
118                     $selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';
119                     $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
120                 }
121             }
7fe908 122             $app->tpl->setVar("ip_address", $ip_select);
146783 123             unset($tmp);
MC 124             unset($ips);
7fe908 125
30848e 126             //* Fill the IPv6 select field with the IP addresses that are allowed for this client; if website was created on a different server (e.g. by admin), display IP addresses from that server
FT 127             $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".($app->functions->intval($this->dataRecord["server_id"]) > 0 && $app->functions->intval($this->dataRecord["server_id"]) != $app->functions->intval($client['default_webserver'])? $app->functions->intval($this->dataRecord["server_id"]) : $app->functions->intval($client['default_webserver']))." AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")";
146783 128             $ips = $app->db->queryAllRecords($sql);
MC 129             $ip_select = "<option value=''></option>";
130             //$ip_select = "";
131             if(is_array($ips)) {
132                 foreach( $ips as $ip) {
133                     $selected = ($ip["ip_address"] == $this->dataRecord["ipv6_address"])?'SELECTED':'';
134                     $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
135                 }
136             }
7fe908 137             $app->tpl->setVar("ipv6_address", $ip_select);
146783 138             unset($tmp);
MC 139             unset($ips);
7fe908 140
146783 141             //PHP Version Selection (FastCGI)
MC 142             $server_type = 'apache';
143             if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
144             if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm';
145             if($this->dataRecord['php'] == 'php-fpm'){
604c0c 146                 $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ".($this->id > 0 ? $app->functions->intval($this->dataRecord['server_id']) : $app->functions->intval($client['default_webserver']))." AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")");
146783 147             }
MC 148             if($this->dataRecord['php'] == 'fast-cgi'){
604c0c 149                 $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".($this->id > 0 ? $app->functions->intval($this->dataRecord['server_id']) : $app->functions->intval($client['default_webserver']))." AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")");
146783 150             }
MC 151             $php_select = "<option value=''>Default</option>";
152             if(is_array($php_records) && !empty($php_records)) {
153                 foreach( $php_records as $php_record) {
154                     if($this->dataRecord['php'] == 'php-fpm'){
155                         $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
156                     } else {
157                         $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
158                     }
159                     $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':'';
160                     $php_select .= "<option value='$php_version' $selected>".$php_record['name']."</option>\r\n";
161                 }
162             }
7fe908 163             $app->tpl->setVar("fastcgi_php_version", $php_select);
146783 164             unset($php_records);
MC 165
7fe908 166             // add limits to template to be able to hide settings
MC 167             foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]);
168
169
146783 170             //* Reseller: If the logged in user is not admin and has sub clients (is a reseller)
MC 171         } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
172
173             // Get the limits of the client
604c0c 174             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
146783 175             $client = $app->db->queryOneRecord("SELECT client.client_id, client.limit_web_domain, client.default_webserver, client.contact_name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname, sys_group.name, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
7fe908 176
146783 177             //* Get global web config
MC 178             $web_config = $app->getconf->get_server_config($client['default_webserver'], 'web');
7fe908 179
146783 180             // Set the webserver to the default server of the client
604c0c 181             $tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".$app->functions->intval($client['default_webserver']));
7fe908 182             $app->tpl->setVar("server_id", "<option value='$client[default_webserver]'>$tmp[server_name]</option>");
146783 183             unset($tmp);
MC 184
185             // Fill the client select field
ca4b71 186             $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$client['client_id']." ORDER BY client.company_name, client.contact_name, sys_group.name";
146783 187             $records = $app->db->queryAllRecords($sql);
604c0c 188             $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($client['client_id']));
146783 189             $client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>';
MC 190             //$tmp_data_record = $app->tform->getDataRecord($this->id);
191             if(is_array($records)) {
192                 $selected_client_group_id = 0; // needed to get list of PHP versions
193                 foreach( $records as $rec) {
194                     if(is_array($this->dataRecord) && ($rec["groupid"] == $this->dataRecord['client_group_id'] || $rec["groupid"] == $this->dataRecord['sys_groupid']) && !$selected_client_group_id) $selected_client_group_id = $rec["groupid"];
195                     $selected = @(is_array($this->dataRecord) && ($rec["groupid"] == $this->dataRecord['client_group_id'] || $rec["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
196                     if($selected == 'SELECTED') $selected_client_group_id = $rec["groupid"];
197                     $client_select .= "<option value='$rec[groupid]' $selected>$rec[contactname]</option>\r\n";
198                 }
199             }
7fe908 200             $app->tpl->setVar("client_group_id", $client_select);
146783 201
30848e 202             //* Fill the IPv4 select field with the IP addresses that are allowed for this client; if website was created on a different server (e.g. by admin), display IP addresses from that server - otherwise IP will be changed to * if user changes the tab
FT 203             $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".($app->functions->intval($this->dataRecord["server_id"]) > 0 && $app->functions->intval($this->dataRecord["server_id"]) != $app->functions->intval($client['default_webserver'])? $app->functions->intval($this->dataRecord["server_id"]) : $app->functions->intval($client['default_webserver']))." AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")";
146783 204             $ips = $app->db->queryAllRecords($sql);
MC 205             $ip_select = ($web_config['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
30848e 206             //if(!in_array($this->dataRecord["ip_address"], $ips)) $ip_select .= "<option value='".$this->dataRecord["ip_address"]."' SELECTED>".$this->dataRecord["ip_address"]."</option>\r\n";
146783 207             //$ip_select = "";
MC 208             if(is_array($ips)) {
209                 foreach( $ips as $ip) {
210                     $selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';
211                     $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
212                 }
213             }
7fe908 214             $app->tpl->setVar("ip_address", $ip_select);
146783 215             unset($tmp);
MC 216             unset($ips);
7fe908 217
30848e 218             //* Fill the IPv6 select field with the IP addresses that are allowed for this client; if website was created on a different server (e.g. by admin), display IP addresses from that server
FT 219             $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".($app->functions->intval($this->dataRecord["server_id"]) > 0 && $app->functions->intval($this->dataRecord["server_id"]) != $app->functions->intval($client['default_webserver'])? $app->functions->intval($this->dataRecord["server_id"]) : $app->functions->intval($client['default_webserver']))." AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")";
146783 220             $ips = $app->db->queryAllRecords($sql);
MC 221             $ip_select = "<option value=''></option>";
222             //$ip_select = "";
223             if(is_array($ips)) {
224                 foreach( $ips as $ip) {
225                     $selected = ($ip["ip_address"] == $this->dataRecord["ipv6_address"])?'SELECTED':'';
226                     $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
227                 }
228             }
7fe908 229             $app->tpl->setVar("ipv6_address", $ip_select);
146783 230             unset($tmp);
MC 231             unset($ips);
7fe908 232
146783 233             //PHP Version Selection (FastCGI)
MC 234             $server_type = 'apache';
235             if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
236             if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm';
604c0c 237             $selected_client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = ".$app->functions->intval($selected_client_group_id));
146783 238             //$sql_where = " AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id']." OR client_id = ".intval($selected_client['client_id']).")";
MC 239             $sql_where = " AND (client_id = 0 OR client_id = ".intval($selected_client['client_id']).")";
240             if($this->dataRecord['php'] == 'php-fpm'){
604c0c 241                 $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ".($this->id > 0 ? $app->functions->intval($this->dataRecord['server_id']) : $app->functions->intval($client['default_webserver'])).$sql_where);
146783 242             }
MC 243             if($this->dataRecord['php'] == 'fast-cgi') {
604c0c 244                 $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".($this->id > 0 ? $app->functions->intval($this->dataRecord['server_id']) : $app->functions->intval($client['default_webserver'])).$sql_where);
146783 245             }
MC 246             $php_select = "<option value=''>Default</option>";
247             if(is_array($php_records) && !empty($php_records)) {
248                 foreach( $php_records as $php_record) {
249                     if($this->dataRecord['php'] == 'php-fpm'){
250                         $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
251                     } else {
252                         $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
253                     }
254                     $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':'';
255                     $php_select .= "<option value='$php_version' $selected>".$php_record['name']."</option>\r\n";
256                 }
257             }
7fe908 258             $app->tpl->setVar("fastcgi_php_version", $php_select);
146783 259             unset($php_records);
7fe908 260
MC 261             // add limits to template to be able to hide settings
262             foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]);
263
264
146783 265             //* Admin: If the logged in user is admin
MC 266         } else {
267
268             // The user is admin, so we fill in all IP addresses of the server
269             if($this->id > 0) {
270                 if(!isset($this->dataRecord["server_id"])){
271                     $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id));
272                     $this->dataRecord["server_id"] = $tmp["server_id"];
273                     unset($tmp);
274                 }
275                 $server_id = intval(@$this->dataRecord["server_id"]);
276             } else {
277                 // Get the first server ID
278                 $tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
279                 $server_id = intval($tmp['server_id']);
280             }
7fe908 281
146783 282             //* get global web config
MC 283             $web_config = $app->getconf->get_server_config($server_id, 'web');
7fe908 284
146783 285             //* Fill the IPv4 select field
604c0c 286             $sql = "SELECT ip_address FROM server_ip WHERE ip_type = 'IPv4' AND server_id = ".$app->functions->intval($server_id);
146783 287             $ips = $app->db->queryAllRecords($sql);
MC 288             $ip_select = ($web_config['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
289             //$ip_select = "";
290             if(is_array($ips)) {
291                 foreach( $ips as $ip) {
292                     $selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';
293                     $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
294                 }
295             }
7fe908 296             $app->tpl->setVar("ip_address", $ip_select);
146783 297             unset($tmp);
MC 298             unset($ips);
7fe908 299
146783 300             //* Fill the IPv6 select field
604c0c 301             $sql = "SELECT ip_address FROM server_ip WHERE ip_type = 'IPv6' AND server_id = ".$app->functions->intval($server_id);
146783 302             $ips = $app->db->queryAllRecords($sql);
MC 303             $ip_select = "<option value=''></option>";
304             //$ip_select = "";
305             if(is_array($ips)) {
306                 foreach( $ips as $ip) {
307                     $selected = ($ip["ip_address"] == $this->dataRecord["ipv6_address"])?'SELECTED':'';
308                     $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
309                 }
310             }
7fe908 311             $app->tpl->setVar("ipv6_address", $ip_select);
146783 312             unset($tmp);
MC 313             unset($ips);
314
315             // Fill the client select field
ca4b71 316             $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
146783 317             $clients = $app->db->queryAllRecords($sql);
MC 318             $client_select = "<option value='0'></option>";
319             //$tmp_data_record = $app->tform->getDataRecord($this->id);
320             if(is_array($clients)) {
321                 $selected_client_group_id = 0; // needed to get list of PHP versions
322                 foreach($clients as $client) {
323                     if(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']) && !$selected_client_group_id) $selected_client_group_id = $client["groupid"];
324                     //$selected = @($client["groupid"] == $tmp_data_record["sys_groupid"])?'SELECTED':'';
325                     $selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
326                     if($selected == 'SELECTED') $selected_client_group_id = $client["groupid"];
327                     $client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
328                 }
329             }
7fe908 330             $app->tpl->setVar("client_group_id", $client_select);
MC 331
146783 332             //PHP Version Selection (FastCGI)
MC 333             $server_type = 'apache';
334             if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
335             if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm';
604c0c 336             $selected_client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = ".$app->functions->intval($selected_client_group_id));
146783 337             //$sql_where = " AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id']." OR client_id = ".intval($selected_client['client_id']).")";
604c0c 338             $sql_where = " AND (client_id = 0 OR client_id = ".$app->functions->intval($selected_client['client_id']).")";
146783 339             if($this->dataRecord['php'] == 'php-fpm'){
MC 340                 $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = $server_id".$sql_where);
341             }
342             if($this->dataRecord['php'] == 'fast-cgi') {
604c0c 343                 $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".$app->functions->intval($server_id).$sql_where);
146783 344             }
MC 345             $php_select = "<option value=''>Default</option>";
346             if(is_array($php_records) && !empty($php_records)) {
347                 foreach( $php_records as $php_record) {
348                     if($this->dataRecord['php'] == 'php-fpm'){
349                         $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
350                     } else {
351                         $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
352                     }
353                     $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':'';
354                     $php_select .= "<option value='$php_version' $selected>".$php_record['name']."</option>\r\n";
355                 }
356             }
7fe908 357             $app->tpl->setVar("fastcgi_php_version", $php_select);
146783 358             unset($php_records);
7fe908 359
MC 360             foreach($read_limits as $limit) $app->tpl->setVar($limit, ($limit == 'force_suexec' ? 'n' : 'y'));
361
146783 362             // Directive Snippets
MC 363             $php_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'php' AND active = 'y'");
364             $php_directive_snippets_txt = '';
365             if(is_array($php_directive_snippets) && !empty($php_directive_snippets)){
7fe908 366                 foreach($php_directive_snippets as $php_directive_snippet){
MC 367                     $php_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$php_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.htmlentities($php_directive_snippet['snippet']).'</pre></a> ';
368                 }
146783 369             }
MC 370             if($php_directive_snippets_txt == '') $php_directive_snippets_txt = '------';
7fe908 371             $app->tpl->setVar("php_directive_snippets_txt", $php_directive_snippets_txt);
MC 372
146783 373             if($server_type == 'apache'){
MC 374                 $apache_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'apache' AND active = 'y'");
375                 $apache_directive_snippets_txt = '';
376                 if(is_array($apache_directive_snippets) && !empty($apache_directive_snippets)){
7fe908 377                     foreach($apache_directive_snippets as $apache_directive_snippet){
MC 378                         $apache_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$apache_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.htmlentities($apache_directive_snippet['snippet']).'</pre></a> ';
379                     }
146783 380                 }
MC 381                 if($apache_directive_snippets_txt == '') $apache_directive_snippets_txt = '------';
7fe908 382                 $app->tpl->setVar("apache_directive_snippets_txt", $apache_directive_snippets_txt);
146783 383             }
7fe908 384
146783 385             if($server_type == 'nginx'){
MC 386                 $nginx_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'nginx' AND active = 'y'");
387                 $nginx_directive_snippets_txt = '';
388                 if(is_array($nginx_directive_snippets) && !empty($nginx_directive_snippets)){
7fe908 389                     foreach($nginx_directive_snippets as $nginx_directive_snippet){
MC 390                         $nginx_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$nginx_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.htmlentities($nginx_directive_snippet['snippet']).'</pre></a> ';
391                     }
146783 392                 }
MC 393                 if($nginx_directive_snippets_txt == '') $nginx_directive_snippets_txt = '------';
7fe908 394                 $app->tpl->setVar("nginx_directive_snippets_txt", $nginx_directive_snippets_txt);
146783 395             }
7fe908 396
146783 397             $proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y'");
MC 398             $proxy_directive_snippets_txt = '';
399             if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){
7fe908 400                 foreach($proxy_directive_snippets as $proxy_directive_snippet){
MC 401                     $proxy_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$proxy_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.htmlentities($proxy_directive_snippet['snippet']).'</pre></a> ';
402                 }
146783 403             }
MC 404             if($proxy_directive_snippets_txt == '') $proxy_directive_snippets_txt = '------';
7fe908 405             $app->tpl->setVar("proxy_directive_snippets_txt", $proxy_directive_snippets_txt);
146783 406         }
MC 407
408         $ssl_domain_select = '';
409         $tmp = $app->db->queryOneRecord("SELECT domain FROM web_domain WHERE domain_id = ".$this->id);
7fe908 410         $ssl_domains = array($tmp["domain"], 'www.'.$tmp["domain"], '*.'.$tmp["domain"]);
146783 411         if(is_array($ssl_domains)) {
MC 412             foreach( $ssl_domains as $ssl_domain) {
413                 $selected = ($ssl_domain == $this->dataRecord['ssl_domain'])?'SELECTED':'';
414                 $ssl_domain_select .= "<option value='$ssl_domain' $selected>$ssl_domain</option>\r\n";
415             }
416         }
7fe908 417         $app->tpl->setVar("ssl_domain", $ssl_domain_select);
146783 418         unset($ssl_domain_select);
MC 419         unset($ssl_domains);
420         unset($ssl_domain);
421
422         if($this->id > 0) {
423             //* we are editing a existing record
424             $app->tpl->setVar("edit_disabled", 1);
425             $app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
426         } else {
427             $app->tpl->setVar("edit_disabled", 0);
428         }
429
430         $tmp_txt = ($this->dataRecord['traffic_quota_lock'] == 'y')?'<b>('.$app->tform->lng('traffic_quota_exceeded_txt').')</b>':'';
431         $app->tpl->setVar("traffic_quota_exceeded_txt", $tmp_txt);
432
433         /*
434          * Now we have to check, if we should use the domain-module to select the domain
435          * or not
436          */
437         $settings = $app->getconf->get_global_config('domains');
438         if ($settings['use_domain_module'] == 'y') {
439             /*
440              * The domain-module is in use.
441             */
442             $domains = $app->tools_sites->getDomainModuleDomains();
443             $domain_select = '';
444             if(is_array($domains) && sizeof($domains) > 0) {
445                 /* We have domains in the list, so create the drop-down-list */
446                 foreach( $domains as $domain) {
447                     $domain_select .= "<option value=" . $domain['domain_id'] ;
448                     if ($domain['domain'] == $this->dataRecord["domain"]) {
449                         $domain_select .= " selected";
450                     }
451                     $domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n";
452                 }
453             }
454             else {
455                 /*
456                  * We have no domains in the domain-list. This means, we can not add ANY new domain.
457                  * To avoid, that the variable "domain_option" is empty and so the user can
458                  * free enter a domain, we have to create a empty option!
459                 */
460                 $domain_select .= "<option value=''></option>\r\n";
461             }
7fe908 462             $app->tpl->setVar("domain_option", $domain_select);
146783 463         }
7fe908 464
146783 465         // check for configuration errors in sys_datalog
MC 466         if($this->id > 0) {
604c0c 467             $datalog = $app->db->queryOneRecord("SELECT sys_datalog.error, sys_log.tstamp FROM sys_datalog, sys_log WHERE sys_datalog.dbtable = 'web_domain' AND sys_datalog.dbidx = 'domain_id:".$app->functions->intval($this->id)."' AND sys_datalog.datalog_id = sys_log.datalog_id AND sys_log.message = CONCAT('Processed datalog_id ',sys_log.datalog_id) ORDER BY sys_datalog.tstamp DESC");
146783 468             if(is_array($datalog) && !empty($datalog)){
MC 469                 if(trim($datalog['error']) != ''){
7fe908 470                     $app->tpl->setVar("config_error_msg", nl2br(htmlentities($datalog['error'])));
MC 471                     $app->tpl->setVar("config_error_tstamp", date($app->lng('conf_format_datetime'), $datalog['tstamp']));
146783 472                 }
MC 473             }
474         }
475
476         parent::onShowEnd();
477     }
7fe908 478
MC 479     function onShowEdit() {
480         global $app;
481         if($app->tform->checkPerm($this->id, 'riud')) $app->tform->formDef['tabs']['domain']['readonly'] = false;
482         parent::onShowEdit();
483     }
146783 484
MC 485     function onSubmit() {
486         global $app, $conf;
487
7fe908 488         /* check if the domain module is used - and check if the selected domain can be used! */
146783 489         if($app->tform->getCurrentTab() == 'domain') {
7fe908 490             $app->uses('ini_parser,getconf');
MC 491             $settings = $app->getconf->get_global_config('domains');
492             if ($settings['use_domain_module'] == 'y') {
493                 $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['domain']);
494                 if(!$domain_check) {
495                     // invalid domain selected
496                     $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
497                 } else {
498                     $this->dataRecord['domain'] = $domain_check;
499                 }
500             }
501         }
502
146783 503         // nginx: if redirect type is proxy and redirect path is no URL, display error
MC 504         //if($this->dataRecord["redirect_type"] == 'proxy' && substr($this->dataRecord['redirect_path'],0,1) == '/'){
7fe908 505         // $app->tform->errorMessage .= $app->tform->lng("error_proxy_requires_url")."<br />";
146783 506         //}
MC 507
508         // Set a few fixed values
509         $this->dataRecord["parent_domain_id"] = 0;
510         $this->dataRecord["type"] = 'vhost';
511         $this->dataRecord["vhost_type"] = 'name';
512
7fe908 513         $read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl');
146783 514
MC 515
516         if($_SESSION["s"]["user"]["typ"] != 'admin') {
517             // Get the limits of the client
604c0c 518             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
146783 519             $client = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, parent_client_id, limit_web_quota, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
7fe908 520
31143b 521             if($client['limit_cgi'] != 'y') $this->dataRecord['cgi'] = 'n';
TB 522             if($client['limit_ssi'] != 'y') $this->dataRecord['ssi'] = 'n';
523             if($client['limit_perl'] != 'y') $this->dataRecord['perl'] = 'n';
524             if($client['limit_ruby'] != 'y') $this->dataRecord['ruby'] = 'n';
525             if($client['limit_python'] != 'y') $this->dataRecord['python'] = 'n';
7fe908 526             if($client['force_suexec'] == 'y') $this->dataRecord['suexec'] = 'y';
31143b 527             if($client['limit_hterror'] != 'y') $this->dataRecord['errordocs'] = 'n';
TB 528             if($client['limit_wildcard'] != 'y' && $this->dataRecord['subdomain'] == '*') $this->dataRecord['subdomain'] = 'n';
529             if($client['limit_ssl'] != 'y') $this->dataRecord['ssl'] = 'n';
7fe908 530
146783 531             // only generate quota and traffic warnings if value has changed
MC 532             if($this->id > 0) {
533                 $old_web_values = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id));
1c3655 534             } else {
f9c424 535                 $old_web_values = array();
146783 536             }
7fe908 537
146783 538             //* Check the website quota of the client
MC 539             if(isset($_POST["hd_quota"]) && $client["limit_web_quota"] >= 0 && $_POST["hd_quota"] != $old_web_values["hd_quota"]) {
540                 $tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".$app->functions->intval($this->id)." AND type = 'vhost' AND ".$app->tform->getAuthSQL('u'));
541                 $webquota = $tmp["webquota"];
542                 $new_web_quota = $app->functions->intval($this->dataRecord["hd_quota"]);
543                 if(($webquota + $new_web_quota > $client["limit_web_quota"]) || ($new_web_quota < 0 && $client["limit_web_quota"] >= 0)) {
544                     $max_free_quota = floor($client["limit_web_quota"] - $webquota);
545                     if($max_free_quota < 0) $max_free_quota = 0;
546                     $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB<br>";
547                     // Set the quota field to the max free space
548                     $this->dataRecord["hd_quota"] = $max_free_quota;
549                 }
550                 unset($tmp);
551                 unset($tmp_quota);
552             }
553
554             //* Check the traffic quota of the client
555             if(isset($_POST["traffic_quota"]) && $client["limit_traffic_quota"] > 0 && $_POST["traffic_quota"] != $old_web_values["traffic_quota"]) {
556                 $tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".$app->functions->intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
557                 $trafficquota = $tmp["trafficquota"];
558                 $new_traffic_quota = $app->functions->intval($this->dataRecord["traffic_quota"]);
559                 if(($trafficquota + $new_traffic_quota > $client["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $client["limit_traffic_quota"] >= 0)) {
560                     $max_free_quota = floor($client["limit_traffic_quota"] - $trafficquota);
561                     if($max_free_quota < 0) $max_free_quota = 0;
562                     $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB<br>";
563                     // Set the quota field to the max free space
564                     $this->dataRecord["traffic_quota"] = $max_free_quota;
565                 }
566                 unset($tmp);
567                 unset($tmp_quota);
568             }
7fe908 569
146783 570             if($client['parent_client_id'] > 0) {
MC 571                 // Get the limits of the reseller
604c0c 572                 $reseller = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, limit_web_quota FROM client WHERE client_id = ".$app->functions->intval($client['parent_client_id']));
146783 573
MC 574                 //* Check the website quota of the client
575                 if(isset($_POST["hd_quota"]) && $reseller["limit_web_quota"] >= 0 && $_POST["hd_quota"] != $old_web_values["hd_quota"]) {
576                     $tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".$app->functions->intval($this->id)." AND type = 'vhost' AND ".$app->tform->getAuthSQL('u'));
577                     $webquota = $tmp["webquota"];
578                     $new_web_quota = $app->functions->intval($this->dataRecord["hd_quota"]);
579                     if(($webquota + $new_web_quota > $reseller["limit_web_quota"]) || ($new_web_quota < 0 && $reseller["limit_web_quota"] >= 0)) {
580                         $max_free_quota = floor($reseller["limit_web_quota"] - $webquota);
581                         if($max_free_quota < 0) $max_free_quota = 0;
582                         $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB<br>";
583                         // Set the quota field to the max free space
584                         $this->dataRecord["hd_quota"] = $max_free_quota;
585                     }
586                     unset($tmp);
587                     unset($tmp_quota);
588                 }
589
590                 //* Check the traffic quota of the client
591                 if(isset($_POST["traffic_quota"]) && $reseller["limit_traffic_quota"] > 0 && $_POST["traffic_quota"] != $old_web_values["traffic_quota"]) {
592                     $tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".$app->functions->intval($this->id)." AND ".$app->tform->getAuthSQL('u'));
593                     $trafficquota = $tmp["trafficquota"];
594                     $new_traffic_quota = $app->functions->intval($this->dataRecord["traffic_quota"]);
595                     if(($trafficquota + $new_traffic_quota > $reseller["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $reseller["limit_traffic_quota"] >= 0)) {
596                         $max_free_quota = floor($reseller["limit_traffic_quota"] - $trafficquota);
597                         if($max_free_quota < 0) $max_free_quota = 0;
598                         $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB<br>";
599                         // Set the quota field to the max free space
600                         $this->dataRecord["traffic_quota"] = $max_free_quota;
601                     }
602                     unset($tmp);
603                     unset($tmp_quota);
604                 }
605             }
606
607             // When the record is updated
608             if($this->id > 0) {
609                 // restore the server ID if the user is not admin and record is edited
64ea56 610                 $tmp = $app->db->queryOneRecord("SELECT server_id, `system_user`, `system_group`, `cgi`, `ssi`, `perl`, `ruby`, `python`, `suexec`, `errordocs`, `subdomain`, `ssl` FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id));
146783 611                 $this->dataRecord["server_id"] = $tmp["server_id"];
7fe908 612
64ea56 613                 $this->dataRecord['system_user'] = $tmp['system_user'];
MC 614                 $this->dataRecord['system_group'] = $tmp['system_group'];
7fe908 615                 // set the settings to current if not provided (or cleared due to limits)
31143b 616                 if($this->dataRecord['cgi'] == 'n') $this->dataRecord['cgi'] = $tmp['cgi'];
TB 617                 if($this->dataRecord['ssi'] == 'n') $this->dataRecord['ssi'] = $tmp['ssi'];
618                 if($this->dataRecord['perl'] == 'n') $this->dataRecord['perl'] = $tmp['perl'];
619                 if($this->dataRecord['ruby'] == 'n') $this->dataRecord['ruby'] = $tmp['ruby'];
620                 if($this->dataRecord['python'] == 'n') $this->dataRecord['python'] = $tmp['python'];
621                 if($this->dataRecord['suexec'] == 'n') $this->dataRecord['suexec'] = $tmp['suexec'];
622                 if($this->dataRecord['errordocs'] == 'n') $this->dataRecord['errordocs'] = $tmp['errordocs'];
623                 if($this->dataRecord['subdomain'] == 'n') $this->dataRecord['subdomain'] = $tmp['subdomain'];
624                 if($this->dataRecord['ssl'] == 'n') $this->dataRecord['ssl'] = $tmp['ssl'];
7fe908 625
146783 626                 unset($tmp);
MC 627                 // When the record is inserted
628             } else {
629                 //* set the server ID to the default webserver of the client
630                 $this->dataRecord["server_id"] = $client["default_webserver"];
631
632                 // Check if the user may add another web_domain
633                 if($client["limit_web_domain"] >= 0) {
634                     $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = $client_group_id and type = 'vhost'");
635                     if($tmp["number"] >= $client["limit_web_domain"]) {
636                         $app->error($app->tform->wordbook["limit_web_domain_txt"]);
637                     }
638                 }
639
640             }
641
642             // Clients may not set the client_group_id, so we unset them if user is not a admin and the client is not a reseller
643             if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
644         }
7fe908 645
146783 646         //* make sure that the email domain is lowercase
MC 647         if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
7fe908 648
146783 649         //* get the server config for this server
MC 650         $app->uses("getconf");
651         if($this->id > 0){
652             $web_rec = $app->tform->getDataRecord($this->id);
653             $server_id = $web_rec["server_id"];
654         } else {
655             // Get the first server ID
656             $tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
657             $server_id = intval($tmp['server_id']);
658         }
7fe908 659         $web_config = $app->getconf->get_server_config($app->functions->intval(isset($this->dataRecord["server_id"]) ? $this->dataRecord["server_id"] : $server_id), 'web');
146783 660         //* Check for duplicate ssl certs per IP if SNI is disabled
MC 661         if(isset($this->dataRecord['ssl']) && $this->dataRecord['ssl'] == 'y' && $web_config['enable_sni'] != 'y') {
662             $sql = "SELECT count(domain_id) as number FROM web_domain WHERE `ssl` = 'y' AND ip_address = '".$app->db->quote($this->dataRecord['ip_address'])."' and domain_id != ".$this->id;
663             $tmp = $app->db->queryOneRecord($sql);
664             if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("error_no_sni_txt");
665         }
7fe908 666
146783 667         // Check if pm.max_children >= pm.max_spare_servers >= pm.start_servers >= pm.min_spare_servers > 0
MC 668         if(isset($this->dataRecord['pm_max_children']) && $this->dataRecord['pm'] == 'dynamic') {
669             if($app->functions->intval($this->dataRecord['pm_max_children'], true) >= $app->functions->intval($this->dataRecord['pm_max_spare_servers'], true) && $app->functions->intval($this->dataRecord['pm_max_spare_servers'], true) >= $app->functions->intval($this->dataRecord['pm_start_servers'], true) && $app->functions->intval($this->dataRecord['pm_start_servers'], true) >= $app->functions->intval($this->dataRecord['pm_min_spare_servers'], true) && $app->functions->intval($this->dataRecord['pm_min_spare_servers'], true) > 0){
7fe908 670
146783 671             } else {
MC 672                 $app->tform->errorMessage .= $app->tform->lng("error_php_fpm_pm_settings_txt").'<br>';
673             }
674         }
7fe908 675
146783 676         // Check rewrite rules
MC 677         $server_type = $web_config['server_type'];
7fe908 678
146783 679         if($server_type == 'nginx' && isset($this->dataRecord['rewrite_rules']) && trim($this->dataRecord['rewrite_rules']) != '') {
MC 680             $rewrite_rules = trim($this->dataRecord['rewrite_rules']);
681             $rewrites_are_valid = true;
682             // use this counter to make sure all curly brackets are properly closed
683             $if_level = 0;
684             // Make sure we only have Unix linebreaks
685             $rewrite_rules = str_replace("\r\n", "\n", $rewrite_rules);
686             $rewrite_rules = str_replace("\r", "\n", $rewrite_rules);
687             $rewrite_rule_lines = explode("\n", $rewrite_rules);
688             if(is_array($rewrite_rule_lines) && !empty($rewrite_rule_lines)){
689                 foreach($rewrite_rule_lines as $rewrite_rule_line){
690                     // ignore comments
7fe908 691                     if(substr(ltrim($rewrite_rule_line), 0, 1) == '#') continue;
146783 692                     // empty lines
MC 693                     if(trim($rewrite_rule_line) == '') continue;
694                     // rewrite
695                     if(preg_match('@^\s*rewrite\s+(^/)?\S+(\$)?\s+\S+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
b5b613 696                     if(preg_match('@^\s*rewrite\s+(^/)?(\'[^\']+\'|"[^"]+")+(\$)?\s+(\'[^\']+\'|"[^"]+")+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
FT 697                     if(preg_match('@^\s*rewrite\s+(^/)?(\'[^\']+\'|"[^"]+")+(\$)?\s+\S+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
698                     if(preg_match('@^\s*rewrite\s+(^/)?\S+(\$)?\s+(\'[^\']+\'|"[^"]+")+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
146783 699                     // if
MC 700                     if(preg_match('@^\s*if\s+\(\s*\$\S+(\s+(\!?(=|~|~\*))\s+(\S+|\".+\"))?\s*\)\s*\{\s*$@', $rewrite_rule_line)){
701                         $if_level += 1;
702                         continue;
703                     }
704                     // if - check for files, directories, etc.
705                     if(preg_match('@^\s*if\s+\(\s*\!?-(f|d|e|x)\s+\S+\s*\)\s*\{\s*$@', $rewrite_rule_line)){
706                         $if_level += 1;
707                         continue;
708                     }
709                     // break
710                     if(preg_match('@^\s*break\s*;\s*$@', $rewrite_rule_line)){
711                         continue;
712                     }
713                     // return code [ text ]
714                     if(preg_match('@^\s*return\s+\d\d\d.*;\s*$@', $rewrite_rule_line)) continue;
715                     // return code URL
716                     // return URL
717                     if(preg_match('@^\s*return(\s+\d\d\d)?\s+(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*\@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*\s*;\s*$@', $rewrite_rule_line)) continue;
718                     // set
719                     if(preg_match('@^\s*set\s+\$\S+\s+\S+\s*;\s*$@', $rewrite_rule_line)) continue;
720                     // closing curly bracket
721                     if(trim($rewrite_rule_line) == '}'){
722                         $if_level -= 1;
723                         continue;
724                     }
725                     $rewrites_are_valid = false;
726                     break;
727                 }
728             }
7fe908 729
146783 730             if(!$rewrites_are_valid || $if_level != 0){
MC 731                 $app->tform->errorMessage .= $app->tform->lng("invalid_rewrite_rules_txt").'<br>';
732             }
733         }
03cc01 734         
FT 735         // check custom php.ini settings
736         if(isset($this->dataRecord['custom_php_ini']) && trim($this->dataRecord['custom_php_ini']) != '') {
737             $custom_php_ini_settings = trim($this->dataRecord['custom_php_ini']);
738             $custom_php_ini_settings_are_valid = true;
739             // Make sure we only have Unix linebreaks
740             $custom_php_ini_settings = str_replace("\r\n", "\n", $custom_php_ini_settings);
741             $custom_php_ini_settings = str_replace("\r", "\n", $custom_php_ini_settings);
742             $custom_php_ini_settings_lines = explode("\n", $custom_php_ini_settings);
743             if(is_array($custom_php_ini_settings_lines) && !empty($custom_php_ini_settings_lines)){
744                 foreach($custom_php_ini_settings_lines as $custom_php_ini_settings_line){
745                     if(trim($custom_php_ini_settings_line) == '') continue;
746                     if(substr(trim($custom_php_ini_settings_line),0,1) == ';') continue;
747                     // empty value
748                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
749                     // value inside ""
750                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*".*"\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
751                     // value inside ''
752                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*\'.*\'\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
753                     // everything else
b00e47 754                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*[-a-zA-Z0-9~&=_\@/,.#\s|()]*\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
03cc01 755                     $custom_php_ini_settings_are_valid = false;
FT 756                     break;
757                 }
758             }
759             if(!$custom_php_ini_settings_are_valid){
760                 $app->tform->errorMessage .= $app->tform->lng("invalid_custom_php_ini_settings_txt").'<br>';
761             }
762         }
146783 763
MC 764         parent::onSubmit();
765     }
766
767     function onAfterInsert() {
768         global $app, $conf;
769
770         // make sure that the record belongs to the clinet group and not the admin group when admin inserts it
771         // also make sure that the user can not delete domain created by a admin
772         if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
773             $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
774             $app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
775         }
776         if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
777             $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
778             $app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$this->id);
779         }
780
781         // Get configuration for the web system
782         $app->uses("getconf");
783         $web_rec = $app->tform->getDataRecord($this->id);
7fe908 784         $web_config = $app->getconf->get_server_config($app->functions->intval($web_rec["server_id"]), 'web');
MC 785         $document_root = str_replace("[website_id]", $this->id, $web_config["website_path"]);
786         $document_root = str_replace("[website_idhash_1]", $this->id_hash($page_form->id, 1), $document_root);
787         $document_root = str_replace("[website_idhash_2]", $this->id_hash($page_form->id, 1), $document_root);
788         $document_root = str_replace("[website_idhash_3]", $this->id_hash($page_form->id, 1), $document_root);
789         $document_root = str_replace("[website_idhash_4]", $this->id_hash($page_form->id, 1), $document_root);
146783 790
MC 791         // get the ID of the client
792         if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
604c0c 793             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
146783 794             $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = $client_group_id");
MC 795             $client_id = $app->functions->intval($client["client_id"]);
796         } else {
797             //$client_id = $app->functions->intval($this->dataRecord["client_group_id"]);
798             $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".$app->functions->intval($this->dataRecord["client_group_id"]));
799             $client_id = $app->functions->intval($client["client_id"]);
800         }
801
802         // Set the values for document_root, system_user and system_group
803         $system_user = $app->db->quote('web'.$this->id);
804         $system_group = $app->db->quote('client'.$client_id);
7fe908 805         $document_root = str_replace("[client_id]", $client_id, $document_root);
MC 806         $document_root = str_replace("[client_idhash_1]", $this->id_hash($client_id, 1), $document_root);
807         $document_root = str_replace("[client_idhash_2]", $this->id_hash($client_id, 2), $document_root);
808         $document_root = str_replace("[client_idhash_3]", $this->id_hash($client_id, 3), $document_root);
809         $document_root = str_replace("[client_idhash_4]", $this->id_hash($client_id, 4), $document_root);
146783 810         $document_root = $app->db->quote($document_root);
7fe908 811         $php_open_basedir = str_replace("[website_path]", $document_root, $web_config["php_open_basedir"]);
MC 812         $php_open_basedir = $app->db->quote(str_replace("[website_domain]", $web_rec['domain'], $php_open_basedir));
146783 813         $htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
3d96c5 814         $added_date = date($app->lng('conf_format_dateshort'));
TB 815         $added_by = $app->db->quote($_SESSION['s']['user']['username']);
146783 816
3d96c5 817         $sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir', added_date = '$added_date', added_by = '$added_by'  WHERE domain_id = ".$this->id;
146783 818         $app->db->query($sql);
MC 819     }
820
821     function onBeforeUpdate () {
822         global $app, $conf;
823
824         //* Check if the server has been changed
825         // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
826         if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
827             if (isset($this->dataRecord["server_id"])) {
828                 $rec = $app->db->queryOneRecord("SELECT server_id from web_domain WHERE domain_id = ".$this->id);
829                 if($rec['server_id'] != $this->dataRecord["server_id"]) {
830                     //* Add a error message and switch back to old server
831                     $app->tform->errorMessage .= $app->lng('The Server can not be changed.');
832                     $this->dataRecord["server_id"] = $rec['server_id'];
833                 }
834                 unset($rec);
835             }
836             //* If the user is neither admin nor reseller
837         } else {
838             //* We do not allow users to change a domain which has been created by the admin
839             $rec = $app->db->queryOneRecord("SELECT sys_perm_group, domain, ip_address, ipv6_address from web_domain WHERE domain_id = ".$this->id);
7fe908 840             if(isset($this->dataRecord["domain"]) && $rec['domain'] != $this->dataRecord["domain"] && $app->tform->checkPerm($this->id, 'u')) {
146783 841                 //* Add a error message and switch back to old server
MC 842                 $app->tform->errorMessage .= $app->lng('The Domain can not be changed. Please ask your Administrator if you want to change the domain name.');
843                 $this->dataRecord["domain"] = $rec['domain'];
844             }
845             if(isset($this->dataRecord["ip_address"]) && $rec['ip_address'] != $this->dataRecord["ip_address"] && $rec['sys_perm_group'] != 'riud') {
7fe908 846                 $this->dataRecord["ip_address"] = $rec['ip_address'];
MC 847             }
146783 848             if(isset($this->dataRecord["ipv6_address"]) && $rec['ipv6_address'] != $this->dataRecord["ipv6_address"] && $rec['sys_perm_group'] != 'riud') {
7fe908 849                 $this->dataRecord["ipv6_address"] = $rec['ipv6_address'];
MC 850             }
146783 851             unset($rec);
MC 852         }
853
854         //* Check that all fields for the SSL cert creation are filled
855         if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'create') {
856             if($this->dataRecord['ssl_state'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_state_empty').'<br />';
857             if($this->dataRecord['ssl_locality'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_locality_empty').'<br />';
858             if($this->dataRecord['ssl_organisation'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_empty').'<br />';
859             if($this->dataRecord['ssl_organisation_unit'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_unit_empty').'<br />';
860             if($this->dataRecord['ssl_country'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_country_empty').'<br />';
861         }
7fe908 862
146783 863         if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'save') {
MC 864             if(trim($this->dataRecord['ssl_cert']) == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_cert_empty').'<br />';
865         }
866
867     }
868
869     function onAfterUpdate() {
870         global $app, $conf;
871
872         // make sure that the record belongs to the client group and not the admin group when a admin inserts it
873         // also make sure that the user can not delete domain created by a admin
874         if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
875             $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
876             $app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
877         }
878         if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
879             $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
880             $app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$this->id);
881         }
882
883         // Get configuration for the web system
884         $app->uses("getconf");
885         $web_rec = $app->tform->getDataRecord($this->id);
7fe908 886         $web_config = $app->getconf->get_server_config($app->functions->intval($web_rec["server_id"]), 'web');
MC 887         $document_root = str_replace("[website_id]", $this->id, $web_config["website_path"]);
146783 888         $page_formid = isset($page_form->id) ? $page_form->id : '';
7fe908 889         $document_root = str_replace("[website_idhash_1]", $this->id_hash($page_formid, 1), $document_root);
MC 890         $document_root = str_replace("[website_idhash_2]", $this->id_hash($page_formid, 1), $document_root);
891         $document_root = str_replace("[website_idhash_3]", $this->id_hash($page_formid, 1), $document_root);
892         $document_root = str_replace("[website_idhash_4]", $this->id_hash($page_formid, 1), $document_root);
146783 893
MC 894         // get the ID of the client
895         if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
604c0c 896             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
146783 897             $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = $client_group_id");
MC 898             $client_id = $app->functions->intval($client["client_id"]);
899         } elseif (isset($this->dataRecord["client_group_id"])) {
900             $client_group_id = $this->dataRecord["client_group_id"];
901             $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".$app->functions->intval(@$this->dataRecord["client_group_id"]));
902             $client_id = $app->functions->intval($client["client_id"]);
903         } else {
904             $client_group_id = $web_rec['sys_groupid'];
905             $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".$app->functions->intval($client_group_id));
906             $client_id = $app->functions->intval($client["client_id"]);
907         }
87f67a 908         
TB 909         $tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id");
910         $client_user_id = $app->functions->intval(($tmp['userid'] > 0)?$tmp['userid']:1);
146783 911
MC 912         if(($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) &&  isset($this->dataRecord["client_group_id"]) && $this->dataRecord["client_group_id"] != $this->oldDataRecord["sys_groupid"]) {
913             // Set the values for document_root, system_user and system_group
914             $system_user = $app->db->quote('web'.$this->id);
915             $system_group = $app->db->quote('client'.$client_id);
7fe908 916             $document_root = str_replace("[client_id]", $client_id, $document_root);
MC 917             $document_root = str_replace("[client_idhash_1]", $this->id_hash($client_id, 1), $document_root);
918             $document_root = str_replace("[client_idhash_2]", $this->id_hash($client_id, 2), $document_root);
919             $document_root = str_replace("[client_idhash_3]", $this->id_hash($client_id, 3), $document_root);
920             $document_root = str_replace("[client_idhash_4]", $this->id_hash($client_id, 4), $document_root);
146783 921             $document_root = $app->db->quote($document_root);
MC 922
87f67a 923             $sql = "UPDATE web_domain SET sys_userid = '$client_user_id' ,system_user = '$system_user', system_group = '$system_group', document_root = '$document_root' WHERE domain_id = ".$this->id;
146783 924             //$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group' WHERE domain_id = ".$this->id;
MC 925             $app->db->query($sql);
926
927             // Update the FTP user(s) too
928             $records = $app->db->queryAllRecords("SELECT ftp_user_id FROM ftp_user WHERE parent_domain_id = ".$this->id);
929             foreach($records as $rec) {
87f67a 930                 $app->db->datalogUpdate('ftp_user', "sys_userid = '".$app->functions->intval($client_user_id)."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."', uid = '$system_user', gid = '$system_group', dir = '$document_root'", 'ftp_user_id', $app->functions->intval($rec['ftp_user_id']));
146783 931             }
MC 932             unset($records);
933             unset($rec);
934
935             // Update the Shell user(s) too
936             $records = $app->db->queryAllRecords("SELECT shell_user_id FROM shell_user WHERE parent_domain_id = ".$this->id);
937             foreach($records as $rec) {
87f67a 938                 $app->db->datalogUpdate('shell_user', "sys_userid = '".$client_user_id."', sys_groupid = '".$web_rec['sys_groupid']."', puser = '$system_user', pgroup = '$system_group', dir = '$document_root'", 'shell_user_id', $app->functions->intval($rec['shell_user_id']));
146783 939             }
MC 940             unset($records);
941             unset($rec);
7fe908 942
146783 943             //* Update all subdomains and alias domains
MC 944             $records = $app->db->queryAllRecords("SELECT domain_id, `domain`, `type`, `web_folder` FROM web_domain WHERE parent_domain_id = ".$this->id);
945             foreach($records as $rec) {
87f67a 946                 $update_columns = "sys_userid = '".$client_user_id."', sys_groupid = '".$web_rec['sys_groupid']."'";
7fe908 947                 if($rec['type'] == 'vhostsubdomain') {
MC 948                     $php_open_basedir = str_replace("[website_path]/web", $document_root.'/'.$rec['web_folder'], $web_config["php_open_basedir"]);
949                     $php_open_basedir = str_replace("[website_domain]/web", $rec['domain'].'/'.$rec['web_folder'], $php_open_basedir);
950                     $php_open_basedir = str_replace("[website_path]", $document_root, $php_open_basedir);
951                     $php_open_basedir = $app->db->quote(str_replace("[website_domain]", $rec['domain'], $php_open_basedir));
146783 952
7fe908 953                     $update_columns .= ", document_root = '".$document_root."', `php_open_basedir` = '".$php_open_basedir."'";
MC 954                 }
146783 955                 $app->db->datalogUpdate('web_domain', $update_columns, 'domain_id', $rec['domain_id']);
MC 956             }
957             unset($records);
958             unset($rec);
7fe908 959
146783 960             //* Update all databases
MC 961             $records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE parent_domain_id = ".$this->id);
962             foreach($records as $rec) {
87f67a 963                 $app->db->datalogUpdate('web_database', "sys_userid = '".$app->functions->intval($client_user_id)."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."'", 'database_id', $app->functions->intval($rec['database_id']));
146783 964             }
MC 965             unset($records);
966             unset($rec);
967
968         }
969
970         //* If the domain name has been changed, we will have to change all subdomains + APS instances
971         if(!empty($this->dataRecord["domain"]) && !empty($this->oldDataRecord["domain"]) && $this->dataRecord["domain"] != $this->oldDataRecord["domain"]) {
972             $records = $app->db->queryAllRecords("SELECT domain_id,domain FROM web_domain WHERE (type = 'subdomain' OR type = 'vhostsubdomain') AND domain LIKE '%.".$app->db->quote($this->oldDataRecord["domain"])."'");
973             foreach($records as $rec) {
7fe908 974                 $subdomain = $app->db->quote(str_replace($this->oldDataRecord["domain"], $this->dataRecord["domain"], $rec['domain']));
146783 975                 $app->db->datalogUpdate('web_domain', "domain = '".$subdomain."'", 'domain_id', $rec['domain_id']);
MC 976             }
977             unset($records);
978             unset($rec);
979             unset($subdomain);
7fe908 980
146783 981             // Update APS instances
604c0c 982             $records = $app->db->queryAllRecords("SELECT id, instance_id FROM aps_instances_settings WHERE name = 'main_domain' AND value = '".$app->db->quote($this->oldDataRecord["domain"])."'");
146783 983             if(is_array($records) && !empty($records)){
MC 984                 foreach($records as $rec){
604c0c 985                     $app->db->datalogUpdate('aps_instances_settings', "value = '".$app->db->quote($this->dataRecord["domain"])."'", 'id', $rec['id']);
146783 986                     // Reinstall of package needed?
MC 987                     //$app->db->datalogUpdate('aps_instances', "instance_status = '1'", 'id', $rec['instance_id']);
988                 }
989             }
990             unset($records);
991             unset($rec);
992         }
993
994         //* Set allow_override if empty
995         if($web_rec['allow_override'] == '') {
996             $sql = "UPDATE web_domain SET allow_override = '".$app->db->quote($web_config["htaccess_allow_override"])."' WHERE domain_id = ".$this->id;
997             $app->db->query($sql);
998         }
7fe908 999
146783 1000         //* Set php_open_basedir if empty or domain or client has been changed
MC 1001         if(empty($web_rec['php_open_basedir']) ||
7fe908 1002             (!empty($this->dataRecord["domain"]) && !empty($this->oldDataRecord["domain"]) && $this->dataRecord["domain"] != $this->oldDataRecord["domain"])) {
146783 1003             $php_open_basedir = $web_rec['php_open_basedir'];
604c0c 1004             $php_open_basedir = $app->db->quote(str_replace($this->oldDataRecord['domain'], $web_rec['domain'], $php_open_basedir));
146783 1005             $sql = "UPDATE web_domain SET php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$this->id;
MC 1006             $app->db->query($sql);
1007         }
1008         if(empty($web_rec['php_open_basedir']) ||
7fe908 1009             (isset($this->dataRecord["client_group_id"]) && $this->dataRecord["client_group_id"] != $this->oldDataRecord["sys_groupid"])) {
MC 1010             $document_root = $app->db->quote(str_replace("[client_id]", $client_id, $document_root));
1011             $php_open_basedir = str_replace("[website_path]", $document_root, $web_config["php_open_basedir"]);
1012             $php_open_basedir = $app->db->quote(str_replace("[website_domain]", $web_rec['domain'], $php_open_basedir));
146783 1013             $sql = "UPDATE web_domain SET php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$this->id;
MC 1014             $app->db->query($sql);
1015         }
7fe908 1016
146783 1017         //* Change database backup options when web backup options have been changed
MC 1018         if(isset($this->dataRecord['backup_interval']) && ($this->dataRecord['backup_interval'] != $this->oldDataRecord['backup_interval'] || $this->dataRecord['backup_copies'] != $this->oldDataRecord['backup_copies'])) {
1019             //* Update all databases
7c19f2 1020             $backup_interval = $app->db->quote($this->dataRecord['backup_interval']);
604c0c 1021             $backup_copies = $app->functions->intval($this->dataRecord['backup_copies']);
146783 1022             $records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE parent_domain_id = ".$this->id);
MC 1023             foreach($records as $rec) {
1024                 $app->db->datalogUpdate('web_database', "backup_interval = '$backup_interval', backup_copies = '$backup_copies'", 'database_id', $rec['database_id']);
1025             }
1026             unset($records);
1027             unset($rec);
1028             unset($backup_copies);
1029             unset($backup_interval);
1030         }
7fe908 1031
MC 1032         //* Change vhost subdomain ip/ipv6 if domain ip/ipv6 has changed
1033         if(isset($this->dataRecord['ip_address']) && ($this->dataRecord['ip_address'] != $this->oldDataRecord['ip_address'] || $this->dataRecord['ipv6_address'] != $this->oldDataRecord['ipv6_address'])) {
146783 1034             $records = $app->db->queryAllRecords("SELECT domain_id FROM web_domain WHERE type = 'vhostsubdomain' AND parent_domain_id = ".$this->id);
MC 1035             foreach($records as $rec) {
604c0c 1036                 $app->db->datalogUpdate('web_domain', "ip_address = '".$app->db->quote($web_rec['ip_address'])."', ipv6_address = '".$app->db->quote($web_rec['ipv6_address'])."'", 'domain_id', $rec['domain_id']);
146783 1037             }
MC 1038             unset($records);
1039             unset($rec);
7fe908 1040         }
146783 1041     }
MC 1042
1043     function onAfterDelete() {
1044         global $app, $conf;
1045
1046         // Delete the sub and alias domains
1047         $child_domains = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE parent_domain_id = ".$this->id);
1048         foreach($child_domains as $d) {
1049             // Saving record to datalog when db_history enabled
1050             if($app->tform->formDef["db_history"] == 'yes') {
7fe908 1051                 $app->tform->datalogSave('DELETE', $d["domain_id"], $d, array());
146783 1052             }
MC 1053
604c0c 1054             $app->db->query("DELETE FROM web_domain WHERE domain_id = ".$app->functions->intval($d["domain_id"])." LIMIT 0,1");
146783 1055         }
MC 1056         unset($child_domains);
1057         unset($d);
1058
1059     }
1060
1061 }
1062
1063 $page = new page_action;
1064 $page->onLoad();
1065
7fe908 1066 ?>