From ebbc3f1a0744ec16f366ace7c4cd49c6a353b8a8 Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Tue, 14 Jun 2016 11:35:33 -0400
Subject: [PATCH] Fixed Issue #3948 reseller missing '*' option in ipv4 address.

---
 interface/web/sites/web_vhost_domain_edit.php |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/interface/web/sites/web_vhost_domain_edit.php b/interface/web/sites/web_vhost_domain_edit.php
index 7d6f17a..82a8fa6 100644
--- a/interface/web/sites/web_vhost_domain_edit.php
+++ b/interface/web/sites/web_vhost_domain_edit.php
@@ -50,6 +50,7 @@
 
 class page_action extends tform_actions {
 	var $_vhostdomain_type = 'domain';
+	var $_letsencrypt_on_insert = false;
 
 	//* Returna a "3/2/1" path hash from a numeric id '123'
 	function id_hash($id, $levels) {
@@ -218,8 +219,9 @@
 			//* 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 IN ? AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=?)";
 			$ips = $app->db->queryAllRecords($sql, explode(',', $client['web_servers']), $_SESSION['s']['user']['client_id']);
-			$ip_select = ($web_config[$server_id]['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
+			//$ip_select = ($web_config[$server_id]['enable_ip_wildcard'] == 'y')?"<option value='*'>*</option>":"";
 			//$ip_select = "";
+			$ip_select = "<option value=''></option>";
 			if(is_array($ips)) {
 				foreach( $ips as $ip) {
 					$selected = ($ip["ip_address"] == $this->dataRecord["ipv6_address"])?'SELECTED':'';
@@ -303,6 +305,17 @@
 
 			$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 = ?", $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 ($settings['use_domain_module'] != 'y') {
 				// Fill the client select field
@@ -757,6 +770,7 @@
 		 * Now we have to check, if we should use the domain-module to select the domain
 		 * or not
 		 */
+		$settings = $app->getconf->get_global_config('domains');
 		if ($settings['use_domain_module'] == 'y') {
 			/*
 			 * The domain-module is in use.
@@ -1332,6 +1346,23 @@
 		
 		parent::onSubmit();
 	}
+	
+	function onBeforeInsert() {
+		global $app, $conf;
+		
+		// Letsencrypt can not be activated before the website has been created
+		// So we deactivate it here and add a datalog update in onAfterInsert
+		if(isset($this->dataRecord['ssl_letsencrypt']) && $this->dataRecord['ssl_letsencrypt'] == 'y' && isset($this->dataRecord['ssl']) && $this->dataRecord['ssl'] == 'y') {
+			// Disable letsencrypt and ssl temporarily
+			$this->dataRecord['ssl_letsencrypt'] = 'n';
+			$this->dataRecord['ssl'] = 'n';
+			// Prevent that the datalog history gets written
+			$app->tform->formDef['db_history'] = 'no';
+			// Set variable that we check in onAfterInsert
+			$this->_letsencrypt_on_insert = true;
+		}
+	}
+	
 
 	function onAfterInsert() {
 		global $app, $conf;
@@ -1402,6 +1433,16 @@
 			$app->db->query($sql, $this->parent_domain_record['sys_groupid'], $system_user, $system_group, $document_root, $htaccess_allow_override, $php_open_basedir, $added_by, $this->id);
 		}
 		if(isset($this->dataRecord['folder_directive_snippets'])) $app->db->query("UPDATE web_domain SET folder_directive_snippets = ? WHERE domain_id = ?", $this->dataRecord['folder_directive_snippets'], $this->id);
+		
+		// Add a datalog insert without letsencrypt and then an update with letsencrypt enabled (see also onBeforeInsert)
+		if($this->_letsencrypt_on_insert == true) {
+			$new_data_record = $app->tform->getDataRecord($this->id);
+			$app->tform->datalogSave('INSERT', $this->id, array(), $new_data_record);
+			$new_data_record['ssl_letsencrypt'] = 'y';
+			$new_data_record['ssl'] = 'y';
+			$app->db->datalogUpdate('web_domain', $new_data_record, 'domain_id', $this->id);
+		}
+	
 	}
 
 	function onBeforeUpdate () {
@@ -1430,9 +1471,13 @@
 					$this->dataRecord["domain"] = $rec['domain'];
 				}
 				if(isset($this->dataRecord["ip_address"]) && $rec['ip_address'] != $this->dataRecord["ip_address"] && $rec['sys_perm_group'] != 'riud') {
+					//* Add a error message and switch back to old server
+					$app->tform->errorMessage .= $app->lng('The IP can not be changed. Please ask your Administrator if you want to change the IPv4-Address.');
 					$this->dataRecord["ip_address"] = $rec['ip_address'];
 				}
 				if(isset($this->dataRecord["ipv6_address"]) && $rec['ipv6_address'] != $this->dataRecord["ipv6_address"] && $rec['sys_perm_group'] != 'riud') {
+					//* Add a error message and switch back to old server
+					$app->tform->errorMessage .= $app->lng('The IP can not be changed. Please ask your Administrator if you want to change the IPv6-Address.');
 					$this->dataRecord["ipv6_address"] = $rec['ipv6_address'];
 				}
 				unset($rec);

--
Gitblit v1.9.1