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