Skip to content

Commit 9c6782b

Browse files
author
Florian Schaal
committed
updated installer for postfix-services for postfix >= 2.11
1 parent 42e4c6e commit 9c6782b

File tree

6 files changed

+53
-140
lines changed

6 files changed

+53
-140
lines changed

install/dist/lib/centos_base.lib.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,9 @@ public function configure_amavis() {
7070
$config_dir = $conf['postfix']['config_dir'];
7171

7272
// Adding amavis-services to the master.cf file if the service does not already exists
73-
if ($this->postfix_master()) {
74-
exec ("postconf -M amavis.unix &> /dev/null", $out, $ret);
75-
$add_amavis = @($out[0]=='')?true:false;
76-
unset($out);
77-
exec ("postconf -M 127.0.0.1:10025.inet &> /dev/null", $out, $ret);
78-
$add_amavis_10025 = @($out[0]=='')?true:false;
79-
unset($out);
80-
exec ("postconf -M 127.0.0.1:10027.inet &> /dev/null", $out, $ret);
81-
$add_amavis_10027 = @($out[0]=='')?true:false;
82-
unset($out);
83-
} else { //* fallback - postfix < 2.9
84-
$content = rf($conf['postfix']['config_dir'].'/master.cf');
85-
$add_amavis = @(!preg_match('/^amavis\s+unix\s+/m', $content))?true:false;
86-
$add_amavis_10025 = @(!preg_match('/^127.0.0.1:10025\s+/m', $content))?true:false;
87-
$add_amavis_10027 = @(!preg_match('/^127.0.0.1:10027\s+/m', $content))?true:false;
88-
}
73+
$add_amavis = !$this->get_postfix_service('amavis','unix');
74+
$add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
75+
$add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
8976

9077
if ($add_amavis || $add_amavis_10025 || $add_amavis_10027) {
9178
//* backup master.cf

install/dist/lib/debian60.lib.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,7 @@ public function configure_dovecot()
5151
}
5252

5353
$config_dir = $conf['postfix']['config_dir'];
54-
//* Configure master.cf and add a line for deliver
55-
if ($this->postfix_master()) {
56-
exec ("postconf -M dovecot.unix", $out, $ret); //* Postfix 2.9
57-
if (!isset($out[0])) exec ("postconf -M dovecot/unix", $out, $ret); //* Postfix >= 2.11
58-
$add_dovecot_service = @($out[0]=='')?true:false;
59-
} else { //* fallback - postfix < 2.9
60-
$content = rf($config_dir.'/master.cf');
61-
$add_dovecot_service = @(!stristr($content, "dovecot/deliver"))?true:false;
62-
}
63-
if($add_dovecot_service) {
54+
if(!$this->get_postfix_service('dovecot', 'unix')) {
6455
//* backup
6556
if(is_file($config_dir.'/master.cf')){
6657
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
@@ -70,7 +61,7 @@ public function configure_dovecot()
7061
}
7162
//* Configure master.cf and add a line for deliver
7263
$content = rf($conf["postfix"]["config_dir"].'/master.cf');
73-
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
64+
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'."\n";
7465
af($config_dir.'/master.cf', $deliver_content);
7566
unset($content);
7667
unset($deliver_content);

install/dist/lib/fedora.lib.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,9 @@ public function configure_dovecot()
350350
}
351351

352352
$config_dir = $conf['postfix']['config_dir'];
353+
353354
//* Configure master.cf and add a line for deliver
354-
if ($this->postfix_master()) {
355-
exec ("postconf -M dovecot.unix", $out, $ret); //* Postfix 2.9
356-
if (!isset($out[0])) exec ("postconf -M dovecot/unix", $out, $ret); //* Postfix >= 2.11
357-
$add_dovecot_service = @($out[0]=='')?true:false;
358-
} else { //* fallback - postfix < 2.9
359-
$content = rf($config_dir.'/master.cf');
360-
$add_dovecot_service = @(!stristr($content, "dovecot/deliver"))?true:false;
361-
}
362-
if($add_dovecot_service) {
355+
if(!$this->get_postfix_service('dovecot', 'unix')) {
363356
//* backup
364357
if(is_file($config_dir.'/master.cf')){
365358
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
@@ -369,7 +362,7 @@ public function configure_dovecot()
369362
}
370363
//* Configure master.cf and add a line for deliver
371364
$content = rf($conf["postfix"]["config_dir"].'/master.cf');
372-
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
365+
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'."\n";
373366
af($conf["postfix"]["config_dir"].'/master.cf', $deliver_content);
374367
unset($content);
375368
unset($deliver_content);
@@ -493,22 +486,9 @@ public function configure_amavis() {
493486
$config_dir = $conf['postfix']['config_dir'];
494487

495488
// Adding amavis-services to the master.cf file if the service does not already exists
496-
if ($this->postfix_master()) {
497-
exec ("postconf -M amavis.unix &> /dev/null", $out, $ret);
498-
$add_amavis = @($out[0]=='')?true:false;
499-
unset($out);
500-
exec ("postconf -M 127.0.0.1:10025.inet &> /dev/null", $out, $ret);
501-
$add_amavis_10025 = @($out[0]=='')?true:false;
502-
unset($out);
503-
exec ("postconf -M 127.0.0.1:10027.inet &> /dev/null", $out, $ret);
504-
$add_amavis_10027 = @($out[0]=='')?true:false;
505-
unset($out);
506-
} else { //* fallback - postfix < 2.9
507-
$content = rf($conf['postfix']['config_dir'].'/master.cf');
508-
$add_amavis = @(!preg_match('/^amavis\s+unix\s+/m', $content))?true:false;
509-
$add_amavis_10025 = @(!preg_match('/^127.0.0.1:10025\s+/m', $content))?true:false;
510-
$add_amavis_10027 = @(!preg_match('/^127.0.0.1:10027\s+/m', $content))?true:false;
511-
}
489+
$add_amavis = !$this->get_postfix_service('amavis','unix');
490+
$add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
491+
$add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
512492

513493
if ($add_amavis || $add_amavis_10025 || $add_amavis_10027) {
514494
//* backup master.cf

install/dist/lib/gentoo.lib.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,9 @@ public function configure_dovecot()
271271
}
272272

273273
$config_dir = $conf['postfix']['config_dir'];
274+
274275
//* Configure master.cf and add a line for deliver
275-
if ($this->postfix_master()) {
276-
exec ("postconf -M dovecot.unix", $out, $ret); //* Postfix 2.9
277-
if (!isset($out[0])) exec ("postconf -M dovecot/unix", $out, $ret); //* Postfix >= 2.11
278-
$add_dovecot_service = @($out[0]=='')?true:false;
279-
} else { //* fallback - postfix < 2.9
280-
$content = rf($config_dir.'/master.cf');
281-
$add_dovecot_service = @(!stristr($content, "dovecot/deliver"))?true:false;
282-
}
283-
if($add_dovecot_service) {
276+
if(!$this->get_postfix_service('dovecot', 'unix')) {
284277
//* backup
285278
if(is_file($config_dir.'/master.cf')){
286279
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
@@ -290,7 +283,7 @@ public function configure_dovecot()
290283
}
291284
//* Configure master.cf and add a line for deliver
292285
$content = rf($conf["postfix"]["config_dir"].'/master.cf');
293-
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DROhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
286+
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DROhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'."\n";
294287
af($config_dir.'/master.cf', $deliver_content);
295288
unset($content);
296289
unset($deliver_content);
@@ -395,22 +388,9 @@ public function configure_amavis()
395388
$config_dir = $conf['postfix']['config_dir'];
396389

397390
// Adding amavis-services to the master.cf file if the service does not already exists
398-
if ($this->postfix_master()) {
399-
exec ("postconf -M amavis.unix &> /dev/null", $out, $ret);
400-
$add_amavis = @($out[0]=='')?true:false;
401-
unset($out);
402-
exec ("postconf -M 127.0.0.1:10025.inet &> /dev/null", $out, $ret);
403-
$add_amavis_10025 = @($out[0]=='')?true:false;
404-
unset($out);
405-
exec ("postconf -M 127.0.0.1:10027.inet &> /dev/null", $out, $ret);
406-
$add_amavis_10027 = @($out[0]=='')?true:false;
407-
unset($out);
408-
} else { //* fallback - postfix < 2.9
409-
$content = rf($conf['postfix']['config_dir'].'/master.cf');
410-
$add_amavis = @(!preg_match('/^amavis\s+unix\s+/m', $content))?true:false;
411-
$add_amavis_10025 = @(!preg_match('/^127.0.0.1:10025\s+/m', $content))?true:false;
412-
$add_amavis_10027 = @(!preg_match('/^127.0.0.1:10027\s+/m', $content))?true:false;
413-
}
391+
$add_amavis = !$this->get_postfix_service('amavis','unix');
392+
$add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
393+
$add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
414394

415395
if ($add_amavis || $add_amavis_10025 || $add_amavis_10027) {
416396
//* backup master.cf

install/dist/lib/opensuse.lib.php

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ function configure_postfix($options = '')
228228
//* Check maildrop service in posfix master.cf
229229
$regex = "/^maildrop unix.*pipe flags=DRhu user=vmail argv=\\/usr\\/bin\\/maildrop -d ".$cf['vmail_username']." \\$\{extension} \\$\{recipient} \\$\{user} \\$\{nexthop} \\$\{sender}/";
230230
$configfile = $config_dir.'/master.cf';
231-
if ($this->postfix_master()) {
231+
if($this->get_postfix_service('maildrop', 'unix')) {
232232
exec ("postconf -M maildrop.unix &> /dev/null", $out, $ret);
233233
$change_maildrop_flags = @(preg_match($regex, $out[0]) && $out[0] !='')?false:true;
234-
} else { //* fallback - postfix < 2.9
234+
} else {
235235
$change_maildrop_flags = @(preg_match($regex, $configfile))?false:true;
236236
}
237237
if ($change_maildrop_flags) {
@@ -365,16 +365,9 @@ public function configure_dovecot()
365365
}
366366

367367
$config_dir = $conf['postfix']['config_dir'];
368+
368369
//* Configure master.cf and add a line for deliver
369-
if ($this->postfix_master()) {
370-
exec ("postconf -M dovecot.unix", $out, $ret); //* Postfix 2.9
371-
if (!isset($out[0])) exec ("postconf -M dovecot/unix", $out, $ret); //* Postfix >= 2.11
372-
$add_dovecot_service = @($out[0]=='')?true:false;
373-
} else { //* fallback - postfix < 2.9
374-
$content = rf($config_dir.'/master.cf');
375-
$add_dovecot_service = @(!stristr($content, "dovecot/deliver"))?true:false;
376-
}
377-
if($add_dovecot_service) {
370+
if(!$this->get_postfix_service('dovecot', 'unix')) {
378371
//* backup
379372
if(is_file($config_dir.'/master.cf')){
380373
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
@@ -384,7 +377,7 @@ public function configure_dovecot()
384377
}
385378
//* Configure master.cf and add a line for deliver
386379
$content = rf($conf["postfix"]["config_dir"].'/master.cf');
387-
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
380+
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'."\n";
388381
af($conf["postfix"]["config_dir"].'/master.cf', $deliver_content);
389382
unset($content);
390383
unset($deliver_content);
@@ -503,22 +496,9 @@ public function configure_amavis() {
503496
$config_dir = $conf['postfix']['config_dir'];
504497

505498
// Adding amavis-services to the master.cf file if the service does not already exists
506-
if ($this->postfix_master()) {
507-
exec ("postconf -M amavis.unix &> /dev/null", $out, $ret);
508-
$add_amavis = @($out[0]=='')?true:false;
509-
unset($out);
510-
exec ("postconf -M 127.0.0.1:10025.inet &> /dev/null", $out, $ret);
511-
$add_amavis_10025 = @($out[0]=='')?true:false;
512-
unset($out);
513-
exec ("postconf -M 127.0.0.1:10027.inet &> /dev/null", $out, $ret);
514-
$add_amavis_10027 = @($out[0]=='')?true:false;
515-
unset($out);
516-
} else { //* fallback - postfix < 2.9
517-
$content = rf($conf['postfix']['config_dir'].'/master.cf');
518-
$add_amavis = @(!preg_match('/^amavis\s+unix\s+/m', $content))?true:false;
519-
$add_amavis_10025 = @(!preg_match('/^127.0.0.1:10025\s+/m', $content))?true:false;
520-
$add_amavis_10027 = @(!preg_match('/^127.0.0.1:10027\s+/m', $content))?true:false;
521-
}
499+
$add_amavis = !$this->get_postfix_service('amavis','unix');
500+
$add_amavis_10025 = !$this->get_postfix_service('127.0.0.1:10025','inet');
501+
$add_amavis_10027 = !$this->get_postfix_service('127.0.0.1:10027','inet');
522502

523503
if ($add_amavis || $add_amavis_10025 || $add_amavis_10027) {
524504
//* backup master.cf

install/lib/installer_base.lib.php

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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,16 +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", $out, $ret); //* Postfix 2.9
1173-
if (!isset($out[0])) exec ("postconf -M dovecot/unix", $out, $ret); //* Postfix >= 2.11
1174-
$add_dovecot_service = @($out[0]=='')?true:false;
1175-
} else { //* fallback - postfix < 2.9
1176-
$content = rf($config_dir.'/master.cf');
1177-
$add_dovecot_service = @(!stristr($content, "dovecot/deliver"))?true:false;
1178-
}
1179-
if($add_dovecot_service) {
1187+
if(!$this->get_postfix_service('dovecot', 'unix')) {
11801188
//* backup
11811189
if(is_file($config_dir.'/master.cf')){
11821190
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
@@ -1186,7 +1194,7 @@ public function configure_dovecot() {
11861194
}
11871195
//* Configure master.cf and add a line for deliver
11881196
$content = rf($conf["postfix"]["config_dir"].'/master.cf');
1189-
$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";
11901198
af($config_dir.'/master.cf', $deliver_content);
11911199
unset($content);
11921200
unset($deliver_content);
@@ -1308,25 +1316,12 @@ public function configure_amavis() {
13081316
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
13091317
}
13101318

1311-
$config_dir = $conf['postfix'];
1319+
$config_dir = $conf['postfix']['config_dir'];
13121320

13131321
// Adding amavis-services to the master.cf file if the service does not already exists
1314-
if ($this->postfix_master()) {
1315-
exec ("postconf -M amavis.unix &> /dev/null", $out, $ret);
1316-
$add_amavis = @($out[0]=='')?true:false;
1317-
unset($out);
1318-
exec ("postconf -M 127.0.0.1:10025.inet &> /dev/null", $out, $ret);
1319-
$add_amavis_10025 = @($out[0]=='')?true:false;
1320-
unset($out);
1321-
exec ("postconf -M 127.0.0.1:10027.inet &> /dev/null", $out, $ret);
1322-
$add_amavis_10027 = @($out[0]=='')?true:false;
1323-
unset($out);
1324-
} else { //* fallback - postfix < 2.9
1325-
$content = rf($conf['postfix']['config_dir'].'/master.cf');
1326-
$add_amavis = @(!preg_match('/^amavis\s+unix\s+/m', $content))?true:false;
1327-
$add_amavis_10025 = @(!preg_match('/^127.0.0.1:10025\s+/m', $content))?true:false;
1328-
$add_amavis_10027 = @(!preg_match('/^127.0.0.1:10027\s+/m', $content))?true:false;
1329-
}
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');
13301325

13311326
if ($add_amavis || $add_amavis_10025 || $add_amavis_10027) {
13321327
//* backup master.cf

0 commit comments

Comments
 (0)