@@ -967,6 +967,11 @@ public function configure_postfix($options = '') {
967967 $ this ->error ("The postfix configuration directory ' $ config_dir' does not exist. " );
968968 }
969969
970+ //* Get postfix version
971+ exec ('postconf -d mail_version 2>&1 ' , $ out );
972+ $ postfix_version = preg_replace ('/.*=\s*/ ' , '' , $ out [0 ]);
973+ unset($ out );
974+
970975 //* mysql-virtual_domains.cf
971976 $ this ->process_postfix_config ('mysql-virtual_domains.cf ' );
972977
@@ -1072,12 +1077,28 @@ public function configure_postfix($options = '') {
10721077 }
10731078
10741079 $ reject_sender_login_mismatch = '' ;
1075- if (isset ($ server_ini_array ['mail ' ]['reject_sender_login_mismatch ' ]) && ($ server_ini_array ['mail ' ]['reject_sender_login_mismatch ' ] == 'y ' )) {
1076- $ reject_sender_login_mismatch = ', reject_authenticated_sender_login_mismatch ' ;
1080+ $ reject_authenticated_sender_login_mismatch = '' ;
1081+ if (isset ($ server_ini_array ['mail ' ]['reject_sender_login_mismatch ' ]) && ($ server_ini_array ['mail ' ]['reject_sender_login_mismatch ' ] == 'y ' )) {
1082+ $ reject_sender_login_mismatch = ',reject_sender_login_mismatch, ' ;
1083+ $ reject_authenticated_sender_login_mismatch = 'reject_authenticated_sender_login_mismatch, ' ;
10771084 }
1078- unset($ server_ini_array );
10791085
1080- $ tmp = str_replace ('. ' ,'\. ' ,$ conf ['hostname ' ]);
1086+ # placeholder includes comment char
1087+ $ stress_adaptive_placeholder = '#{stress_adaptive} ' ;
1088+ $ stress_adaptive = (isset ($ server_ini_array ['mail ' ]['stress_adaptive ' ]) && ($ server_ini_array ['mail ' ]['stress_adaptive ' ] == 'y ' )) ? '' : $ stress_adaptive_placeholder ;
1089+
1090+ $ reject_unknown_client_hostname ='' ;
1091+ if (isset ($ server_ini_array ['mail ' ]['reject_unknown ' ]) && ($ server_ini_array ['mail ' ]['reject_unknown ' ] == 'client ' || $ server_ini_array ['mail ' ]['reject_unknown ' ] == 'client_helo ' )) {
1092+ $ reject_unknown_client_hostname =',reject_unknown_client_hostname ' ;
1093+ }
1094+ $ reject_unknown_helo_hostname ='' ;
1095+ if ((!isset ($ server_ini_array ['mail ' ]['reject_unknown ' ])) || $ server_ini_array ['mail ' ]['reject_unknown ' ] == 'helo ' || $ server_ini_array ['mail ' ]['reject_unknown ' ] == 'client_helo ' ) {
1096+ $ reject_unknown_helo_hostname =',reject_unknown_helo_hostname ' ;
1097+ }
1098+
1099+ unset($ server_ini_array );
1100+
1101+ $ myhostname = str_replace ('. ' ,'\. ' ,$ conf ['hostname ' ]);
10811102
10821103 $ postconf_placeholders = array ('{config_dir} ' => $ config_dir ,
10831104 '{vmail_mailbox_base} ' => $ cf ['vmail_mailbox_base ' ],
@@ -1086,13 +1107,43 @@ public function configure_postfix($options = '') {
10861107 '{rbl_list} ' => $ rbl_list ,
10871108 '{greylisting} ' => $ greylisting ,
10881109 '{reject_slm} ' => $ reject_sender_login_mismatch ,
1089- '{myhostname} ' => $ tmp ,
1110+ '{reject_aslm} ' => $ reject_authenticated_sender_login_mismatch ,
1111+ '{myhostname} ' => $ myhostname ,
1112+ $ stress_adaptive_placeholder => $ stress_adaptive ,
1113+ '{reject_unknown_client_hostname} ' => $ reject_unknown_client_hostname ,
1114+ '{reject_unknown_helo_hostname} ' => $ reject_unknown_helo_hostname ,
10901115 );
10911116
10921117 $ postconf_tpl = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/debian_postfix.conf.master ' , 'tpl/debian_postfix.conf.master ' );
10931118 $ postconf_tpl = strtr ($ postconf_tpl , $ postconf_placeholders );
10941119 $ postconf_commands = array_filter (explode ("\n" , $ postconf_tpl )); // read and remove empty lines
10951120
1121+ //* Merge version-specific postfix config
1122+ if (version_compare ($ postfix_version , '2.5 ' , '>= ' )) {
1123+ $ configfile = 'postfix_2-5.conf ' ;
1124+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/ ' .$ configfile .'.master ' , 'tpl/ ' .$ configfile .'.master ' );
1125+ $ content = strtr ($ content , $ postconf_placeholders );
1126+ $ postconf_commands = array_merge ($ postconf_commands , array_filter (explode ("\n" , $ content )));
1127+ }
1128+ if (version_compare ($ postfix_version , '2.10 ' , '>= ' )) {
1129+ $ configfile = 'postfix_2-10.conf ' ;
1130+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/ ' .$ configfile .'.master ' , 'tpl/ ' .$ configfile .'.master ' );
1131+ $ content = strtr ($ content , $ postconf_placeholders );
1132+ $ postconf_commands = array_merge ($ postconf_commands , array_filter (explode ("\n" , $ content )));
1133+ }
1134+ if (version_compare ($ postfix_version , '3.0 ' , '>= ' )) {
1135+ $ configfile = 'postfix_3-0.conf ' ;
1136+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/ ' .$ configfile .'.master ' , 'tpl/ ' .$ configfile .'.master ' );
1137+ $ content = strtr ($ content , $ postconf_placeholders );
1138+ $ postconf_commands = array_merge ($ postconf_commands , array_filter (explode ("\n" , $ content )));
1139+ }
1140+ if (version_compare ($ postfix_version , '3.3 ' , '>= ' )) {
1141+ $ configfile = 'postfix_3-3.conf ' ;
1142+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/ ' .$ configfile .'.master ' , 'tpl/ ' .$ configfile .'.master ' );
1143+ $ content = strtr ($ content , $ postconf_placeholders );
1144+ $ postconf_commands = array_merge ($ postconf_commands , array_filter (explode ("\n" , $ content )));
1145+ }
1146+
10961147 //* These postconf commands will be executed on installation only
10971148 if ($ this ->is_update == false ) {
10981149 $ postconf_commands = array_merge ($ postconf_commands , array (
@@ -1399,7 +1450,7 @@ public function configure_dovecot() {
13991450 if ($ configure_lmtp ) {
14001451 for ($ i = 0 ; isset ($ new_options [$ i ]); $ i ++) {
14011452 if ($ new_options [$ i ] == 'reject_unlisted_recipient ' ) {
1402- array_splice ($ new_options , $ i +1 , 0 , array ("check_recipient_access proxy:mysql: $ {config_dir }/mysql-verify_recipients.cf " ));
1453+ array_splice ($ new_options , $ i +1 , 0 , array ("check_recipient_access proxy:mysql: $ {quoted_config_dir }/mysql-verify_recipients.cf " ));
14031454 break ;
14041455 }
14051456 }
@@ -1408,7 +1459,6 @@ public function configure_dovecot() {
14081459 $ postconf_commands [] = "enable_original_recipient = yes " ;
14091460 }
14101461 }
1411- #exec("postconf -e 'smtpd_recipient_restrictions = ".implode(", ", $new_options)."'");
14121462 $ postconf_commands [] = "smtpd_recipient_restrictions = " .implode (", " , $ new_options );
14131463
14141464 // Executing the postconf commands
@@ -1630,7 +1680,7 @@ public function configure_amavis() {
16301680
16311681 public function configure_rspamd () {
16321682 global $ conf ;
1633-
1683+
16341684 //* These postconf commands will be executed on installation and update
16351685 $ server_ini_rec = $ this ->db ->queryOneRecord ("SELECT config FROM ?? WHERE server_id = ? " , $ conf ["mysql " ]["database " ] . '.server ' , $ conf ['server_id ' ]);
16361686 $ server_ini_array = ini_to_array (stripslashes ($ server_ini_rec ['config ' ]));
@@ -1647,8 +1697,33 @@ public function configure_rspamd() {
16471697 exec ("postconf -e 'milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}' " );
16481698 exec ("postconf -e 'milter_default_action = accept' " );
16491699
1650- exec ("postconf -e 'smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf, permit_mynetworks, permit_sasl_authenticated' " );
1700+ if (! isset ($ mail_config ['reject_sender_login_mismatch ' ])) {
1701+ $ mail_config ['reject_sender_login_mismatch ' ] = 'n ' ;
1702+ }
1703+ $ options = preg_split ("/,\s*/ " , exec ("postconf -h smtpd_sender_restrictions " ));
1704+ $ new_options = array ();
1705+ foreach ($ options as $ key => $ value ) {
1706+ $ value = trim ($ value );
1707+ if ($ value == '' ) continue ;
1708+ if (preg_match ('/tag_as_(originating|foreign)\.re/ ' , $ value )) {
1709+ continue ;
1710+ }
1711+ if (preg_match ('/reject_(authenticated_)?sender_login_mismatch/ ' , $ value )) {
1712+ continue ;
1713+ }
1714+ $ new_options [] = $ value ;
1715+ }
1716+ if ($ mail_config ['reject_sender_login_mismatch ' ] == 'y ' ) {
1717+ array_splice ($ new_options , 0 , 0 , array ('reject_authenticated_sender_login_mismatch ' ));
16511718
1719+ for ($ i = 0 ; isset ($ new_options [$ i ]); $ i ++) {
1720+ if ($ new_options [$ i ] == 'permit_mynetworks ' ) {
1721+ array_splice ($ new_options , $ i +1 , 0 , array ('reject_sender_login_mismatch ' ));
1722+ break ;
1723+ }
1724+ }
1725+ }
1726+ exec ("postconf -e 'smtpd_sender_restrictions = " .implode (", " , $ new_options )."' " );
16521727
16531728 $ options = preg_split ("/,\s*/ " , exec ("postconf -h smtpd_recipient_restrictions " ));
16541729 $ new_options = array ();
0 commit comments