@@ -793,10 +793,25 @@ public function configure_mailman($status = 'insert') {
793793 exec ('/usr/sbin/postmap /var/lib/mailman/data/transport-mailman ' );
794794 }
795795
796- //* with postfix >= 2.9 we can detect configured services with postconf
797- public function postfix_master () {
798- exec ("postconf -M " , $ out , $ ret );
799- return $ ret ===0 ?true :false ;
796+ public function get_postfix_service ($ service , $ type ) {
797+ global $ conf ;
798+
799+ exec ("postconf -M " , $ out , $ ret );
800+
801+ if ($ ret === 0 ) { //* with postfix >= 2.9 we can detect configured services with postconf
802+ unset($ out );
803+ exec ("postconf -M $ service/ $ type 2> /dev/null " , $ out , $ ret ); //* Postfix >= 2.11
804+ if (!isset ($ out [0 ])) { //* try Postfix 2.9
805+ exec ("postconf -M $ service. $ type 2> /dev/null " , $ out , $ ret );
806+ }
807+ $ postfix_service = @($ out [0 ]=='' )?false :true ;
808+ } else { //* fallback - Postfix < 2.9
809+ rf ($ conf ['postfix ' ]['config_dir ' ].'/master.cf ' );
810+ $ regex = '/[^#] ' .$ service .'.*. ' .$ type .'.*/ ' ;
811+ $ postfix_service = @(!preg_match ($ regex , $ content ))?true :false ;
812+ }
813+
814+ return $ postfix_service ;
800815 }
801816
802817 public function configure_postfix ($ options = '' ) {
@@ -988,10 +1003,10 @@ public function configure_postfix($options = '') {
9881003 //* Check maildrop service in posfix master.cf
9891004 $ regex = "/^maildrop unix.*pipe flags=DRhu user=vmail argv= \\/usr \\/bin \\/maildrop -d " .$ cf ['vmail_username ' ]." \\$\{extension} \\$\{recipient} \\$\{user} \\$\{nexthop} \\$\{sender}/ " ;
9901005 $ configfile = $ config_dir .'/master.cf ' ;
991- if ($ this ->postfix_master ( )) {
1006+ if ($ this ->get_postfix_service ( ' maildrop ' , ' unix ' )) {
9921007 exec ("postconf -M maildrop.unix &> /dev/null " , $ out , $ ret );
9931008 $ change_maildrop_flags = @(preg_match ($ regex , $ out [0 ]) && $ out [0 ] !='' )?false :true ;
994- } else { //* fallback - postfix < 2.9
1009+ } else {
9951010 $ change_maildrop_flags = @(preg_match ($ regex , $ configfile ))?false :true ;
9961011 }
9971012 if ($ change_maildrop_flags ) {
@@ -1167,15 +1182,9 @@ public function configure_dovecot() {
11671182 }
11681183
11691184 $ config_dir = $ conf ['postfix ' ]['config_dir ' ];
1185+
11701186 //* Configure master.cf and add a line for deliver
1171- if ($ this ->postfix_master ()) {
1172- exec ("postconf -M dovecot.unix &> /dev/null " , $ out , $ ret );
1173- $ add_dovecot_service = @($ out [0 ]=='' )?true :false ;
1174- } else { //* fallback - postfix < 2.9
1175- $ content = rf ($ config_dir .'/master.cf ' );
1176- $ add_dovecot_service = @(!stristr ($ content , "dovecot/deliver " ))?true :false ;
1177- }
1178- if ($ add_dovecot_service ) {
1187+ if (!$ this ->get_postfix_service ('dovecot ' , 'unix ' )) {
11791188 //* backup
11801189 if (is_file ($ config_dir .'/master.cf ' )){
11811190 copy ($ config_dir .'/master.cf ' , $ config_dir .'/master.cf~2 ' );
@@ -1185,7 +1194,7 @@ public function configure_dovecot() {
11851194 }
11861195 //* Configure master.cf and add a line for deliver
11871196 $ content = rf ($ conf ["postfix " ]["config_dir " ].'/master.cf ' );
1188- $ deliver_content = 'dovecot unix - n n - - pipe ' ."\n" .' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop} ' ;
1197+ $ deliver_content = 'dovecot unix - n n - - pipe ' ."\n" .' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop} ' . "\n" ;
11891198 af ($ config_dir .'/master.cf ' , $ deliver_content );
11901199 unset($ content );
11911200 unset($ deliver_content );
@@ -1307,25 +1316,12 @@ public function configure_amavis() {
13071316 caselog ($ command ." &> /dev/null " , __FILE__ , __LINE__ , "EXECUTED: $ command " , "Failed to execute the command $ command " );
13081317 }
13091318
1310- $ config_dir = $ conf ['postfix ' ];
1319+ $ config_dir = $ conf ['postfix ' ][ ' config_dir ' ] ;
13111320
13121321 // Adding amavis-services to the master.cf file if the service does not already exists
1313- if ($ this ->postfix_master ()) {
1314- exec ("postconf -M amavis.unix &> /dev/null " , $ out , $ ret );
1315- $ add_amavis = @($ out [0 ]=='' )?true :false ;
1316- unset($ out );
1317- exec ("postconf -M 127.0.0.1:10025.inet &> /dev/null " , $ out , $ ret );
1318- $ add_amavis_10025 = @($ out [0 ]=='' )?true :false ;
1319- unset($ out );
1320- exec ("postconf -M 127.0.0.1:10027.inet &> /dev/null " , $ out , $ ret );
1321- $ add_amavis_10027 = @($ out [0 ]=='' )?true :false ;
1322- unset($ out );
1323- } else { //* fallback - postfix < 2.9
1324- $ content = rf ($ conf ['postfix ' ]['config_dir ' ].'/master.cf ' );
1325- $ add_amavis = @(!preg_match ('/^amavis\s+unix\s+/m ' , $ content ))?true :false ;
1326- $ add_amavis_10025 = @(!preg_match ('/^127.0.0.1:10025\s+/m ' , $ content ))?true :false ;
1327- $ add_amavis_10027 = @(!preg_match ('/^127.0.0.1:10027\s+/m ' , $ content ))?true :false ;
1328- }
1322+ $ add_amavis = !$ this ->get_postfix_service ('amavis ' ,'unix ' );
1323+ $ add_amavis_10025 = !$ this ->get_postfix_service ('127.0.0.1:10025 ' ,'inet ' );
1324+ $ add_amavis_10027 = !$ this ->get_postfix_service ('127.0.0.1:10027 ' ,'inet ' );
13291325
13301326 if ($ add_amavis || $ add_amavis_10025 || $ add_amavis_10027 ) {
13311327 //* backup master.cf
0 commit comments