@@ -1107,7 +1107,7 @@ public function configure_postfix($options = '') {
11071107 $ server_ini_array = ini_to_array (stripslashes ($ server_ini_rec ['config ' ]));
11081108 unset($ server_ini_rec );
11091109
1110- //* If there are RBL's defined, format the list and add them to smtp_recipient_restrictions to prevent removeal after an update
1110+ //* If there are RBL's defined, format the list and add them to smtp_recipient_restrictions to prevent removal after an update
11111111 $ rbl_list = '' ;
11121112 if (@isset ($ server_ini_array ['mail ' ]['realtime_blackhole_list ' ]) && $ server_ini_array ['mail ' ]['realtime_blackhole_list ' ] != '' ) {
11131113 $ rbl_hosts = explode (", " , str_replace (" " , "" , $ server_ini_array ['mail ' ]['realtime_blackhole_list ' ]));
@@ -1647,6 +1647,12 @@ public function configure_dovecot() {
16471647 public function configure_amavis () {
16481648 global $ conf ;
16491649
1650+ //* These postconf commands will be executed on installation and update
1651+ $ server_ini_rec = $ this ->db ->queryOneRecord ("SELECT mail_server, config FROM ?? WHERE server_id = ? " , $ conf ["mysql " ]["database " ] . '.server ' , $ conf ['server_id ' ]);
1652+ $ server_ini_array = ini_to_array (stripslashes ($ server_ini_rec ['config ' ]));
1653+ $ mail_server = ($ server_ini_rec ['mail_server ' ]) ? true : false ;
1654+ unset($ server_ini_rec );
1655+
16501656 // amavisd user config file
16511657 $ configfile = 'amavisd_user_config ' ;
16521658 if (is_file ($ conf ['amavis ' ]['config_dir ' ].'/conf.d/50-user ' )) copy ($ conf ['amavis ' ]['config_dir ' ].'/conf.d/50-user ' , $ conf ['amavis ' ]['config_dir ' ].'/50-user~ ' );
@@ -1660,63 +1666,85 @@ public function configure_amavis() {
16601666 wf ($ conf ['amavis ' ]['config_dir ' ].'/conf.d/50-user ' , $ content );
16611667 chmod ($ conf ['amavis ' ]['config_dir ' ].'/conf.d/50-user ' , 0640 );
16621668
1663- // TODO: chmod and chown on the config file
1669+ $ mail_config = $ server_ini_array ['mail ' ];
1670+ //* only change postfix config if amavisd is active filter
1671+ if ($ mail_server && $ mail_config ['content_filter ' ] === 'amavisd ' ) {
1672+ // test if lmtp if available
1673+ $ configure_lmtp = $ this ->get_postfix_service ('lmtp ' ,'unix ' );
16641674
1665- // test if lmtp if available
1666- $ configure_lmtp = $ this -> get_postfix_service ( ' lmtp ' , ' unix ' );
1675+ // Adding the amavisd commands to the postfix configuration
1676+ $ postconf_commands = array ( );
16671677
1668- // Adding the amavisd commands to the postfix configuration
1669- // Add array for no error in foreach and maybe future options
1670- $ postconf_commands = array ();
1678+ // Check for amavisd -> pure webserver with postfix for mailing without antispam
1679+ if ($ conf ['amavis ' ]['installed ' ]) {
1680+ $ content_filter_service = ($ configure_lmtp ) ? 'lmtp ' : 'amavis ' ;
1681+ $ postconf_commands [] = "content_filter = $ {content_filter_service}:[127.0.0.1]:10024 " ;
1682+ $ postconf_commands [] = 'receive_override_options = no_address_mappings ' ;
1683+ $ postconf_commands [] = 'address_verify_virtual_transport = smtp:[127.0.0.1]:10025 ' ;
1684+ $ postconf_commands [] = 'address_verify_transport_maps = static:smtp:[127.0.0.1]:10025 ' ;
1685+ }
16711686
1672- // Check for amavisd -> pure webserver with postfix for mailing without antispam
1673- if ($ conf ['amavis ' ]['installed ' ]) {
1674- $ content_filter_service = ($ configure_lmtp ) ? 'lmtp ' : 'amavis ' ;
1675- $ postconf_commands [] = "content_filter = $ {content_filter_service}:[127.0.0.1]:10024 " ;
1676- $ postconf_commands [] = 'receive_override_options = no_address_mappings ' ;
1677- }
1687+ $ options = preg_split ("/,\s*/ " , exec ("postconf -h smtpd_recipient_restrictions " ));
1688+ $ new_options = array ();
1689+ foreach ($ options as $ value ) {
1690+ $ value = trim ($ value );
1691+ if ($ value == '' ) continue ;
1692+ if (preg_match ("|check_recipient_access\s+proxy:mysql: $ {quoted_config_dir}/mysql-verify_recipients.cf| " , $ value )) {
1693+ continue ;
1694+ }
1695+ $ new_options [] = $ value ;
1696+ }
1697+ if ($ configure_lmtp ) {
1698+ for ($ i = 0 ; isset ($ new_options [$ i ]); $ i ++) {
1699+ if ($ new_options [$ i ] == 'reject_unlisted_recipient ' ) {
1700+ array_splice ($ new_options , $ i +1 , 0 , array ("check_recipient_access proxy:mysql: $ {config_dir}/mysql-verify_recipients.cf " ));
1701+ break ;
1702+ }
1703+ }
1704+ # postfix < 3.3 needs this when using reject_unverified_recipient:
1705+ if (version_compare ($ postfix_version , 3.3 , '< ' )) {
1706+ $ postconf_commands [] = "enable_original_recipient = yes " ;
1707+ }
1708+ }
1709+ $ postconf_commands [] = "smtpd_recipient_restrictions = " .implode (", " , $ new_options );
16781710
1679- // Make a backup copy of the main.cf file
1680- copy ($ conf ['postfix ' ]['config_dir ' ].'/main.cf ' , $ conf ['postfix ' ]['config_dir ' ].'/main.cf~2 ' );
1711+ // Make a backup copy of the main.cf file
1712+ copy ($ conf ['postfix ' ]['config_dir ' ].'/main.cf ' , $ conf ['postfix ' ]['config_dir ' ].'/main.cf~2 ' );
16811713
1682- // Executing the postconf commands
1683- foreach ($ postconf_commands as $ cmd ) {
1684- $ command = "postconf -e ' $ cmd' " ;
1685- caselog ($ command ." &> /dev/null " , __FILE__ , __LINE__ , "EXECUTED: $ command " , "Failed to execute the command $ command " );
1686- }
1714+ // Executing the postconf commands
1715+ foreach ($ postconf_commands as $ cmd ) {
1716+ $ command = "postconf -e ' $ cmd' " ;
1717+ caselog ($ command ." &> /dev/null " , __FILE__ , __LINE__ , "EXECUTED: $ command " , "Failed to execute the command $ command " );
1718+ }
16871719
1688- $ config_dir = $ conf ['postfix ' ]['config_dir ' ];
1720+ $ config_dir = $ conf ['postfix ' ]['config_dir ' ];
16891721
1690- // Adding amavis-services to the master.cf file if the service does not already exists
1691- // $add_amavis = !$this->get_postfix_service('amavis','unix');
1692- // $add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
1693- // $add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
1694- //*TODO: check templates against existing postfix-services to make sure we use the template
1695-
1696- // Or just remove the old service definitions and add them again?
1697- $ add_amavis = $ this ->remove_postfix_service ('amavis ' ,'unix ' );
1698- $ add_amavis_10025 = $ this ->remove_postfix_service ('127.0.0.1:10025 ' ,'inet ' );
1699- $ add_amavis_10027 = $ this ->remove_postfix_service ('127.0.0.1:10027 ' ,'inet ' );
1700-
1701- if ($ add_amavis || $ add_amavis_10025 || $ add_amavis_10027 ) {
1702- //* backup master.cf
1703- if (is_file ($ config_dir .'/master.cf ' )) copy ($ config_dir .'/master.cf ' , $ config_dir .'/master.cf~ ' );
1704- // adjust amavis-config
1705- if ($ add_amavis ) {
1706- $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis.master ' , 'tpl/master_cf_amavis.master ' );
1707- af ($ config_dir .'/master.cf ' , $ content );
1708- unset($ content );
1709- }
1710- if ($ add_amavis_10025 ) {
1711- $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis10025.master ' , 'tpl/master_cf_amavis10025.master ' );
1712- af ($ config_dir .'/master.cf ' , $ content );
1713- unset($ content );
1722+ // Adding amavis-services to the master.cf file if the service does not already exists
1723+ // (just remove the old service definitions and add them again)
1724+ $ add_amavis = $ this ->remove_postfix_service ('amavis ' ,'unix ' );
1725+ $ add_amavis_10025 = $ this ->remove_postfix_service ('127.0.0.1:10025 ' ,'inet ' );
1726+ $ add_amavis_10027 = $ this ->remove_postfix_service ('127.0.0.1:10027 ' ,'inet ' );
1727+
1728+ if ($ add_amavis || $ add_amavis_10025 || $ add_amavis_10027 ) {
1729+ //* backup master.cf
1730+ if (is_file ($ config_dir .'/master.cf ' )) copy ($ config_dir .'/master.cf ' , $ config_dir .'/master.cf~ ' );
1731+ // adjust amavis-config
1732+ if ($ add_amavis ) {
1733+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis.master ' , 'tpl/master_cf_amavis.master ' );
1734+ af ($ config_dir .'/master.cf ' , $ content );
1735+ unset($ content );
1736+ }
1737+ if ($ add_amavis_10025 ) {
1738+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis10025.master ' , 'tpl/master_cf_amavis10025.master ' );
1739+ af ($ config_dir .'/master.cf ' , $ content );
1740+ unset($ content );
1741+ }
1742+ if ($ add_amavis_10027 ) {
1743+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis10027.master ' , 'tpl/master_cf_amavis10027.master ' );
1744+ af ($ config_dir .'/master.cf ' , $ content );
1745+ unset($ content );
1746+ }
17141747 }
1715- if ($ add_amavis_10027 ) {
1716- $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis10027.master ' , 'tpl/master_cf_amavis10027.master ' );
1717- af ($ config_dir .'/master.cf ' , $ content );
1718- unset($ content );
1719- }
17201748 }
17211749
17221750 // Add the clamav user to the amavis group
@@ -1746,14 +1774,18 @@ public function configure_rspamd() {
17461774 global $ conf ;
17471775
17481776 //* These postconf commands will be executed on installation and update
1749- $ server_ini_rec = $ this ->db ->queryOneRecord ("SELECT config FROM ?? WHERE server_id = ? " , $ conf ["mysql " ]["database " ] . '.server ' , $ conf ['server_id ' ]);
1777+ $ server_ini_rec = $ this ->db ->queryOneRecord ("SELECT mail_server, config FROM ?? WHERE server_id = ? " , $ conf ["mysql " ]["database " ] . '.server ' , $ conf ['server_id ' ]);
17501778 $ server_ini_array = ini_to_array (stripslashes ($ server_ini_rec ['config ' ]));
1779+ $ mail_server = ($ server_ini_rec ['mail_server ' ]) ? true : false ;
17511780 unset($ server_ini_rec );
17521781
17531782 $ mail_config = $ server_ini_array ['mail ' ];
1754- if ($ mail_config ['content_filter ' ] === 'rspamd ' ) {
1755- exec ("postconf -X 'receive_override_options' " );
1756- exec ("postconf -X 'content_filter' " );
1783+ //* only change postfix config if rspamd is active filter
1784+ if ($ mail_server && $ mail_config ['content_filter ' ] === 'rspamd ' ) {
1785+ exec ("postconf -X receive_override_options " );
1786+ exec ("postconf -X content_filter " );
1787+ exec ("postconf -X address_verify_virtual_transport " );
1788+ exec ("postconf -X address_verify_transport_maps " );
17571789
17581790 exec ("postconf -e 'smtpd_milters = inet:localhost:11332' " );
17591791 exec ("postconf -e 'non_smtpd_milters = inet:localhost:11332' " );
@@ -1804,6 +1836,9 @@ public function configure_rspamd() {
18041836 if (preg_match ('/check_policy_service\s+inet:127.0.0.1:10023/ ' , $ value )) {
18051837 continue ;
18061838 }
1839+ if (preg_match ("|check_recipient_access\s+proxy:mysql: $ {quoted_config_dir}/mysql-verify_recipients.cf| " , $ value )) {
1840+ continue ;
1841+ }
18071842 $ new_options [] = $ value ;
18081843 }
18091844 exec ("postconf -e 'smtpd_recipient_restrictions = " .implode (", " , $ new_options )."' " );
0 commit comments