Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
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"];
cc7a82 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);
bd6659 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
67b0cb 142         $read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl', 'limit_ssl_letsencrypt', 'limit_directive_snippets');
02384b 143
cc7a82 144         if($this->_vhostdomain_type != 'domain') $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ?", @$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') {
cc7a82 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);
73813a 155             } elseif($this->_vhostdomain_type == 'subdomain') {
cc7a82 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);
73813a 157             } elseif($this->_vhostdomain_type == 'aliasdomain') {
cc7a82 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);
73813a 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
2af58c 170             $sql = "SELECT server_id, server_name FROM server WHERE server_id IN ?";
MC 171             $web_servers = $app->db->queryAllRecords($sql, $client['web_servers_ids']);
bd6659 172
SJ 173             $options_web_servers = "";
174
175             foreach ($web_servers as $web_server) {
75b7fc 176                 $options_web_servers .= '<option value="'.$web_server['server_id'].'"'.($this->id > 0 && $this->dataRecord["server_id"] == $web_server['server_id'] ? ' selected="selected"' : '').'>'.$web_server['server_name'].'</option>';
bd6659 177             }
SJ 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"])){
2af58c 184                     $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->id);
bd6659 185                     $this->dataRecord["server_id"] = $tmp["server_id"];
SJ 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
2af58c 203             $sql = "SELECT ip_address FROM server_ip WHERE server_id IN ? AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")";
MC 204             $ips = $app->db->queryAllRecords($sql, explode(',', $client['web_servers']));
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
2af58c 219             $sql = "SELECT ip_address FROM server_ip WHERE server_id IN ? AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=?)";
MC 220             $ips = $app->db->queryAllRecords($sql, explode(',', $client['web_servers']), $_SESSION['s']['user']['client_id']);
a56c8a 221             $ip_select = ($web_config[$server_id]['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
76ebcb 222             //$ip_select = "";
F 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') {
d22277 239                 if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
2af58c 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 = ? AND (client_id = 0 OR client_id=?)", ($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver']), $_SESSION['s']['user']['client_id']);
73813a 241                 }
MC 242                 if($this->dataRecord['php'] == 'fast-cgi'){
2af58c 243                     $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?)", ($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver']), $_SESSION['s']['user']['client_id']);
73813a 244                 }
MC 245             } else {
d22277 246                 if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
2af58c 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 = ? AND (client_id = 0 OR client_id=?)", $parent_domain['server_id'], $_SESSION['s']['user']['client_id']);
73813a 248                 }
MC 249                 if($this->dataRecord['php'] == 'fast-cgi'){
2af58c 250                     $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?)", $parent_domain['server_id'], $_SESSION['s']['user']['client_id']);
73813a 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) {
d22277 256                     if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
76ebcb 257                         $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
F 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') {
cc7a82 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);
73813a 280                 $app->tpl->setVar('only_one_server', $only_one_server);
MC 281             } elseif($this->_vhostdomain_type == 'subdomain') {
cc7a82 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);
73813a 283             } elseif($this->_vhostdomain_type == 'aliasdomain') {
cc7a82 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);
73813a 285             }
MC 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
2af58c 295             $sql = "SELECT server_id, server_name FROM server WHERE server_id IN ?";
MC 296             $web_servers = $app->db->queryAllRecords($sql, $client['web_servers_ids']);
bd6659 297
SJ 298             $options_web_servers = "";
299
300             foreach ($web_servers as $web_server) {
75b7fc 301                 $options_web_servers .= '<option value="'.$web_server['server_id'].'"'.($this->id > 0 && $this->dataRecord["server_id"] == $web_server['server_id'] ? ' selected="selected"' : '').'>'.$web_server['server_name'].'</option>';
bd6659 302             }
SJ 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
2af58c 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 = ? ORDER BY client.company_name, client.contact_name, sys_group.name";
MC 310                 $records = $app->db->queryAllRecords($sql, $client['client_id']);
311                 $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']);
3e94c8 312                 $client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>';
SC 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
2af58c 336             $sql = "SELECT ip_address FROM server_ip WHERE server_id IN ? AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=?)";
MC 337             $ips = $app->db->queryAllRecords($sql, explode(',', $client['web_servers']), $_SESSION['s']['user']['client_id']);
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
2af58c 352             $sql = "SELECT ip_address FROM server_ip WHERE server_id IN ? AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=?)";
MC 353             $ips = $app->db->queryAllRecords($sql, $client['web_servers'], $_SESSION['s']['user']['client_id']);
76ebcb 354             $ip_select = "<option value=''></option>";
F 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';
2af58c 370             $selected_client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = ?", $selected_client_group_id);
MC 371             $sql_where = " AND (client_id = 0 OR client_id = ?)";
73813a 372             if($this->_vhostdomain_type == 'domain') {
d22277 373                 if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
2af58c 374                     $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 = ?".$sql_where, ($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver']), $selected_client['client_id']);
73813a 375                 }
MC 376                 if($this->dataRecord['php'] == 'fast-cgi') {
2af58c 377                     $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ?".$sql_where, ($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver']), $selected_client['client_id']);
73813a 378                 }
MC 379             } else {
d22277 380                 if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
2af58c 381                     $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 = ? AND (client_id = 0 OR client_id=?)", $parent_domain['server_id'], $_SESSION['s']['user']['client_id']);
73813a 382                 }
MC 383                 if($this->dataRecord['php'] == 'fast-cgi') {
2af58c 384                     $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?)", $parent_domain['server_id'], $_SESSION['s']['user']['client_id']);
73813a 385                 }
76ebcb 386             }
F 387             $php_select = "<option value=''>Default</option>";
388             if(is_array($php_records) && !empty($php_records)) {
389                 foreach( $php_records as $php_record) {
d22277 390                     if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
76ebcb 391                         $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
F 392                     } else {
393                         $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
394                     }
395                     $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':'';
396                     $php_select .= "<option value='$php_version' $selected>".$php_record['name']."</option>\r\n";
397                 }
398             }
b1a6a5 399             $app->tpl->setVar("fastcgi_php_version", $php_select);
76ebcb 400             unset($php_records);
b1a6a5 401
MC 402             // add limits to template to be able to hide settings
403             foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]);
404
405             $sites_config = $app->getconf->get_global_config('sites');
406             if($sites_config['reseller_can_use_options']) {
407                 // Directive Snippets
408                 $php_directive_snippets_txt = '';
d22277 409                 $php_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'php' AND active = 'y' AND master_directive_snippets_id > 0 ORDER BY name");
b1a6a5 410                 if(is_array($php_directive_snippets) && !empty($php_directive_snippets)){
d22277 411                     $php_directive_snippets_txt .= $app->tform->wordbook["select_master_directive_snippet_txt"].'<br>';
b1a6a5 412                     foreach($php_directive_snippets as $php_directive_snippet){
9e5a11 413                         $php_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $php_directive_snippet['snippet'] . PHP_EOL;
d22277 414                         $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
MB 415                     }
416                     $php_directive_snippets_txt .= '<br><br>';
417                 }
418                 
419                 $php_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'php' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name");
420                 if(is_array($php_directive_snippets) && !empty($php_directive_snippets)){
421                     $php_directive_snippets_txt .= $app->tform->wordbook["select_directive_snippet_txt"].'<br>';
422                     foreach($php_directive_snippets as $php_directive_snippet){
423                         $php_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $php_directive_snippet['snippet'] . PHP_EOL;
424                         $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
b1a6a5 425                     }
MC 426                 }
427                 if($php_directive_snippets_txt == '') $php_directive_snippets_txt = '------';
428                 $app->tpl->setVar("php_directive_snippets_txt", $php_directive_snippets_txt);
429
430                 if($server_type == 'apache'){
431                     $apache_directive_snippets_txt = '';
d22277 432                     $apache_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'apache' AND active = 'y' AND master_directive_snippets_id > 0 ORDER BY name");
b1a6a5 433                     if(is_array($apache_directive_snippets) && !empty($apache_directive_snippets)){
d22277 434                         $apache_directive_snippets_txt .= $app->tform->wordbook["select_master_directive_snippet_txt"].'<br>';
b1a6a5 435                         foreach($apache_directive_snippets as $apache_directive_snippet){
9e5a11 436                             $apache_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $apache_directive_snippet['snippet'] . PHP_EOL;
d22277 437                             $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
MB 438                         }
439                         $apache_directive_snippets_txt .= '<br><br>';
440                     }
441                     
442                     $apache_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'apache' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name");
443                     if(is_array($apache_directive_snippets) && !empty($apache_directive_snippets)){
444                         $apache_directive_snippets_txt .= $app->tform->wordbook["select_directive_snippet_txt"].'<br>';
445                         foreach($apache_directive_snippets as $apache_directive_snippet){
446                             $apache_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $apache_directive_snippet['snippet'] . PHP_EOL;
447                             $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
b1a6a5 448                         }
MC 449                     }
450                     if($apache_directive_snippets_txt == '') $apache_directive_snippets_txt = '------';
451                     $app->tpl->setVar("apache_directive_snippets_txt", $apache_directive_snippets_txt);
452                 }
453
454                 if($server_type == 'nginx'){
455                     $nginx_directive_snippets_txt = '';
d22277 456                     $nginx_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'nginx' AND active = 'y' AND master_directive_snippets_id > 0 ORDER BY name");
b1a6a5 457                     if(is_array($nginx_directive_snippets) && !empty($nginx_directive_snippets)){
d22277 458                         $nginx_directive_snippets_txt .= $app->tform->wordbook["select_master_directive_snippet_txt"].'<br>';
b1a6a5 459                         foreach($nginx_directive_snippets as $nginx_directive_snippet){
9e5a11 460                             $nginx_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $nginx_directive_snippet['snippet'] . PHP_EOL;
d22277 461                             $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
MB 462                         }
463                         $nginx_directive_snippets_txt .= '<br><br>';
464                     }
465                     
466                     $nginx_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'nginx' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name");
467                     if(is_array($nginx_directive_snippets) && !empty($nginx_directive_snippets)){
468                         $nginx_directive_snippets_txt .= $app->tform->wordbook["select_directive_snippet_txt"].'<br>';
469                         foreach($nginx_directive_snippets as $nginx_directive_snippet){
470                             $nginx_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $nginx_directive_snippet['snippet'] . PHP_EOL;
471                             $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
b1a6a5 472                         }
MC 473                     }
474                     if($nginx_directive_snippets_txt == '') $nginx_directive_snippets_txt = '------';
475                     $app->tpl->setVar("nginx_directive_snippets_txt", $nginx_directive_snippets_txt);
476                 }
477
478                 $proxy_directive_snippets_txt = '';
d22277 479                 $proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y' AND master_directive_snippets_id > 0 ORDER BY name");
b1a6a5 480                 if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){
d22277 481                     $proxy_directive_snippets_txt .= $app->tform->wordbook["select_master_directive_snippet_txt"].'<br>';
b1a6a5 482                     foreach($proxy_directive_snippets as $proxy_directive_snippet){
9e5a11 483                         $proxy_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $proxy_directive_snippet['snippet'] . PHP_EOL;
d22277 484                         $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
MB 485                     }
486                     $proxy_directive_snippets_txt .= '<br><br>';
487                 }
488                 
489                 $proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name");
490                 if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){
491                     $proxy_directive_snippets_txt .= $app->tform->wordbook["select_directive_snippet_txt"].'<br>';
492                     foreach($proxy_directive_snippets as $proxy_directive_snippet){
493                         $proxy_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $proxy_directive_snippet['snippet'] . PHP_EOL;
494                         $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
b1a6a5 495                     }
MC 496                 }
497                 if($proxy_directive_snippets_txt == '') $proxy_directive_snippets_txt = '------';
498                 $app->tpl->setVar("proxy_directive_snippets_txt", $proxy_directive_snippets_txt);
499             }
500
76ebcb 501             //* Admin: If the logged in user is admin
F 502         } else {
8173c6 503         
FT 504             $is_admin = true;
76ebcb 505
73813a 506             if($this->_vhostdomain_type == 'domain') {
MC 507                 // The user is admin, so we fill in all IP addresses of the server
508                 if($this->id > 0) {
509                     if(!isset($this->dataRecord["server_id"])){
2af58c 510                         $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->id);
73813a 511                         $this->dataRecord["server_id"] = $tmp["server_id"];
MC 512                         unset($tmp);
513                     }
514                     $server_id = intval(@$this->dataRecord["server_id"]);
515                 } else {
eed9fb 516                     $settings = $app->getconf->get_global_config('sites');
SC 517                     $server_id = intval($settings['default_webserver']);
518                     if (!$server_id) {
519                         // Get the first server ID
520                         $tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
521                         $server_id = intval($tmp['server_id']);
522                     }
76ebcb 523                 }
b1a6a5 524
73813a 525                 //* get global web config
MC 526                 $web_config = $app->getconf->get_server_config($server_id, 'web');
527             } else {
528                 //* get global web config
529                 $web_config = $app->getconf->get_server_config($parent_domain['server_id'], 'web');
530             }
b1a6a5 531
76ebcb 532             //* Fill the IPv4 select field
2af58c 533             $sql = "SELECT ip_address FROM server_ip WHERE ip_type = 'IPv4' AND server_id = ?";
MC 534             $ips = $app->db->queryAllRecords($sql, $server_id);
02384b 535             $ip_select = ($web_config['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
76ebcb 536             //$ip_select = "";
F 537             if(is_array($ips)) {
538                 foreach( $ips as $ip) {
539                     $selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';
540                     $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
541                 }
542             }
b1a6a5 543             $app->tpl->setVar("ip_address", $ip_select);
76ebcb 544             unset($tmp);
F 545             unset($ips);
b1a6a5 546
76ebcb 547             //* Fill the IPv6 select field
2af58c 548             $sql = "SELECT ip_address FROM server_ip WHERE ip_type = 'IPv6' AND server_id = ?";
MC 549             $ips = $app->db->queryAllRecords($sql, $server_id);
76ebcb 550             $ip_select = "<option value=''></option>";
F 551             //$ip_select = "";
552             if(is_array($ips)) {
553                 foreach( $ips as $ip) {
554                     $selected = ($ip["ip_address"] == $this->dataRecord["ipv6_address"])?'SELECTED':'';
555                     $ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
556                 }
557             }
b1a6a5 558             $app->tpl->setVar("ipv6_address", $ip_select);
76ebcb 559             unset($tmp);
F 560             unset($ips);
7b47c0 561
3e94c8 562             if ($settings['use_domain_module'] != 'y') {
d22277 563                 if(!isset($this->dataRecord["sys_groupid"])){
MB 564                     $tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id));
565                     $this->dataRecord["sys_groupid"] = $tmp["sys_groupid"];
566                 }
3e94c8 567                 // Fill the client select field
SC 568                 $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";
569                 $clients = $app->db->queryAllRecords($sql);
570                 $client_select = "<option value='0'></option>";
571                 //$tmp_data_record = $app->tform->getDataRecord($this->id);
572                 if(is_array($clients)) {
573                     $selected_client_group_id = 0; // needed to get list of PHP versions
574                     foreach($clients as $client) {
575                         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"];
576                         //$selected = @($client["groupid"] == $tmp_data_record["sys_groupid"])?'SELECTED':'';
577                         $selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
578                         if($selected == 'SELECTED') $selected_client_group_id = $client["groupid"];
579                         $client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
580                     }
7b47c0 581                 }
3e94c8 582                 $app->tpl->setVar("client_group_id", $client_select);
7b47c0 583             }
b1a6a5 584
76ebcb 585             //PHP Version Selection (FastCGI)
F 586             $server_type = 'apache';
587             if(!empty($web_config['server_type'])) $server_type = $web_config['server_type'];
588             if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm';
2af58c 589             $selected_client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = ?", $selected_client_group_id);
MC 590             $sql_where = " AND (client_id = 0 OR client_id = ?)";
73813a 591             if($this->_vhostdomain_type == 'domain') {
d22277 592                 if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
2af58c 593                     $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 = ?".$sql_where, $server_id, $selected_client['client_id']);
73813a 594                 }
MC 595                 if($this->dataRecord['php'] == 'fast-cgi') {
2af58c 596                     $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ?".$sql_where, $server_id, $selected_client['client_id']);
73813a 597                 }
MC 598             } else {
d22277 599                 if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
2af58c 600                     $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 = ?", $parent_domain['server_id']);
73813a 601                 }
MC 602                 if($this->dataRecord['php'] == 'fast-cgi') {
2af58c 603                     $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ?", $parent_domain['server_id']);
73813a 604                 }
76ebcb 605             }
F 606             $php_select = "<option value=''>Default</option>";
607             if(is_array($php_records) && !empty($php_records)) {
608                 foreach( $php_records as $php_record) {
d22277 609                     if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
76ebcb 610                         $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir'];
F 611                     } else {
612                         $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir'];
613                     }
614                     $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':'';
615                     $php_select .= "<option value='$php_version' $selected>".$php_record['name']."</option>\r\n";
616                 }
617             }
b1a6a5 618             $app->tpl->setVar("fastcgi_php_version", $php_select);
76ebcb 619             unset($php_records);
b1a6a5 620
MC 621             foreach($read_limits as $limit) $app->tpl->setVar($limit, ($limit == 'force_suexec' ? 'n' : 'y'));
622
ef55b5 623             // Directive Snippets
F 624             $php_directive_snippets_txt = '';
d22277 625             $php_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'php' AND active = 'y' AND master_directive_snippets_id > 0 ORDER BY name");
ef55b5 626             if(is_array($php_directive_snippets) && !empty($php_directive_snippets)){
d22277 627                 $php_directive_snippets_txt .= $app->tform->wordbook["select_master_directive_snippet_txt"].'<br>';
b1a6a5 628                 foreach($php_directive_snippets as $php_directive_snippet){
9e5a11 629                     $php_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $php_directive_snippet['snippet'] . PHP_EOL;
d22277 630                     $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
MB 631                 }
632                 $php_directive_snippets_txt .= '<br><br>';
633             }
634             
635             $php_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'php' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name");
636             if(is_array($php_directive_snippets) && !empty($php_directive_snippets)){
637                 $php_directive_snippets_txt .= $app->tform->wordbook["select_directive_snippet_txt"].'<br>';
638                 foreach($php_directive_snippets as $php_directive_snippet){
639                     $php_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $php_directive_snippet['snippet'] . PHP_EOL;
640                     $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
b1a6a5 641                 }
ef55b5 642             }
F 643             if($php_directive_snippets_txt == '') $php_directive_snippets_txt = '------';
b1a6a5 644             $app->tpl->setVar("php_directive_snippets_txt", $php_directive_snippets_txt);
MC 645
ef55b5 646             if($server_type == 'apache'){
F 647                 $apache_directive_snippets_txt = '';
d22277 648                 $apache_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'apache' AND active = 'y' AND master_directive_snippets_id > 0 ORDER BY name");
ef55b5 649                 if(is_array($apache_directive_snippets) && !empty($apache_directive_snippets)){
d22277 650                     $apache_directive_snippets_txt .= $app->tform->wordbook["select_master_directive_snippet_txt"].'<br>';
b1a6a5 651                     foreach($apache_directive_snippets as $apache_directive_snippet){
9e5a11 652                         $apache_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $apache_directive_snippet['snippet'] . PHP_EOL;
d22277 653                         $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
MB 654                     }
655                     $apache_directive_snippets_txt .= '<br><br>';
656                 }
657                 
658                 $apache_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'apache' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name");
659                 if(is_array($apache_directive_snippets) && !empty($apache_directive_snippets)){
660                     $apache_directive_snippets_txt .= $app->tform->wordbook["select_directive_snippet_txt"].'<br>';
661                     foreach($apache_directive_snippets as $apache_directive_snippet){
662                         $apache_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $apache_directive_snippet['snippet'] . PHP_EOL;
663                         $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
b1a6a5 664                     }
ef55b5 665                 }
F 666                 if($apache_directive_snippets_txt == '') $apache_directive_snippets_txt = '------';
b1a6a5 667                 $app->tpl->setVar("apache_directive_snippets_txt", $apache_directive_snippets_txt);
ef55b5 668             }
b1a6a5 669
3a93f2 670             if($server_type == 'nginx'){
ef55b5 671                 $nginx_directive_snippets_txt = '';
d22277 672                 $nginx_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'nginx' AND active = 'y' AND master_directive_snippets_id > 0 ORDER BY name");
ef55b5 673                 if(is_array($nginx_directive_snippets) && !empty($nginx_directive_snippets)){
d22277 674                     $nginx_directive_snippets_txt .= $app->tform->wordbook["select_master_directive_snippet_txt"].'<br>';
b1a6a5 675                     foreach($nginx_directive_snippets as $nginx_directive_snippet){
9e5a11 676                         $nginx_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $nginx_directive_snippet['snippet'] . PHP_EOL;
d22277 677                         $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
MB 678                     }
679                     $nginx_directive_snippets_txt .= '<br><br>';
680                 }
681                 
682                 $nginx_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'nginx' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name");
683                 if(is_array($nginx_directive_snippets) && !empty($nginx_directive_snippets)){
684                     $nginx_directive_snippets_txt .= $app->tform->wordbook["select_directive_snippet_txt"].'<br>';
685                     foreach($nginx_directive_snippets as $nginx_directive_snippet){
686                         $nginx_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $nginx_directive_snippet['snippet'] . PHP_EOL;
687                         $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
b1a6a5 688                     }
ef55b5 689                 }
F 690                 if($nginx_directive_snippets_txt == '') $nginx_directive_snippets_txt = '------';
b1a6a5 691                 $app->tpl->setVar("nginx_directive_snippets_txt", $nginx_directive_snippets_txt);
ef55b5 692             }
b1a6a5 693
bfcdef 694             $proxy_directive_snippets_txt = '';
d22277 695             $proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y' AND master_directive_snippets_id > 0 ORDER BY name");
bfcdef 696             if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){
d22277 697                 $proxy_directive_snippets_txt .= $app->tform->wordbook["select_master_directive_snippet_txt"].'<br>';
b1a6a5 698                 foreach($proxy_directive_snippets as $proxy_directive_snippet){
9e5a11 699                     $proxy_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $proxy_directive_snippet['snippet'] . PHP_EOL;
d22277 700                     $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
MB 701                 }
702                 $proxy_directive_snippets_txt .= '<br><br>';
703             }
704             
705             $proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name");
706             if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){
707                 $proxy_directive_snippets_txt .= $app->tform->wordbook["select_directive_snippet_txt"].'<br>';
708                 foreach($proxy_directive_snippets as $proxy_directive_snippet){
709                     $proxy_directive_snippet['snippet'] = PHP_EOL . PHP_EOL . $proxy_directive_snippet['snippet'] . PHP_EOL;
710                     $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
b1a6a5 711                 }
bfcdef 712             }
T 713             if($proxy_directive_snippets_txt == '') $proxy_directive_snippets_txt = '------';
b1a6a5 714             $app->tpl->setVar("proxy_directive_snippets_txt", $proxy_directive_snippets_txt);
76ebcb 715         }
F 716
717         $ssl_domain_select = '';
797215 718         $ssl_domains = array();
2af58c 719         $tmpd = $app->db->queryAllRecords("SELECT domain, type FROM web_domain WHERE domain_id = ? OR parent_domain_id = ?", $this->id, $this->id);
797215 720         foreach($tmpd as $tmp) {
MC 721             if($tmp['type'] == 'subdomain' || $tmp['type'] == 'vhostsubdomain') {
722                 $ssl_domains[] = $tmp["domain"];
723             } else {
724                 $ssl_domains = array_merge($ssl_domains, array($tmp["domain"],'www.'.$tmp["domain"],'*.'.$tmp["domain"]));
725             }
726         }
76ebcb 727         if(is_array($ssl_domains)) {
F 728             foreach( $ssl_domains as $ssl_domain) {
729                 $selected = ($ssl_domain == $this->dataRecord['ssl_domain'])?'SELECTED':'';
024e13 730                 $ssl_domain_select .= "<option value='$ssl_domain' $selected>".$app->functions->idn_decode($ssl_domain)."</option>\r\n";
76ebcb 731             }
F 732         }
b1a6a5 733         $app->tpl->setVar("ssl_domain", $ssl_domain_select);
76ebcb 734         unset($ssl_domain_select);
F 735         unset($ssl_domains);
736         unset($ssl_domain);
737
738         if($this->id > 0) {
739             //* we are editing a existing record
740             $app->tpl->setVar("edit_disabled", 1);
73813a 741             $app->tpl->setVar('fixed_folder', 'y');
568b4b 742             if($this->_vhostdomain_type == 'domain') {
FS 743                 $app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]);
744                 $app->tpl->setVar("document_root", $this->dataRecord["document_root"]);
745             }
73813a 746             else $app->tpl->setVar('server_id_value', $parent_domain['server_id']);
76ebcb 747         } else {
F 748             $app->tpl->setVar("edit_disabled", 0);
73813a 749             $app->tpl->setVar('fixed_folder', 'n');
MC 750             if($this->_vhostdomain_type != 'domain') $app->tpl->setVar('server_id_value', $parent_domain['server_id']);
76ebcb 751         }
F 752
753         $tmp_txt = ($this->dataRecord['traffic_quota_lock'] == 'y')?'<b>('.$app->tform->lng('traffic_quota_exceeded_txt').')</b>':'';
754         $app->tpl->setVar("traffic_quota_exceeded_txt", $tmp_txt);
755
756         /*
757          * Now we have to check, if we should use the domain-module to select the domain
758          * or not
759          */
760         if ($settings['use_domain_module'] == 'y') {
761             /*
762              * The domain-module is in use.
763             */
9ec304 764             $domains = $app->tools_sites->getDomainModuleDomains($this->_vhostdomain_type == 'subdomain' ? null : "web_domain", $this->dataRecord["domain"]);
76ebcb 765             $domain_select = '';
73813a 766             $selected_domain = '';
76ebcb 767             if(is_array($domains) && sizeof($domains) > 0) {
F 768                 /* We have domains in the list, so create the drop-down-list */
769                 foreach( $domains as $domain) {
4e18bd 770                     $domain_select .= "<option value=" . $domain['domain_id'] ;
73813a 771                     if ($this->_vhostdomain_type == 'subdomain' && '.' . $domain['domain'] == substr($this->dataRecord["domain"], -strlen($domain['domain']) - 1)) {
MC 772                         $domain_select .= " selected";
773                         $selected_domain = $domain['domain'];
774                     } elseif($this->_vhostdomain_type == 'aliasdomain' && $domain['domain'] == $this->dataRecord["domain"]) {
775                         $domain_select .= " selected";
776                     } elseif($this->_vhostdomain_type == 'domain' && $domain['domain'] == $this->dataRecord["domain"]) {
76ebcb 777                         $domain_select .= " selected";
F 778                     }
8c1761 779                     $domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n";
76ebcb 780                 }
F 781             }
782             else {
783                 /*
784                  * We have no domains in the domain-list. This means, we can not add ANY new domain.
785                  * To avoid, that the variable "domain_option" is empty and so the user can
786                  * free enter a domain, we have to create a empty option!
787                 */
788                 $domain_select .= "<option value=''></option>\r\n";
789             }
b1a6a5 790             $app->tpl->setVar("domain_option", $domain_select);
0998a3 791         } else {
MC 792
793             // remove the parent domain part of the domain name before we show it in the text field.
794             if($this->dataRecord["type"] == 'vhostsubdomain') $this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"], '', $this->dataRecord["domain"]);
7b47c0 795         }
73813a 796         if($this->_vhostdomain_type != 'domain') $app->tpl->setVar("domain", $this->dataRecord["domain"]);
b1a6a5 797
7b47c0 798         // check for configuration errors in sys_datalog
T 799         if($this->id > 0) {
2af58c 800             $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 = ? 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", 'domain_id:' . $this->id);
7b47c0 801             if(is_array($datalog) && !empty($datalog)){
T 802                 if(trim($datalog['error']) != ''){
b1a6a5 803                     $app->tpl->setVar("config_error_msg", nl2br(htmlentities($datalog['error'])));
MC 804                     $app->tpl->setVar("config_error_tstamp", date($app->lng('conf_format_datetime'), $datalog['tstamp']));
7b47c0 805                 }
T 806             }
76ebcb 807         }
73813a 808         
MC 809         $app->tpl->setVar('vhostdomain_type', $this->_vhostdomain_type);
76ebcb 810
dcf94e 811         $app->tpl->setVar('is_spdy_enabled', ($web_config['enable_spdy'] === 'y'));
8173c6 812         $app->tpl->setVar("is_admin", $is_admin);
FT 813         
814         if($this->id > 0) {
815             $tmp_web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", intval($this->id));
816             $tmp_sys_group = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE groupid = ?", intval($tmp_web['sys_groupid']));
817             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']));
818             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);
819         }
dcf94e 820
d5f2d5 821         $sys_config = $app->getconf->get_global_config('misc');
MC 822         if($sys_config['use_combobox'] == 'y') {
823             $app->tpl->setVar('use_combobox', 'y');
824         }
d22277 825         
MB 826         $directive_snippets_id_select = '<option value="0"'.($this->dataRecord['directive_snippets_id'] == 0? ' selected="selected"' : '').'>-</option>';
827         $server_type = $app->getconf->get_server_config($server_id, 'web');
828         $server_type = $server_type['server_type'];
829         
830         $m_directive_snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND active = 'y' AND master_directive_snippets_id > 0 AND type = ? ORDER BY name ASC", $server_type);
831         if(is_array($m_directive_snippets) && !empty($m_directive_snippets)){
832             $directive_snippets_id_select .= '<optgroup label="'.$app->tform->wordbook["select_master_directive_snippet_txt"].'">';
833             foreach($m_directive_snippets as $m_directive_snippet){
834                 $directive_snippets_id_select .= '<option value="'.$m_directive_snippet['directive_snippets_id'].'"'.($this->dataRecord['directive_snippets_id'] == $m_directive_snippet['directive_snippets_id']? ' selected="selected"' : '').'>'.$m_directive_snippet['name'].'</option>';
835             }
836             $directive_snippets_id_select .= '</optgroup>';
837         }
838         
839         $directive_snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND active = 'y' AND master_directive_snippets_id = 0 AND type = ? ORDER BY name ASC", $server_type);
840         if(is_array($directive_snippets) && !empty($directive_snippets)){
841             $directive_snippets_id_select .= '<optgroup label="'.$app->tform->wordbook["select_directive_snippet_txt"].'">';
842             foreach($directive_snippets as $directive_snippet){
843                 $directive_snippets_id_select .= '<option value="'.$directive_snippet['directive_snippets_id'].'"'.($this->dataRecord['directive_snippets_id'] == $directive_snippet['directive_snippets_id']? ' selected="selected"' : '').'>'.$directive_snippet['name'].'</option>';
844             }
845             $directive_snippets_id_select .= '</optgroup>';
846         }
847         $app->tpl->setVar("directive_snippets_id", $directive_snippets_id_select);
848         
849         // folder_directive_snippets
850         if(isset($_POST['folder_directive_snippets']) && !isset($this->dataRecord['folder_directive_snippets'])){
851             $this->dataRecord['folder_directive_snippets'] = '';
852             if(is_array($_POST['folder_directive_snippets']) && !empty($_POST['folder_directive_snippets'])){
853                 foreach($_POST['folder_directive_snippets'] as $folder_directive_snippet){
854                     if(trim($folder_directive_snippet['folder']) != '' && intval($folder_directive_snippet['snippets_id']) > 0) $this->dataRecord['folder_directive_snippets'] .= trim($folder_directive_snippet['folder']).':'.intval($folder_directive_snippet['snippets_id'])."\n";
855                 }
856             }
857             $this->dataRecord['folder_directive_snippets'] = trim($this->dataRecord['folder_directive_snippets']);
858         }
859         
860         $master_directive_snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND active = 'y' AND snippet LIKE '%{FOLDER}%' AND master_directive_snippets_id > 0 AND type = ? ORDER BY name ASC", $server_type);
861         $c_directive_snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND active = 'y' AND snippet LIKE '%{FOLDER}%' AND master_directive_snippets_id = 0 AND type = ? ORDER BY name ASC", $server_type);
862         
863         $folder_directive_snippets = array();
864         $this->dataRecord['folder_directive_snippets'] = str_replace("\r\n", "\n", $this->dataRecord['folder_directive_snippets']);
865         $this->dataRecord['folder_directive_snippets'] = str_replace("\r", "\n", $this->dataRecord['folder_directive_snippets']);
866         $folder_directive_snippets_lines = explode("\n", trim($this->dataRecord['folder_directive_snippets']));
867         for($i=0;$i<sizeof($folder_directive_snippets_lines)+50;$i++){
868             $folder_directive_snippets[$i]['folder_directive_snippets_index'] = $i;
869             $folder_directive_snippets[$i]['folder_directive_snippets_index_plus_1'] = $i + 1;
870             if($i > sizeof($folder_directive_snippets_lines)){
871                 $folder_directive_snippets[$i]['folder_directive_snippets_css'] = 'hidden';
872             } else {
873                 $folder_directive_snippets[$i]['folder_directive_snippets_css'] = '';
874             }
875             if(trim($folder_directive_snippets_lines[$i]) != ''){
876                 list($folder_directive_snippets[$i]['folder_directive_snippets_folder'], $selected_snippet) = explode(':', trim($folder_directive_snippets_lines[$i]));
877                 $folder_directive_snippets[$i]['folder_directive_snippets_id'] = '<option value="0">-</option>';
878                 if(is_array($master_directive_snippets) && !empty($master_directive_snippets)){
879                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<optgroup label="'.$app->tform->wordbook["select_master_directive_snippet_txt"].'">';
880                     foreach($master_directive_snippets as $master_directive_snippet){
881                         $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<option value="'.$master_directive_snippet['directive_snippets_id'].'"'.($master_directive_snippet['directive_snippets_id'] == $selected_snippet ? ' selected="selected"' : '').'>'.$master_directive_snippet['name'].'</option>';
882                     }
883                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '</optgroup>';
884                 }
885                 
886                 if(is_array($c_directive_snippets) && !empty($c_directive_snippets)){
887                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<optgroup label="'.$app->tform->wordbook["select_directive_snippet_txt"].'">';
888                     foreach($c_directive_snippets as $c_directive_snippet){
889                         $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<option value="'.$c_directive_snippet['directive_snippets_id'].'"'.($c_directive_snippet['directive_snippets_id'] == $selected_snippet? ' selected="selected"' : '').'>'.$c_directive_snippet['name'].'</option>';
890                     }
891                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '</optgroup>';
892                 }
893             } else {
894                 $folder_directive_snippets[$i]['folder_directive_snippets_folder'] = '';
895                 $folder_directive_snippets[$i]['folder_directive_snippets_id'] = '<option value="0">-</option>';
896                 if(is_array($master_directive_snippets) && !empty($master_directive_snippets)){
897                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<optgroup label="'.$app->tform->wordbook["select_master_directive_snippet_txt"].'">';
898                     foreach($master_directive_snippets as $master_directive_snippet){
899                         $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<option value="'.$master_directive_snippet['directive_snippets_id'].'">'.$master_directive_snippet['name'].'</option>';
900                     }
901                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '</optgroup>';
902                 }
903                 
904                 if(is_array($c_directive_snippets) && !empty($c_directive_snippets)){
905                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<optgroup label="'.$app->tform->wordbook["select_directive_snippet_txt"].'">';
906                     foreach($c_directive_snippets as $c_directive_snippet){
907                         $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<option value="'.$c_directive_snippet['directive_snippets_id'].'">'.$c_directive_snippet['name'].'</option>';
908                     }
909                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '</optgroup>';
910                 }
911             }
912         }
913         $app->tpl->setLoop('folder_directive_snippets', $folder_directive_snippets);
914
76ebcb 915         parent::onShowEnd();
F 916     }
b1a6a5 917
MC 918     function onShowEdit() {
919         global $app;
920         if($app->tform->checkPerm($this->id, 'riud')) $app->tform->formDef['tabs']['domain']['readonly'] = false;
921         parent::onShowEdit();
922     }
76ebcb 923
F 924     function onSubmit() {
925         global $app, $conf;
926
73813a 927         // Set a few fixed values
MC 928         $this->dataRecord["vhost_type"] = 'name';
929         if($this->_vhostdomain_type == 'domain') {
930             $this->dataRecord["parent_domain_id"] = 0;
931             $this->dataRecord["type"] = 'vhost';
932         } else {
933             // Get the record of the parent domain
934             if(!@$this->dataRecord["parent_domain_id"] && $this->id) {
2af58c 935                 $tmp = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_domain WHERE domain_id = ?", $this->id);
73813a 936                 if($tmp) $this->dataRecord["parent_domain_id"] = $tmp['parent_domain_id'];
MC 937                 unset($tmp);
938             }
939
2af58c 940             $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]);
73813a 941             if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
MC 942
943             if($this->_vhostdomain_type == 'subdomain') {
944                 $this->dataRecord["type"] = 'vhostsubdomain';
945             } else {
946                 $this->dataRecord["type"] = 'vhostalias';
947             }
948             $this->dataRecord["server_id"] = $parent_domain["server_id"];
949             $this->dataRecord["ip_address"] = $parent_domain["ip_address"];
950             $this->dataRecord["ipv6_address"] = $parent_domain["ipv6_address"];
951             $this->dataRecord["client_group_id"] = $parent_domain["client_group_id"];
952
953             $this->parent_domain_record = $parent_domain;
954         }
955
67b0cb 956         $read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl', 'limit_ssl_letsencrypt', 'limit_directive_snippets');
73813a 957
b1a6a5 958         /* check if the domain module is used - and check if the selected domain can be used! */
f601d9 959         if($app->tform->getCurrentTab() == 'domain') {
ebbe63 960             if($this->_vhostdomain_type == 'subdomain') {
MC 961                 // Check that domain (the subdomain part) is not empty
962                 if(!preg_match('/^[a-zA-Z0-9].*/',$this->dataRecord['domain'])) {
963                     $app->tform->errorMessage .= $app->tform->lng("subdomain_error_empty")."<br />";
964                 }
965             }
966             
967             /* check if the domain module is used - and check if the selected domain can be used! */
b1a6a5 968             $app->uses('ini_parser,getconf');
MC 969             $settings = $app->getconf->get_global_config('domains');
970             if ($settings['use_domain_module'] == 'y') {
73813a 971                 if($this->_vhostdomain_type == 'subdomain') $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['sel_domain']);
MC 972                 else $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['domain']);
b1a6a5 973                 if(!$domain_check) {
MC 974                     // invalid domain selected
975                     $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
976                 } else {
3e94c8 977                     if ($this->_vhostdomain_type == 'domain' &&
SC 978                             ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid']))) {
979                         $this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['domain']);
980                     }
73813a 981                     if($this->_vhostdomain_type == 'subdomain') $this->dataRecord['domain'] = $this->dataRecord['domain'] . '.' . $domain_check;
MC 982                     else $this->dataRecord['domain'] = $domain_check;
b1a6a5 983                 }
73813a 984             } else {
MC 985                 if($this->_vhostdomain_type == 'subdomain') $this->dataRecord["domain"] = $this->dataRecord["domain"].'.'.$parent_domain["domain"];
986             }
987
988             if($this->_vhostdomain_type != 'domain') {
989                 $this->dataRecord['web_folder'] = strtolower($this->dataRecord['web_folder']);
990                 if(substr($this->dataRecord['web_folder'], 0, 1) === '/') $this->dataRecord['web_folder'] = substr($this->dataRecord['web_folder'], 1);
991                 if(substr($this->dataRecord['web_folder'], -1) === '/') $this->dataRecord['web_folder'] = substr($this->dataRecord['web_folder'], 0, -1);
992                 $forbidden_folders = array('', 'cgi-bin', 'log', 'private', 'ssl', 'tmp', 'webdav');
993                 $check_folder = strtolower($this->dataRecord['web_folder']);
994                 if(substr($check_folder, 0, 1) === '/') $check_folder = substr($check_folder, 1); // strip / at beginning to check against forbidden entries
995                 if(strpos($check_folder, '/') !== false) $check_folder = substr($check_folder, 0, strpos($check_folder, '/')); // get the first part of the path to check it
996                 if(in_array($check_folder, $forbidden_folders)) {
997                     $app->tform->errorMessage .= $app->tform->lng("web_folder_invalid_txt")."<br>";
998                 }
999
1000                 // vhostaliasdomains do not have a quota of their own
1001                 $this->dataRecord["hd_quota"] = 0;
b1a6a5 1002             }
MC 1003         }
1004
ac099e 1005
M 1006
76ebcb 1007         if($_SESSION["s"]["user"]["typ"] != 'admin') {
F 1008             // Get the limits of the client
73813a 1009             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
cc7a82 1010             $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 1011
SJ 1012             $client['web_servers_ids'] = explode(',', $client['web_servers']);
b1a6a5 1013
ebbe63 1014             if($client['limit_cgi'] != 'y') $this->dataRecord['cgi'] = 'n';
MC 1015             if($client['limit_ssi'] != 'y') $this->dataRecord['ssi'] = 'n';
1016             if($client['limit_perl'] != 'y') $this->dataRecord['perl'] = 'n';
1017             if($client['limit_ruby'] != 'y') $this->dataRecord['ruby'] = 'n';
1018             if($client['limit_python'] != 'y') $this->dataRecord['python'] = 'n';
b1a6a5 1019             if($client['force_suexec'] == 'y') $this->dataRecord['suexec'] = 'y';
ebbe63 1020             if($client['limit_hterror'] != 'y') $this->dataRecord['errordocs'] = 'n';
MC 1021             if($client['limit_wildcard'] != 'y' && $this->dataRecord['subdomain'] == '*') $this->dataRecord['subdomain'] = 'n';
1022             if($client['limit_ssl'] != 'y') $this->dataRecord['ssl'] = 'n';
67b0cb 1023             if($client['limit_ssl_letsencrypt'] != 'y') $this->dataRecord['ssl_letsencrypt'] = 'n';
af56b4 1024             if($client['limit_directive_snippets'] != 'y') $this->dataRecord['directive_snippets_id'] = 0;
b1a6a5 1025
146783 1026             // only generate quota and traffic warnings if value has changed
MC 1027             if($this->id > 0) {
2af58c 1028                 $old_web_values = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->id);
1c3655 1029             } else {
f9c424 1030                 $old_web_values = array();
146783 1031             }
73813a 1032             
MC 1033             if($this->_vhostdomain_type == 'domain') {
1034                 //* Check the website quota of the client
1035                 if(isset($_POST["hd_quota"]) && $client["limit_web_quota"] >= 0 && $_POST["hd_quota"] != $old_web_values["hd_quota"]) {
2af58c 1036                     $tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ? AND type = 'vhost' AND ".$app->tform->getAuthSQL('u'), $this->id);
73813a 1037                     $webquota = $tmp["webquota"];
MC 1038                     $new_web_quota = $app->functions->intval($this->dataRecord["hd_quota"]);
1039                     if(($webquota + $new_web_quota > $client["limit_web_quota"]) || ($new_web_quota < 0 && $client["limit_web_quota"] >= 0)) {
1040                         $max_free_quota = floor($client["limit_web_quota"] - $webquota);
1041                         if($max_free_quota < 0) $max_free_quota = 0;
1042                         $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB<br>";
1043                         // Set the quota field to the max free space
1044                         $this->dataRecord["hd_quota"] = $max_free_quota;
1045                     }
1046                     unset($tmp);
1047                     unset($tmp_quota);
76ebcb 1048                 }
F 1049             }
1050
1051             //* Check the traffic quota of the client
146783 1052             if(isset($_POST["traffic_quota"]) && $client["limit_traffic_quota"] > 0 && $_POST["traffic_quota"] != $old_web_values["traffic_quota"]) {
2af58c 1053                 $tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ? AND ".$app->tform->getAuthSQL('u'), $this->id);
76ebcb 1054                 $trafficquota = $tmp["trafficquota"];
65ea2e 1055                 $new_traffic_quota = $app->functions->intval($this->dataRecord["traffic_quota"]);
76ebcb 1056                 if(($trafficquota + $new_traffic_quota > $client["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $client["limit_traffic_quota"] >= 0)) {
F 1057                     $max_free_quota = floor($client["limit_traffic_quota"] - $trafficquota);
1058                     if($max_free_quota < 0) $max_free_quota = 0;
1059                     $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB<br>";
1060                     // Set the quota field to the max free space
1061                     $this->dataRecord["traffic_quota"] = $max_free_quota;
1062                 }
1063                 unset($tmp);
1064                 unset($tmp_quota);
1065             }
b1a6a5 1066
76ebcb 1067             if($client['parent_client_id'] > 0) {
F 1068                 // Get the limits of the reseller
2af58c 1069                 $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 1070
73813a 1071                 if($this->_vhostdomain_type == 'domain') {
MC 1072                     //* Check the website quota of the client
1073                     if(isset($_POST["hd_quota"]) && $reseller["limit_web_quota"] >= 0 && $_POST["hd_quota"] != $old_web_values["hd_quota"]) {
2af58c 1074                         $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 ? IN (client.parent_client_id, client.client_id) AND domain_id != ? AND type = 'vhost'", $client['parent_client_id'], $this->id);
dcd2c0 1075
73813a 1076                         $webquota = $tmp["webquota"];
MC 1077                         $new_web_quota = $app->functions->intval($this->dataRecord["hd_quota"]);
1078                         if(($webquota + $new_web_quota > $reseller["limit_web_quota"]) || ($new_web_quota < 0 && $reseller["limit_web_quota"] >= 0)) {
1079                             $max_free_quota = floor($reseller["limit_web_quota"] - $webquota);
1080                             if($max_free_quota < 0) $max_free_quota = 0;
1081                             $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB<br>";
1082                             // Set the quota field to the max free space
1083                             $this->dataRecord["hd_quota"] = $max_free_quota;
1084                         }
1085                         unset($tmp);
1086                         unset($tmp_quota);
76ebcb 1087                     }
F 1088                 }
1089
1090                 //* Check the traffic quota of the client
146783 1091                 if(isset($_POST["traffic_quota"]) && $reseller["limit_traffic_quota"] > 0 && $_POST["traffic_quota"] != $old_web_values["traffic_quota"]) {
2af58c 1092                     $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 ? IN (client.parent_client_id, client.client_id) AND domain_id != ? AND type = 'vhost'", $client['parent_client_id'], $this->id);
76ebcb 1093                     $trafficquota = $tmp["trafficquota"];
65ea2e 1094                     $new_traffic_quota = $app->functions->intval($this->dataRecord["traffic_quota"]);
76ebcb 1095                     if(($trafficquota + $new_traffic_quota > $reseller["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $reseller["limit_traffic_quota"] >= 0)) {
F 1096                         $max_free_quota = floor($reseller["limit_traffic_quota"] - $trafficquota);
1097                         if($max_free_quota < 0) $max_free_quota = 0;
1098                         $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB<br>";
1099                         // Set the quota field to the max free space
1100                         $this->dataRecord["traffic_quota"] = $max_free_quota;
1101                     }
1102                     unset($tmp);
1103                     unset($tmp_quota);
1104                 }
1105             }
1106
1107             // When the record is updated
1108             if($this->id > 0) {
1109                 // restore the server ID if the user is not admin and record is edited
2af58c 1110                 $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 = ?", $this->id);
76ebcb 1111                 $this->dataRecord["server_id"] = $tmp["server_id"];
d22277 1112                 if($this->_vhostdomain_type != 'domain') $this->dataRecord['web_folder'] = $tmp['web_folder']; // cannot be changed!
797215 1113                 $this->dataRecord['system_user'] = $tmp['system_user'];
MC 1114                 $this->dataRecord['system_group'] = $tmp['system_group'];
b1a6a5 1115
MC 1116                 // set the settings to current if not provided (or cleared due to limits)
ebbe63 1117                 if($this->dataRecord['cgi'] == 'n') $this->dataRecord['cgi'] = $tmp['cgi'];
MC 1118                 if($this->dataRecord['ssi'] == 'n') $this->dataRecord['ssi'] = $tmp['ssi'];
1119                 if($this->dataRecord['perl'] == 'n') $this->dataRecord['perl'] = $tmp['perl'];
1120                 if($this->dataRecord['ruby'] == 'n') $this->dataRecord['ruby'] = $tmp['ruby'];
1121                 if($this->dataRecord['python'] == 'n') $this->dataRecord['python'] = $tmp['python'];
1122                 if($this->dataRecord['suexec'] == 'n') $this->dataRecord['suexec'] = $tmp['suexec'];
1123                 if($this->dataRecord['errordocs'] == 'n') $this->dataRecord['errordocs'] = $tmp['errordocs'];
1124                 if($this->dataRecord['subdomain'] == 'n') $this->dataRecord['subdomain'] = $tmp['subdomain'];
1125                 if($this->dataRecord['ssl'] == 'n') $this->dataRecord['ssl'] = $tmp['ssl'];
b1a6a5 1126
76ebcb 1127                 unset($tmp);
F 1128                 // When the record is inserted
1129             } else {
73813a 1130                 if($this->_vhostdomain_type == 'domain') {
MC 1131                     //* display an error if chosen server is not allowed for this client
1132                     if (!is_array($client['web_servers_ids']) || !in_array($this->dataRecord['server_id'], $client['web_servers_ids'])) {
1133                         $app->error($app->tform->wordbook['server_chosen_not_ok']);
1134                     }
bd6659 1135                 }
76ebcb 1136
F 1137                 // Check if the user may add another web_domain
73813a 1138                 if($this->_vhostdomain_type == 'domain' && $client["limit_web_domain"] >= 0) {
2af58c 1139                     $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = ? and type = 'vhost'", $client_group_id);
76ebcb 1140                     if($tmp["number"] >= $client["limit_web_domain"]) {
F 1141                         $app->error($app->tform->wordbook["limit_web_domain_txt"]);
1142                     }
73813a 1143                 } elseif($this->_vhostdomain_type == 'aliasdomain' && $client["limit_web_aliasdomain"] >= 0) {
2af58c 1144                     $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = ? and (type = 'alias' OR type = 'vhostalias')", $client_group_id);
73813a 1145                     if($tmp["number"] >= $client["limit_web_aliasdomain"]) {
MC 1146                         $app->error($app->tform->wordbook["limit_web_aliasdomain_txt"]);
1147                     }
1148                 } elseif($this->_vhostdomain_type == 'subdomain' && $client["limit_web_subdomain"] >= 0) {
2af58c 1149                     $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = ? and (type = 'subdomain' OR type = 'vhostsubdomain')", $client_group_id);
73813a 1150                     if($tmp["number"] >= $client["limit_web_subdomain"]) {
MC 1151                         $app->error($app->tform->wordbook["limit_web_subdomain_txt"]);
1152                     }
76ebcb 1153                 }
F 1154             }
1155
1156             // 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
1157             if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
1158         }
b1a6a5 1159
73813a 1160         //* make sure that the domain is lowercase
76ebcb 1161         if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
b1a6a5 1162
76ebcb 1163         //* get the server config for this server
F 1164         $app->uses("getconf");
615a0a 1165         if($this->id > 0){
T 1166             $web_rec = $app->tform->getDataRecord($this->id);
1167             $server_id = $web_rec["server_id"];
1168         } else {
1169             // Get the first server ID
1170             $tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
1171             $server_id = intval($tmp['server_id']);
1172         }
b1a6a5 1173         $web_config = $app->getconf->get_server_config($app->functions->intval(isset($this->dataRecord["server_id"]) ? $this->dataRecord["server_id"] : $server_id), 'web');
76ebcb 1174         //* Check for duplicate ssl certs per IP if SNI is disabled
F 1175         if(isset($this->dataRecord['ssl']) && $this->dataRecord['ssl'] == 'y' && $web_config['enable_sni'] != 'y') {
2af58c 1176             $sql = "SELECT count(domain_id) as number FROM web_domain WHERE `ssl` = 'y' AND ip_address = ? and domain_id != ?";
MC 1177             $tmp = $app->db->queryOneRecord($sql, $this->dataRecord['ip_address'], $this->id);
76ebcb 1178             if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("error_no_sni_txt");
F 1179         }
b1a6a5 1180
76ebcb 1181         // Check if pm.max_children >= pm.max_spare_servers >= pm.start_servers >= pm.min_spare_servers > 0
dd7ce4 1182         if(isset($this->dataRecord['pm_max_children']) && $this->dataRecord['pm'] == 'dynamic') {
65ea2e 1183             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 1184
76ebcb 1185             } else {
F 1186                 $app->tform->errorMessage .= $app->tform->lng("error_php_fpm_pm_settings_txt").'<br>';
1187             }
1188         }
b1a6a5 1189
615a0a 1190         // Check rewrite rules
T 1191         $server_type = $web_config['server_type'];
b1a6a5 1192
615a0a 1193         if($server_type == 'nginx' && isset($this->dataRecord['rewrite_rules']) && trim($this->dataRecord['rewrite_rules']) != '') {
T 1194             $rewrite_rules = trim($this->dataRecord['rewrite_rules']);
1195             $rewrites_are_valid = true;
1196             // use this counter to make sure all curly brackets are properly closed
1197             $if_level = 0;
1198             // Make sure we only have Unix linebreaks
1199             $rewrite_rules = str_replace("\r\n", "\n", $rewrite_rules);
1200             $rewrite_rules = str_replace("\r", "\n", $rewrite_rules);
1201             $rewrite_rule_lines = explode("\n", $rewrite_rules);
1202             if(is_array($rewrite_rule_lines) && !empty($rewrite_rule_lines)){
1203                 foreach($rewrite_rule_lines as $rewrite_rule_line){
7b47c0 1204                     // ignore comments
b1a6a5 1205                     if(substr(ltrim($rewrite_rule_line), 0, 1) == '#') continue;
7b47c0 1206                     // empty lines
T 1207                     if(trim($rewrite_rule_line) == '') continue;
615a0a 1208                     // rewrite
T 1209                     if(preg_match('@^\s*rewrite\s+(^/)?\S+(\$)?\s+\S+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
7c2179 1210                     if(preg_match('@^\s*rewrite\s+(^/)?(\'[^\']+\'|"[^"]+")+(\$)?\s+(\'[^\']+\'|"[^"]+")+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
MC 1211                     if(preg_match('@^\s*rewrite\s+(^/)?(\'[^\']+\'|"[^"]+")+(\$)?\s+\S+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
1212                     if(preg_match('@^\s*rewrite\s+(^/)?\S+(\$)?\s+(\'[^\']+\'|"[^"]+")+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
615a0a 1213                     // if
T 1214                     if(preg_match('@^\s*if\s+\(\s*\$\S+(\s+(\!?(=|~|~\*))\s+(\S+|\".+\"))?\s*\)\s*\{\s*$@', $rewrite_rule_line)){
1215                         $if_level += 1;
1216                         continue;
1217                     }
1218                     // if - check for files, directories, etc.
1219                     if(preg_match('@^\s*if\s+\(\s*\!?-(f|d|e|x)\s+\S+\s*\)\s*\{\s*$@', $rewrite_rule_line)){
1220                         $if_level += 1;
1221                         continue;
1222                     }
1223                     // break
1224                     if(preg_match('@^\s*break\s*;\s*$@', $rewrite_rule_line)){
1225                         continue;
1226                     }
1227                     // return code [ text ]
1228                     if(preg_match('@^\s*return\s+\d\d\d.*;\s*$@', $rewrite_rule_line)) continue;
1229                     // return code URL
1230                     // return URL
1231                     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;
1232                     // set
1233                     if(preg_match('@^\s*set\s+\$\S+\s+\S+\s*;\s*$@', $rewrite_rule_line)) continue;
1234                     // closing curly bracket
1235                     if(trim($rewrite_rule_line) == '}'){
1236                         $if_level -= 1;
1237                         continue;
1238                     }
1239                     $rewrites_are_valid = false;
1240                     break;
1241                 }
1242             }
b1a6a5 1243
615a0a 1244             if(!$rewrites_are_valid || $if_level != 0){
T 1245                 $app->tform->errorMessage .= $app->tform->lng("invalid_rewrite_rules_txt").'<br>';
1246             }
1247         }
3faab0 1248         
MC 1249         // check custom php.ini settings
1250         if(isset($this->dataRecord['custom_php_ini']) && trim($this->dataRecord['custom_php_ini']) != '') {
1251             $custom_php_ini_settings = trim($this->dataRecord['custom_php_ini']);
1252             $custom_php_ini_settings_are_valid = true;
1253             // Make sure we only have Unix linebreaks
1254             $custom_php_ini_settings = str_replace("\r\n", "\n", $custom_php_ini_settings);
1255             $custom_php_ini_settings = str_replace("\r", "\n", $custom_php_ini_settings);
1256             $custom_php_ini_settings_lines = explode("\n", $custom_php_ini_settings);
1257             if(is_array($custom_php_ini_settings_lines) && !empty($custom_php_ini_settings_lines)){
1258                 foreach($custom_php_ini_settings_lines as $custom_php_ini_settings_line){
1259                     if(trim($custom_php_ini_settings_line) == '') continue;
1260                     if(substr(trim($custom_php_ini_settings_line),0,1) == ';') continue;
1261                     // empty value
1262                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
1263                     // value inside ""
1264                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*".*"\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
1265                     // value inside ''
1266                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*\'.*\'\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
1267                     // everything else
1268                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*[-a-zA-Z0-9~&=_\@/,.#\s]*\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
1269                     $custom_php_ini_settings_are_valid = false;
1270                     break;
1271                 }
1272             }
1273             if(!$custom_php_ini_settings_are_valid){
1274                 $app->tform->errorMessage .= $app->tform->lng("invalid_custom_php_ini_settings_txt").'<br>';
1275             }
1276         }
76ebcb 1277
dcf94e 1278         if($web_config['enable_spdy'] === 'n') {
PA 1279             unset($app->tform->formDef["tabs"]['ssl']['fields']['enable_spdy']);
1280         }
86bc65 1281         if($this->dataRecord["directive_snippets_id"] < 1) $this->dataRecord["enable_pagespeed"] = 'n';
d22277 1282         
MB 1283         //print_r($_POST['folder_directive_snippets']);
1284         //print_r($_POST['folder_directive_snippets_id']);
1285         if(isset($_POST['folder_directive_snippets'])){
1286             $this->dataRecord['folder_directive_snippets'] = '';
1287             if(is_array($_POST['folder_directive_snippets']) && !empty($_POST['folder_directive_snippets'])){
1288                 $existing_directive_snippets_folders = array();
1289                 foreach($_POST['folder_directive_snippets'] as $folder_directive_snippet){
1290                     $folder_directive_snippet['folder'] = trim($folder_directive_snippet['folder']);
1291                     if($folder_directive_snippet['folder'] != '' && intval($folder_directive_snippet['snippets_id']) > 0){
1292                         if(substr($folder_directive_snippet['folder'], -1) != '/') $folder_directive_snippet['folder'] .= '/';
1293                         if(substr($folder_directive_snippet['folder'], 0, 1) == '/') $folder_directive_snippet['folder'] = substr($folder_directive_snippet['folder'], 1);
1294                         if(in_array($folder_directive_snippet['folder'], $existing_directive_snippets_folders)){
1295                             $app->tform->errorMessage .= $app->tform->lng("config_for_folder_exists_already_txt").'<br>';
1296                         } else {
1297                             $existing_directive_snippets_folders[] = $folder_directive_snippet['folder'];
1298                         }
1299                         $this->dataRecord['folder_directive_snippets'] .= $folder_directive_snippet['folder'].':'.intval($folder_directive_snippet['snippets_id'])."\n";
1300                     }
1301                     if(!preg_match('@^((?!(.*\.\.)|(.*\./)|(.*//))[^/][\w/_\.\-]{1,100})?$@', $folder_directive_snippet['folder'])) $app->tform->errorMessage .= $app->tform->lng("web_folder_error_regex").'<br>';
1302                 }
1303             }
1304             $this->dataRecord['folder_directive_snippets'] = trim($this->dataRecord['folder_directive_snippets']);
1305         }
1306         
b5f6a1 1307         // Check custom PHP version
TB 1308         if(isset($this->dataRecord['fastcgi_php_version']) && $this->dataRecord['fastcgi_php_version'] != '') {
1309             // Check php-fpm mode
1310             if($this->dataRecord['php'] == 'php-fpm'){
1311                 $tmp = $app->db->queryOneRecord("SELECT * FROM server_php WHERE CONCAT(name,':',php_fpm_init_script,':',php_fpm_ini_dir,':',php_fpm_pool_dir) = '".$app->db->quote($this->dataRecord['fastcgi_php_version'])."'");
1312                 if(is_array($tmp)) {
1313                     $this->dataRecord['fastcgi_php_version'] = $tmp['name'].':'.$tmp['php_fpm_init_script'].':'.$tmp['php_fpm_ini_dir'].':'.$tmp['php_fpm_pool_dir'];
1314                 } else {
1315                     $this->dataRecord['fastcgi_php_version'] = '';
1316                 }
1317                 unset($tmp);
1318             // Check fast-cgi mode
1319             } elseif($this->dataRecord['php'] == 'fast-cgi') {
1320                 $tmp = $app->db->queryOneRecord("SELECT * FROM server_php WHERE CONCAT(name,':',php_fastcgi_binary,':',php_fastcgi_ini_dir) = '".$app->db->quote($this->dataRecord['fastcgi_php_version'])."'");
1321                 if(is_array($tmp)) {
1322                     $this->dataRecord['fastcgi_php_version'] = $tmp['name'].':'.$tmp['php_fastcgi_binary'].':'.$tmp['php_fastcgi_ini_dir'];
1323                 } else {
1324                     $this->dataRecord['fastcgi_php_version'] = '';
1325                 }
1326                 unset($tmp);
1327             } else {
1328                 // Other PHP modes do not have custom versions, so we force the value to be empty
1329                 $this->dataRecord['fastcgi_php_version'] = '';
1330             }
1331         }
1332         
76ebcb 1333         parent::onSubmit();
F 1334     }
1335
1336     function onAfterInsert() {
1337         global $app, $conf;
1338
1339         // make sure that the record belongs to the clinet group and not the admin group when admin inserts it
1340         // also make sure that the user can not delete domain created by a admin
1341         if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
65ea2e 1342             $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
2af58c 1343             $app->db->query("UPDATE web_domain SET sys_groupid = ?, sys_perm_group = 'ru' WHERE domain_id = ?", $client_group_id, $this->id);
76ebcb 1344         }
F 1345         if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
65ea2e 1346             $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
2af58c 1347             $app->db->query("UPDATE web_domain SET sys_groupid = ?, sys_perm_group = 'riud' WHERE domain_id = ?", $client_group_id, $this->id);
76ebcb 1348         }
F 1349
1350         // Get configuration for the web system
1351         $app->uses("getconf");
1352         $web_rec = $app->tform->getDataRecord($this->id);
b1a6a5 1353         $web_config = $app->getconf->get_server_config($app->functions->intval($web_rec["server_id"]), 'web');
76ebcb 1354
73813a 1355         if($this->_vhostdomain_type == 'domain') {
MC 1356             $document_root = str_replace("[website_id]", $this->id, $web_config["website_path"]);
1357             $document_root = str_replace("[website_idhash_1]", $this->id_hash($page_form->id, 1), $document_root);
1358             $document_root = str_replace("[website_idhash_2]", $this->id_hash($page_form->id, 1), $document_root);
1359             $document_root = str_replace("[website_idhash_3]", $this->id_hash($page_form->id, 1), $document_root);
1360             $document_root = str_replace("[website_idhash_4]", $this->id_hash($page_form->id, 1), $document_root);
1361
1362             // get the ID of the client
1363             if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
1364                 $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
2af58c 1365                 $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ?", $client_group_id);
73813a 1366                 $client_id = $app->functions->intval($client["client_id"]);
MC 1367             } else {
1368                 //$client_id = $app->functions->intval($this->dataRecord["client_group_id"]);
2af58c 1369                 $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ?", $this->dataRecord["client_group_id"]);
73813a 1370                 $client_id = $app->functions->intval($client["client_id"]);
MC 1371             }
1372
1373             // Set the values for document_root, system_user and system_group
2af58c 1374             $system_user = 'web'.$this->id;
MC 1375             $system_group = 'client'.$client_id;
73813a 1376             $document_root = str_replace("[client_id]", $client_id, $document_root);
MC 1377             $document_root = str_replace("[client_idhash_1]", $this->id_hash($client_id, 1), $document_root);
1378             $document_root = str_replace("[client_idhash_2]", $this->id_hash($client_id, 2), $document_root);
1379             $document_root = str_replace("[client_idhash_3]", $this->id_hash($client_id, 3), $document_root);
1380             $document_root = str_replace("[client_idhash_4]", $this->id_hash($client_id, 4), $document_root);
2af58c 1381             $document_root = $document_root;
73813a 1382             $php_open_basedir = str_replace("[website_path]", $document_root, $web_config["php_open_basedir"]);
2af58c 1383             $php_open_basedir = str_replace("[website_domain]", $web_rec['domain'], $php_open_basedir);
MC 1384             $htaccess_allow_override = $web_config["htaccess_allow_override"];
1385             $added_by = $_SESSION['s']['user']['username'];
73813a 1386
c1e0c6 1387             $sql = "UPDATE web_domain SET system_user = ?, system_group = ?, document_root = ?, allow_override = ?, php_open_basedir = ?, added_date = CURDATE(), added_by = ?  WHERE domain_id = ?";
MB 1388             $app->db->query($sql, $system_user, $system_group, $document_root, $htaccess_allow_override, $php_open_basedir, $added_by, $this->id);
73813a 1389         } else  {
MC 1390             // Set the values for document_root, system_user and system_group
2af58c 1391             $system_user = $this->parent_domain_record['system_user'];
MC 1392             $system_group = $this->parent_domain_record['system_group'];
1393             $document_root = $this->parent_domain_record['document_root'];
73813a 1394             $php_open_basedir = str_replace("[website_path]/web", $document_root.'/'.$web_rec['web_folder'], $web_config["php_open_basedir"]);
MC 1395             $php_open_basedir = str_replace("[website_domain]/web", $web_rec['domain'].'/'.$web_rec['web_folder'], $php_open_basedir);
1396             $php_open_basedir = str_replace("[website_path]", $document_root, $php_open_basedir);
2af58c 1397             $php_open_basedir = str_replace("[website_domain]", $web_rec['domain'], $php_open_basedir);
MC 1398             $htaccess_allow_override = $this->parent_domain_record['allow_override'];
1399             $added_by = $_SESSION['s']['user']['username'];
1400             
c1e0c6 1401             $sql = "UPDATE web_domain SET sys_groupid = ?, system_user = ?, system_group = ?, document_root = ?, allow_override = ?, php_open_basedir = ?, added_date = CURDATE(), added_by = ?  WHERE domain_id = ?";
MB 1402             $app->db->query($sql, $this->parent_domain_record['sys_groupid'], $system_user, $system_group, $document_root, $htaccess_allow_override, $php_open_basedir, $added_by, $this->id);
76ebcb 1403         }
d22277 1404         if(isset($this->dataRecord['folder_directive_snippets'])) $app->db->query("UPDATE web_domain SET folder_directive_snippets = ? WHERE domain_id = ?", $this->dataRecord['folder_directive_snippets'], $this->id);
76ebcb 1405     }
F 1406
1407     function onBeforeUpdate () {
1408         global $app, $conf;
1409
73813a 1410         if($this->_vhostdomain_type == 'domain') {
MC 1411             //* Check if the server has been changed
1412             // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
1413             if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
1414                 if (isset($this->dataRecord["server_id"])) {
2af58c 1415                     $rec = $app->db->queryOneRecord("SELECT server_id from web_domain WHERE domain_id = ?", $this->id);
73813a 1416                     if($rec['server_id'] != $this->dataRecord["server_id"]) {
MC 1417                         //* Add a error message and switch back to old server
1418                         $app->tform->errorMessage .= $app->lng('The Server can not be changed.');
1419                         $this->dataRecord["server_id"] = $rec['server_id'];
1420                     }
1421                     unset($rec);
1422                 }
1423                 //* If the user is neither admin nor reseller
1424             } else {
1425                 //* We do not allow users to change a domain which has been created by the admin
2af58c 1426                 $rec = $app->db->queryOneRecord("SELECT sys_perm_group, domain, ip_address, ipv6_address from web_domain WHERE domain_id = ?", $this->id);
f7bdb7 1427                 if(isset($this->dataRecord["domain"]) && $rec['domain'] != $this->dataRecord["domain"] && !$app->tform->checkPerm($this->id, 'u')) {
76ebcb 1428                     //* Add a error message and switch back to old server
73813a 1429                     $app->tform->errorMessage .= $app->lng('The Domain can not be changed. Please ask your Administrator if you want to change the domain name.');
MC 1430                     $this->dataRecord["domain"] = $rec['domain'];
1431                 }
1432                 if(isset($this->dataRecord["ip_address"]) && $rec['ip_address'] != $this->dataRecord["ip_address"] && $rec['sys_perm_group'] != 'riud') {
1433                     $this->dataRecord["ip_address"] = $rec['ip_address'];
1434                 }
1435                 if(isset($this->dataRecord["ipv6_address"]) && $rec['ipv6_address'] != $this->dataRecord["ipv6_address"] && $rec['sys_perm_group'] != 'riud') {
1436                     $this->dataRecord["ipv6_address"] = $rec['ipv6_address'];
76ebcb 1437                 }
F 1438                 unset($rec);
1439             }
1440         }
1441
1442         //* Check that all fields for the SSL cert creation are filled
1443         if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'create') {
1444             if($this->dataRecord['ssl_country'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_country_empty').'<br />';
1445         }
b1a6a5 1446
76ebcb 1447         if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'save') {
F 1448             if(trim($this->dataRecord['ssl_cert']) == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_cert_empty').'<br />';
1449         }
1450
1451     }
d22277 1452     
MB 1453     function onAfterUpdate() {
1454         global $app, $conf;
1455
1456         if(isset($this->dataRecord['folder_directive_snippets'])) $app->db->query("UPDATE web_domain SET folder_directive_snippets = ? WHERE domain_id = ?", $this->dataRecord['folder_directive_snippets'], $this->id);
1457     }
76ebcb 1458 }
F 1459
1460 $page = new page_action;
1461 $page->onLoad();
1462
b1a6a5 1463 ?>