majordomo2mailman.pl [plain text]
use strict;
use Getopt::Long;
use Fcntl;
use POSIX qw (tmpnam);
use vars qw (
$majordomo $mydomain $myurl
$aliasin $listdir
$aliasout $mailmanbin
$umbrella_member_suffix $private
$newsserver $newsprefix
$susehack $susearchuser
$help $debug $update $all $usagemsg
*FH
%mlaliases %mlowners %mlapprovers
%defaultmlconf %mlconf
%defaultmmconf %mmconf
);
$mydomain = "my.domain";
$majordomo = "majordomo"; $aliasin = "/var/lib/majordomo/aliases";
$listdir = "/var/lib/majordomo/lists";
$aliasout = "/tmp/aliases";
$myurl = "http://my.domain/mailman/";
$mailmanbin = "/usr/lib/mailman/bin";
$umbrella_member_suffix = "-owner";
$private = "yes"; $newsserver = "news.my.domain";
$newsprefix = "intern.";
$susehack = "no";
$susearchuser = "archdummy";
$usagemsg = "usage: majordomo2mailman [-h|--help] [-d|--debug] [-u|--update] < (-a|--all) | list-of-mailinglists >";
GetOptions(
"h|help" => \$help,
"d|debug" => \$debug,
"a|all" => \$all,
"u|update" => \$update
) or die "$usagemsg\n";
if (defined($help)) { die "$usagemsg\n"; }
if ((not defined($all)) and (@ARGV<1)) { die "$usagemsg\n"; }
if ($<) { die "this script must be run as root!\n"; }
%mlaliases = %mlowners = %mlapprovers = ();
open (FH, "< $aliasin") or die "can't open $aliasin\n";
while (<FH>) {
if (/^([^\ $mlaliases{$1} = $2;
}
}
my $mlalias;
for $mlalias (keys %mlaliases) {
if ($mlaliases{$mlalias} =~ /\:include\:/) {
my $ml;
($ml = $mlalias) =~ s/-outgoing//g;
$mlowners{$ml} = $mlaliases{"owner-$ml"};
$mlapprovers{$ml} = $mlaliases{"$ml-approval"};
}
}
close (FH);
my $ml;
for $ml ((defined ($all)) ? sort keys %mlowners : @ARGV) {
init_defaultmlconf($ml);
%mlconf = %defaultmlconf;
init_defaultmmconf($ml);
%mmconf = %defaultmmconf;
my @privileged; my @members;
my ($primaryowner, @secondaryowner);
my ($primaryapprover, @secondaryapprover);
my ($skey, $terminator);
my $filename;
my @args;
open (FH, "< $listdir/$ml.config") or die "can't open $listdir/$ml.config\n";
while (<FH>) {
if (/^\s*([^=\ $mlconf{$1} = $2;
}
elsif (/^\s*([^<\ ($skey, $terminator) = ($1, $2);
while (<FH>) {
last if (/^$terminator\s*$/);
$mlconf{$skey} .= $_;
}
chomp $mlconf{$skey};
}
}
close (FH);
if ( -e "$listdir/$ml.private") {
$mlconf{"get_access"} = "closed";
$mlconf{"index_access"} = "closed";
$mlconf{"who_access"} = "closed";
$mlconf{"which_access"} = "closed";
}
$mlconf{"subscribe_policy"} = "closed" if ( -e "$listdir/$ml.closed");
$mlconf{"unsubscribe_policy"} = "closed" if ( -e "$listdir/$ml.closed");
if ( -e "$listdir/$ml.auto" && -e "$listdir/$ml.closed") {
print STDERR "sowohl $ml.auto als auch $ml.closed existieren. Wähle $ml.closed\n";
}
else {
$mlconf{"subscribe_policy"} = "auto" if ( -e"$listdir/$ml.auto");
$mlconf{"unsubscribe_policy"} = "auto" if ( -e"$listdir/$ml.auto");
}
$mlconf{"strip"} = 1 if ( -e "$listdir/$ml.strip");
$mlconf{"noadvertise"} = "/.*/" if ( -e "$listdir/$ml.hidden");
$filename = "$listdir/" . $mlconf{"admin_passwd"};
if ( -e "$listdir/$ml.passwd" ) {
$mlconf{"admin_passwd"} = read_from_file("$listdir/$ml.passwd");
}
elsif ( -e "$filename" ) {
$mlconf{"admin_passwd"} = read_from_file("$filename");
}
$filename = "$listdir/" . $mlconf{"approve_passwd"};
if ( -e "$listdir/$ml.passwd" ) {
$mlconf{"approve_passwd"} = read_from_file("$listdir/$ml.passwd");
}
elsif ( -e "$filename" ) {
$mlconf{"approve_passwd"} = read_from_file("$filename");
}
if (defined ($mlconf{"restrict_post"})) {
@privileged = ();
for $filename (split /\s+/, $mlconf{"restrict_post"}) {
open (FH, "< $listdir/$filename") or die "can't open $listdir/$filename\n";
push (@privileged, <FH>);
chomp @privileged;
close (FH);
}
}
if ($susehack =~ m/yes/i) {
@privileged = grep(!/$susearchuser\@$mydomain/i, @privileged);
}
$mlconf{"privileged"} = \@privileged;
@members = ();
open (FH, "< $listdir/$ml") or die "can't open $listdir/$ml\n";
push (@members, <FH>);
chomp @members;
close (FH);
$mlconf{"gated"} = "no";
if ($susehack =~ m/yes/i) {
if (grep(/$susearchuser\@$mydomain/i, @members)) {
$mlconf{"gated"} = "yes";
}
@members = grep(!/$susearchuser\@$mydomain/i, @members);
}
$mlconf{"members"} = \@members;
if (open (FH, "< $listdir/$ml.intro")) {
{ local $/; $mlconf{"intro"} = <FH>; }
}
else { $mlconf{"intro"} = ""; }
if (open (FH, "< $listdir/$ml.info")) {
{ local $/; $mlconf{"info"} = <FH>; }
}
else { $mlconf{"info"} = ""; }
$mlconf{"name"} = "$ml";
($primaryowner, @secondaryowner) =
expand_alias (split (/\s*,\s*/, aliassub($mlowners{$ml})));
($primaryapprover, @secondaryapprover) =
expand_alias (split (/\s*,\s*/, aliassub($mlapprovers{$ml})));
$mlconf{"primaryowner"} = $primaryowner;
$mlconf{"secondaryowner"} = \@secondaryowner;
$mlconf{"primaryapprover"} = $primaryapprover;
$mlconf{"secondaryapprover"} = \@secondaryapprover;
if (defined ($debug)) {
print "##################### $ml ####################\n";
for $skey (sort keys %mlconf) {
if (defined ($mlconf{$skey})) { print "$skey = $mlconf{$skey}\n"; }
else { print "$skey = (?)\n"; }
}
my $priv;
for $priv (@privileged) {
print "\t$ml: $priv\n";
}
}
if (defined($update)) {
print "updating configuration of \"$ml\"\n";
}
else {
@args = ("$mailmanbin/newlist", "-q", "-o", "$aliasout", "$ml", $mlconf{"primaryowner"}, $mlconf{"admin_passwd"});
system (@args) == 0 or die "system @args failed: $?";
}
if (@members > 0) {
$filename = tmpnam();
open (FH, "> $filename") or die "can't open $filename\n";
for $skey (@members) {
print FH "$skey" . "\n";
}
close (FH);
@args = ("$mailmanbin/add_members", "-n", "$filename", "--welcome-msg=n", "$ml");
system (@args) == 0 or die "system @args failed: $?";
}
m2m();
$filename = tmpnam();
open (FH, "> $filename") or die "can't open $filename\n";
for $skey (sort keys %mmconf) {
print FH "$skey = " . $mmconf{$skey} . "\n";
}
close (FH);
@args = ("$mailmanbin/config_list", "-i", "$filename", "$ml");
system (@args) == 0 or die "system @args failed: $?";
unlink($filename) or print STDERR "unable to unlink \"$filename\"!\n";
}
exit 0;
sub read_from_file {
my $value;
local *FH;
open (FH, "< $_[0]") or die "can't open $_[0]\n";
$value = <FH>;
chomp $value;
close (FH);
return $value;
}
sub expand_alias {
return map { (not $_ =~ /@/) ? $_ .= "\@$mydomain" : $_ } @_;
}
sub aliassub {
my $string = $_[0];
$string =~ s/(owner-$majordomo|$majordomo-owner)/mailman-owner/gi;
return $string;
}
sub init_defaultmlconf {
my $ml = $_[0];
%defaultmlconf=(
'welcome', "yes",
'announcements', "yes",
'get_access', "open",
'index_access', "open",
'who_access', "open",
'which_access', "open",
'info_access', "open",
'intro_access', "open",
'advertise', "",
'noadvertise', "",
'description', "",
'subscribe_policy', "open",
'unsubscribe_policy', "open",
'mungedomain', "no",
'admin_passwd', "$ml.admin",
'strip', "yes",
'date_info', "yes",
'date_intro', "yes",
'archive_dir', "",
'moderate', "no",
'moderator', "",
'approve_passwd', "$ml.pass",
'sender', "owner-$ml",
'maxlength', "40000",
'precedence', "bulk",
'reply_to', "",
'restrict_post', "",
'purge_received', "no",
'administrivia', "yes",
'resend_host', "",
'debug', "no",
'message_fronter', "",
'message_footer', "",
'message_headers', "",
'subject_prefix', "",
'taboo_headers', "",
'taboo_body', "",
'digest_volume', "1",
'digest_issue', "1",
'digest_work_dir', "",
'digest_name', "$ml",
'digest_archive', "",
'digest_rm_footer', "",
'digest_rm_fronter', "",
'digest_maxlines', "",
'digest_maxdays', "",
'comments', ""
);
}
sub init_defaultmmconf {
%defaultmmconf=(
'goodbye_msg', "\'\'",
'umbrella_list', "0",
'umbrella_member_suffix', "\'$umbrella_member_suffix\'",
'send_reminders', "0",
'admin_immed_notify', "1",
'admin_notify_mchanges', "0",
'dont_respond_to_post_requests', "0",
'obscure_addresses', "1",
'require_explicit_destination', "1",
'acceptable_aliases', "\"\"\"\n\"\"\"\n",
'max_num_recipients', "10",
'forbidden_posters', "[]",
'bounce_matching_headers', "\"\"\"\n\"\"\"\n",
'anonymous_list', "0",
'nondigestable', "1",
'digestable', "1",
'digest_is_default', "0",
'mime_is_default_digest', "0",
'digest_size_threshhold', "40",
'digest_send_periodic', "1",
'digest_header', "\'\'",
'bounce_processing', "1",
'minimum_removal_date', "4",
'minimum_post_count_before_bounce_action', "3",
'max_posts_between_bounces', "5",
'automatic_bounce_action', "3",
'archive_private', "0",
'clobber_date', "1",
'archive_volume_frequency', "1",
'autorespond_postings', "0",
'autoresponse_postings_text', "\'\'",
'autorespond_admin', "0",
'autoresponse_admin_text', "\'\'",
'autorespond_requests', "0",
'autoresponse_request_text', "\'\'",
'autoresponse_graceperiod', "90"
);
}
sub m2m {
my $elem;
my $admin;
$mmconf{"real_name"} = "\'" . $mlconf{"name"} . "\'";
for $admin (($mlconf{"primaryowner"}, @{$mlconf{"secondaryowner"}},
$mlconf{"primaryapprover"}, @{$mlconf{"secondarapprover"}})) {
if (lc($admin) ne lc("owner-" . $mlconf{"name"} . "\@" . $mydomain)) {
$mmconf{"owner"} .= ",\'" . "$admin" . "\'";
}
}
$mmconf{"owner"} =~ s/^,//g;
$mmconf{"owner"} = "\[" . $mmconf{"owner"} . "\]";
($mmconf{"description"} = $mlconf{"description"}) =~ s/\'/\\\'/g;
$mmconf{"description"} = "\'" . $mmconf{"description"} . "\'";
$mmconf{"info"} = "\"\"\"\n" . $mlconf{"info"} . "\"\"\"\n";
$mmconf{"subject_prefix"} = "\'" . $mlconf{"subject_prefix"} . "\'";
$mmconf{"welcome_msg"} = "\"\"\"\n" . $mlconf{"intro"} . "\"\"\"\n";
if ($mlconf{"reply_to"} =~ /\S+/) {
if ($mlconf{"name"} . "\@" =~ m/$mlconf{"reply_to"}/i) {
$mmconf{"reply_goes_to_list"} = "1";
$mmconf{"reply_to_address"} = "\'\'";
}
else {
$mmconf{"reply_goes_to_list"} = "2";
$mmconf{"reply_to_address"} = "\'" . $mlconf{"reply_to"} . "\'";
}
}
else {
$mmconf{"reply_goes_to_list"} = "0";
$mmconf{"reply_to_address"} = "\'\'";
}
$mmconf{"administrivia"} = ($mlconf{"administrivia"} =~ m/yes/i) ? "1" : "0";
$mmconf{"send_welcome_msg"} = ($mlconf{"welcome"} =~ m/yes/i) ? "1" : "0";
$mmconf{"max_message_size"} = int ($mlconf{"maxlength"} / 1000);
$mmconf{"host_name"} = ($mlconf{"resend_host"} =~ /\S+/) ?
$mlconf{"resend_host"} : "\'" . $mydomain . "\'";
$mmconf{"web_page_url"} = "\'" . $myurl . "\'";
$mmconf{"advertised"} = ($mlconf{"noadvertise"} =~ /\.\*/) ? "0" : "1";
$mmconf{"subscribe_policy"} =
($mlconf{"subscribe_policy"} =~ m/(open|auto)/i) ? "1" :
($private =~ m/yes/i) ? "2" : "3";
$mmconf{"private_roster"} =
($mlconf{"who_access"} =~ m/open/i and not $private =~ m/yes/i) ? "0" :
($mlconf{"who_access"} =~ m/open|list/i) ? "1" : "2";
$mmconf{"moderated"} = ($mlconf{"moderate"} =~ m/yes/i) ? "1" : "0";
mm_posters();
if ($mlconf{"message_fronter"} =~ /\S+/) {
$mmconf{"msg_header"} = "\"\"\"\n" . $mlconf{"message_fronter"} . "\"\"\"\n";
}
else {
$mmconf{"msg_header"} = "\'\'";
}
if ($mlconf{"message_footer"} =~ /\S+/) {
$mmconf{"msg_footer"} = "\"\"\"\n" . $mlconf{"message_footer"} . "\"\"\"\n";
}
else {
$mmconf{"msg_footer"} = "\'\'";
}
$mmconf{"nntp_host"} = "\'" . $newsserver . "\'";
$mmconf{"linked_newsgroup"} = "\'" . $newsprefix . $mlconf{"name"} . "\'";
if ($mlconf{"gated"} =~ m/yes/i) {
$mmconf{"gateway_to_news"} = "1";
$mmconf{"gateway_to_mail"} = "1";
$mmconf{"archive"} = "1";
}
else {
$mmconf{"gateway_to_news"} = "0";
$mmconf{"gateway_to_mail"} = "0";
$mmconf{"archive"} = "0";
}
for $elem (@{$mlconf{"privileged"}}, @{$mlconf{"members"}}) {
$elem =~ s/\@$mydomain//gi;
if (defined($mlaliases{$elem . $umbrella_member_suffix})) {
print STDERR "\"" . $mlconf{"name"} .
"\" possibly forms part off/is an umbrella list, since \"$elem\" is a local mailing list alias\n";
}
}
if ($mlconf{"taboo_headers"} =~ /\S+/ or $mlconf{"taboo_body"} =~ /\S+/) {
print STDERR "\"" . $mlconf{"name"} . "\" taboo_headers or taboo_body seem to be set - please check manually.\n";
}
}
sub mm_posters {
if ($mlconf{"restrict_post"} =~ /\S+/) {
my %privileged = ();
my %members = ();
my $key;
foreach $key (@{$mlconf{"privileged"}}) { $privileged{$key} = "OK"; }
foreach $key (@{$mlconf{"members"}}) { $members{$key} = "OK"; }
my $included = 1;
foreach $key (keys %members) {
if (not exists $privileged{$key}) {
$included = 0;
last;
}
}
if ($included) {
$mmconf{"member_posting_only"} = "1";
my %diff = %privileged;
foreach $key (keys %members) {
delete $diff{$key} if exists $members{$key};
}
$mmconf{"posters"} = "";
for $key (sort keys %diff) {
$mmconf{"posters"} .= ",\'" . $key . "\'";
}
$mmconf{"posters"} =~ s/^,//g;
$mmconf{"posters"} = "[" . $mmconf{"posters"} . "]";
}
else {
$mmconf{"member_posting_only"} = "0";
$mmconf{"posters"} = "";
for $key (sort keys %privileged) {
$mmconf{"posters"} .= ",\'" . $key . "\'";
}
$mmconf{"posters"} =~ s/^,//g;
$mmconf{"posters"} = "[" . $mmconf{"posters"} . "]";
}
}
else {
$mmconf{"member_posting_only"} = "0";
$mmconf{"posters"} = "[]";
}
}