From 06008e59a1dfbda99eace3d5e66d194b7e8e5c38 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 4 May 2012 09:02:59 +0200 Subject: Adding a flag --force --- fripost-newalias | 12 +++++++++--- fripost-searchalias | 8 ++++---- lib/Fripost/Schema/Type/Alias.pm | 5 ++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/fripost-newalias b/fripost-newalias index e00adcb..0ca009b 100755 --- a/fripost-newalias +++ b/fripost-newalias @@ -12,7 +12,7 @@ fripost-newalias - Add a new alias to the system =head1 SYNOPSIS B [B<--verbose>] [B<--debug>] [B<--pretend>] -[I [I...]] +[B<--force>] [I [I...]] =head1 DESCRIPTION @@ -32,6 +32,11 @@ B raises an error. Only simulates the insertion. (But still query the LDAP server to ensure that the virtual domains of aliases are know, for example.) +=item B<--force> + +Force creating the creation, even if I is already an alias. Also, +disable the sending of the confirmation. + =item B<--server_host=>I The LDAP URI to connect to. @@ -127,6 +132,7 @@ GetOptions( 'bind_dn=s' => \$conf->{bind_dn}, 'bind_pw=s' => \$conf->{bind_pw}, 'pretend' => \$conf->{pretend}, + 'force' => \$conf->{force}, 'debug' => \$conf->{debug}, 'v|verbose' => \$conf->{verbose}, 'man' => sub { pod2usage(-exitstatus => 0, @@ -178,7 +184,7 @@ confirm_or_abort(); ## Insert alias into database for my $addr (@addr) { my $rs = $ldap->alias->search({ address => $addr }); - if (!$rs->count) { + if (!$rs->count or defined $conf->{force}) { if (!$ldap->user->search({ username => $addr })->count) { if (!$conf->{pretend}) { $ldap->alias->add({ address => $addr, goto => $goto, @@ -218,7 +224,7 @@ my $msg = MIME::Lite->new( Encoding => 'quoted-printable', ); -{ +unless (defined $conf->{force}) { my ($vars, $data); $vars = { addrs => \@addr, diff --git a/fripost-searchalias b/fripost-searchalias index 2e5d35f..1c674fe 100755 --- a/fripost-searchalias +++ b/fripost-searchalias @@ -17,8 +17,8 @@ B [B<--debug>] [I [I]] B list virtual aliases matching exactly I, targetting to I. -Wildcards I<*> can appear in I or I, to match zero or more -characters. +Wildcards I<*> can appear in the login part of I, to match zero +or more characters. If no I is given, list all aliases whose target matches I. If neither I nor I are given, B list all existing virtual aliases. @@ -115,8 +115,8 @@ GetOptions( my $ldap = Fripost::Schema->new( $conf ); my %alias; -$alias{goto} = $ARGV[0] if defined $ARGV[0]; -$alias{address} = $ARGV[1] if defined $ARGV[1]; +$alias{goto} = $ARGV[0] if (defined $ARGV[0]) and $ARGV[0] ne ''; +$alias{address} = $ARGV[1] if (defined $ARGV[1]) and $ARGV[1] ne ''; if (defined $alias{address}) { my ($u,$d) = split /\@/, $alias{address}, 2; diff --git a/lib/Fripost/Schema/Type/Alias.pm b/lib/Fripost/Schema/Type/Alias.pm index 8c0b25e..dee2fbc 100644 --- a/lib/Fripost/Schema/Type/Alias.pm +++ b/lib/Fripost/Schema/Type/Alias.pm @@ -21,7 +21,10 @@ sub search { my ($username, $domain); ($username, $domain) = split /\@/, $alias->{address}, 2 if defined $alias->{address}; - $domain = $username if (defined $username) and not (defined $domain); + if ((defined $username) and not (defined $domain)) { + $domain = $username; + undef $username; + } my $base = $self->{_options}->{base_dn}; $base = join ',', ( 'dc='.$domain, $base ) -- cgit v1.2.3