Marius Burkard
2016-05-04 c3189ce6c7301c3ec17878fd3918f31d0d3cb18a
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          */
f93927 760         $settings = $app->getconf->get_global_config('domains');
76ebcb 761         if ($settings['use_domain_module'] == 'y') {
F 762             /*
763              * The domain-module is in use.
764             */
9ec304 765             $domains = $app->tools_sites->getDomainModuleDomains($this->_vhostdomain_type == 'subdomain' ? null : "web_domain", $this->dataRecord["domain"]);
76ebcb 766             $domain_select = '';
73813a 767             $selected_domain = '';
76ebcb 768             if(is_array($domains) && sizeof($domains) > 0) {
F 769                 /* We have domains in the list, so create the drop-down-list */
770                 foreach( $domains as $domain) {
4e18bd 771                     $domain_select .= "<option value=" . $domain['domain_id'] ;
73813a 772                     if ($this->_vhostdomain_type == 'subdomain' && '.' . $domain['domain'] == substr($this->dataRecord["domain"], -strlen($domain['domain']) - 1)) {
MC 773                         $domain_select .= " selected";
774                         $selected_domain = $domain['domain'];
775                     } elseif($this->_vhostdomain_type == 'aliasdomain' && $domain['domain'] == $this->dataRecord["domain"]) {
776                         $domain_select .= " selected";
777                     } elseif($this->_vhostdomain_type == 'domain' && $domain['domain'] == $this->dataRecord["domain"]) {
76ebcb 778                         $domain_select .= " selected";
F 779                     }
8c1761 780                     $domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n";
76ebcb 781                 }
F 782             }
783             else {
784                 /*
785                  * We have no domains in the domain-list. This means, we can not add ANY new domain.
786                  * To avoid, that the variable "domain_option" is empty and so the user can
787                  * free enter a domain, we have to create a empty option!
788                 */
789                 $domain_select .= "<option value=''></option>\r\n";
790             }
b1a6a5 791             $app->tpl->setVar("domain_option", $domain_select);
0998a3 792         } else {
MC 793
794             // remove the parent domain part of the domain name before we show it in the text field.
795             if($this->dataRecord["type"] == 'vhostsubdomain') $this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"], '', $this->dataRecord["domain"]);
7b47c0 796         }
73813a 797         if($this->_vhostdomain_type != 'domain') $app->tpl->setVar("domain", $this->dataRecord["domain"]);
b1a6a5 798
7b47c0 799         // check for configuration errors in sys_datalog
T 800         if($this->id > 0) {
2af58c 801             $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 802             if(is_array($datalog) && !empty($datalog)){
T 803                 if(trim($datalog['error']) != ''){
b1a6a5 804                     $app->tpl->setVar("config_error_msg", nl2br(htmlentities($datalog['error'])));
MC 805                     $app->tpl->setVar("config_error_tstamp", date($app->lng('conf_format_datetime'), $datalog['tstamp']));
7b47c0 806                 }
T 807             }
76ebcb 808         }
73813a 809         
MC 810         $app->tpl->setVar('vhostdomain_type', $this->_vhostdomain_type);
76ebcb 811
dcf94e 812         $app->tpl->setVar('is_spdy_enabled', ($web_config['enable_spdy'] === 'y'));
8173c6 813         $app->tpl->setVar("is_admin", $is_admin);
FT 814         
815         if($this->id > 0) {
816             $tmp_web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", intval($this->id));
817             $tmp_sys_group = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE groupid = ?", intval($tmp_web['sys_groupid']));
818             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']));
819             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);
820         }
dcf94e 821
d5f2d5 822         $sys_config = $app->getconf->get_global_config('misc');
MC 823         if($sys_config['use_combobox'] == 'y') {
824             $app->tpl->setVar('use_combobox', 'y');
825         }
d22277 826         
MB 827         $directive_snippets_id_select = '<option value="0"'.($this->dataRecord['directive_snippets_id'] == 0? ' selected="selected"' : '').'>-</option>';
828         $server_type = $app->getconf->get_server_config($server_id, 'web');
829         $server_type = $server_type['server_type'];
830         
831         $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);
832         if(is_array($m_directive_snippets) && !empty($m_directive_snippets)){
833             $directive_snippets_id_select .= '<optgroup label="'.$app->tform->wordbook["select_master_directive_snippet_txt"].'">';
834             foreach($m_directive_snippets as $m_directive_snippet){
835                 $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>';
836             }
837             $directive_snippets_id_select .= '</optgroup>';
838         }
839         
840         $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);
841         if(is_array($directive_snippets) && !empty($directive_snippets)){
842             $directive_snippets_id_select .= '<optgroup label="'.$app->tform->wordbook["select_directive_snippet_txt"].'">';
843             foreach($directive_snippets as $directive_snippet){
844                 $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>';
845             }
846             $directive_snippets_id_select .= '</optgroup>';
847         }
848         $app->tpl->setVar("directive_snippets_id", $directive_snippets_id_select);
849         
850         // folder_directive_snippets
851         if(isset($_POST['folder_directive_snippets']) && !isset($this->dataRecord['folder_directive_snippets'])){
852             $this->dataRecord['folder_directive_snippets'] = '';
853             if(is_array($_POST['folder_directive_snippets']) && !empty($_POST['folder_directive_snippets'])){
854                 foreach($_POST['folder_directive_snippets'] as $folder_directive_snippet){
855                     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";
856                 }
857             }
858             $this->dataRecord['folder_directive_snippets'] = trim($this->dataRecord['folder_directive_snippets']);
859         }
860         
861         $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);
862         $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);
863         
864         $folder_directive_snippets = array();
865         $this->dataRecord['folder_directive_snippets'] = str_replace("\r\n", "\n", $this->dataRecord['folder_directive_snippets']);
866         $this->dataRecord['folder_directive_snippets'] = str_replace("\r", "\n", $this->dataRecord['folder_directive_snippets']);
867         $folder_directive_snippets_lines = explode("\n", trim($this->dataRecord['folder_directive_snippets']));
868         for($i=0;$i<sizeof($folder_directive_snippets_lines)+50;$i++){
869             $folder_directive_snippets[$i]['folder_directive_snippets_index'] = $i;
870             $folder_directive_snippets[$i]['folder_directive_snippets_index_plus_1'] = $i + 1;
871             if($i > sizeof($folder_directive_snippets_lines)){
872                 $folder_directive_snippets[$i]['folder_directive_snippets_css'] = 'hidden';
873             } else {
874                 $folder_directive_snippets[$i]['folder_directive_snippets_css'] = '';
875             }
876             if(trim($folder_directive_snippets_lines[$i]) != ''){
877                 list($folder_directive_snippets[$i]['folder_directive_snippets_folder'], $selected_snippet) = explode(':', trim($folder_directive_snippets_lines[$i]));
878                 $folder_directive_snippets[$i]['folder_directive_snippets_id'] = '<option value="0">-</option>';
879                 if(is_array($master_directive_snippets) && !empty($master_directive_snippets)){
880                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<optgroup label="'.$app->tform->wordbook["select_master_directive_snippet_txt"].'">';
881                     foreach($master_directive_snippets as $master_directive_snippet){
882                         $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>';
883                     }
884                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '</optgroup>';
885                 }
886                 
887                 if(is_array($c_directive_snippets) && !empty($c_directive_snippets)){
888                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<optgroup label="'.$app->tform->wordbook["select_directive_snippet_txt"].'">';
889                     foreach($c_directive_snippets as $c_directive_snippet){
890                         $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>';
891                     }
892                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '</optgroup>';
893                 }
894             } else {
895                 $folder_directive_snippets[$i]['folder_directive_snippets_folder'] = '';
896                 $folder_directive_snippets[$i]['folder_directive_snippets_id'] = '<option value="0">-</option>';
897                 if(is_array($master_directive_snippets) && !empty($master_directive_snippets)){
898                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<optgroup label="'.$app->tform->wordbook["select_master_directive_snippet_txt"].'">';
899                     foreach($master_directive_snippets as $master_directive_snippet){
900                         $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<option value="'.$master_directive_snippet['directive_snippets_id'].'">'.$master_directive_snippet['name'].'</option>';
901                     }
902                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '</optgroup>';
903                 }
904                 
905                 if(is_array($c_directive_snippets) && !empty($c_directive_snippets)){
906                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<optgroup label="'.$app->tform->wordbook["select_directive_snippet_txt"].'">';
907                     foreach($c_directive_snippets as $c_directive_snippet){
908                         $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '<option value="'.$c_directive_snippet['directive_snippets_id'].'">'.$c_directive_snippet['name'].'</option>';
909                     }
910                     $folder_directive_snippets[$i]['folder_directive_snippets_id'] .= '</optgroup>';
911                 }
912             }
913         }
914         $app->tpl->setLoop('folder_directive_snippets', $folder_directive_snippets);
915
76ebcb 916         parent::onShowEnd();
F 917     }
b1a6a5 918
MC 919     function onShowEdit() {
920         global $app;
921         if($app->tform->checkPerm($this->id, 'riud')) $app->tform->formDef['tabs']['domain']['readonly'] = false;
922         parent::onShowEdit();
923     }
76ebcb 924
F 925     function onSubmit() {
926         global $app, $conf;
927
73813a 928         // Set a few fixed values
MC 929         $this->dataRecord["vhost_type"] = 'name';
930         if($this->_vhostdomain_type == 'domain') {
931             $this->dataRecord["parent_domain_id"] = 0;
932             $this->dataRecord["type"] = 'vhost';
933         } else {
934             // Get the record of the parent domain
935             if(!@$this->dataRecord["parent_domain_id"] && $this->id) {
2af58c 936                 $tmp = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_domain WHERE domain_id = ?", $this->id);
73813a 937                 if($tmp) $this->dataRecord["parent_domain_id"] = $tmp['parent_domain_id'];
MC 938                 unset($tmp);
939             }
940
2af58c 941             $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]);
73813a 942             if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
MC 943
944             if($this->_vhostdomain_type == 'subdomain') {
945                 $this->dataRecord["type"] = 'vhostsubdomain';
946             } else {
947                 $this->dataRecord["type"] = 'vhostalias';
948             }
949             $this->dataRecord["server_id"] = $parent_domain["server_id"];
950             $this->dataRecord["ip_address"] = $parent_domain["ip_address"];
951             $this->dataRecord["ipv6_address"] = $parent_domain["ipv6_address"];
952             $this->dataRecord["client_group_id"] = $parent_domain["client_group_id"];
953
954             $this->parent_domain_record = $parent_domain;
955         }
956
67b0cb 957         $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 958
b1a6a5 959         /* check if the domain module is used - and check if the selected domain can be used! */
f601d9 960         if($app->tform->getCurrentTab() == 'domain') {
ebbe63 961             if($this->_vhostdomain_type == 'subdomain') {
MC 962                 // Check that domain (the subdomain part) is not empty
963                 if(!preg_match('/^[a-zA-Z0-9].*/',$this->dataRecord['domain'])) {
964                     $app->tform->errorMessage .= $app->tform->lng("subdomain_error_empty")."<br />";
965                 }
966             }
967             
968             /* check if the domain module is used - and check if the selected domain can be used! */
b1a6a5 969             $app->uses('ini_parser,getconf');
MC 970             $settings = $app->getconf->get_global_config('domains');
971             if ($settings['use_domain_module'] == 'y') {
73813a 972                 if($this->_vhostdomain_type == 'subdomain') $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['sel_domain']);
MC 973                 else $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['domain']);
b1a6a5 974                 if(!$domain_check) {
MC 975                     // invalid domain selected
976                     $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />";
977                 } else {
3e94c8 978                     if ($this->_vhostdomain_type == 'domain' &&
SC 979                             ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid']))) {
980                         $this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['domain']);
981                     }
73813a 982                     if($this->_vhostdomain_type == 'subdomain') $this->dataRecord['domain'] = $this->dataRecord['domain'] . '.' . $domain_check;
MC 983                     else $this->dataRecord['domain'] = $domain_check;
b1a6a5 984                 }
73813a 985             } else {
MC 986                 if($this->_vhostdomain_type == 'subdomain') $this->dataRecord["domain"] = $this->dataRecord["domain"].'.'.$parent_domain["domain"];
987             }
988
989             if($this->_vhostdomain_type != 'domain') {
990                 $this->dataRecord['web_folder'] = strtolower($this->dataRecord['web_folder']);
991                 if(substr($this->dataRecord['web_folder'], 0, 1) === '/') $this->dataRecord['web_folder'] = substr($this->dataRecord['web_folder'], 1);
992                 if(substr($this->dataRecord['web_folder'], -1) === '/') $this->dataRecord['web_folder'] = substr($this->dataRecord['web_folder'], 0, -1);
993                 $forbidden_folders = array('', 'cgi-bin', 'log', 'private', 'ssl', 'tmp', 'webdav');
994                 $check_folder = strtolower($this->dataRecord['web_folder']);
995                 if(substr($check_folder, 0, 1) === '/') $check_folder = substr($check_folder, 1); // strip / at beginning to check against forbidden entries
996                 if(strpos($check_folder, '/') !== false) $check_folder = substr($check_folder, 0, strpos($check_folder, '/')); // get the first part of the path to check it
997                 if(in_array($check_folder, $forbidden_folders)) {
998                     $app->tform->errorMessage .= $app->tform->lng("web_folder_invalid_txt")."<br>";
999                 }
1000
1001                 // vhostaliasdomains do not have a quota of their own
1002                 $this->dataRecord["hd_quota"] = 0;
b1a6a5 1003             }
MC 1004         }
1005
ac099e 1006
M 1007
76ebcb 1008         if($_SESSION["s"]["user"]["typ"] != 'admin') {
F 1009             // Get the limits of the client
73813a 1010             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
cc7a82 1011             $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 1012
SJ 1013             $client['web_servers_ids'] = explode(',', $client['web_servers']);
b1a6a5 1014
ebbe63 1015             if($client['limit_cgi'] != 'y') $this->dataRecord['cgi'] = 'n';
MC 1016             if($client['limit_ssi'] != 'y') $this->dataRecord['ssi'] = 'n';
1017             if($client['limit_perl'] != 'y') $this->dataRecord['perl'] = 'n';
1018             if($client['limit_ruby'] != 'y') $this->dataRecord['ruby'] = 'n';
1019             if($client['limit_python'] != 'y') $this->dataRecord['python'] = 'n';
b1a6a5 1020             if($client['force_suexec'] == 'y') $this->dataRecord['suexec'] = 'y';
ebbe63 1021             if($client['limit_hterror'] != 'y') $this->dataRecord['errordocs'] = 'n';
MC 1022             if($client['limit_wildcard'] != 'y' && $this->dataRecord['subdomain'] == '*') $this->dataRecord['subdomain'] = 'n';
1023             if($client['limit_ssl'] != 'y') $this->dataRecord['ssl'] = 'n';
67b0cb 1024             if($client['limit_ssl_letsencrypt'] != 'y') $this->dataRecord['ssl_letsencrypt'] = 'n';
af56b4 1025             if($client['limit_directive_snippets'] != 'y') $this->dataRecord['directive_snippets_id'] = 0;
b1a6a5 1026
146783 1027             // only generate quota and traffic warnings if value has changed
MC 1028             if($this->id > 0) {
2af58c 1029                 $old_web_values = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->id);
1c3655 1030             } else {
f9c424 1031                 $old_web_values = array();
146783 1032             }
73813a 1033             
MC 1034             if($this->_vhostdomain_type == 'domain') {
1035                 //* Check the website quota of the client
1036                 if(isset($_POST["hd_quota"]) && $client["limit_web_quota"] >= 0 && $_POST["hd_quota"] != $old_web_values["hd_quota"]) {
2af58c 1037                     $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 1038                     $webquota = $tmp["webquota"];
MC 1039                     $new_web_quota = $app->functions->intval($this->dataRecord["hd_quota"]);
1040                     if(($webquota + $new_web_quota > $client["limit_web_quota"]) || ($new_web_quota < 0 && $client["limit_web_quota"] >= 0)) {
1041                         $max_free_quota = floor($client["limit_web_quota"] - $webquota);
1042                         if($max_free_quota < 0) $max_free_quota = 0;
1043                         $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB<br>";
1044                         // Set the quota field to the max free space
1045                         $this->dataRecord["hd_quota"] = $max_free_quota;
1046                     }
1047                     unset($tmp);
1048                     unset($tmp_quota);
76ebcb 1049                 }
F 1050             }
1051
1052             //* Check the traffic quota of the client
146783 1053             if(isset($_POST["traffic_quota"]) && $client["limit_traffic_quota"] > 0 && $_POST["traffic_quota"] != $old_web_values["traffic_quota"]) {
2af58c 1054                 $tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ? AND ".$app->tform->getAuthSQL('u'), $this->id);
76ebcb 1055                 $trafficquota = $tmp["trafficquota"];
65ea2e 1056                 $new_traffic_quota = $app->functions->intval($this->dataRecord["traffic_quota"]);
76ebcb 1057                 if(($trafficquota + $new_traffic_quota > $client["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $client["limit_traffic_quota"] >= 0)) {
F 1058                     $max_free_quota = floor($client["limit_traffic_quota"] - $trafficquota);
1059                     if($max_free_quota < 0) $max_free_quota = 0;
1060                     $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB<br>";
1061                     // Set the quota field to the max free space
1062                     $this->dataRecord["traffic_quota"] = $max_free_quota;
1063                 }
1064                 unset($tmp);
1065                 unset($tmp_quota);
1066             }
b1a6a5 1067
76ebcb 1068             if($client['parent_client_id'] > 0) {
F 1069                 // Get the limits of the reseller
2af58c 1070                 $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 1071
73813a 1072                 if($this->_vhostdomain_type == 'domain') {
MC 1073                     //* Check the website quota of the client
1074                     if(isset($_POST["hd_quota"]) && $reseller["limit_web_quota"] >= 0 && $_POST["hd_quota"] != $old_web_values["hd_quota"]) {
2af58c 1075                         $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 1076
73813a 1077                         $webquota = $tmp["webquota"];
MC 1078                         $new_web_quota = $app->functions->intval($this->dataRecord["hd_quota"]);
1079                         if(($webquota + $new_web_quota > $reseller["limit_web_quota"]) || ($new_web_quota < 0 && $reseller["limit_web_quota"] >= 0)) {
1080                             $max_free_quota = floor($reseller["limit_web_quota"] - $webquota);
1081                             if($max_free_quota < 0) $max_free_quota = 0;
1082                             $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB<br>";
1083                             // Set the quota field to the max free space
1084                             $this->dataRecord["hd_quota"] = $max_free_quota;
1085                         }
1086                         unset($tmp);
1087                         unset($tmp_quota);
76ebcb 1088                     }
F 1089                 }
1090
1091                 //* Check the traffic quota of the client
146783 1092                 if(isset($_POST["traffic_quota"]) && $reseller["limit_traffic_quota"] > 0 && $_POST["traffic_quota"] != $old_web_values["traffic_quota"]) {
2af58c 1093                     $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 1094                     $trafficquota = $tmp["trafficquota"];
65ea2e 1095                     $new_traffic_quota = $app->functions->intval($this->dataRecord["traffic_quota"]);
76ebcb 1096                     if(($trafficquota + $new_traffic_quota > $reseller["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $reseller["limit_traffic_quota"] >= 0)) {
F 1097                         $max_free_quota = floor($reseller["limit_traffic_quota"] - $trafficquota);
1098                         if($max_free_quota < 0) $max_free_quota = 0;
1099                         $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB<br>";
1100                         // Set the quota field to the max free space
1101                         $this->dataRecord["traffic_quota"] = $max_free_quota;
1102                     }
1103                     unset($tmp);
1104                     unset($tmp_quota);
1105                 }
1106             }
1107
1108             // When the record is updated
1109             if($this->id > 0) {
1110                 // restore the server ID if the user is not admin and record is edited
2af58c 1111                 $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 1112                 $this->dataRecord["server_id"] = $tmp["server_id"];
d22277 1113                 if($this->_vhostdomain_type != 'domain') $this->dataRecord['web_folder'] = $tmp['web_folder']; // cannot be changed!
797215 1114                 $this->dataRecord['system_user'] = $tmp['system_user'];
MC 1115                 $this->dataRecord['system_group'] = $tmp['system_group'];
b1a6a5 1116
MC 1117                 // set the settings to current if not provided (or cleared due to limits)
ebbe63 1118                 if($this->dataRecord['cgi'] == 'n') $this->dataRecord['cgi'] = $tmp['cgi'];
MC 1119                 if($this->dataRecord['ssi'] == 'n') $this->dataRecord['ssi'] = $tmp['ssi'];
1120                 if($this->dataRecord['perl'] == 'n') $this->dataRecord['perl'] = $tmp['perl'];
1121                 if($this->dataRecord['ruby'] == 'n') $this->dataRecord['ruby'] = $tmp['ruby'];
1122                 if($this->dataRecord['python'] == 'n') $this->dataRecord['python'] = $tmp['python'];
1123                 if($this->dataRecord['suexec'] == 'n') $this->dataRecord['suexec'] = $tmp['suexec'];
1124                 if($this->dataRecord['errordocs'] == 'n') $this->dataRecord['errordocs'] = $tmp['errordocs'];
1125                 if($this->dataRecord['subdomain'] == 'n') $this->dataRecord['subdomain'] = $tmp['subdomain'];
1126                 if($this->dataRecord['ssl'] == 'n') $this->dataRecord['ssl'] = $tmp['ssl'];
b1a6a5 1127
76ebcb 1128                 unset($tmp);
F 1129                 // When the record is inserted
1130             } else {
73813a 1131                 if($this->_vhostdomain_type == 'domain') {
MC 1132                     //* display an error if chosen server is not allowed for this client
1133                     if (!is_array($client['web_servers_ids']) || !in_array($this->dataRecord['server_id'], $client['web_servers_ids'])) {
1134                         $app->error($app->tform->wordbook['server_chosen_not_ok']);
1135                     }
bd6659 1136                 }
76ebcb 1137
F 1138                 // Check if the user may add another web_domain
73813a 1139                 if($this->_vhostdomain_type == 'domain' && $client["limit_web_domain"] >= 0) {
2af58c 1140                     $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = ? and type = 'vhost'", $client_group_id);
76ebcb 1141                     if($tmp["number"] >= $client["limit_web_domain"]) {
F 1142                         $app->error($app->tform->wordbook["limit_web_domain_txt"]);
1143                     }
73813a 1144                 } elseif($this->_vhostdomain_type == 'aliasdomain' && $client["limit_web_aliasdomain"] >= 0) {
2af58c 1145                     $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 1146                     if($tmp["number"] >= $client["limit_web_aliasdomain"]) {
MC 1147                         $app->error($app->tform->wordbook["limit_web_aliasdomain_txt"]);
1148                     }
1149                 } elseif($this->_vhostdomain_type == 'subdomain' && $client["limit_web_subdomain"] >= 0) {
2af58c 1150                     $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 1151                     if($tmp["number"] >= $client["limit_web_subdomain"]) {
MC 1152                         $app->error($app->tform->wordbook["limit_web_subdomain_txt"]);
1153                     }
76ebcb 1154                 }
F 1155             }
1156
1157             // 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
1158             if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
1159         }
b1a6a5 1160
73813a 1161         //* make sure that the domain is lowercase
76ebcb 1162         if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]);
b1a6a5 1163
76ebcb 1164         //* get the server config for this server
F 1165         $app->uses("getconf");
615a0a 1166         if($this->id > 0){
T 1167             $web_rec = $app->tform->getDataRecord($this->id);
1168             $server_id = $web_rec["server_id"];
1169         } else {
1170             // Get the first server ID
1171             $tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
1172             $server_id = intval($tmp['server_id']);
1173         }
b1a6a5 1174         $web_config = $app->getconf->get_server_config($app->functions->intval(isset($this->dataRecord["server_id"]) ? $this->dataRecord["server_id"] : $server_id), 'web');
76ebcb 1175         //* Check for duplicate ssl certs per IP if SNI is disabled
F 1176         if(isset($this->dataRecord['ssl']) && $this->dataRecord['ssl'] == 'y' && $web_config['enable_sni'] != 'y') {
2af58c 1177             $sql = "SELECT count(domain_id) as number FROM web_domain WHERE `ssl` = 'y' AND ip_address = ? and domain_id != ?";
MC 1178             $tmp = $app->db->queryOneRecord($sql, $this->dataRecord['ip_address'], $this->id);
76ebcb 1179             if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("error_no_sni_txt");
F 1180         }
b1a6a5 1181
76ebcb 1182         // Check if pm.max_children >= pm.max_spare_servers >= pm.start_servers >= pm.min_spare_servers > 0
dd7ce4 1183         if(isset($this->dataRecord['pm_max_children']) && $this->dataRecord['pm'] == 'dynamic') {
65ea2e 1184             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 1185
76ebcb 1186             } else {
F 1187                 $app->tform->errorMessage .= $app->tform->lng("error_php_fpm_pm_settings_txt").'<br>';
1188             }
1189         }
b1a6a5 1190
615a0a 1191         // Check rewrite rules
T 1192         $server_type = $web_config['server_type'];
b1a6a5 1193
615a0a 1194         if($server_type == 'nginx' && isset($this->dataRecord['rewrite_rules']) && trim($this->dataRecord['rewrite_rules']) != '') {
T 1195             $rewrite_rules = trim($this->dataRecord['rewrite_rules']);
1196             $rewrites_are_valid = true;
1197             // use this counter to make sure all curly brackets are properly closed
1198             $if_level = 0;
1199             // Make sure we only have Unix linebreaks
1200             $rewrite_rules = str_replace("\r\n", "\n", $rewrite_rules);
1201             $rewrite_rules = str_replace("\r", "\n", $rewrite_rules);
1202             $rewrite_rule_lines = explode("\n", $rewrite_rules);
1203             if(is_array($rewrite_rule_lines) && !empty($rewrite_rule_lines)){
1204                 foreach($rewrite_rule_lines as $rewrite_rule_line){
7b47c0 1205                     // ignore comments
b1a6a5 1206                     if(substr(ltrim($rewrite_rule_line), 0, 1) == '#') continue;
7b47c0 1207                     // empty lines
T 1208                     if(trim($rewrite_rule_line) == '') continue;
615a0a 1209                     // rewrite
T 1210                     if(preg_match('@^\s*rewrite\s+(^/)?\S+(\$)?\s+\S+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
7c2179 1211                     if(preg_match('@^\s*rewrite\s+(^/)?(\'[^\']+\'|"[^"]+")+(\$)?\s+(\'[^\']+\'|"[^"]+")+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
MC 1212                     if(preg_match('@^\s*rewrite\s+(^/)?(\'[^\']+\'|"[^"]+")+(\$)?\s+\S+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
1213                     if(preg_match('@^\s*rewrite\s+(^/)?\S+(\$)?\s+(\'[^\']+\'|"[^"]+")+(\s+(last|break|redirect|permanent|))?\s*;\s*$@', $rewrite_rule_line)) continue;
615a0a 1214                     // if
T 1215                     if(preg_match('@^\s*if\s+\(\s*\$\S+(\s+(\!?(=|~|~\*))\s+(\S+|\".+\"))?\s*\)\s*\{\s*$@', $rewrite_rule_line)){
1216                         $if_level += 1;
1217                         continue;
1218                     }
1219                     // if - check for files, directories, etc.
1220                     if(preg_match('@^\s*if\s+\(\s*\!?-(f|d|e|x)\s+\S+\s*\)\s*\{\s*$@', $rewrite_rule_line)){
1221                         $if_level += 1;
1222                         continue;
1223                     }
1224                     // break
1225                     if(preg_match('@^\s*break\s*;\s*$@', $rewrite_rule_line)){
1226                         continue;
1227                     }
1228                     // return code [ text ]
1229                     if(preg_match('@^\s*return\s+\d\d\d.*;\s*$@', $rewrite_rule_line)) continue;
1230                     // return code URL
1231                     // return URL
1232                     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;
1233                     // set
1234                     if(preg_match('@^\s*set\s+\$\S+\s+\S+\s*;\s*$@', $rewrite_rule_line)) continue;
1235                     // closing curly bracket
1236                     if(trim($rewrite_rule_line) == '}'){
1237                         $if_level -= 1;
1238                         continue;
1239                     }
1240                     $rewrites_are_valid = false;
1241                     break;
1242                 }
1243             }
b1a6a5 1244
615a0a 1245             if(!$rewrites_are_valid || $if_level != 0){
T 1246                 $app->tform->errorMessage .= $app->tform->lng("invalid_rewrite_rules_txt").'<br>';
1247             }
1248         }
3faab0 1249         
MC 1250         // check custom php.ini settings
1251         if(isset($this->dataRecord['custom_php_ini']) && trim($this->dataRecord['custom_php_ini']) != '') {
1252             $custom_php_ini_settings = trim($this->dataRecord['custom_php_ini']);
1253             $custom_php_ini_settings_are_valid = true;
1254             // Make sure we only have Unix linebreaks
1255             $custom_php_ini_settings = str_replace("\r\n", "\n", $custom_php_ini_settings);
1256             $custom_php_ini_settings = str_replace("\r", "\n", $custom_php_ini_settings);
1257             $custom_php_ini_settings_lines = explode("\n", $custom_php_ini_settings);
1258             if(is_array($custom_php_ini_settings_lines) && !empty($custom_php_ini_settings_lines)){
1259                 foreach($custom_php_ini_settings_lines as $custom_php_ini_settings_line){
1260                     if(trim($custom_php_ini_settings_line) == '') continue;
1261                     if(substr(trim($custom_php_ini_settings_line),0,1) == ';') continue;
1262                     // empty value
1263                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
1264                     // value inside ""
1265                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*".*"\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
1266                     // value inside ''
1267                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*\'.*\'\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
1268                     // everything else
1269                     if(preg_match('@^\s*;*\s*[a-zA-Z0-9._]*\s*=\s*[-a-zA-Z0-9~&=_\@/,.#\s]*\s*;*\s*$@', $custom_php_ini_settings_line)) continue;
1270                     $custom_php_ini_settings_are_valid = false;
1271                     break;
1272                 }
1273             }
1274             if(!$custom_php_ini_settings_are_valid){
1275                 $app->tform->errorMessage .= $app->tform->lng("invalid_custom_php_ini_settings_txt").'<br>';
1276             }
1277         }
76ebcb 1278
dcf94e 1279         if($web_config['enable_spdy'] === 'n') {
PA 1280             unset($app->tform->formDef["tabs"]['ssl']['fields']['enable_spdy']);
1281         }
86bc65 1282         if($this->dataRecord["directive_snippets_id"] < 1) $this->dataRecord["enable_pagespeed"] = 'n';
d22277 1283         
MB 1284         //print_r($_POST['folder_directive_snippets']);
1285         //print_r($_POST['folder_directive_snippets_id']);
1286         if(isset($_POST['folder_directive_snippets'])){
1287             $this->dataRecord['folder_directive_snippets'] = '';
1288             if(is_array($_POST['folder_directive_snippets']) && !empty($_POST['folder_directive_snippets'])){
1289                 $existing_directive_snippets_folders = array();
1290                 foreach($_POST['folder_directive_snippets'] as $folder_directive_snippet){
1291                     $folder_directive_snippet['folder'] = trim($folder_directive_snippet['folder']);
1292                     if($folder_directive_snippet['folder'] != '' && intval($folder_directive_snippet['snippets_id']) > 0){
1293                         if(substr($folder_directive_snippet['folder'], -1) != '/') $folder_directive_snippet['folder'] .= '/';
1294                         if(substr($folder_directive_snippet['folder'], 0, 1) == '/') $folder_directive_snippet['folder'] = substr($folder_directive_snippet['folder'], 1);
1295                         if(in_array($folder_directive_snippet['folder'], $existing_directive_snippets_folders)){
1296                             $app->tform->errorMessage .= $app->tform->lng("config_for_folder_exists_already_txt").'<br>';
1297                         } else {
1298                             $existing_directive_snippets_folders[] = $folder_directive_snippet['folder'];
1299                         }
1300                         $this->dataRecord['folder_directive_snippets'] .= $folder_directive_snippet['folder'].':'.intval($folder_directive_snippet['snippets_id'])."\n";
1301                     }
1302                     if(!preg_match('@^((?!(.*\.\.)|(.*\./)|(.*//))[^/][\w/_\.\-]{1,100})?$@', $folder_directive_snippet['folder'])) $app->tform->errorMessage .= $app->tform->lng("web_folder_error_regex").'<br>';
1303                 }
1304             }
1305             $this->dataRecord['folder_directive_snippets'] = trim($this->dataRecord['folder_directive_snippets']);
1306         }
1307         
b5f6a1 1308         // Check custom PHP version
TB 1309         if(isset($this->dataRecord['fastcgi_php_version']) && $this->dataRecord['fastcgi_php_version'] != '') {
1310             // Check php-fpm mode
1311             if($this->dataRecord['php'] == 'php-fpm'){
1312                 $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'])."'");
1313                 if(is_array($tmp)) {
1314                     $this->dataRecord['fastcgi_php_version'] = $tmp['name'].':'.$tmp['php_fpm_init_script'].':'.$tmp['php_fpm_ini_dir'].':'.$tmp['php_fpm_pool_dir'];
1315                 } else {
1316                     $this->dataRecord['fastcgi_php_version'] = '';
1317                 }
1318                 unset($tmp);
1319             // Check fast-cgi mode
1320             } elseif($this->dataRecord['php'] == 'fast-cgi') {
1321                 $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'])."'");
1322                 if(is_array($tmp)) {
1323                     $this->dataRecord['fastcgi_php_version'] = $tmp['name'].':'.$tmp['php_fastcgi_binary'].':'.$tmp['php_fastcgi_ini_dir'];
1324                 } else {
1325                     $this->dataRecord['fastcgi_php_version'] = '';
1326                 }
1327                 unset($tmp);
1328             } else {
1329                 // Other PHP modes do not have custom versions, so we force the value to be empty
1330                 $this->dataRecord['fastcgi_php_version'] = '';
1331             }
1332         }
1333         
76ebcb 1334         parent::onSubmit();
F 1335     }
1336
1337     function onAfterInsert() {
1338         global $app, $conf;
1339
1340         // make sure that the record belongs to the clinet group and not the admin group when admin inserts it
1341         // also make sure that the user can not delete domain created by a admin
1342         if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
65ea2e 1343             $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
2af58c 1344             $app->db->query("UPDATE web_domain SET sys_groupid = ?, sys_perm_group = 'ru' WHERE domain_id = ?", $client_group_id, $this->id);
76ebcb 1345         }
F 1346         if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
65ea2e 1347             $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
2af58c 1348             $app->db->query("UPDATE web_domain SET sys_groupid = ?, sys_perm_group = 'riud' WHERE domain_id = ?", $client_group_id, $this->id);
76ebcb 1349         }
F 1350
1351         // Get configuration for the web system
1352         $app->uses("getconf");
1353         $web_rec = $app->tform->getDataRecord($this->id);
b1a6a5 1354         $web_config = $app->getconf->get_server_config($app->functions->intval($web_rec["server_id"]), 'web');
76ebcb 1355
73813a 1356         if($this->_vhostdomain_type == 'domain') {
MC 1357             $document_root = str_replace("[website_id]", $this->id, $web_config["website_path"]);
1358             $document_root = str_replace("[website_idhash_1]", $this->id_hash($page_form->id, 1), $document_root);
1359             $document_root = str_replace("[website_idhash_2]", $this->id_hash($page_form->id, 1), $document_root);
1360             $document_root = str_replace("[website_idhash_3]", $this->id_hash($page_form->id, 1), $document_root);
1361             $document_root = str_replace("[website_idhash_4]", $this->id_hash($page_form->id, 1), $document_root);
1362
1363             // get the ID of the client
1364             if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
1365                 $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
2af58c 1366                 $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ?", $client_group_id);
73813a 1367                 $client_id = $app->functions->intval($client["client_id"]);
MC 1368             } else {
1369                 //$client_id = $app->functions->intval($this->dataRecord["client_group_id"]);
2af58c 1370                 $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ?", $this->dataRecord["client_group_id"]);
73813a 1371                 $client_id = $app->functions->intval($client["client_id"]);
MC 1372             }
1373
1374             // Set the values for document_root, system_user and system_group
2af58c 1375             $system_user = 'web'.$this->id;
MC 1376             $system_group = 'client'.$client_id;
73813a 1377             $document_root = str_replace("[client_id]", $client_id, $document_root);
MC 1378             $document_root = str_replace("[client_idhash_1]", $this->id_hash($client_id, 1), $document_root);
1379             $document_root = str_replace("[client_idhash_2]", $this->id_hash($client_id, 2), $document_root);
1380             $document_root = str_replace("[client_idhash_3]", $this->id_hash($client_id, 3), $document_root);
1381             $document_root = str_replace("[client_idhash_4]", $this->id_hash($client_id, 4), $document_root);
2af58c 1382             $document_root = $document_root;
73813a 1383             $php_open_basedir = str_replace("[website_path]", $document_root, $web_config["php_open_basedir"]);
2af58c 1384             $php_open_basedir = str_replace("[website_domain]", $web_rec['domain'], $php_open_basedir);
MC 1385             $htaccess_allow_override = $web_config["htaccess_allow_override"];
1386             $added_by = $_SESSION['s']['user']['username'];
73813a 1387
c1e0c6 1388             $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 1389             $app->db->query($sql, $system_user, $system_group, $document_root, $htaccess_allow_override, $php_open_basedir, $added_by, $this->id);
73813a 1390         } else  {
MC 1391             // Set the values for document_root, system_user and system_group
2af58c 1392             $system_user = $this->parent_domain_record['system_user'];
MC 1393             $system_group = $this->parent_domain_record['system_group'];
1394             $document_root = $this->parent_domain_record['document_root'];
73813a 1395             $php_open_basedir = str_replace("[website_path]/web", $document_root.'/'.$web_rec['web_folder'], $web_config["php_open_basedir"]);
MC 1396             $php_open_basedir = str_replace("[website_domain]/web", $web_rec['domain'].'/'.$web_rec['web_folder'], $php_open_basedir);
1397             $php_open_basedir = str_replace("[website_path]", $document_root, $php_open_basedir);
2af58c 1398             $php_open_basedir = str_replace("[website_domain]", $web_rec['domain'], $php_open_basedir);
MC 1399             $htaccess_allow_override = $this->parent_domain_record['allow_override'];
1400             $added_by = $_SESSION['s']['user']['username'];
1401             
c1e0c6 1402             $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 1403             $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 1404         }
d22277 1405         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 1406     }
F 1407
1408     function onBeforeUpdate () {
1409         global $app, $conf;
1410
73813a 1411         if($this->_vhostdomain_type == 'domain') {
MC 1412             //* Check if the server has been changed
1413             // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
1414             if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
1415                 if (isset($this->dataRecord["server_id"])) {
2af58c 1416                     $rec = $app->db->queryOneRecord("SELECT server_id from web_domain WHERE domain_id = ?", $this->id);
73813a 1417                     if($rec['server_id'] != $this->dataRecord["server_id"]) {
MC 1418                         //* Add a error message and switch back to old server
1419                         $app->tform->errorMessage .= $app->lng('The Server can not be changed.');
1420                         $this->dataRecord["server_id"] = $rec['server_id'];
1421                     }
1422                     unset($rec);
1423                 }
1424                 //* If the user is neither admin nor reseller
1425             } else {
1426                 //* We do not allow users to change a domain which has been created by the admin
2af58c 1427                 $rec = $app->db->queryOneRecord("SELECT sys_perm_group, domain, ip_address, ipv6_address from web_domain WHERE domain_id = ?", $this->id);
f7bdb7 1428                 if(isset($this->dataRecord["domain"]) && $rec['domain'] != $this->dataRecord["domain"] && !$app->tform->checkPerm($this->id, 'u')) {
76ebcb 1429                     //* Add a error message and switch back to old server
73813a 1430                     $app->tform->errorMessage .= $app->lng('The Domain can not be changed. Please ask your Administrator if you want to change the domain name.');
MC 1431                     $this->dataRecord["domain"] = $rec['domain'];
1432                 }
1433                 if(isset($this->dataRecord["ip_address"]) && $rec['ip_address'] != $this->dataRecord["ip_address"] && $rec['sys_perm_group'] != 'riud') {
1434                     $this->dataRecord["ip_address"] = $rec['ip_address'];
1435                 }
1436                 if(isset($this->dataRecord["ipv6_address"]) && $rec['ipv6_address'] != $this->dataRecord["ipv6_address"] && $rec['sys_perm_group'] != 'riud') {
1437                     $this->dataRecord["ipv6_address"] = $rec['ipv6_address'];
76ebcb 1438                 }
F 1439                 unset($rec);
1440             }
1441         }
1442
1443         //* Check that all fields for the SSL cert creation are filled
1444         if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'create') {
1445             if($this->dataRecord['ssl_country'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_country_empty').'<br />';
1446         }
b1a6a5 1447
76ebcb 1448         if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'save') {
F 1449             if(trim($this->dataRecord['ssl_cert']) == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_cert_empty').'<br />';
1450         }
1451
1452     }
d22277 1453     
MB 1454     function onAfterUpdate() {
1455         global $app, $conf;
1456
1457         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);
1458     }
76ebcb 1459 }
F 1460
1461 $page = new page_action;
1462 $page->onLoad();
1463
b1a6a5 1464 ?>