summaryrefslogtreecommitdiffstats
path: root/postfix_wizard/scripts/Postfixconf.pm
blob: 03c5658e61b4d11213c16d5ff7fad293e0a48bd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl

package Postfixconf;
require "__WIZ_HOME__/common/scripts/Vareqval.pm";
require "__WIZ_HOME__/common/scripts/DrakconnectConf.pm";
use MDK::Common;
use strict;

my $o = DrakconnectConf->new();

sub	do_it {
    my $wiz_domain_name = $o->get("DomainName");
    my $wiz_host_name = $o->get("SystemName");
    my @conf = qw(/etc/postfix/aliases
		  /etc/postfix/canonical
		  /etc/postfix/main.cf
		  /etc/postfix/master.cf
		  /etc/postfix/virtual);
    foreach (@conf) {
        (-f $_) and MDK::Common::cp_af($_, $_.".orig");
    }
    @conf = ("myhostname = $wiz_host_name.$wiz_domain_name",
	     'myorigin = $mydomain',
	     'inet_interfaces = all',
	     'mydestination = $myhostname, localhost.$mydomain, $mydomain',
	     'masquerade_domains = $mydomain',
	     'alias_maps = hash:/etc/postfix/aliases',
	     'alias_database = hash:/etc/postfix/aliases',
	     'virtual_maps = hash:/etc/postfix/virtual',
	     'canonical_maps = hash:/etc/postfix/canonical',
	     "relayhost = $ENV{wiz_ext_mail_relay}"
	     );
    foreach (@conf) {
	system("postconf -e \'$_\'");
    }
    if (defined $ENV{wiz_ext_mail_relay}) {
	my $file = "/etc/postfix/canonical";
	my $canon = "\n\@$wiz_domain_name \@$ENV{wiz_mail_masquerade}";
	my $t;
	foreach (cat_($file)) {
	    if (/^\s*(?!\#)\s*\@.*\@.*\@.*\..*/) {
		$t = $_;
		last;
	    }
	}
	if ($t) { substInFile { s|$t|\#$&$canon|} $file } 
	else { append_to_file($canon) }
    }
    system("postmap /etc/postfix/canonical");
    system("postmap /etc/postfix/virtual");
    system("postalias /etc/postfix/aliases");
    system("postfix check");
    system("service postfix restart");
    system("service xinetd restart");
    10;
}