1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use LATMOS::Accounts; |
---|
6 | use Getopt::Long; |
---|
7 | use Pod::Usage; |
---|
8 | |
---|
9 | GetOptions( |
---|
10 | 'c|config=s' => \my $config, |
---|
11 | 'b|base=s' => \my $base, |
---|
12 | ) or pod2usage(); |
---|
13 | |
---|
14 | my $otype ||= 'user'; |
---|
15 | |
---|
16 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
17 | my $labase = $base ? $LA->base($base) : $LA->default_base; |
---|
18 | $labase->{wexported} = 1; |
---|
19 | $labase && $labase->load or die "Cannot load base"; |
---|
20 | |
---|
21 | while (my $line = <STDIN>) { |
---|
22 | |
---|
23 | chomp($line); |
---|
24 | |
---|
25 | my @passwd = split("\t", $line); |
---|
26 | |
---|
27 | # warn (join(' - ', map { $_ => $passwd[$_] } 0 ..$#passwd)); |
---|
28 | my @epo; |
---|
29 | |
---|
30 | my $login = $passwd[27]; |
---|
31 | warn $login . ' ' . scalar(@passwd); |
---|
32 | my $obj = $labase->get_object($otype, $login) or do { |
---|
33 | warn "Cannot get $login user"; |
---|
34 | #warn $line . "\n"; |
---|
35 | next; |
---|
36 | }; |
---|
37 | my %changes; |
---|
38 | |
---|
39 | { # le nom/ prénom |
---|
40 | $changes{sn} = $passwd[0]; |
---|
41 | $changes{sn} =~ s/_/ /g; |
---|
42 | $changes{givenName} = $passwd[1]; |
---|
43 | $changes{givenName} =~ s/_/ /g; |
---|
44 | if ($passwd[10] =~ /^NICK(.*)$/) { |
---|
45 | if ($1 eq 'zzz') { |
---|
46 | $changes{nickname} = undef; |
---|
47 | } else { $changes{nickname} = $1 } |
---|
48 | } |
---|
49 | $changes{mail} = $passwd[9]; |
---|
50 | $changes{mail} =~ s/cetp.ipsl.fr/latmos.ipsl.fr/; |
---|
51 | } |
---|
52 | |
---|
53 | { # address, a bit more complex |
---|
54 | # trash old |
---|
55 | foreach ($obj->get_attributes('otheraddress')) { |
---|
56 | $labase->delete_object('address', $_); |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | foreach my $col (3, 5, 7) { |
---|
61 | if($passwd[$col] ne 'AJETER') { |
---|
62 | my %param = (user => $obj->id,); |
---|
63 | $passwd[$col] =~ /^(SAV|SAJ|vel|StM|GY)-(.*)/i or do { |
---|
64 | warn "unknown $passwd[$col]"; |
---|
65 | next; |
---|
66 | }; |
---|
67 | my $eposite = $1; |
---|
68 | $param{physicalDeliveryOfficeName} = $2; |
---|
69 | $param{telephoneNumber} = '+33 1 ' . $passwd[$col + 5]; |
---|
70 | |
---|
71 | for ($eposite) { |
---|
72 | /^SAV$/i and do { |
---|
73 | $param{site} = 'VerriÚres'; |
---|
74 | $passwd[14] =~ /aerov/ and $param{isMainAddress} = 1; |
---|
75 | last; |
---|
76 | }; |
---|
77 | /^Vel$/i and do { |
---|
78 | $param{site} = 'Vélizy'; |
---|
79 | $passwd[14] =~ /cetp/ and $param{isMainAddress} = 1; |
---|
80 | last; |
---|
81 | }; |
---|
82 | /^Stm$/i and do { |
---|
83 | $param{site} = 'St Maur'; |
---|
84 | last; |
---|
85 | }; |
---|
86 | /^SAJ$/i and do { |
---|
87 | $param{site} = 'Jussieu'; |
---|
88 | $passwd[14] =~ /aero$/ and $param{isMainAddress} = 1; |
---|
89 | last; |
---|
90 | }; |
---|
91 | /^GY$/i and do { |
---|
92 | $param{site} = 'Guyancourt'; |
---|
93 | # is not main address at time |
---|
94 | last; |
---|
95 | }; |
---|
96 | warn "unmanaged $eposite"; |
---|
97 | } |
---|
98 | $labase->create_object( |
---|
99 | 'address', |
---|
100 | $obj->id . '-' . $eposite, |
---|
101 | %param |
---|
102 | ); |
---|
103 | } |
---|
104 | } |
---|
105 | $passwd[16] =~ /^T(\d\d\d\d)(\d\d)(\d\d)$/ and do { |
---|
106 | if($1 < 2100) { |
---|
107 | $changes{expire} = "$3/$2/$1 23:59:59"; |
---|
108 | } else { |
---|
109 | $changes{expire} = undef; |
---|
110 | } |
---|
111 | }; |
---|
112 | $passwd[22] =~ /^GRADE(.*)/ and do { |
---|
113 | $changes{grade} = $1; |
---|
114 | }; |
---|
115 | } |
---|
116 | |
---|
117 | { |
---|
118 | my @group = @{ $obj->get_c_field('memberOf') || []}; |
---|
119 | foreach ($passwd[20] =~ /^DOM(.*)/g) { |
---|
120 | $changes{departement} = '$1'; |
---|
121 | push @group, $1; |
---|
122 | next; |
---|
123 | } |
---|
124 | $changes{'memberOf'} = \@group; |
---|
125 | } |
---|
126 | |
---|
127 | keys %changes or next; |
---|
128 | $obj->set_c_fields(%changes); |
---|
129 | $labase->commit; |
---|
130 | } |
---|