aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2012-05-31 18:30:22 +0200
committerGuilhem Moulin <guilhem.moulin@fripost.org>2012-05-31 18:30:22 +0200
commit0461d89edb3f8e272697726208ab7747c30a81df (patch)
treeaf9b674793f2e10f8889a4d5a10949f301626989
parentea06aa8c41d103ff161630fd85d083b9ed6f0b41 (diff)
Catch-All aliases.
-rw-r--r--TODO.org18
-rwxr-xr-xfripost-newalias63
-rwxr-xr-xfripost-newdomain10
3 files changed, 65 insertions, 26 deletions
diff --git a/TODO.org b/TODO.org
index b065808..3da47af 100644
--- a/TODO.org
+++ b/TODO.org
@@ -1,6 +1,18 @@
# -*- mode: org-mode; truncate-lines: nil -*-
* Planned
-** Send email to newly created users
-** Log changes in log table
-
+** DONE Send email to newly created users
+** TODO Log changes in log table
+** TODO Add a flag `--send=EMAIL' to `fripost-passwd' to send the new password to an email
+** TODO Add flags `--sign=KEY' and `--encrypt=KEY' (and extend the configuration file) to respectively sign and encrypt outgoing emails.
+** TODO Detect cycles when creating aliases. (E.g., a->b, b->a should not be allowed.)
+** TODO Add a subroutine is_email_valid with options (e.g., `allow_empty_login'), and add options to prompt_email (e.g., `allow_list', `allow_empty_login', `ensure_domain_known', `ensure_user_known', `allow_empty_user').
+** TODO Merge the tools into a single executable?
+*** fripost-adduser -> fripost user add
+*** fripost-mkpass -> fripost mkpass
+*** fripost-newalias -> fripost alias add
+*** fripost-newdomain -> fripost domain add
+*** fripost-passwd -> fripost user passwd
+*** fripost-searchalias -> fripost alias search
+*** fripost-searchdomain -> fripost domain search
+*** fripost-searchuser -> fripost user search
diff --git a/fripost-newalias b/fripost-newalias
index 0ca009b..3fc68f8 100755
--- a/fripost-newalias
+++ b/fripost-newalias
@@ -23,6 +23,33 @@ If I<goto> is not fully qualified, C<fripost.org> is appended.
If I<from> is already an existing username or alias,
B<fripost-newalias> raises an error.
+Inserted aliases conform to Postfix's B<virtual>(5) alias table format,
+with the restriction that I<from> has to be either in the form:
+
+=over 4
+
+=item .
+
+I<user>@I<domain>, to redirect emails for I<user>@I<domain> to I<goto>, or
+
+=item .
+
+@I<domain>, to catch all emails for users in I<domain> and redirect them
+to I<goto>.
+This form has the lowest precedence: If there is an alias from
+I<user>@I<domain> to I<goto2>, emails to I<user>@I<domain> will be
+redirected to I<goto2> only.
+See B<virtual>(5) for details and warnings.
+
+=back
+
+If serveral entries are matching, for instance if there are an alias from
+I<user>@I<domain> to I<goto> and another for I<user>@I<domain> to
+I<goto2>, emails to I<user>@I<domain> will be redirected to BOTH I<goto>
+and I<goto2>. Note that B<fripost-newalias> forbids the creation of such
+aliases, unless B<--force> is set.
+
+
=head1 OPTIONS
=over 8
@@ -157,7 +184,7 @@ say "goto adress: $goto";
# Show from adresses
@addr = grep {
- if (Email::Valid->address($_)) {
+ if (Email::Valid->address('fake'.$_)) {
# Warn if the domain is unknown.
my $domain = (split /\@/, $_, 2)[1];
if ($ldap->domain->search({ domain => $domain })->count) {
@@ -183,28 +210,30 @@ confirm_or_abort();
## Insert alias into database
for my $addr (@addr) {
- my $rs = $ldap->alias->search({ address => $addr });
- if (!$rs->count or defined $conf->{force}) {
- if (!$ldap->user->search({ username => $addr })->count) {
- if (!$conf->{pretend}) {
- $ldap->alias->add({ address => $addr, goto => $goto,
- isActive => 'TRUE' });
- say "New alias added from $addr to $goto.";
- } else {
- vsay "Pretending, will not add alias."
- }
- }
- else {
- die "Error: Username $addr already exists.\n";
- }
- }
- else {
+
+ my ($u,$d) = split /\@/, $addr, 2;
+ my $rs;
+
+ # Ensure that the alias doesn't already exist.
+ $rs = $ldap->alias->search({ address => $addr });
+ if ($rs->count and not (defined $conf->{force})) {
print STDERR "Error: Alias $addr already exists. ";
print STDERR "(Targetting to ";
print STDERR (join ', ', map { $_->{goto} } $rs->entries);
say STDERR ".)";
exit 1;
}
+
+ die "Error: Username $addr exists.\n"
+ if ($ldap->user->search({ username => $addr })->count);
+
+ if (!$conf->{pretend}) {
+ $ldap->alias->add({ address => $addr, goto => $goto,
+ isActive => 'TRUE' });
+ say "New alias added from $addr to $goto.";
+ } else {
+ vsay "Pretending, will not add alias."
+ }
}
$ldap->unbind();
diff --git a/fripost-newdomain b/fripost-newdomain
index 5c4c2fb..2f204ee 100755
--- a/fripost-newdomain
+++ b/fripost-newdomain
@@ -150,7 +150,7 @@ $domain{domain} //= prompt "Domain name: ";
$domain{isActive} = 'TRUE';
# Ensure that the domain is valid.
-Email::Valid->address('test@'.$domain{domain})
+Email::Valid->address('fake@'.$domain{domain})
or die "Error: Invalid domain `$domain{domain}'.\n";
if (defined $conf->{owner}) {
@@ -220,7 +220,7 @@ else {
# Create aliases.
sub create_alias {
- my ($ldap, $from, $to, $owner) = @_;
+ my ($ldap, $from, $to) = @_;
my %alias = (address => $from, goto => $to);
@@ -233,15 +233,13 @@ sub create_alias {
return unless grep { $_->{goto} eq $alias{goto} } $res->entries;
}
- $alias{owner} = $owner if defined $owner;
$alias{isActive} = 'TRUE';
$ldap->alias->add( \%alias );
say "Created alias from $from to $to.";
}
-create_alias($ldap, 'abuse@' . $domain{domain} ,'abuse@fripost.org', $domain{owner});
-create_alias($ldap, 'postmaster@' . $domain{domain},'postmaster@fripost.org', $domain{owner});
-
+create_alias($ldap, 'abuse@' . $domain{domain} ,'abuse@fripost.org');
+create_alias($ldap, 'postmaster@' . $domain{domain},'postmaster@fripost.org');
$ldap->unbind();