From 6250b7ea002fd99e40d0170d31e7e19e69f97ccd Mon Sep 17 00:00:00 2001
From: Dominik <info@profi-webdesign.net>
Date: Thu, 23 Jan 2014 13:53:43 -0500
Subject: [PATCH] Merge remote-tracking branch 'ispc3master/master'

---
 interface/web/sites/web_domain_edit.php |  167 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 137 insertions(+), 30 deletions(-)

diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index ccb356c..7673895 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -76,9 +76,11 @@
 			}
 
 			// Get the limits of the client
-			$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
-			$client = $app->db->queryOneRecord("SELECT client.default_webserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
-			$app->tpl->setVar("server_id_value", $client['default_webserver']);
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$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");
+			$web_servers = explode(',', $client['web_servers']);
+			$app->tpl->setVar("server_id_value", $web_servers[0]);
+			unset($web_servers);
 		}
 		$app->tform->formDef['tabs']['domain']['readonly'] = false;
 
@@ -96,21 +98,56 @@
 		if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
 
 			// Get the limits of the client
-			$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
-			$client = $app->db->queryOneRecord("SELECT client.limit_web_domain, 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");
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$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");
+
+			$client['web_servers_ids'] = explode(',', $client['web_servers']);
+
+			$only_one_server = count($client['web_servers_ids']) === 1;
+			$app->tpl->setVar('only_one_server', $only_one_server);
 
 			//* Get global web config
-			$web_config = $app->getconf->get_server_config($client['default_webserver'], 'web');
+			foreach ($client['web_servers_ids'] as $web_server_id) {
+				$web_config[$web_server_id] = $app->getconf->get_server_config($web_server_id, 'web');
+			}
 
-			// Set the webserver to the default server of the client
-			$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);
+			$sql = "SELECT server_id, server_name FROM server WHERE server_id IN (" . $client['web_servers'] . ");";
+			$web_servers = $app->db->queryAllRecords($sql);
 
+			$options_web_servers = "";
+
+			foreach ($web_servers as $web_server) {
+				$options_web_servers .= "<option value='$web_server[server_id]'>$web_server[server_name]</option>";
+			}
+
+			$app->tpl->setVar("server_id", $options_web_servers);
+			unset($options_web_servers);
+
+			if($this->id > 0) {
+				if(!isset($this->dataRecord["server_id"])){
+					$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id));
+					$this->dataRecord["server_id"] = $tmp["server_id"];
+					unset($tmp);
+				}
+				$server_id = intval(@$this->dataRecord["server_id"]);
+			} else {
+				$server_id = (isset($web_servers[0])) ? intval($web_servers[0]) : 0;
+			}
+			
+			if($app->functions->intval($this->dataRecord["server_id"]) > 0) {
+				// check if server is in client's servers or add it.
+				$chk_sid = explode(',', $client['web_servers']);
+				if(in_array($this->dataRecord["server_id"], $client['web_servers']) == false) {
+					if($client['web_servers'] != '') $client['web_servers'] .= ',';
+					$client['web_servers'] .= $app->functions->intval($this->dataRecord["server_id"]);
+				}
+			}
+			
 			//* 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 = ".$app->functions->intval($client['default_webserver'])." AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")";
+			$sql = "SELECT ip_address FROM server_ip WHERE server_id IN (" . $client['web_servers'] . ") AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")";
 			$ips = $app->db->queryAllRecords($sql);
 			$ip_select = ($web_config['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
+			//if(!in_array($this->dataRecord["ip_address"], $ips)) $ip_select .= "<option value='".$this->dataRecord["ip_address"]."' SELECTED>".$this->dataRecord["ip_address"]."</option>\r\n";
 			//$ip_select = "";
 			if(is_array($ips)) {
 				foreach( $ips as $ip) {
@@ -123,7 +160,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 = ".$app->functions->intval($client['default_webserver'])." AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")";
+			$sql = "SELECT ip_address FROM server_ip WHERE server_id IN (" . $client['web_servers'] . ") AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")";
 			$ips = $app->db->queryAllRecords($sql);
 			$ip_select = "<option value=''></option>";
 			//$ip_select = "";
@@ -174,12 +211,21 @@
 			$client = $app->db->queryOneRecord("SELECT client.client_id, client.limit_web_domain, 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");
 
 			//* Get global web config
-			$web_config = $app->getconf->get_server_config($client['default_webserver'], 'web');
+			foreach ($client['web_servers_ids'] as $web_server_id) {
+				$web_config[$web_server_id] = $app->getconf->get_server_config($web_server_id, 'web');
+			}
 
-			// Set the webserver to the default server of the client
-			$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ".$app->functions->intval($client['default_webserver']));
-			$app->tpl->setVar("server_id", "<option value='$client[default_webserver]'>$tmp[server_name]</option>");
-			unset($tmp);
+			$sql = "SELECT server_id, server_name FROM server WHERE server_id IN (" . $client['web_servers'] . ");";
+			$web_servers = $app->db->queryAllRecords($sql);
+
+			$options_web_servers = "";
+
+			foreach ($web_servers as $web_server) {
+				$options_web_servers .= "<option value='$web_server[server_id]'>$web_server[server_name]</option>";
+			}
+
+			$app->tpl->setVar("server_id", $options_web_servers);
+			unset($options_web_servers);
 
 			// Fill the client select field
 			$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$client['client_id']." ORDER BY sys_group.name";
@@ -198,10 +244,20 @@
 			}
 			$app->tpl->setVar("client_group_id", $client_select);
 
+			if($app->functions->intval($this->dataRecord["server_id"]) > 0) {
+				// check if server is in client's servers or add it.
+				$chk_sid = explode(',', $client['web_servers']);
+				if(in_array($this->dataRecord["server_id"], $client['web_servers']) == false) {
+					if($client['web_servers'] != '') $client['web_servers'] .= ',';
+					$client['web_servers'] .= $app->functions->intval($this->dataRecord["server_id"]);
+				}
+			}
+			
 			//* 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 = ".$app->functions->intval($client['default_webserver'])." AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")";
+			$sql = "SELECT ip_address FROM server_ip WHERE server_id IN (" . $client['web_servers'] . ") AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")";
 			$ips = $app->db->queryAllRecords($sql);
 			$ip_select = ($web_config['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
+			//if(!in_array($this->dataRecord["ip_address"], $ips)) $ip_select .= "<option value='".$this->dataRecord["ip_address"]."' SELECTED>".$this->dataRecord["ip_address"]."</option>\r\n";
 			//$ip_select = "";
 			if(is_array($ips)) {
 				foreach( $ips as $ip) {
@@ -214,7 +270,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 = ".$app->functions->intval($client['default_webserver'])." AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$app->functions->intval($_SESSION['s']['user']['client_id']).")";
+			$sql = "SELECT ip_address FROM server_ip WHERE server_id IN (" . $client['web_servers'] . ") AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")";
 			$ips = $app->db->queryAllRecords($sql);
 			$ip_select = "<option value=''></option>";
 			//$ip_select = "";
@@ -259,6 +315,53 @@
 			// add limits to template to be able to hide settings
 			foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]);
 
+			$sites_config = $app->getconf->get_global_config('sites');
+			if($sites_config['reseller_can_use_options']) {
+				// Directive Snippets
+				$php_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'php' AND active = 'y'");
+				$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;">'.htmlentities($php_directive_snippet['snippet']).'</pre></a> ';
+					}
+				}
+				if($php_directive_snippets_txt == '') $php_directive_snippets_txt = '------';
+				$app->tpl->setVar("php_directive_snippets_txt", $php_directive_snippets_txt);
+
+				if($server_type == 'apache'){
+					$apache_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'apache' AND active = 'y'");
+					$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;">'.htmlentities($apache_directive_snippet['snippet']).'</pre></a> ';
+						}
+					}
+					if($apache_directive_snippets_txt == '') $apache_directive_snippets_txt = '------';
+					$app->tpl->setVar("apache_directive_snippets_txt", $apache_directive_snippets_txt);
+				}
+
+				if($server_type == 'nginx'){
+					$nginx_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'nginx' AND active = 'y'");
+					$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;">'.htmlentities($nginx_directive_snippet['snippet']).'</pre></a> ';
+						}
+					}
+					if($nginx_directive_snippets_txt == '') $nginx_directive_snippets_txt = '------';
+					$app->tpl->setVar("nginx_directive_snippets_txt", $nginx_directive_snippets_txt);
+				}
+
+				$proxy_directive_snippets = $app->db->queryAllRecords("SELECT * FROM directive_snippets WHERE type = 'proxy' AND active = 'y'");
+				$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;">'.htmlentities($proxy_directive_snippet['snippet']).'</pre></a> ';
+					}
+				}
+				if($proxy_directive_snippets_txt == '') $proxy_directive_snippets_txt = '------';
+				$app->tpl->setVar("proxy_directive_snippets_txt", $proxy_directive_snippets_txt);
+			}
 
 			//* Admin: If the logged in user is admin
 		} else {
@@ -513,8 +616,10 @@
 
 		if($_SESSION["s"]["user"]["typ"] != 'admin') {
 			// Get the limits of the client
-			$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
-			$client = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, 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");
+			$client_group_id = $_SESSION["s"]["user"]["default_group"];
+			$client = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, 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");
+
+			$client['web_servers_ids'] = explode(',', $client['web_servers']);
 
 			if($client['limit_cgi'] != 'y') $this->dataRecord['cgi'] = '-';
 			if($client['limit_ssi'] != 'y') $this->dataRecord['ssi'] = '-';
@@ -529,8 +634,8 @@
 			// only generate quota and traffic warnings if value has changed
 			if($this->id > 0) {
 				$old_web_values = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id));
-			} else {
-				$old_web_values = $_POST;
+			}  else {
+				$old_web_values = array();
 			}
 
 			//* Check the website quota of the client
@@ -567,7 +672,7 @@
 
 			if($client['parent_client_id'] > 0) {
 				// Get the limits of the reseller
-				$reseller = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, limit_web_quota FROM client WHERE client_id = ".$app->functions->intval($client['parent_client_id']));
+				$reseller = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, web_servers, limit_web_quota FROM client WHERE client_id = ".$client['parent_client_id']);
 
 				//* Check the website quota of the client
 				if(isset($_POST["hd_quota"]) && $reseller["limit_web_quota"] >= 0 && $_POST["hd_quota"] != $old_web_values["hd_quota"]) {
@@ -622,8 +727,10 @@
 				unset($tmp);
 				// When the record is inserted
 			} else {
-				//* set the server ID to the default webserver of the client
-				$this->dataRecord["server_id"] = $client["default_webserver"];
+				//* display an error if chosen server is not allowed for this client
+				if (!is_array($client['web_servers_ids']) || !in_array($this->dataRecord['server_id'], $client['web_servers_ids'])) {
+					$app->error($app->tform->wordbook['server_chosen_not_ok']);
+				}
 
 				// Check if the user may add another web_domain
 				if($client["limit_web_domain"] >= 0) {
@@ -905,7 +1012,7 @@
 			$records = $app->db->queryAllRecords("SELECT domain_id, `domain`, `type`, `web_folder` FROM web_domain WHERE parent_domain_id = ".$this->id);
 			foreach($records as $rec) {
 				$update_columns = "sys_userid = '".$web_rec['sys_userid']."', sys_groupid = '".$web_rec['sys_groupid']."'";
-				if($rec['type'] == 'vhostsubdomain') {
+				if($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') {
 					$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);
@@ -930,7 +1037,7 @@
 
 		//* 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"])."'");
+			$records = $app->db->queryAllRecords("SELECT domain_id,domain FROM web_domain WHERE (type = 'subdomain' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND domain LIKE '%.".$app->db->quote($this->oldDataRecord["domain"])."'");
 			foreach($records as $rec) {
 				$subdomain = $app->db->quote(str_replace($this->oldDataRecord["domain"], $this->dataRecord["domain"], $rec['domain']));
 				$app->db->datalogUpdate('web_domain', "domain = '".$subdomain."'", 'domain_id', $rec['domain_id']);
@@ -990,9 +1097,9 @@
 			unset($backup_interval);
 		}
 
-		//* Change vhost subdomain ip/ipv6 if domain ip/ipv6 has changed
+		//* Change vhost subdomain and alias ip/ipv6 if domain ip/ipv6 has changed
 		if(isset($this->dataRecord['ip_address']) && ($this->dataRecord['ip_address'] != $this->oldDataRecord['ip_address'] || $this->dataRecord['ipv6_address'] != $this->oldDataRecord['ipv6_address'])) {
-			$records = $app->db->queryAllRecords("SELECT domain_id FROM web_domain WHERE type = 'vhostsubdomain' AND parent_domain_id = ".$this->id);
+			$records = $app->db->queryAllRecords("SELECT domain_id FROM web_domain WHERE (type = 'vhostsubdomain' OR type = 'vhostalias') AND parent_domain_id = ".$this->id);
 			foreach($records as $rec) {
 				$app->db->datalogUpdate('web_domain', "ip_address = '".$app->db->quote($web_rec['ip_address'])."', ipv6_address = '".$app->db->quote($web_rec['ipv6_address'])."'", 'domain_id', $rec['domain_id']);
 			}

--
Gitblit v1.9.1