From d76f27f46aeb78dd7678a29da800e863fa047dfc Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Tue, 19 Mar 2013 11:34:33 -0400 Subject: [PATCH] Fixed: FS#2776 - Add new Website make error when System->Server services-> Webserver - disabled and no slave server --- interface/web/sites/web_domain_edit.php | 89 +++++++++++++++++++++++++------------------- 1 files changed, 50 insertions(+), 39 deletions(-) diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php index 5cc7f5e..7de4846 100644 --- a/interface/web/sites/web_domain_edit.php +++ b/interface/web/sites/web_domain_edit.php @@ -45,7 +45,7 @@ $app->auth->check_module_permissions('sites'); // Loading classes -$app->uses('tpl,tform,tform_actions'); +$app->uses('tpl,tform,tform_actions,tools_sites'); $app->load('tform_actions'); class page_action extends tform_actions { @@ -103,7 +103,7 @@ $web_config = $app->getconf->get_server_config($client['default_webserver'], 'web'); // Set the webserver to the default server of the client - $tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_webserver]"); + $tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".intval($client['default_webserver'])); $app->tpl->setVar("server_id","<option value='$client[default_webserver]'>$tmp[server_name]</option>"); unset($tmp); @@ -123,7 +123,7 @@ unset($ips); //* Fill the IPv6 select field with the IP addresses that are allowed for this client - $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".$client['default_webserver']." AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"; + $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".intval($client['default_webserver'])." AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"; $ips = $app->db->queryAllRecords($sql); $ip_select = "<option value=''></option>"; //$ip_select = ""; @@ -142,10 +142,10 @@ if(!empty($web_config['server_type'])) $server_type = $web_config['server_type']; if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm'; if($this->dataRecord['php'] == 'php-fpm'){ - $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ".($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver'])." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ".($this->id > 0 ? $this->dataRecord['server_id'] : intval($client['default_webserver']))." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); } if($this->dataRecord['php'] == 'fast-cgi'){ - $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver'])." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".($this->id > 0 ? $this->dataRecord['server_id'] : intval($client['default_webserver']))." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); } $php_select = "<option value=''>Default</option>"; if(is_array($php_records) && !empty($php_records)) { @@ -177,7 +177,7 @@ $web_config = $app->getconf->get_server_config($client['default_webserver'], 'web'); // Set the webserver to the default server of the client - $tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_webserver]"); + $tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".intval($client['default_webserver'])); $app->tpl->setVar("server_id","<option value='$client[default_webserver]'>$tmp[server_name]</option>"); unset($tmp); @@ -196,7 +196,7 @@ $app->tpl->setVar("client_group_id",$client_select); //* Fill the IPv4 select field with the IP addresses that are allowed for this client - $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".$client['default_webserver']." AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"; + $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".intval($client['default_webserver'])." AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"; $ips = $app->db->queryAllRecords($sql); $ip_select = ($web_config['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":""; //$ip_select = ""; @@ -211,7 +211,7 @@ unset($ips); //* Fill the IPv6 select field with the IP addresses that are allowed for this client - $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".$client['default_webserver']." AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"; + $sql = "SELECT ip_address FROM server_ip WHERE server_id = ".intval($client['default_webserver'])." AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"; $ips = $app->db->queryAllRecords($sql); $ip_select = "<option value=''></option>"; //$ip_select = ""; @@ -230,10 +230,10 @@ if(!empty($web_config['server_type'])) $server_type = $web_config['server_type']; if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm'; if($this->dataRecord['php'] == 'php-fpm'){ - $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ".($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver'])." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ".($this->id > 0 ? $this->dataRecord['server_id'] : intval($client['default_webserver']))." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); } if($this->dataRecord['php'] == 'fast-cgi') { - $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver'])." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".($this->id > 0 ? $this->dataRecord['server_id'] : intval($client['default_webserver']))." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); } $php_select = "<option value=''>Default</option>"; if(is_array($php_records) && !empty($php_records)) { @@ -264,11 +264,11 @@ $this->dataRecord["server_id"] = $tmp["server_id"]; unset($tmp); } - $server_id = @$this->dataRecord["server_id"]; + $server_id = intval(@$this->dataRecord["server_id"]); } else { // Get the first server ID $tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1"); - $server_id = $tmp['server_id']; + $server_id = intval($tmp['server_id']); } //* get global web config @@ -350,7 +350,7 @@ $php_directive_snippets_txt = ''; if(is_array($php_directive_snippets) && !empty($php_directive_snippets)){ foreach($php_directive_snippets as $php_directive_snippet){ - $php_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$php_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.$php_directive_snippet['snippet'].'</pre></a> '; + $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> '; } } if($php_directive_snippets_txt == '') $php_directive_snippets_txt = '------'; @@ -361,7 +361,7 @@ $apache_directive_snippets_txt = ''; if(is_array($apache_directive_snippets) && !empty($apache_directive_snippets)){ foreach($apache_directive_snippets as $apache_directive_snippet){ - $apache_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$apache_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.$apache_directive_snippet['snippet'].'</pre></a> '; + $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> '; } } if($apache_directive_snippets_txt == '') $apache_directive_snippets_txt = '------'; @@ -373,7 +373,7 @@ $nginx_directive_snippets_txt = ''; if(is_array($nginx_directive_snippets) && !empty($nginx_directive_snippets)){ foreach($nginx_directive_snippets as $nginx_directive_snippet){ - $nginx_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$nginx_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.$nginx_directive_snippet['snippet'].'</pre></a> '; + $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> '; } } if($nginx_directive_snippets_txt == '') $nginx_directive_snippets_txt = '------'; @@ -384,7 +384,7 @@ $proxy_directive_snippets_txt = ''; if(is_array($proxy_directive_snippets) && !empty($proxy_directive_snippets)){ foreach($proxy_directive_snippets as $proxy_directive_snippet){ - $proxy_directive_snippets_txt .= '<a href="javascript:void(0);" class="addPlaceholderContent">['.$proxy_directive_snippet['name'].']<pre class="addPlaceholderContent" style="display:none;">'.$proxy_directive_snippet['snippet'].'</pre></a> '; + $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> '; } } if($proxy_directive_snippets_txt == '') $proxy_directive_snippets_txt = '------'; @@ -393,7 +393,7 @@ $ssl_domain_select = ''; $tmp = $app->db->queryOneRecord("SELECT domain FROM web_domain WHERE domain_id = ".$this->id); - $ssl_domains = array($tmp["domain"],'www.'.$tmp["domain"]); + $ssl_domains = array($tmp["domain"],'www.'.$tmp["domain"],'*.'.$tmp["domain"]); if(is_array($ssl_domains)) { foreach( $ssl_domains as $ssl_domain) { $selected = ($ssl_domain == $this->dataRecord['ssl_domain'])?'SELECTED':''; @@ -425,16 +425,7 @@ /* * The domain-module is in use. */ - $client_group_id = $_SESSION["s"]["user"]["default_group"]; - /* - * The admin can select ALL domains, the user only the domains assigned to him - */ - $sql = "SELECT domain_id, domain FROM domain "; - if ($_SESSION["s"]["user"]["typ"] != 'admin') { - $sql .= "WHERE sys_groupid =" . $client_group_id; - } - $sql .= " ORDER BY domain"; - $domains = $app->db->queryAllRecords($sql); + $domains = $app->tools_sites->getDomainModuleDomains(); $domain_select = ''; if(is_array($domains) && sizeof($domains) > 0) { /* We have domains in the list, so create the drop-down-list */ @@ -474,21 +465,20 @@ $app->uses('ini_parser,getconf'); $settings = $app->getconf->get_global_config('domains'); if ($settings['use_domain_module'] == 'y') { - $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); - - $sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . $app->functions->intval($this->dataRecord['domain']); - if ($_SESSION["s"]["user"]["typ"] != 'admin') { - $sql .= " AND sys_groupid =" . $client_group_id; - } - $domain_check = $app->db->queryOneRecord($sql); + $domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['domain']); if(!$domain_check) { // invalid domain selected $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />"; } else { - $this->dataRecord['domain'] = $domain_check['domain']; + $this->dataRecord['domain'] = $domain_check; } } } + + // nginx: if redirect type is proxy and redirect path is no URL, display error + //if($this->dataRecord["redirect_type"] == 'proxy' && substr($this->dataRecord['redirect_path'],0,1) == '/'){ + // $app->tform->errorMessage .= $app->tform->lng("error_proxy_requires_url")."<br />"; + //} // Set a few fixed values $this->dataRecord["parent_domain_id"] = 0; @@ -508,7 +498,7 @@ if($client['limit_perl'] != 'y') $this->dataRecord['perl'] = '-'; if($client['limit_ruby'] != 'y') $this->dataRecord['ruby'] = '-'; if($client['limit_python'] != 'y') $this->dataRecord['python'] = '-'; - if($client['force_suexec'] != 'n') $this->dataRecord['suexec'] = '-'; + if($client['force_suexec'] == 'y') $this->dataRecord['suexec'] = 'y'; if($client['limit_hterror'] != 'y') $this->dataRecord['errordocs'] = '-'; if($client['limit_wildcard'] != 'y' && $this->dataRecord['subdomain'] == '*') $this->dataRecord['subdomain'] = '-'; if($client['limit_ssl'] != 'y') $this->dataRecord['ssl'] = '-'; @@ -816,9 +806,18 @@ unset($rec); //* Update all subdomains and alias domains - $records = $app->db->queryAllRecords("SELECT domain_id FROM web_domain WHERE parent_domain_id = ".$this->id); + $records = $app->db->queryAllRecords("SELECT domain_id, `domain`, `type`, `web_folder` FROM web_domain WHERE parent_domain_id = ".$this->id); foreach($records as $rec) { - $app->db->datalogUpdate('web_domain', "sys_userid = '".$web_rec['sys_userid']."', sys_groupid = '".$web_rec['sys_groupid']."'", 'domain_id', $rec['domain_id']); + $update_columns = "sys_userid = '".$web_rec['sys_userid']."', sys_groupid = '".$web_rec['sys_groupid']."'"; + if($rec['type'] == 'vhostsubdomain') { + $php_open_basedir = str_replace("[website_path]/web",$document_root.'/'.$rec['web_folder'],$web_config["php_open_basedir"]); + $php_open_basedir = str_replace("[website_domain]/web",$rec['domain'].'/'.$rec['web_folder'],$php_open_basedir); + $php_open_basedir = str_replace("[website_path]",$document_root,$php_open_basedir); + $php_open_basedir = $app->db->quote(str_replace("[website_domain]",$rec['domain'],$php_open_basedir)); + + $update_columns .= ", document_root = '".$document_root."', `php_open_basedir` = '".$php_open_basedir."'"; + } + $app->db->datalogUpdate('web_domain', $update_columns, 'domain_id', $rec['domain_id']); } unset($records); unset($rec); @@ -833,7 +832,7 @@ } - //* If the domain name has been changed, we will have to change all subdomains + //* If the domain name has been changed, we will have to change all subdomains + APS instances if(!empty($this->dataRecord["domain"]) && !empty($this->oldDataRecord["domain"]) && $this->dataRecord["domain"] != $this->oldDataRecord["domain"]) { $records = $app->db->queryAllRecords("SELECT domain_id,domain FROM web_domain WHERE (type = 'subdomain' OR type = 'vhostsubdomain') AND domain LIKE '%.".$app->db->quote($this->oldDataRecord["domain"])."'"); foreach($records as $rec) { @@ -843,6 +842,18 @@ unset($records); unset($rec); unset($subdomain); + + // Update APS instances + $records = $app->db->queryAllRecords("SELECT id, instance_id FROM aps_instances_settings WHERE name = 'main_domain' AND value = '".$this->oldDataRecord["domain"]."'"); + if(is_array($records) && !empty($records)){ + foreach($records as $rec){ + $app->db->datalogUpdate('aps_instances_settings', "value = '".$this->dataRecord["domain"]."'", 'id', $rec['id']); + // Reinstall of package needed? + //$app->db->datalogUpdate('aps_instances', "instance_status = '1'", 'id', $rec['instance_id']); + } + } + unset($records); + unset($rec); } //* Set allow_override if empty -- Gitblit v1.9.1