From 69dd95827b2da92b34f3b14f4f69465c6daf78c2 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 28 May 2012 01:56:04 +0200 Subject: searchalias: Match 'from' and 'goto' address by default --- fripost-searchalias | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/fripost-searchalias b/fripost-searchalias index 1c674fe..719cd01 100755 --- a/fripost-searchalias +++ b/fripost-searchalias @@ -11,7 +11,7 @@ fripost-searchalias - List matching aliases =head1 SYNOPSIS -B [B<--debug>] [I [I]] +B [B<--debug>] [B<--from>] [B<--goto>] [I] =head1 DESCRIPTION @@ -52,6 +52,16 @@ The default value is read from the configuration file, see B. Debug mode. +=item B<--from> + +Match on 'from' addresses. +The default is to match both the 'from' and 'goto' address. + +=item B<--goto> + +Match on 'goto' addresses. +The default is to match both the 'from' and 'goto' address. + =back =head1 CONFIGURATION @@ -106,6 +116,8 @@ GetOptions( 'bind_pw=s' => \$conf->{bind_pw}, 'pretend' => \$conf->{pretend}, 'debug' => \$conf->{debug}, + 'from' => \$conf->{from}, + 'goto' => \$conf->{goto}, 'man' => sub { pod2usage(-exitstatus => 0, -verbose => 2) } ) or pod2usage(2); @@ -114,24 +126,37 @@ GetOptions( # Connect to the LDAP server my $ldap = Fripost::Schema->new( $conf ); -my %alias; -$alias{goto} = $ARGV[0] if (defined $ARGV[0]) and $ARGV[0] ne ''; -$alias{address} = $ARGV[1] if (defined $ARGV[1]) and $ARGV[1] ne ''; +sub perform_search { + my %alias = @_; -if (defined $alias{address}) { - my ($u,$d) = split /\@/, $alias{address}, 2; - $d = $u if (defined $u) and not (defined $d); - $ldap->domain->search({ domain => $d })->count - or die "Error: Unknown domain `$d'.\n"; + foreach my $alias ($ldap->alias->search( \%alias )->entries) { + say "From: " . (join ', ', @{$alias->{address}}); + say "Goto: " . $alias->{goto}; + say "IsActive: " . $alias->{isActive}; + say "--------------------------------" + } } -foreach my $alias ($ldap->alias->search( \%alias )->entries) { - say "From: " . (join ', ', @{$alias->{address}}); - say "Goto: " . $alias->{goto}; - say "IsActive: " . $alias->{isActive}; - say "--------------------------------" +my $f = $conf->{from}; +my $g = $conf->{goto}; +my $from ||= $f || not $f && not $g; +my $goto ||= $g || not $f && not $g; + +if ($g) { + say " Searchin 'goto'"; + perform_search(goto => $ARGV[0]); } +if ($f) { + say " Searchin 'from'"; + perform_search(address => $ARGV[0]); + + my ($u,$d) = split /\@/, $ARGV[0], 2; + $d = $u if (defined $u) and not (defined $d); + $ldap->domain->search({ domain => $d })->count + or die "Error: Unknown domain `$d'.\n"; +} + $ldap->unbind(); -- cgit v1.2.3