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