Skip to content

Commit e9b92aa

Browse files
committed
bugfixes and remove/add master.cf templates to effect changes
1 parent 5353f1d commit e9b92aa

File tree

3 files changed

+92
-16
lines changed

3 files changed

+92
-16
lines changed

install/dist/lib/debian60.lib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ public function configure_dovecot()
164164

165165
//* dovecot-lmtpd
166166
if($configure_lmtp) {
167-
$dovecot_protocols .= ' lmtp'
167+
$dovecot_protocols .= ' lmtp';
168168
}
169169

170170
//* dovecot-managesieved
171171
if(is_file('/usr/lib/dovecot/managesieve')) {
172-
$dovecot_protocols .= ' sieve'
172+
$dovecot_protocols .= ' sieve';
173173
}
174174

175175
replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', "protocols = $dovecot_protocols", 1, 0);

install/lib/install.lib.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,29 +471,38 @@ function rf($file){
471471
}
472472

473473
function wf($file, $content){
474-
mkdirs(dirname($file));
474+
if(!$ret_val = mkdirs(dirname($file))) return false;
475475
if(!$fp = fopen($file, 'wb')){
476476
ilog('WARNING: could not open file '.$file);
477+
// implicitly returned false because the following fwrite and fclose both fail,
478+
// but to be explicit:
479+
$ret_val = false;
477480
}
478-
fwrite($fp, $content);
479-
fclose($fp);
481+
fwrite($fp, $content) or $ret_val = false;
482+
fclose($fp) or $ret_val = false;
483+
return $ret_val;
480484
}
481485

482486
function af($file, $content){
483-
mkdirs(dirname($file));
487+
if(!$ret_val = mkdirs(dirname($file))) return false;
484488
if(!$fp = fopen($file, 'ab')){
485489
ilog('WARNING: could not open file '.$file);
490+
$ret_val = false;
486491
}
487-
fwrite($fp, $content);
488-
fclose($fp);
492+
fwrite($fp, $content) or $ret_val = false;
493+
fclose($fp) or $ret_val = false;
494+
return $ret_val;
489495
}
490496

491497
function aftsl($file, $content){
498+
$ret_val = true;
492499
if(!$fp = fopen($file, 'ab')){
493500
ilog('WARNING: could not open file '.$file);
501+
$ret_val = false;
494502
}
495-
fwrite($fp, $content);
496-
fclose($fp);
503+
fwrite($fp, $content) or $ret_val = false;
504+
fclose($fp) or $ret_val = false;
505+
return $ret_val;
497506
}
498507

499508
function unix_nl($input){

install/lib/installer_base.lib.php

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ public function get_postfix_service($service, $type) {
864864
exec ("postconf -M $service.$type 2> /dev/null", $out, $ret);
865865
}
866866
$postfix_service = @($out[0]=='')?false:true;
867-
} else { //* fallback - Postfix < 2.9
867+
} else { //* fallback - Postfix < 2.9
868868
$content = rf($conf['postfix']['config_dir'].'/master.cf');
869869
$regex = "/^((?!#)".$service.".*".$type.".*)$/m";
870870
$postfix_service = @(preg_match($regex, $content))?true:false;
@@ -873,6 +873,68 @@ public function get_postfix_service($service, $type) {
873873
return $postfix_service;
874874
}
875875

876+
public function remove_postfix_service( $service, $type ) {
877+
global $conf;
878+
879+
// nothing to do if the service isn't even defined.
880+
if (! $this->get_postfix_service( $service, $type ) ) {
881+
return true;
882+
}
883+
884+
$postfix_version = `postconf -d mail_version 2>/dev/null`;
885+
$postfix_version = preg_replace( '/mail_version\s*=\s*(.*)\s*/', '$1', $postfix_version );
886+
887+
if ( version_compare( $postfix_version, '2.11', '>=' ) ) {
888+
889+
exec("postconf -X -M $service/$type 2> /dev/null", $out, $ret);
890+
891+
# reduce 3 or more newlines to 2
892+
$content = rf($conf['postfix']['config_dir'].'/master.cf');
893+
$content = preg_replace( '/(\r?\n){3,}/', '$1$1', $content );
894+
wf( $conf['postfix']['config_dir'].'/master.cf', $content );
895+
896+
} else { //* fallback - Postfix < 2.11
897+
898+
if ( ! $cf = fopen( $conf['postfix']['config_dir'].'/master.cf', 'r' ) ) {
899+
return false;
900+
}
901+
902+
$out = "";
903+
$reading_service = false;
904+
905+
while ( !feof( $cf ) ) {
906+
$line = fgets( $cf );
907+
908+
if ( $reading_service ) {
909+
# regex matches a new service or "empty" (whitespace) line
910+
if ( preg_match( '/^([^\s#]+.*|\s*)$/', $line ) &&
911+
! preg_match( '/^'.$service.'\s+'.$type.'/', $line ) ) {
912+
$out .= $line;
913+
$reading_service = false;
914+
}
915+
916+
# $skipped_lines .= $line;
917+
918+
# regex matches definition matching service to be removed
919+
} else if ( preg_match( '/^'.$service.'\s+'.$type.'/', $line ) ) {
920+
921+
$reading_service = true;
922+
# $skipped_lines .= $line;
923+
924+
} else {
925+
$out .= $line;
926+
}
927+
}
928+
fclose( $cf );
929+
930+
$out = preg_replace( '/(\r?\n){3,}/', '$1$1', $out ); # reduce 3 or more newlines to 2
931+
932+
return wf( $conf['postfix']['config_dir'].'/master.cf', $out );
933+
}
934+
935+
return true;
936+
}
937+
876938
public function configure_postfix($options = '') {
877939
global $conf,$autoinstall;
878940
$cf = $conf['postfix'];
@@ -1376,12 +1438,12 @@ public function configure_dovecot() {
13761438

13771439
//* dovecot-lmtpd
13781440
if($configure_lmtp) {
1379-
$dovecot_protocols .= ' lmtp'
1441+
$dovecot_protocols .= ' lmtp';
13801442
}
13811443

13821444
//* dovecot-managesieved
13831445
if(is_file('/usr/lib/dovecot/managesieve')) {
1384-
$dovecot_protocols .= ' sieve'
1446+
$dovecot_protocols .= ' sieve';
13851447
}
13861448

13871449
replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', "protocols = $dovecot_protocols", 1, 0);
@@ -1458,11 +1520,16 @@ public function configure_amavis() {
14581520
$config_dir = $conf['postfix']['config_dir'];
14591521

14601522
// Adding amavis-services to the master.cf file if the service does not already exists
1461-
$add_amavis = !$this->get_postfix_service('amavis','unix');
1462-
$add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
1463-
$add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
1523+
// $add_amavis = !$this->get_postfix_service('amavis','unix');
1524+
// $add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
1525+
// $add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
14641526
//*TODO: check templates against existing postfix-services to make sure we use the template
14651527

1528+
// Or just remove the old service definitions and add them again?
1529+
$add_amavis = $this->remove_postfix_service('amavis','unix');
1530+
$add_amavis_10025 = $this->remove_postfix_service('127.0.0.1:10025','inet');
1531+
$add_amavis_10027 = $this->remove_postfix_service('127.0.0.1:10027','inet');
1532+
14661533
if ($add_amavis || $add_amavis_10025 || $add_amavis_10027) {
14671534
//* backup master.cf
14681535
if(is_file($config_dir.'/master.cf')) copy($config_dir.'/master.cf', $config_dir.'/master.cf~');

0 commit comments

Comments
 (0)