From a29401db0d1ceb9cbd19f0fd19f670df5a64eb4a Mon Sep 17 00:00:00 2001
From: Thom Pol <thom@thompol.nl>
Date: Thu, 4 Feb 2021 11:50:25 +0100
Subject: [PATCH] Add new function for custom config usage for Postfix and
 Dovecot (#5988)

---
 install/lib/installer_base.lib.php       | 6 ++++++
 install/tpl/debian6_dovecot2.conf.master | 4 +++-
 install/tpl/debian_dovecot2.conf.master  | 4 +++-
 install/tpl/fedora_dovecot2.conf.master  | 4 +++-
 install/tpl/postfix_custom.conf.master   | 3 +++
 5 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 install/tpl/postfix_custom.conf.master

diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index 696a7042bd..6188b39708 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -1182,6 +1182,12 @@ class installer_base {
 		    $content = strtr($content, $postconf_placeholders);
 		    $postconf_commands = array_merge($postconf_commands, array_filter(explode("\n", $content)));
 		}
+		if(file_exists($conf['ispconfig_install_dir'].'/server/conf-custom/install/postfix_custom.conf.master')) {
+			$configfile = 'postfix_custom.conf';
+			$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/'.$configfile.'.master');
+			$content = strtr($content, $postconf_placeholders);
+			$postconf_commands = array_merge($postconf_commands, array_filter(explode("\n", $content)));
+		}
 
 		// Remove comment lines, these would give fatal errors when passed to postconf.
 		$postconf_commands = array_filter($postconf_commands, function($line) { return preg_match('/^[^#]/', $line); });
diff --git a/install/tpl/debian6_dovecot2.conf.master b/install/tpl/debian6_dovecot2.conf.master
index 5032488a6f..55e02fef30 100644
--- a/install/tpl/debian6_dovecot2.conf.master
+++ b/install/tpl/debian6_dovecot2.conf.master
@@ -1,3 +1,4 @@
+# Do not change this file, as changes will be overwritten by any ISPConfig update. Put your custom settings in /etc/dovecot/conf.d/99-custom-config.conf
 listen = *,[::]
 protocols = imap pop3
 auth_mechanisms = plain login
@@ -88,7 +89,7 @@ protocol lmtp {
 #2.3+         group = vmail
 #2.3+         mode = 0660
 #2.3+     }
-#2.3+ 
+#2.3+
 #2.3+     unix_listener stats-writer {
 #2.3+         user = vmail
 #2.3+         group = vmail
@@ -131,3 +132,4 @@ namespace inbox {
     special_use = \Trash
   }
 }
+!include_try conf.d/99-custom-config.conf
diff --git a/install/tpl/debian_dovecot2.conf.master b/install/tpl/debian_dovecot2.conf.master
index 4a44bfbfc6..62bed414fe 100644
--- a/install/tpl/debian_dovecot2.conf.master
+++ b/install/tpl/debian_dovecot2.conf.master
@@ -1,3 +1,4 @@
+# Do not change this file, as changes will be overwritten by any ISPConfig update. Put your custom settings in /etc/dovecot/conf.d/99-custom-config.conf
 listen = *,[::]
 protocols = imap pop3
 auth_mechanisms = plain login
@@ -86,7 +87,7 @@ protocol lmtp {
 #2.3+         group = vmail
 #2.3+         mode = 0660
 #2.3+     }
-#2.3+ 
+#2.3+
 #2.3+     unix_listener stats-writer {
 #2.3+         user = vmail
 #2.3+         group = vmail
@@ -108,3 +109,4 @@ plugin {
   quota_status_nouser = DUNNO
   quota_status_overquota = "552 5.2.2 Mailbox is full"
 }
+!include_try conf.d/99-custom-config.conf
diff --git a/install/tpl/fedora_dovecot2.conf.master b/install/tpl/fedora_dovecot2.conf.master
index 81d71a37fe..4644371450 100644
--- a/install/tpl/fedora_dovecot2.conf.master
+++ b/install/tpl/fedora_dovecot2.conf.master
@@ -1,3 +1,4 @@
+# Do not change this file, as changes will be overwritten by any ISPConfig update. Put your custom settings in /etc/dovecot/conf.d/99-custom-config.conf
 listen = *,[::]
 protocols = imap pop3
 auth_mechanisms = plain login
@@ -82,7 +83,7 @@ protocol lmtp {
 #2.3+         group = vmail
 #2.3+         mode = 0660
 #2.3+     }
-#2.3+ 
+#2.3+
 #2.3+     unix_listener stats-writer {
 #2.3+         user = vmail
 #2.3+         group = vmail
@@ -125,3 +126,4 @@ namespace inbox {
     special_use = \Trash
   }
 }
+!include_try conf.d/99-custom-config.conf
diff --git a/install/tpl/postfix_custom.conf.master b/install/tpl/postfix_custom.conf.master
new file mode 100644
index 0000000000..4f3f2124c8
--- /dev/null
+++ b/install/tpl/postfix_custom.conf.master
@@ -0,0 +1,3 @@
+# You can use this file for custom Postfix settings. The used settings will overrule the settings set by ISPConfig.
+# Use with caution!
+# Put this file in /usr/local/ispconfig/server/conf-custom/install/ and make your changes there.
-- 
GitLab