aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Commands/search_alias.pm
blob: 22414363dbacb30b4832c1d430f467ef604186d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package Fripost::Commands::search_alias;

use 5.010_000;
use strict;
use warnings;
use utf8;

=head1 NAME

search_alias.pm - List matching virtual aliases

=cut

use FindBin qw($Bin);
use lib "$Bin/lib";

use Fripost::Schema;

our $VERSION = '0.01';

sub perform_search {
    my $ldap = shift;

    foreach my $alias ($ldap->alias->search( $_[0] )->entries) {
        say "" . ($alias->{isActive} ? "ACTIVE" : "INACTIVE")
            . " alias for " . $alias->{goto} . " are "
            . (join ', ', @{$alias->{address}});
    }
}

sub main {
    my ($ldap, $conf, $search) = @_;
    $search //= '';

    my $f = $conf->{from};
    my $g = $conf->{goto};
    my $from = $f || !$f && !$g;
    my $goto = $g || !$f && !$g;

    if ($from) {
        perform_search($ldap, {address => $search});
    
        my ($u,$d) = split /\@/, $search, 2;
        $d = $u if (defined $u) and not (defined $d);
        $ldap->domain->search({ domain => $d })->count
            or die "Error: Unknown domain `$d'.\n";
    } 
    
    if ($goto) {
        perform_search($ldap, {goto => $search});
    }
}


=head1 AUTHOR

Guilhem Moulin C<< <guilhem at fripost.org> >>

=head1 COPYRIGHT

Copyright 2012 Guilhem Moulin.

Copyright 2012 Stefan Kangas <skangas@skangas.se>.

=head1 LICENSE

This program is free software; you can redistribute it and/or modify it
under the same terms as perl itself.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

=cut

1; # End of search_alias.pm

__END__