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

Last change on this file since 831 was 831, checked in by vivat, 14 years ago

Prise en charge des heberges sauf Novimet dans l'annuaire

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8use POSIX qw(strftime);
9
10=head1 NAME
11
12    la-query - Tools to query base in LATMOS::Accounts system
13
14=head1 SYNOPSIS
15
16    la-query [options] [obj_id]
17
18=item [obj_id] : If present, all set attributes (rw) will be displayed for that obj_id.
19        If none is given, all obj_ids will be printed.
20
21For the default object_type (user), obj_id = login.
22
23Example : la-query lambda
24
25=cut
26
27GetOptions(
28    'c|config=s' => \my $config,
29    'b|base=s'   => \my $base,
30    'noexp'      => \my $noexp,
31    'exp'        => \my $exp,
32    'noexpire'   => \my $noexpire,
33    'filter=s'   => \my @filters,
34    'help'       => sub { pod2usage(0) },
35) or pod2usage();
36
37=head1 OPTIONS
38
39=over 4
40
41=item -c|--config configfile
42
43Use this configuration file instead of the default one.
44
45=item -b|--base basename
46
47Query this specific base instead of the default one.
48
49=item --noexp
50
51Take into account all objects (even non propagated ones, with attribute 'exported'=0)
52(default)
53
54=item --exp
55
56Take into account only propagated objects (attribute 'exported'=1)
57
58=item --noexpire
59
60Exclude expired accounts
61
62=cut
63
64my $LA = LATMOS::Accounts->new($config, noacl => 1);
65my $labase = $base ? $LA->base($base) : $LA->default_base;
66$labase && $labase->load or die "Cannot load base";
67
68$labase->wexported($exp ? 1 : 0);
69my %users;
70my $now = strftime('%Y/%m/%d', gmtime);
71
72foreach my $user (sort $labase->search_objects('user',
73            @filters ? @filters : 'sn=*')) {
74    my $ouser = $labase->get_object('user', $user);
75    $ouser->get_attributes('sn') or next;
76    if ($noexpire && (my $expdate = $ouser->get_attributes('expireText'))) {
77        if ($now gt $expdate) {
78            next;
79        }
80    }
81
82# On ne prend que le personnel LATMOS et les heberges, sauf Novimet
83
84    my $company = $ouser->get_attributes('company');
85    my $contrat = $ouser->get_attributes('contratType');
86    if ($company){
87            if (($company ne "LATMOS")&&($contrat ne "heberges")) {
88                next;
89        }
90            if ($company eq "Novimet") {
91                next;
92        }
93    } else {
94            if ((!$contrat)||($contrat ne "heberges")) {
95                next;
96        }
97    }
98
99    my @oaddress;
100
101    if ($labase->is_supported_object('address')) {
102        @oaddress = 
103            grep { $_ } (
104            map { $labase->get_object('address', $_) }
105                $ouser->get_attributes('otheraddress'),
106            );
107    } else {
108        @oaddress = ($ouser);
109    }
110
111# Si c'est un heberge, on place departement a "EXT"
112
113    my $department;
114
115    if ($contrat eq "heberges") {
116            $department = "EXT";
117    } else {
118            $department = $ouser->get_attributes('department');
119    }
120           
121    my $line = join(';', map { $_ || '' } (
122            $ouser->get_attributes('sn'),
123            $ouser->get_attributes('givenName'),
124            $department,
125            ($oaddress[0] ? join(' ', map { $_ || '' }
126                    $oaddress[0]->get_attributes('l'), grep { $_ }
127                    $oaddress[0]->get_attributes('physicalDeliveryOfficeName'),
128                ) : ''),
129            ($oaddress[1] ? join(' ', map { $_ || '' } grep { $_ }
130                    $oaddress[1]->get_attributes('l'),
131                    $oaddress[1]->get_attributes('physicalDeliveryOfficeName'),
132                ) : ''),
133            ($oaddress[0] ? $oaddress[0]->get_attributes('telephoneNumber') : ''),
134            ($oaddress[1] ? $oaddress[1]->get_attributes('telephoneNumber') : ''),
135            $ouser->get_attributes('mail'),
136            $ouser->get_attributes('nickname'),
137        ));
138        $line =~s/Paris */PAR-/g;
139        $line =~s/Guyancourt */GUY-/g;
140        $line =~s/Vélizy-Villacoublay */VEL-/g;
141        $line =~s/VerriÚres le Buisson */VLB-/g;
142        $line =~s/St Maur des Fossés */STM-/g;
143        $line =~s/\+ *33 *1 *//g;
144
145    $users{$ouser->get_attributes('sn')}{$ouser->get_attributes('givenName')} = $line;
146}
147
148foreach my $sn (sort keys %users) {
149    foreach my $givenName (sort keys %{$users{$sn}}) {
150        print "$users{$sn}{$givenName}\n";
151    }
152}
Note: See TracBrowser for help on using the repository browser.