41 lines
1.2 KiB
Perl
41 lines
1.2 KiB
Perl
#!/usr/bin/perl -w
|
|
|
|
use esmith::DomainsDB;
|
|
use esmith::ConfigDB;
|
|
use File::Find;
|
|
|
|
my $d = esmith::DomainsDB->open_ro || die "Couldn't open the domains database";
|
|
my $c = esmith::ConfigDB->open_ro || die "Couldn't open the configurtion database";
|
|
|
|
my $qpsmtpd = $c->get('qpsmtpd');
|
|
die "qpsmtpd service entry not found" unless ($qpsmtpd);
|
|
|
|
my $dkim_sign = $qpsmtpd->prop('DKIMSigning') || 'disabled';
|
|
|
|
find({ wanted => \&wanted }, qw(/var/service/qpsmtpd/config/dkim/));
|
|
|
|
# Build a list of domain for which we want to sign emails
|
|
my @dkim_domains = ();
|
|
|
|
if ($dkim_sign =~ m/^enabled|yes|1|on$/){
|
|
foreach my $dom ($d->domains){
|
|
next if ($dom->prop('DKIMSigning') || 'enabled') eq 'disabled';
|
|
next if ($dom->prop('MailServer'));
|
|
push @dkim_domains, $dom->key;
|
|
}
|
|
}
|
|
|
|
|
|
sub wanted{
|
|
my $domain = $d->get($_);
|
|
if ( -l && !grep { $_ eq $domain->key } @dkim_domains ){
|
|
unlink $_;
|
|
}
|
|
}
|
|
|
|
foreach my $dom (@dkim_domains){
|
|
next if (-e '/var/service/qpsmtpd/config/dkim/' . $dom);
|
|
my $src = ( -e '/home/e-smith/dkim_keys/' . $dom ) ? '/home/e-smith/dkim_keys/' . $dom : '/home/e-smith/dkim_keys/default';
|
|
symlink $src, '/var/service/qpsmtpd/config/dkim/' . $dom;
|
|
}
|