diff options
author | Guilhem Moulin <guilhem.moulin@fripost.org> | 2012-04-19 00:12:57 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem.moulin@fripost.org> | 2012-04-19 00:12:57 +0200 |
commit | 47135d7827c75073278089d43220df48f250b118 (patch) | |
tree | b32e0ee5a3a70eff8836b719928a0c08bad65572 /fripost-searchuser | |
parent | 5f15ee93f79af5af0ee064ffdb5c03f2af14ee3a (diff) |
Search tools.
Diffstat (limited to 'fripost-searchuser')
-rwxr-xr-x | fripost-searchuser | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/fripost-searchuser b/fripost-searchuser new file mode 100755 index 0000000..30df331 --- /dev/null +++ b/fripost-searchuser @@ -0,0 +1,140 @@ +#!/usr/bin/perl + +use 5.010_000; +use strict; +use warnings; +use utf8; + +=head1 NAME + +fripost-searchuser - List matching users + +=head1 SYNOPSIS + +B<fripost-searchuser> [B<--debug>] [I<username>] + +=head1 DESCRIPTION + +B<fripost-searchuser> list virtual mailboxes whose username exactly matches +I<username>. +Wildcards I<*> can appear in I<username>, to match zero or more characters. +If no I<username> is given, B<fripost-searchuser> list all existing mailboxes. + +=head1 OPTIONS + +=over 8 + +=item B<--server_host=>I<host> + +The LDAP URI to connect to. +The default value is read from the configuration file, see B<CONFIGURATION>. + +=item B<--bind_dn=>I<binddn> + +The Distinguished Name (DN) to bind to the LDAP directory. +(If not set, B<fripost-searchuser> binds anonymously.) +The default value is read from the configuration file, see B<CONFIGURATION>. + +=item B<--bind_pw=>I<password> + +The password to to bind with. +The default value is read from the configuration file, see B<CONFIGURATION>. + +=item B<--base_dn=>I<basedn> + +The root DN for everything done by B<fripost-searchuser>. +The default value is read from the configuration file, see B<CONFIGURATION>. + +=item B<--debug> + +Debug mode. + +=back + +=head1 CONFIGURATION + +The configuration is read from the file C<$HOME/.fripost.yml>. +Valid keys include: + +=over 4 + +=item I<server_host> + +The LDAP URI to connect to. Defaults to C<ldap://127.0.0.1:389>. + +=item I<bind_dn> + +The Distinguished Name (DN) to bind to the LDAP directory. +(If not set, B<fripost-searchuser> binds anonymously.) + +=item I<bind_pw> + +The password to to bind with. + +=item I<base_dn> + +The root DN for everything done by B<fripost-searchuser>. + +=back + +=cut + +use FindBin qw($Bin); +use lib "$Bin/lib"; + +use Env qw /HOME/; +use File::Spec::Functions; + +use Fripost::Schema; +use Getopt::Long qw /:config noauto_abbrev no_ignore_case + gnu_compat bundling permute nogetopt_compat + auto_version auto_help/; +use Pod::Usage; +use YAML::Syck; + + +## Get command line options +our $conf = LoadFile( catfile ($HOME, '.fripost.yml') ); + +GetOptions( + 'server_host=s' => \$conf->{server_host}, + 'base_dn=s' => \$conf->{base_dn}, + 'bind_dn=s' => \$conf->{bind_dn}, + 'bind_pw=s' => \$conf->{bind_pw}, + 'pretend' => \$conf->{pretend}, + 'debug' => \$conf->{debug}, + 'man' => sub { pod2usage(-exitstatus => 0, + -verbose => 2) } +) or pod2usage(2); + + +# Connect to the LDAP server +my $ldap = Fripost::Schema->new( $conf ); + +my %user; +$user{username} = $ARGV[0] if defined $ARGV[0]; + +foreach my $user ($ldap->user->search( \%user )->entries) { + say "User: " . $user->{username}; + say "Maildir: " . $user->{maildir}; + say "IsActive: " . $user->{isActive}; + say "--------------------------------" +} + +$ldap->unbind(); + + +=head1 AUTHOR + +Guilhem Moulin C<< <guilhem at fripost.org> >> + +=head1 COPYRIGHT + +Copyright 2012 Guilhem Moulin. + +=head1 LICENSE + +This program is free software; you can redistribute it and/or modify it +under the same terms as perl itself. + +=cut |