@@ -349,27 +349,30 @@ public function configure_dovecot()
349349 }
350350 }
351351
352- $ config_dir = $ conf ['dovecot ' ]['config_dir ' ];
353-
354- //* Use /etc/dovecot as config dir if exists
355- if (is_dir ('/etc/dovecot ' )) $ config_dir = '/etc/dovecot ' ;
356-
352+ $ config_dir = $ conf ['postfix ' ]['config_dir ' ];
357353 //* Configure master.cf and add a line for deliver
358- if (is_file ($ config_dir .'/master.cf ' )){
359- copy ($ config_dir .'/master.cf ' , $ config_dir .'/master.cf~2 ' );
360- }
361- if (is_file ($ config_dir .'/master.cf~ ' )){
362- exec ('chmod 400 ' .$ config_dir .'/master.cf~2 ' );
354+ if ($ this ->postfix_master ()) {
355+ exec ("postconf -M dovecot.unix " , $ out , $ ret );
356+ $ add_dovecot_service = @($ out [0 ]=='' )?true :false ;
357+ } else { //* fallback - postfix < 2.9
358+ $ content = rf ($ config_dir'/master.cf ' );
359+ $ add_dovecot_service = @(!stristr ($ content , "dovecot/deliver " ))?true :false ;
363360 }
364- $ content = rf ($ conf ["postfix " ]["config_dir " ].'/master.cf ' );
365- // Only add the content if we had not addded it before
366- if (!stristr ($ content , "dovecot/deliver " )) {
367- $ deliver_content = 'dovecot unix - n n - - pipe ' ."\n" .' flags=DROhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop} ' ;
361+ if ($ add_dovecot_service ) {
362+ //* backup
363+ if (is_file ($ config_dir .'/master.cf ' )){
364+ copy ($ config_dir .'/master.cf ' , $ config_dir .'/master.cf~2 ' );
365+ }
366+ if (is_file ($ config_dir .'/master.cf~ ' )){
367+ chmod ($ config_dir .'/master.cf~2 ' , 0400 );
368+ }
369+ //* Configure master.cf and add a line for deliver
370+ $ content = rf ($ conf ["postfix " ]["config_dir " ].'/master.cf ' );
371+ $ deliver_content = 'dovecot unix - n n - - pipe ' ."\n" .' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop} ' ;
368372 af ($ conf ["postfix " ]["config_dir " ].'/master.cf ' , $ deliver_content );
373+ unset($ content );
374+ unset($ deliver_content );
369375 }
370- unset($ content );
371- unset($ deliver_content );
372-
373376
374377 //* Reconfigure postfix to use dovecot authentication
375378 // Adding the amavisd commands to the postfix configuration
@@ -389,6 +392,10 @@ public function configure_dovecot()
389392 caselog ($ command ." &> /dev/null " , __FILE__ , __LINE__ , "EXECUTED: $ command " , "Failed to execute the command $ command " );
390393 }
391394
395+ //* Use /etc/dovecot as config dir if exists
396+ // if(is_dir('/etc/dovecot')) $config_dir = '/etc/dovecot';
397+ $ config_dir = $ conf ['dovecot ' ]['config_dir ' ];
398+
392399 //* backup dovecot.conf
393400 $ configfile = 'dovecot.conf ' ;
394401 if (is_file ("$ config_dir/ $ configfile " )){
@@ -482,28 +489,46 @@ public function configure_amavis() {
482489 caselog ($ command ." &> /dev/null " , __FILE__ , __LINE__ , "EXECUTED: $ command " , "Failed to execute the command $ command " );
483490 }
484491
485- // Append the configuration for amavisd to the master.cf file
486- if ( is_file ( $ conf [ ' postfix ' ][ ' config_dir ' ]. ' /master.cf ' )) copy ( $ conf [ ' postfix ' ][ ' config_dir ' ]. ' /master.cf ' , $ conf [ ' postfix ' ][ ' config_dir ' ]. ' /master.cf~ ' );
487- $ content = rf ( $ conf [ ' postfix ' ][ ' config_dir ' ]. ' / master.cf' );
488- // Only add the content if we had not addded it before
489- if (! preg_match ( ' /^ amavis\s+ unix\s+/m ' , $ content )) {
490- unset( $ content ) ;
491- $ content = rfsel ( $ conf [ ' ispconfig_install_dir ' ]. ' /server/conf-custom/install/master_cf_amavis.master ' , ' tpl/master_cf_amavis.master ' );
492- af ( $ conf [ ' postfix ' ][ ' config_dir ' ]. ' /master.cf ' , $ content );
493- $ content = rf ( $ conf [ ' postfix ' ][ ' config_dir ' ]. ' /master.cf ' ) ;
494- }
495- if (! preg_match ( ' /^ 127.0.0.1:10025\s+/m ' , $ content )) {
496- unset( $ content ) ;
497- $ content = rfsel ( $ conf [ ' ispconfig_install_dir ' ]. ' /server/conf-custom/install/master_cf_amavis10025.master ' , ' tpl/master_cf_amavis10025.master ' );
498- af ( $ conf [ ' postfix ' ][ ' config_dir ' ]. ' /master.cf ' , $ content );
492+ $ config_dir = $ conf [ ' postfix ' ][ ' config_dir ' ];
493+
494+ // Adding amavis-services to the master.cf file if the service does not already exists
495+ if ( $ this -> postfix_master ()) {
496+ exec ( " postconf -M amavis. unix" , $ out , $ ret );
497+ $ add_amavis = @( $ out [ 0 ]== '' )? true : false ;
498+ unset( $ out );
499+ exec ( " postconf -M 127.0.0.1:10025.inet " , $ out , $ ret );
500+ $ add_amavis_10025 = @( $ out [ 0 ]== '' )? true : false ;
501+ unset( $ out );
502+ exec ( " postconf -M 127.0.0.1:10027.inet " , $ out , $ ret );
503+ $ add_amavis_10027 = @( $ out [ 0 ]== '' )? true : false ;
504+ unset( $ out );
505+ } else { //* fallback - postfix < 2.9
499506 $ content = rf ($ conf ['postfix ' ]['config_dir ' ].'/master.cf ' );
507+ $ add_amavis = @(!preg_match ('/^amavis\s+unix\s+/m ' , $ content ))?true :false ;
508+ $ add_amavis_10025 = @(!preg_match ('/^127.0.0.1:10025\s+/m ' , $ content ))?true :false ;
509+ $ add_amavis_10027 = @(!preg_match ('/^127.0.0.1:10027\s+/m ' , $ content ))?true :false ;
500510 }
501- if (!preg_match ('/^127.0.0.1:10027\s+/m ' , $ content )) {
502- unset($ content );
503- $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis10027.master ' , 'tpl/master_cf_amavis10027.master ' );
504- af ($ conf ['postfix ' ]['config_dir ' ].'/master.cf ' , $ content );
511+
512+ if ($ add_amavis || $ add_amavis_10025 || $ add_amavis_10027 ) {
513+ //* backup master.cf
514+ if (is_file ($ config_dir .'/master.cf ' )) copy ($ config_dir .'/master.cf ' , $ config_dir .'/master.cf~ ' );
515+ // adjust amavis-config
516+ if ($ add_amavis ) {
517+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis.master ' , 'tpl/master_cf_amavis.master ' );
518+ af ($ config_dir .'/master.cf ' , $ content );
519+ unset($ content );
520+ }
521+ if ($ add_amavis_10025 ) {
522+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis10025.master ' , 'tpl/master_cf_amavis10025.master ' );
523+ af ($ config_dir .'/master.cf ' , $ content );
524+ unset($ content );
525+ }
526+ if ($ add_amavis_10027 ) {
527+ $ content = rfsel ($ conf ['ispconfig_install_dir ' ].'/server/conf-custom/install/master_cf_amavis10027.master ' , 'tpl/master_cf_amavis10027.master ' );
528+ af ($ config_dir .'/master.cf ' , $ content );
529+ unset($ content );
530+ }
505531 }
506- unset($ content );
507532
508533 removeLine ('/etc/sysconfig/freshclam ' , 'FRESHCLAM_DELAY=disabled-warn # REMOVE ME ' , 1 );
509534 replaceLine ('/etc/freshclam.conf ' , 'Example ' , '# Example ' , 1 );
0 commit comments