diff options
-rwxr-xr-x | fripost-searchalias | 53 |
1 files 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<fripost-searchalias> [B<--debug>] [I<goto> [I<from>]] +B<fripost-searchalias> [B<--debug>] [B<--from>] [B<--goto>] [I<goto/from>] =head1 DESCRIPTION @@ -52,6 +52,16 @@ The default value is read from the configuration file, see B<CONFIGURATION>. 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(); |