Commit 96e3f771 authored by salaun's avatar salaun
Browse files

New feature: Alias manager, for installing/deleting sendmail aliases


git-svn-id: https://subversion.renater.fr/sympa/trunk@352 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent fe4897dc
......@@ -61,6 +61,16 @@ SHADED_COLOR = '\#eeeeee'
## Target directory for installing Icons
ICONSDIR = /home/httpd/icons
## Path to newaliases command (or what else may be called to rebuild
## Mail aliases database)
NEWALIASES = /usr/bin/newaliases
## The sendmail aliases file we use. Better use a seperate one for sympa.
## Of cause a extra alias file must be generated with proper permissions
## (owner sympa, write access for sympa, no write access for anyone else)
## and declared in sendmail.cf!
SENDMAIL_ALIASES= /etc/mail/sympa_aliases
## Path to gencat program (creates the .cat catalog file using the .msg)
GENCAT = /usr/bin/gencat
......@@ -117,7 +127,8 @@ sources:
DIR='${DIR}' BINDIR='${BINDIR}' WWSBINDIR='${WWSBINDIR}' \
MAILERPROGDIR='${MAILERPROGDIR}' ETCBINDIR='${ETCBINDIR}' \
CONFIG='${CONFIG}' WWSCONFIG='${WWSCONFIG}' \
USER='${USER}' GROUP='${GROUP}');
USER='${USER}' GROUP='${GROUP}' \
SENDMAIL_ALIASES='${SENDMAIL_ALIASES}' NEWALIASES='${NEWALIASES}');
doc: doc/sympa.tex
@echo "Making doc"
......@@ -155,7 +166,8 @@ installsrc:
DIR='${DIR}' BINDIR='${BINDIR}' WWSBINDIR='${WWSBINDIR}' MAILERPROGDIR='${MAILERPROGDIR}' \
DESTDIR='${DESTDIR}' DARK_COLOR='${DARK_COLOR}' LIGHT_COLOR='${LIGHT_COLOR}' \
TEXT_COLOR='${TEXT_COLOR}' BG_COLOR='${BG_COLOR}' ERROR_COLOR='${ERROR_COLOR}' \
SHADED_COLOR='${SHADED_COLOR}' CONFIG='${CONFIG}' WWSCONFIG='${WWSCONFIG}' ETCBINDIR='${ETCBINDIR}' \
SHADED_COLOR='${SHADED_COLOR}' CONFIG='${CONFIG}' WWSCONFIG='${WWSCONFIG}' \
ETCBINDIR='${ETCBINDIR}' SENDMAIL_ALIASES='${SENDMAIL_ALIASES}' \
USER='${USER}' GROUP='${GROUP}' newinstall) || exit 1;
installnls:
......@@ -163,6 +175,7 @@ installnls:
$(MAKE) SH='${SH}' CC='${CC}' CFLAGS='${CFLAGS}' PERL='${PERL}' \
DIR='${DIR}' NLSDIR='${NLSDIR}' ETCBINDIR='${ETCBINDIR}' \
DESTDIR='${DESTDIR}' CONFIG='${CONFIG}' WWSCONFIG='${WWSCONFIG}' \
SENDMAIL_ALIASES='${SENDMAIL_ALIASES}' \
USER='${USER}' GROUP='${GROUP}' GENCAT='${GENCAT}' newinstall) || exit 1;
installwws:
......
......@@ -2,7 +2,7 @@ CDEFS = -DCONFIG=\"$(CONFIG)\"
SRC = sympa.pl Archive.pm Commands.pm Conf.pm \
Language.pm List.pm Log.pm mail.pm msg.pl \
smtp.pm tools.pl Version.pm parser.pl
smtp.pm tools.pl Version.pm parser.pl alias_manager.pl
all: queue bouncequeue
......@@ -112,6 +112,7 @@ subst:
ETCBINDIR=$(ETCBINDIR); export ETCBINDIR;\
CONFIG=$(CONFIG); export CONFIG;\
SYMPA_VERSION=$(SYMPA_VERSION); export SYMPA_VERSION;\
SENDMAIL_ALIASES=$(SENDMAIL_ALIASES); export SENDMAIL_ALIASES;\
$(PERL) ../subst.pl $(SRC) \
)
......
#!--PERL--
# this script is intended to create automatically list aliases
# when using sympa. Aliases can be added or removed in file --SENDMAIL_ALIASES--
my $alias_file = '--SENDMAIL_ALIASES--';
my $tmp_alias_file = '/tmp/sympa_aliases.new';
my $default_domain;
my $path_to_queue = '--MAILERPROGDIR--/queue';
my $path_to_bouncequeue = '--MAILERPROGDIR--/bouncequeue';
my $sympa_conf_file = '--CONFIG--';
my ($operation, $listname, $domain) = @ARGV;
if (($#ARGV != 2)
|| ($operation !~ /^(add)|(del)$/)) {
printf "Usage: $0 <add|del> <listname> <domain>\n";
exit(1);
}
## Get default domain from sympa.conf
unless (open CONF, $sympa_conf_file) {
die "Could not read $sympa_conf_file";
}
while (<CONF>) {
if (/^\s*host\s+(\S+)\s*$/) {
$default_domain = $1;
last;
}
}
close CONF;
unless ($default_domain) {
print STDERR "Could not get default domain from $sympa_conf_file\n";
}
unless (-w "$alias_file") {
die "Unable to access to $alias_file";
}
if ($operation eq 'add') {
## Check existing aliases
exit(-1) if (&already_defined($listname.$suffix, $domain));
unless (open ALIAS, ">> $alias_file") {
die "Unable to append to $alias_file";
}
## Write aliases
print ALIAS "# --- aliases for list $listname\n";
foreach my $suffix ('', '-request', '-owner', '-unsubscribe') {
my $address = $listname . $suffix;
$address .= '@'.$domain
unless ($domain eq $default_domain);
if ($suffix eq '-owner') {
printf ALIAS "$address: \"\|$path_to_bouncequeue $listname\"\n";
}else {
printf ALIAS "$address: \"\|$path_to_queue $listname$suffix\"\n";
}
}
}elsif ($operation eq 'del') {
unless (open ALIAS, "$alias_file") {
die "Could not read $alias_file";
}
unless (open NEWALIAS, ">$tmp_alias_file") {
die "Could not create $tmp_alias_file";
}
my $deleted_lines;
FIC: while (<ALIAS>) {
if (/^\s*$listname/) {
foreach my $suffix ('', '-request', '-owner', '-unsubscribe') {
my $local = $listname . $suffix;
if (( /^\s*$local(\s*\:)/) ||
( ("$default_domain" eq "$domain") && (/^\s*$local\@/)) ||
( /^\s*$local\@$domain/)) {
## delete alias
$deleted_lines++;
next FIC;
}
}
}
## append to new aliases file
print NEWALIAS $_;
}
close ALIAS ;
close NEWALIAS;
print STDERR "No matching line in $alias_file\n"
unless $deleted_lines;
## replace old aliases file
unless (open NEWALIAS, "$tmp_alias_file") {
die "Could not read $tmp_alias_file";
}
unless (open OLDALIAS, ">$alias_file") {
die "Could not overwrite $alias_file";
}
print OLDALIAS <NEWALIAS>;
close OLDALIAS ;
close NEWALIAS;
}else {
die "Action $operation not implemented yet";
}
exit 0;
## Check if an alias is already defined
sub already_defined {
my $listname = shift;
my $domain = shift;
unless (open ALIAS, "$alias_file") {
die "Could not read $alias_file";
}
while (<ALIAS>) {
if (/^\s*$listname/) {
foreach my $suffix ('', '-request', '-owner', '-unsubscribe') {
my $local = $listname . $suffix;
if (( /^\s*$local(\s*\:)/) ||
( ("$default_domain" eq "$domain") && (/^\s*$local\@/)) ||
( /^\s*$local\@$domain/)) {
print STDERR "Alias already defined : $local\n";
return 1;
}
}
}
}
close ALIAS ;
return 0;
}
#!/usr/bin/perl
# this script is intended to create automatically list aliases
# when using sympa. Aliases can be added or removed in file $path_alias
my $path_alias = '/tmp/aliases.listes';
my $defaultdomaine = 'cru.fr';
($operation,$listname,$domaine,$path_to_queue,$path_to_bouncequeue) = @ARGV;
if (($#ARGV != 4)||($operation !~ /^(add)|(del)$/)) {
printf "Usage $ARGV[-1] <add|del> <listname> <domaine> <path_to_queue> <path_to_bouncequeue>\n";
exit(1);
}
unless (-w "$path_alias") {
printf "Unable to access to $path_alias \n";
exit(1);
}
if ("$operation" eq 'add') {
exit(1) if (&allready_defined($listname,$domaine));
exit(1) if (&allready_defined($listname-request,$domaine));
exit(1) if (&allready_defined($listname-owner,$domaine));
exit(1) if (&allready_defined($listname-unsubscribe,$domaine));
exit(1) if (&allready_defined($listname-subscribe,$domaine));
open ALIAS, ">> $path_alias";
printf ALIAS "$listname\@$domaine: \"\|$path_to_queue $listname\"\n";
printf ALIAS "$listname-request\@$domaine: \"\|$path_to_queue $listname-request\"\n";
printf ALIAS "$listname-unsubscribe\@$domaine: \"\|$path_to_queue $listname-unsubscribe\"\n";
printf ALIAS "\#$listname-subscribe\@$domaine: \"\|$path_to_queue $listname-subscribe\"\n";
printf ALIAS "$listname-owner\@$domaine: \"\|$path_to_bouncequeue $listname\"\n";
}
sub allready_defined {
my $local = shift;
my $domaine = shift;
open ALIAS, "$path_alias";
while (<ALIAS>) {
if (( /^\s*$local(\s*\:)/) ||
( ("$defaultdomaine" eq "$domaine") && (/^\s*$local\@/)) ||
( /^\s*$local\@$domaine/)) {
printf "alias allready exist : $local \n";
return undef;
}
}
close ALIAS ;
return (1);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment