aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xfripost-adduser13
-rwxr-xr-xfripost-newdomain11
-rw-r--r--lib/Fripost/Schema/Search.pm7
-rw-r--r--lib/Fripost/Schema/Type/Alias.pm20
-rw-r--r--lib/Fripost/Schema/Type/User.pm4
5 files changed, 30 insertions, 25 deletions
diff --git a/fripost-adduser b/fripost-adduser
index a3c78a8..f509e49 100755
--- a/fripost-adduser
+++ b/fripost-adduser
@@ -161,12 +161,11 @@ my ($domain, $login);
if (defined $ARGV[0]) {
$username = fix_username ($ARGV[0]);
Email::Valid->address($username)
- or die "Error: `" .$username. "' is not a valid e-mail.\n";
+ or die "Error: $username is not a valid e-mail.\n";
}
else {
$username = prompt_email("New username: ", 'is_user');
}
- # TODO: Ensure that the domain is valid.
($login, $domain) = split /\@/, $username, 2;
my $maildir = "$domain/$login/Maildir/"; # Trailing slash important
my $isActive = 'TRUE';
@@ -197,14 +196,14 @@ my ($domain, $login);
{
# Ensure that the username doesn't already exist.
die "Error: User `" .$user->{username}. "' already exists.\n"
- if $ldap->user->search($user->{username})->count;
+ if $ldap->user->search({ username => $user->{username} })->count;
# Ensure that the username doesn't correspond to an existing alias.
my $res = $ldap->alias->search({ address => $user->{username} });
if ($res->count) {
- print STDERR "Error: Alias `" .$user->{username}. "' already exists. ";
+ print STDERR "Error: Alias $user->{username} already exists. ";
print STDERR "(Targetting to ";
- print STDERR (join ', ', map { '`' .$_->{goto}. "'"} ($res->entries));
+ print STDERR (join ', ', map { $_->{goto} } ($res->entries));
say STDERR ".)";
exit 1;
}
@@ -237,8 +236,8 @@ my $tt = Template->new({
INTERPOLATE => 1,
}) || die "$Template::ERROR\n";
-my $admin_email = 'admin@fripost.org';
-$admin_email = $conf->{admin_email} if defined $conf->{admin_email};
+my $admin_email = $conf->{admin_email};
+$admin_email //= 'admin@fripost.org';
my $msg = MIME::Lite->new(
From => encode('MIME-Q', 'Friposts administratörer') . ' <' .$admin_email. '>',
diff --git a/fripost-newdomain b/fripost-newdomain
index 8ab48bf..0e1cb37 100755
--- a/fripost-newdomain
+++ b/fripost-newdomain
@@ -156,7 +156,7 @@ if (defined $conf->{owner}) {
}
else {
Email::Valid->address($conf->{owner})
- or die "Error: `" .$conf->{owner}. "' is not a valid e-mail.\n";
+ or die "Error: $conf->{owner} is not a valid e-mail.\n";
$domain{owner} = $conf->{owner};
}
}
@@ -169,7 +169,7 @@ else {
# Check that the owner exists.
die "Error: Unknown user `" .$domain{owner}. "'.\n"
unless (not defined $domain{owner})
- or $ldap->user->search($domain{owner})->count;
+ or $ldap->user->search({ username => $domain{owner} })->count;
# Check that the owner doesn't already own this very domain, or that the
# domain isn't an existing "global" domain.
@@ -223,9 +223,9 @@ sub create_alias {
my $res = $ldap->alias->search(\%alias);
if ($res->count) {
- print STDERR "WARN: Alias `" .$alias{address}. "' already exists.";
+ print STDERR "WARN: Alias $alias{address} already exists.";
print STDERR "(Targetting to ";
- print STDERR (join ', ', map { '`' .$_->{goto}. "'"} ($res->entries));
+ print STDERR (join ', ', map { $_->{goto} } ($res->entries));
say STDERR ".)";
return unless grep { $_->{goto} eq $alias{goto} } $res->entries;
}
@@ -239,6 +239,9 @@ sub create_alias {
create_alias($ldap, 'abuse@' . $domain{domain} ,'abuse@fripost.org', $domain{owner});
create_alias($ldap, 'postmaster@' . $domain{domain},'postmaster@fripost.org', $domain{owner});
+$ldap->unbind();
+
+
=head1 AUTHOR
Stefan Kangas C<< <skangas at skangas.se> >>
diff --git a/lib/Fripost/Schema/Search.pm b/lib/Fripost/Schema/Search.pm
index 30d92d6..7c0ece6 100644
--- a/lib/Fripost/Schema/Search.pm
+++ b/lib/Fripost/Schema/Search.pm
@@ -51,11 +51,8 @@ sub _domainEntry {
my $entry = shift;
my %domain;
&_get_values( $entry, \%domain, 'domain', 'dc');
- &_get_values( $entry, \%domain, 'isActive');
- my $parent = &_get_dn($entry)->[1];
- unless ($parent eq 'ou=domains') {
- $domain{owner} = (split /=/, $parent, 2)[1];
- }
+ map { &_get_values($entry, \%domain, $_) }
+ qw /isActive owner/;
return \%domain;
}
diff --git a/lib/Fripost/Schema/Type/Alias.pm b/lib/Fripost/Schema/Type/Alias.pm
index fa78d6f..7949b4b 100644
--- a/lib/Fripost/Schema/Type/Alias.pm
+++ b/lib/Fripost/Schema/Type/Alias.pm
@@ -14,10 +14,15 @@ our $VERSION = '0.01';
# alias is given, returns all aliases.
# Filters on values of both keys `address' and `goto' (unless they are
# undefined).
+# An extra key `domain' can be given to scope the search on aliases for
+# this domain only.
sub search {
my $self = shift;
- my $base = $self->{_options}->{base_dn};
+ my $base = join ',', ( 'ou=domains'
+ , $self->{_options}->{base_dn} );
+ $base = 'dc='.$_[0]->{domain} .','. $base
+ if defined $_[0]->{domain};
my @filters = ('(ObjectClass=virtualAliases)');
push @filters, '(mailLocalAddress=' .$_[0]->{address}. ')'
@@ -54,15 +59,15 @@ sub add {
"' targetting to itself.\n"
if $alias->{address} eq $alias->{goto};
+ my $domain = (split /\@/, $alias->{address}, 2)[1];
my $base = join ',', ( 'mailTarget='.$alias->{goto}
- , 'dc='. (split /\@/, $alias->{address}, 2)[1]
+ , 'dc='. $domain
, 'ou=domains'
, $self->{_options}->{base_dn} );
- my @attrs = ( mailLocalAddress => $alias->{address}
- , isActive => $alias->{isActive} );
+ my @attrs = ( mailLocalAddress => $alias->{address} );
my $res;
- if ($self->search($alias)->count) {
+ if ($self->search({ goto => $alias->{goto}, domain => $domain })->count) {
$res = $self->{_ldap}->modify( $base, add => [ @attrs ] );
}
else {
@@ -70,8 +75,9 @@ sub add {
attrs => [ mailTarget => $alias->{goto}
, objectClass => [ 'top',
'inetLocalMailRecipient',
- 'virtualAliases' ],
- @attrs
+ 'virtualAliases' ]
+ , @attrs
+ , isActive => $alias->{isActive}
]
);
}
diff --git a/lib/Fripost/Schema/Type/User.pm b/lib/Fripost/Schema/Type/User.pm
index 09c3aa0..544687c 100644
--- a/lib/Fripost/Schema/Type/User.pm
+++ b/lib/Fripost/Schema/Type/User.pm
@@ -19,8 +19,8 @@ sub search {
my $base = join ',', ('ou=mailboxes',$self->{_options}->{base_dn});
my $filter = "(ObjectClass=virtualMailbox)";
- $filter = "(&" .$filter. "(uid=" .$_[0]. ")" .")"
- if defined $_[0];
+ $filter = "(&" .$filter. "(uid=" .$_[0]->{username}. ")" .")"
+ if defined $_[0]->{username};
my $res = $self->{_ldap}->search(
base => $base,