source: LATMOS-Accounts/bin/la-web-directory @ 806

Last change on this file since 806 was 801, checked in by nanardon, 14 years ago
  • ajout des champs expireText et contratType dans la sortie
  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9=head1 NAME
10
11    la-query - Tools to query base in LATMOS::Accounts system
12
13=head1 SYNOPSIS
14
15    la-query [options] [obj_id]
16
17=item [obj_id] : If present, all set attributes (rw) will be displayed for that obj_id.
18        If none is given, all obj_ids will be printed.
19
20For the default object_type (user), obj_id = login.
21
22Example : la-query lambda
23
24=cut
25
26GetOptions(
27    'c|config=s' => \my $config,
28    'b|base=s'   => \my $base,
29    'noexp'      => \my $noexp,
30    'exp'        => \my $exp,
31    'help'       => sub { pod2usage(0) },
32) or pod2usage();
33
34=head1 OPTIONS
35
36=over 4
37
38=item -c|--config configfile
39
40Use this configuration file instead of the default one.
41
42=item -b|--base basename
43
44Query this specific base instead of the default one.
45
46=item --noexp
47
48Take into account all objects (even non propagated ones, with attribute 'exported'=0)
49(default)
50
51=item --exp
52
53Take into account only propagated objects (attribute 'exported'=1)
54
55=cut
56
57my $LA = LATMOS::Accounts->new($config, noacl => 1);
58my $labase = $base ? $LA->base($base) : $LA->default_base;
59$labase && $labase->load or die "Cannot load base";
60
61$labase->wexported($exp ? 1 : 0);
62
63foreach my $user (sort $labase->search_objects('user')) {
64    my $ouser = $labase->get_object('user', $user);
65    my @oaddress;
66
67    if ($labase->is_supported_object('address')) {
68        @oaddress = 
69            grep { $_ } (
70            map { $labase->get_object('address', $_) }
71            #$ouser->get_attributes('mainaddress'),
72                $ouser->get_attributes('otheraddress'),
73            );
74    } else {
75        @oaddress = ($ouser);
76    }
77           
78    my $line = join(':', map { $_ || '' } (
79            $ouser->get_attributes('sn'),
80            $ouser->get_attributes('givenName'),
81            $ouser->get_attributes('department'),
82            ($oaddress[0] ? join(' ', map { $_ || '' }
83                    $oaddress[0]->get_attributes('l'), grep { $_ }
84                    $oaddress[0]->get_attributes('physicalDeliveryOfficeName'),
85                ) : ''),
86            ($oaddress[1] ? join(' ', map { $_ || '' } grep { $_ }
87                    $oaddress[1]->get_attributes('l'),
88                    $oaddress[1]->get_attributes('physicalDeliveryOfficeName'),
89                ) : ''),
90            ($oaddress[0] ? $oaddress[0]->get_attributes('telephoneNumber') : ''),
91            ($oaddress[1] ? $oaddress[1]->get_attributes('telephoneNumber') : ''),
92            $ouser->get_attributes('mail'),
93            $ouser->get_attributes('nickname'),
94            $ouser->get_attributes('expireText'),
95            $ouser->get_attributes('contratType'),
96        ));
97    print "$line\n";
98}
Note: See TracBrowser for help on using the repository browser.