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