source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm @ 2262

Last change on this file since 2262 was 2262, checked in by nanardon, 5 years ago

Precompute more attribute

  • Property svn:keywords set to Id Rev
File size: 80.6 KB
Line 
1package LATMOS::Accounts::Bases::Sql::User;
2
3use 5.010000;
4use strict;
5use warnings;
6use overload '""' => 'stringify';
7
8use LATMOS::Accounts::Utils;
9use LATMOS::Accounts::Log;
10use POSIX qw(strftime);
11use Date::Parse qw(str2time);
12use DateTime;
13use DateTime::TimeZone;
14use base qw(LATMOS::Accounts::Bases::Sql::objects);
15use LATMOS::Accounts::I18N;
16use Date::Calc;
17use LATMOS::Accounts::Mail;
18
19our $VERSION = (q$Rev: 2158 $ =~ /^Rev: (\d+) /)[0];
20
21=head1 NAME
22
23LATMOS::Ad - Perl extension for blah blah blah
24
25=head1 DESCRIPTION
26
27Account base access over standard unix file format.
28
29=head1 FUNCTIONS
30
31=cut
32
33=head2 new(%config)
34
35Create a new LATMOS::Ad object for windows AD $domain.
36
37domain / server: either the Ad domain or directly the server
38
39ldap_args is an optionnal list of arguments to pass to L<Net::LDAP>.
40
41=cut
42
43sub _object_table { 'user' }
44
45sub _key_field { 'name' }
46
47sub _has_extended_attributes { 1 }
48
49sub stringify {
50    my ($self) = @_;
51
52    return join(' ', grep { $_ }
53        (
54            $self->get_field('givenName'),
55            $self->get_field('sn')
56        )
57    )
58    || $self->get_field('description')
59    || $self->id;
60}
61
62sub GetOtypeDef {
63    my ($class) = @_;
64
65    {
66        address => 'user',
67        employment => 'user',
68    },
69}
70
71sub _get_attr_schema {
72    my ($class, $base) = @_;
73
74    my $subsetaddress = sub {
75        my ($self, $data) = @_;
76        my $fmainaddress = $self->object->_get_c_field('mainaddress');
77
78        # set address attribute => create address object on the fly
79        # except if attr is empty !
80        if (!$fmainaddress && $data) {
81            $fmainaddress = $self->object->id . '-' . join('', map { ('a'..'z')[rand(26)] }
82                (0..4));
83            $self->base->_create_c_object(
84                'address', $fmainaddress,
85                user => $self->object->id,
86                isMainAddress => 1, ) or do {
87                $self->base->log(LA_ERR,
88                    "Cannot create main address for user %s", $self->object->id);
89                return;
90            };
91        }
92        if ($fmainaddress && 
93            (my $address = $self->base->get_object('address', $fmainaddress))) {
94            if ($address->attribute($self->name) &&
95                !$address->attribute($self->name)->ro) {
96                return $address->set_c_fields($self->name => $data) ||0;
97            }
98        }
99    };
100
101    my $attrs = {
102            exported => {
103                post => sub {
104                    my ($self, $value) = @_;
105                    my $attr = $self->name;
106
107                    if (my $obj = $self->base->
108                            get_object('revaliases', $self->object->id)) {
109                        my $ares = $obj->set_c_fields(
110                            ($attr eq 'exported' ? 'exported' : 'unexported') => $value
111                        );
112                        if (!defined($ares)) {
113                            $self->base->log(LA_ERR,
114                                'Cannot set revaliases exported attribute for user %s',
115                                $self->object->id);
116                        }
117                    }
118                    my $must_expire = $self->name eq 'exported'
119                        ? ($value ? 0 : 1 )
120                        : ($value ? 1 : 0 );
121
122                    foreach my $al (grep { $_ } $self->object->get_attributes('aliases'), $self->object->id) {
123                        my $obj = $self->base->get_object('aliases', $al) or next;
124                        $obj->_set_c_fields(
125                            exported => $value,
126                        );
127                    }
128                    foreach my $al ($self->object->get_attributes('otheraddress')) {
129                        my $obj = $self->base->get_object('address', $al) or next;
130                        $obj->_set_c_fields(
131                            exported => $value,
132                        );
133                    }
134                },
135            },
136            uidNumber => {
137                inline => 1,
138                iname => 'uidnumber',
139                uniq => 1,
140                mandatory => 1,
141                formopts => { length => 7 },
142                label => l('UID'),
143            },
144            uidnumber => { inline => 1, hide => 1, monitored => 1 },
145            gidNumber => {
146                inline => 1,
147                iname => 'gidnumber',
148                mandatory => 1,
149                can_values => sub {
150                    map { $_->id, $_->get_attributes('gidNumber') }
151                    map { $base->get_object('group', $_) }
152                    $base->list_objects('group')
153                },
154                can_values => sub {
155                    my $sth = $base->db->prepare_cached(
156                        q{
157                        select name, gidnumber from "group" where exported = true
158                        }
159                    );
160                    $sth->execute();
161                    my @res;
162                    while (my $res = $sth->fetchrow_hashref) {
163                        push(@res, $res->{name});
164                        push(@res, $res->{gidnumber});
165                    }
166                    return @res;
167                },
168                display => sub {
169                    my ($self, $val) = @_;
170                    if ($val =~ /^\d+$/) {
171                        my ($gr) = $self->base->search_objects('group', "gidNumber=$val")
172                            or return;
173                        return $gr;
174                    } else {
175                        my ($gr) = $self->base->search_objects('group', "name=$val")
176                            or return;
177                        return $gr;
178                    }
179                },
180                input => sub {
181                    my ($val) = @_;
182                    $val =~ /^\d+$/ and return $val;
183                    my ($gr) = $base->search_objects('group', "name=$val") or return;
184                    return $base->get_object('group', $gr)->get_attributes('gidNumber');
185                },
186                #reference => 'group',
187                label => l('GID'),
188            },
189            loginShell => {
190                mandatory => 1,
191                label => l('Shell'),
192            },
193            gidnumber => { inline => 1, hide => 1,
194                can_values => sub {
195                    map { $_->id, $_->get_attributes('gidNumber') }
196                    map { $base->get_object('group', $_) }
197                    $base->list_objects('group')
198                },
199                display => sub {
200                    my ($self, $val) = @_;
201                    my ($gr) = $self->base->search_objects('group', "gidNumber=$val")
202                        or return;
203                    return $gr;
204                },
205                input => sub {
206                    my ($val) = @_;
207                    $val =~ /^\d+$/ and return $val;
208                    my ($gr) = $base->search_objects('group', "name=$val") or return;
209                    return $base->get_object('group', $gr)->get_attributes('gidNumber');
210                },
211                mandatory => 1,
212                reference => 'group',
213                monitored => 1,
214            },
215            locked    => {
216                formtype => 'CHECKBOX',
217                formopts => { rawvalue => 1, },
218                monitored => 1,
219                label => l('Locked'),
220            },
221            expire        => {
222                inline => 1,
223                formtype => 'DATETIME',
224                monitored => 1,
225                label => l('Expire on'),
226            },
227            endcircuit    => {
228                inline => 1,
229                formtype => 'DATE',
230                monitored => 1,
231                label => l('End of entrance'),
232            },
233            _endEmployment => {
234                formtype => 'DATETIME',
235                managed => 1,
236                ro => 1,
237                hide => 1,
238                get => sub {
239                    my ($attr) = @_;
240                    my $self = $attr->object;
241                    $self->_computeEndEmployment($self->base->config('employment_delay') || 0);
242                },
243                label => l('End of employment'),
244            },
245            endEmployment => {
246                formtype => 'DATETIME',
247                ro => 1,
248                label => l('End of employment'),
249            },
250            _departure => {
251                formtype => 'DATETIME',
252                managed => 1,
253                ro => 1,
254                hide => 1,
255                get => sub {
256                    my ($attr) = @_;
257                    my $self = $attr->object;
258                    $self->_computeEndEmployment($self->base->config('employment_delay') || 0, 1, 1);
259                },
260                label => l('Start of employment'),
261            },
262            departure => {
263                formtype => 'DATETIME',
264                ro => 1,
265                label => l('Leaving'),
266            },
267            _endStrictEmployment => {
268                formtype => 'DATETIME',
269                managed => 1,
270                ro => 1,
271                hide => 1,
272                get => sub {
273                    my ($attr) = @_;
274                    my $self = $attr->object;
275                    $self->_computeEndEmployment();
276                },
277            },
278            endStrictEmployment => {
279                formtype => 'DATETIME',
280                ro => 1,
281            },
282            _endCurrentEmployment => {
283                formtype => 'DATETIME',
284                managed => 1,
285                ro => 1,
286                hide => 1,
287                get => sub {
288                    my ($attr) = @_;
289                    my $self = $attr->object;
290
291                    my $list_empl = $self->base->db->prepare_cached(q{
292                        SELECT * FROM employment WHERE "user" = ? and
293                            firstday <= now() and
294                            (lastday is null or lastday >= now() - '1 days'::interval)
295                            order by firstday asc
296                    });
297                    $list_empl->execute($self->id);
298                    my $end;
299                    while (my $res = $list_empl->fetchrow_hashref) {
300                        if (!$res->{lastday}) {
301                            # Ultimate employment.
302                            $list_empl->finish;
303                            return undef;
304                        } else {
305                            $end = DateTime->from_epoch(epoch => str2time($res->{lastday}));
306                            $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
307                            $end->add(hours => 23, minutes => 59, seconds => 59);
308                        }
309                        last;
310                    }
311                    $list_empl->finish;
312
313                    return $end ? $end->iso8601 : undef
314                },
315            },
316            endCurrentEmployment => {
317                formtype => 'DATETIME',
318                ro => 1,
319            },
320            _endLastEmployment => {
321                formtype => 'DATETIME',
322                managed => 1,
323                ro => 1,
324                hide => 1,
325                get => sub {
326                    my ($attr) = @_;
327                    my $self = $attr->object;
328
329                    my $list_empl = $self->base->db->prepare_cached(q{
330                        SELECT * FROM employment WHERE "user" = ?
331                        order by lastday desc nulls first
332                    });
333                    $list_empl->execute($self->id);
334                    my $res = $list_empl->fetchrow_hashref;
335                    $list_empl->finish;
336                    my $end;
337                    if ($res && $res->{lastday}) {
338                        $end = DateTime->from_epoch(epoch => str2time($res->{lastday}));
339                        $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
340                        $end->add(hours => 23, minutes => 59, seconds => 59);
341                    }
342                    return $end ? $end->iso8601 : undef
343                },
344                label => l('End of any employment'),
345            },
346            endLastEmployment => {
347                formtype => 'DATETIME',
348                ro => 1,
349                label => l('End of any employment'),
350            },
351            _startEmployment => {
352                formtype => 'DATETIME',
353                managed => 1,
354                ro => 1,
355                hide => 1,
356                get => sub {
357                    my ($attr) = @_;
358                    my $self = $attr->object;
359                    $self->_computeStartEmployment($self->base->config('employment_delay') || 0);
360                },
361                label => l('Start of employment'),
362            },
363            startEmployment => {
364                formtype => 'DATETIME',
365                ro => 1,
366                label => l('Start of employment'),
367            },
368            _arrival => {
369                formtype => 'DATETIME',
370                managed => 1,
371                ro => 1,
372                hide => 1,
373                get => sub {
374                    my ($attr) = @_;
375                    my $self = $attr->object;
376                    $self->_computeStartEmployment($self->base->config('employment_delay') || 0, 1, 1);
377                },
378                label => l('Start of employment'),
379            },
380            arrival => {
381                formtype => 'DATETIME',
382                ro => 1,
383                label => l('Arrival'),
384            },           
385            _startStrictEmployment => {
386                formtype => 'DATETIME',
387                managed => 1,
388                ro => 1,
389                hide => 1,
390                get => sub {
391                    my ($attr) = @_;
392                    my $self = $attr->object;
393                    $self->_computeStartEmployment();
394                },
395            },
396            startStrictEmployment => {
397                formtype => 'DATETIME',
398                ro => 1,
399            },
400            _startCurrentEmployment => {
401                formtype => 'DATETIME',
402                managed => 1,
403                ro => 1,
404                hide => 1,
405                get => sub {
406                    my ($attr) = @_;
407                    my $self = $attr->object;
408
409                    my $list_empl = $self->base->db->prepare_cached(q{
410                        SELECT * FROM employment WHERE "user" = ? and
411                            firstday <= now() and
412                            (lastday is null or lastday >= now() - '1 days'::interval)
413                            order by firstday asc
414                    });
415                    $list_empl->execute($self->id);
416                    my $start;
417                    while (my $res = $list_empl->fetchrow_hashref) {
418                        $start = DateTime->from_epoch(epoch => str2time($res->{firstday}));
419                        $start->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
420                        last;
421                    }
422                    $list_empl->finish;
423
424                    return $start ? $start->iso8601 : undef
425                },
426            },
427            startCurrentEmployment => {
428                formtype => 'DATETIME',
429                ro => 1,
430            },
431            _startFirstEmployment => {
432                formtype => 'DATETIME',
433                managed => 1,
434                ro => 1,
435                hide => 1,
436                get => sub {
437                    my ($attr) = @_;
438                    my $self = $attr->object;
439
440                    my $list_empl = $self->base->db->prepare_cached(q{
441                        SELECT * FROM employment WHERE "user" = ?
442                        order by firstday asc
443                    });
444                    $list_empl->execute($self->id);
445                    my $res = $list_empl->fetchrow_hashref;
446                    $list_empl->finish;
447                    my $start;
448                    if ($res && $res->{firstday}) {
449                        $start = DateTime->from_epoch(epoch => str2time($res->{firstday}));
450                        $start->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
451                    }
452                    return $start ? $start->iso8601 : undef
453                },
454                label => l('Start of any employment'),
455            },
456            startFirstEmployment => {
457                formtype => 'DATETIME',
458                ro => 1,
459                label => l('Start of any employment'),
460            },
461            employmentLength => {
462                ro => 1,
463                auto => 1,
464            },
465            _employmentLength => {
466                ro => 1,
467                managed => 1,
468                hide => 1,
469                get => sub {
470                    my ($self) = @_;
471                    my $lastday = $self->object->get_attributes('endEmployment') || DateTime->now->ymd('-');
472                    my $firstday = $self->object->get_attributes('startEmployment') or return;
473
474                    my @fd = split('-', DateTime->from_epoch(epoch => str2time($firstday))->ymd('-'));
475                    my @ld = split('-', DateTime->from_epoch(epoch => str2time($lastday))->ymd('-'));
476
477                    return Date::Calc::Delta_Days(@fd, @ld) +1;
478                },
479                label => l('Work duration'),
480            },
481            employmentLengthText => {
482                ro => 1,
483                auto => 1,
484            },
485            _employmentLengthText => {
486                ro => 1,
487                managed => 1,
488                hide => 1,
489                get => sub {
490                    my ($self) = @_;
491                    my $firstday = $self->object->get_attributes('startEmployment') or return;
492                    my $lastday = $self->object->get_attributes('endEmployment')|| DateTime->now->ymd('-');
493                    {
494                        my $dtlast = DateTime->from_epoch(epoch => str2time($lastday));
495                        $dtlast->add(days => 1);
496                        $lastday = $dtlast->ymd('-');
497                    }
498
499                    my @fd = split('-', DateTime->from_epoch(epoch => str2time($firstday))->ymd('-'));
500                    my @ld = split('-', DateTime->from_epoch(epoch => str2time($lastday))->ymd('-'));
501
502                    my ($Dy,$Dm,$Dd) = Date::Calc::N_Delta_YMD(@fd, @ld);
503                    return join(', ',
504                        ($Dy ? l('%d years', $Dy)  : ()),
505                        ($Dm ? l('%d months', $Dm) : ()),
506                        ($Dd ? l('%d days', $Dd)   : ()),
507                    );
508                },
509                label => l('Work duration'),
510            },
511            cn        => {
512                inline => 1, ro => 1,
513                get => sub {
514                    my ($self) = @_;
515                    return join(' ', grep { $_ } 
516                        (
517                            $self->object->_get_c_field('givenName'),
518                            $self->object->_get_c_field('sn')
519                        )
520                    )
521                    || $self->object->_get_c_field('description')
522                    || $self->object->id;
523                },
524            },
525            memberOf  => {
526                reference => 'group',
527                multiple => 1, delayed => 1,
528                get => sub {
529                    my ($self) = @_;
530                    my $obj = $self->object;
531                    my $sth = $obj->db->prepare_cached(
532                        q{
533                        select name from "group" join
534                        group_attributes on group_attributes.okey = "group".ikey
535                        where value = ? and attr = ? and internobject = false
536                        } . ($self->base->{wexported} ? '' : ' and "group".exported = true')
537                    );
538                    $sth->execute($obj->id, 'memberUID');
539                    my @res;
540                    while (my $res = $sth->fetchrow_hashref) {
541                        push(@res, $res->{name});
542                    }
543                    return \@res;
544                },
545                set => sub {
546                    my ($self, $values) = @_;
547                    my %old = map { $_ => 'o' } @{ $self->get };
548                    foreach my $group (grep { $_ } ref $values ? @{ $values } : $values) {
549                        if ($old{$group}) {
550                            $old{$group} = undef; # no change
551                        } else {
552                            $old{$group} = 'n';
553                        }
554                    }
555
556                    my $res = 0;
557                    foreach my $group (keys %old) {
558                        $old{$group} or next; # no change
559
560                        my $ogroup = $self->base->get_object('group', $group) or next;
561                        ($ogroup->_get_c_field('sutype') || '') =~ /^(jobtype|contrattype)$/ and next;
562
563                        if ($old{$group} eq 'n') {
564                            $res += $ogroup->_addAttributeValue('memberUID', $self->object->id);
565                        } else {
566                            if (($self->object->_get_c_field('department') || '') eq $ogroup->id) {
567                                $self->base->log(LA_WARN,
568                                    "Don't removing user %s from group %s: is its department",
569                                    $self->object->id, $ogroup->id);
570                                next;
571                            }
572                            $res += $ogroup->_delAttributeValue('memberUID', $self->object->id);
573                        }
574                    }
575                    return $res;
576                },
577                label => l('Member of'),
578            },
579            forward => {
580                managed => 1,
581                multiple => 1,
582                get => sub {
583                    my ($self) = @_;
584                    my $sth = $self->base->db->prepare(q{
585                        select forward from aliases where name = ? and internobject = false
586                        } . ($self->base->{wexported} ? '' : ' and exported = true'));
587                    $sth->execute($self->object->id);
588                    my $res = $sth->fetchrow_hashref;
589                    $sth->finish;
590                    return $res->{forward}
591                },
592                set => sub {
593                    my ($self, $data) = @_;
594                    if ($data) {
595                        my @datas = ref $data ? @$data : split(/\s*,\s*/, $data);
596                        if (my $f = $self->base->get_object('aliases', $self->object->id)) {
597                            return $f->_set_c_fields(
598                                forward => \@datas,
599                                comment => undef,
600                                description => 'Forward for user ' . $self->object->id,
601                            );
602                        } else {
603                            if ($self->base->_create_c_object(
604                                    'aliases', $self->object->id,
605                                    forward => \@datas,
606                                    description => 'automatically created for ' . $self->object->id,
607                                )) {
608                                return 1;
609                            } else {
610                                $self->base->log(LA_ERR, "Cannot add forward for %s",
611                                    $self->object->id);
612                            }
613                        }
614                    } elsif ($self->base->get_object('aliases', $self->object->id)) {
615                        if (my $res = $self->base->_delete_object('aliases', $self->object->id)) {
616                            return $res;
617                        } else {
618                            $self->base->log(LA_ERR, "Cannot remove forward for %s",
619                                $self->object->id);
620                        }
621                    } else {
622                        return 1;
623                    }
624                    return;
625                },
626                label => l('Forward'),
627            },
628            aliases   => {
629                #reference => 'aliases',
630                delayed => 1,
631                formtype => 'TEXT',
632                multiple => 1,
633                get => sub {
634                    my ($self) = @_;
635                    my $sth = $self->base->db->prepare(q{
636                        select name from aliases where internobject = false and lower($1) =
637                        lower(array_to_string("forward", ','))
638                        } . ($self->base->{wexported} ? '' : 'and exported = true'));
639                    $sth->execute($self->object->id);
640                    my @values;
641                    while (my $res = $sth->fetchrow_hashref) {
642                        push(@values, $res->{name});
643                    }
644                    return \@values;
645                },
646                set => sub {
647                    my ($self, $data) = @_;
648
649                    my $res = 0;
650                    my %aliases = map { $_ => 1 } grep { $_ } (ref $data ? @{$data} : $data);
651                    foreach ($self->object->_get_attributes('aliases')) {
652                        $aliases{$_} ||= 0;
653                        $aliases{$_} +=2;
654                    }
655                    foreach (keys %aliases) {
656                        if ($aliases{$_} == 2) {
657                            if ($self->base->_delete_object('aliases', $_)) {
658                                $res++
659                            } else {
660                                $self->base->log(LA_ERR,
661                                    "Cannot remove aliases %s from user %s", $_,
662                                    $self->object->id);
663                            }
664                        } elsif ($aliases{$_} == 1) {
665                            if ($self->base->_create_c_object(
666                                    'aliases', $_,
667                                    forward => [ $self->object->id ],
668                                    description => 'automatically created for ' . $self->object->id,
669                                )) {
670                                $res++
671                            } else {
672                                $self->base->log(LA_ERR, 'Cannot set forward %s to user %s',
673                                    $_, $self->object->id);
674                                return;
675                            }
676                        } # 3 no change
677                    }
678                    $res
679                },
680                label => l('Aliases'),
681            },
682            revaliases => {
683                formtype => 'TEXT',
684                get => sub {
685                    my ($self) = @_;
686
687                    if (my $obj = $self->base->
688                        get_object('revaliases', $self->object->id)) {
689                        return $obj->get_attributes('as');
690                    } else {
691                        return;
692                    }
693                },
694                set => sub {
695                    my ($self, $data) = @_;
696               
697                    my $res = 0;
698                    if ($data) {
699                        if (my $obj = $self->base->
700                            get_object('revaliases', $self->object->id)) {
701                            my $ares = $obj->set_c_fields(
702                                'as' => $data,
703                                'exported' => ($self->object->get_attributes('exported') || 0),
704                            );
705                            if (defined($ares)) {
706                                $res+=$ares;
707                            } else {
708                                $self->base->log(LA_ERR, 'Cannot set revaliases for user %s',
709                                    $self->object->id);
710                            }
711                        } else {
712                            if ($self->base->_create_c_object(
713                                    'revaliases',
714                                    $self->object->id, as => $data,
715                                    'exported' => ($self->object->get_attributes('exported') || 0),
716                                    description => 'automatically created for ' . $self->object->id,
717                                )) {
718                                $res++;
719                            } else {
720                                $self->base->log(LA_ERR, 'Cannot set revaliases for user %s',
721                                    $self->object->id);
722                            }
723                        }
724                    } else {
725                        $self->base->_delete_object('revaliases', $self->object->id);
726                        $res++;
727                    }
728
729                    $res
730                },
731            },
732            manager => {
733                reference => 'user',
734                ro => 1,
735                get => sub {
736                    my ($self) = @_;
737                    if (my $manager = $self->object->_get_c_field('managerContact')) {
738                        return $manager;
739                    } elsif (my $department = $self->object->_get_c_field('department')) {
740                        my $obj = $self->base->get_object('group', $department);
741                        return $obj->_get_c_field('managedBy');
742                    } else {
743                        return;
744                    }
745                },
746                label => l('Responsible'),
747            },
748            department => {
749                reference => 'group',
750                can_values => sub {
751                    $base->search_objects('group', 'sutype=dpmt')
752                },
753                monitored => 1,
754                label => l('Department'),
755            },
756            contratType => {
757                reference => 'group',
758                can_values => sub {
759                    $base->search_objects('group', 'sutype=contrattype')
760                },
761                monitored => 1,
762                label => l('Type of contract'),
763            },
764            site => {
765                reference => 'site',
766                can_values => sub {
767                    $base->search_objects('site')
768                },
769                get => sub {
770                    my ($self) = @_;
771                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
772                        $self->base->get_object('address', $fmainaddress)
773                            ->_get_c_field($self->name);
774                    } else {
775                        return;
776                    }
777                },
778                set => $subsetaddress,
779                label => l('Site'),
780            },
781            co => {
782                get => sub {
783                    my ($self) = @_;
784                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
785                        $self->base->get_object('address', $fmainaddress)
786                            ->_get_c_field($self->name);
787                    } else {
788                        return;
789                    }
790                },
791                set => $subsetaddress,
792            },
793            l => {
794                get => sub {
795                    my ($self) = @_;
796                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
797                        $self->base->get_object('address', $fmainaddress)
798                            ->_get_c_field($self->name);
799                    } else {
800                        return;
801                    }
802                },
803                set => $subsetaddress,
804                label => l('City'),
805            },
806            postalCode => {
807                get => sub {
808                    my ($self) = @_;
809                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
810                        $self->base->get_object('address', $fmainaddress)
811                            ->_get_c_field($self->name);
812                    } else {
813                        return;
814                    }
815                },
816                set => $subsetaddress,
817                label => l('Postal code'),
818            },
819            streetAddress => {
820                formtype => 'TEXTAREA',
821                get => sub {
822                    my ($self) = @_;
823                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
824                        $self->base->get_object('address', $fmainaddress)
825                            ->_get_c_field($self->name);
826                    } else {
827                        return;
828                    }
829                },
830                set => $subsetaddress,
831                label => l('Street'),
832            },
833            postOfficeBox => {
834                get => sub {
835                    my ($self) = @_;
836                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
837                        $self->base->get_object('address', $fmainaddress)
838                            ->_get_c_field($self->name);
839                    } else {
840                        return;
841                    }
842                },
843                set => $subsetaddress,
844                label => l('Post office box'),
845            },
846            st => {
847                get => sub {
848                    my ($self) = @_;
849                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
850                        $self->base->get_object('address', $fmainaddress)
851                            ->_get_c_field($self->name);
852                    } else {
853                        return;
854                    }
855                },
856                set => $subsetaddress,
857            },
858            facsimileTelephoneNumber => {
859                get => sub {
860                    my ($self) = @_;
861                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
862                        $self->base->get_object('address', $fmainaddress)
863                            ->_get_c_field($self->name);
864                    } else {
865                        return;
866                    }
867                },
868                set => $subsetaddress,
869                label => l('Fax number'),
870            },
871            o => {
872                ro => 1,
873                iname => 'company',
874                label => l('Company'),
875            },
876            ou => {
877                iname => 'department',
878                ro => 1,
879                label => l('Department'),
880            },
881            telephoneNumber => {
882                get => sub {
883                    my ($self) = @_;
884                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
885                        $self->base->get_object('address', $fmainaddress)
886                            ->_get_c_field($self->name);
887                    } else {
888                        return;
889                    }
890                },
891                set => $subsetaddress,
892                label => l('Phone number'),
893            },
894            physicalDeliveryOfficeName => {
895                get => sub {
896                    my ($self) = @_;
897                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
898                        $self->base->get_object('address', $fmainaddress)
899                            ->_get_c_field($self->name);
900                    } else {
901                        return;
902                    }
903                },
904                set => $subsetaddress,
905                label => l('Office'),
906            },
907            uid => {
908                iname => 'name',
909                ro => 1,
910                label => l('Login'),
911            },
912            cn =>  { iname => 'name', ro => 1 },
913            gecos => {
914                ro => 1,
915                auto => 1,
916            },
917            _gecos => {
918                managed => 1,
919                hide => 1,
920                ro => 1,
921                get => sub {
922                    my ($self) = @_;
923                    my $obj = $self->object;
924
925                    my $fmt = $self->base->config('gecosformat') ||
926                        '%{_displayName},%{l}-%{physicalDeliveryOfficeName},%{telephoneNumber},%{?endcircuit:%{endcircuit}}%{?!endcircuit:%{expireText}}';
927                    my $gecos = $obj->queryformat($fmt);
928                    return to_ascii($gecos);
929                },
930                label => l('GECOS'),
931            },
932            displayName => {
933                ro => 1,
934                auto => 1,
935            },
936            _displayName  => {
937                ro => 1, managed => 1,
938                hide => 1,
939                get => sub {
940                    my ($self) = @_;
941                    return join(' ', grep { $_ } 
942                        (
943                            $self->object->_get_c_field('givenName'),
944                            $self->object->_get_c_field('sn')
945                        )
946                    )
947                    || $self->object->_get_c_field('description')
948                    || $self->object->id;
949                },
950                label => l('Name'),
951            },
952            sAMAccountName => {
953                auto => 1,
954            },
955            _sAMAccountName  => {
956                ro => 1,
957                hide => 1,
958                managed => 1,
959                iname => 'name',
960                get => sub {
961                    my ($self) = @_;
962                    substr($self->object->id, 0, 19)
963                },
964            },
965            accountExpires => {
966                ro => 1,
967                auto => 1,
968            },
969            _accountExpires => {
970                ro => 1,
971                managed => 1,
972                hide => 1,
973                get => sub {
974                    my ($self) = @_;
975                    my $obj = $self->object;
976                    my $sth = $obj->db->prepare_cached(
977                        sprintf(
978                            q{select extract(epoch from %s) + 11644474161 as expire
979                            from %s where %s = ?},
980                            $base->config('endCircuitdontExpire') ? 'expire' : 'COALESCE(endcircuit,  expire)',
981                            $obj->db->quote_identifier($obj->_object_table),
982                            $obj->db->quote_identifier($obj->_key_field),
983                        )
984                    );
985                    $sth->execute($obj->id);
986                    my $res = $sth->fetchrow_hashref;
987                    $sth->finish;
988                    return $res->{expire} ? sprintf("%.f", $res->{expire} * 1E7) : '9223372036854775807';
989                }
990            },
991            shadowExpire => {
992                ro => 1,
993                auto => 1,
994            },
995            _shadowExpire => {
996                ro => 1,
997                hide => 1,
998                managed => 1,
999                get => sub {
1000                    my ($self) = @_;
1001                    my $obj = $self->object;
1002                    my $sth = $obj->db->prepare_cached(
1003                        sprintf(
1004                            q{select justify_hours(%s - '1/1/1970'::timestamp) as expire
1005                            from %s where %s = ?},
1006                            $base->config('endCircuitdontExpire') ? 'expire' : 'COALESCE(endcircuit,  expire)',
1007                            $obj->db->quote_identifier($obj->_object_table),
1008                            $obj->db->quote_identifier($obj->_key_field),
1009                        )
1010                    );
1011                    $sth->execute($obj->id);
1012                    my $res = $sth->fetchrow_hashref;
1013                    $sth->finish;
1014                    return -1 unless($res->{expire});
1015                    $res->{expire} =~ /(\d+) days\s*(\w)?/;
1016                    # Add one day is time is not 00H00
1017                    return $1 + ($2 ? 1 : 0);
1018                }
1019            },
1020            directReports => {
1021                auto => 1,
1022                ro => 1,
1023            },
1024            _directReports => {
1025                reference => 'user',
1026                ro => 1,
1027                hide => 1,
1028                delayed => 1,
1029                get => sub {
1030                    my ($self) = @_;
1031                    my $obj = $self->object;
1032                    my $sth = $obj->db->prepare_cached(
1033                        q{
1034                        SELECT
1035                        "user".name FROM
1036                        public."user",
1037                        public.user_attributes_groups,
1038                        public.group_attributes_users,
1039                        public.group_attributes_base gb,
1040                        public."group"
1041                        WHERE
1042                        "user".ikey = user_attributes_groups.okey AND
1043                        user_attributes_groups.value = "group".name AND
1044                        group_attributes_users.okey = gb.okey AND
1045                        "group".ikey = group_attributes_users.okey AND
1046                        gb.attr = 'sutype' AND
1047                        gb.value = 'dpmt' AND
1048                        group_attributes_users.attr = 'managedBy' AND
1049                        group_attributes_users.value = ?
1050                        } . ($self->base->{wexported} ? '' : ' and "user".exported = true') . q{
1051                            and "user".ikey not in
1052                        (select okey from user_attributes_users
1053                        where attr = 'manager' and value != ? )
1054                        union
1055                        select "user".name FROM public."user",
1056                        user_attributes_users where
1057                        user_attributes_users.attr = 'manager' and user_attributes_users.value = ?
1058                            and "user".ikey = user_attributes_users.okey
1059                        } . ($self->base->{wexported} ? '' : ' and "user".exported = true')
1060                    );
1061                    $sth->execute($obj->id, $obj->id, $obj->id);
1062                    my @res;
1063                    while (my $res = $sth->fetchrow_hashref) {
1064                        push(@res, $res->{name});
1065                    }
1066                    return \@res;
1067                },
1068            },
1069            managedObjects => { ro => 1, reference => 'group', },
1070            otheraddress => {
1071                ro => 1,
1072                auto => 1,
1073            },
1074            _otheraddress => {
1075                ro => 1,
1076                hide => 1,
1077                reference => 'address',
1078                get => sub {
1079                    my ($self) = @_;
1080                    my $sth = $self->base->db->prepare_cached(q{
1081                        select name from address left join address_attributes
1082                        on address.ikey = address_attributes.okey and
1083                        address_attributes.attr = 'isMainAddress'
1084                        where "user" = ?
1085                        } . ($self->base->{wexported} ? '' : ' and "address".exported = true') . q{
1086                        order by address_attributes.attr
1087                        } );
1088                    $sth->execute($self->object->id);
1089                    my @values;
1090                    while (my $res = $sth->fetchrow_hashref) {
1091                        push(@values, $res->{name});
1092                    }
1093                    return \@values;
1094                },
1095            },
1096            mainaddress => { auto => 1 },
1097            _mainaddress => {
1098                hide => 1,
1099                ro => 1,
1100                reference => 'address',
1101                get => sub {
1102                    my ($self) = @_;
1103                    my $sth = $self->base->db->prepare_cached(q{
1104                        select name from address join address_attributes on ikey = okey
1105                        where "user" = ? and attr = 'isMainAddress'
1106                        } . ($self->base->{wexported} ? '' : ' and "address".exported = true'));
1107                    $sth->execute($self->object->id);
1108                    my $res = $sth->fetchrow_hashref;
1109                    $sth->finish;
1110                    return $res->{name};
1111                },
1112            },
1113            postalAddress => { auto => 1 },
1114            _postalAddress => {
1115                hide => 1,
1116                ro => 1,
1117                get => sub {
1118                    my ($self) = @_;
1119                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
1120                        $self->base->get_object('address', $fmainaddress)
1121                            ->_get_c_field($self->name);
1122                    } else {
1123                        return;
1124                    }
1125                },
1126                label => l('Postal Address'),
1127            },
1128            facsimileTelephoneNumber => {
1129                ro => 1,
1130                label => l('Fax number'),
1131            },
1132            allsite   => {
1133                ro => 1,
1134                reference => 'site',
1135            },
1136            managerContact => {
1137                delayed => 1,
1138                can_values => sub {
1139                    my %uniq = map { $_ => 1 } grep { $_ }
1140                    (($_[1] ? $_[1]->get_attributes('managerContact') : ()),
1141                    $base->search_objects('user', 'active=1'));
1142                    sort keys %uniq;
1143                },
1144                reference => 'user',
1145                monitored => 1,
1146                iname => 'manager',
1147                label => l('Manager'),
1148            },
1149            expireTextEC => {
1150                ro => 1,
1151                auto => 1,
1152            },
1153            _expireTextEC => {
1154                ro => 1,
1155                managed => 1,
1156                hide => 1,
1157                get => sub {
1158                    my ($self) = @_;
1159                    my $obj = $self->object;
1160                    my $sth = $obj->db->prepare_cached(
1161                        sprintf(
1162                            q{select to_char(%s, 'YYYY/MM/DD') as expire
1163                            from %s where %s = ?},
1164                            $base->config('endCircuitdontExpire') ? 'expire' : 'COALESCE(endcircuit,  expire)',
1165                            $obj->db->quote_identifier($obj->_object_table),
1166                            $obj->db->quote_identifier($obj->_key_field),
1167                        )
1168                    );
1169                    $sth->execute($obj->id) or $obj->db->rollback;
1170                    my $res = $sth->fetchrow_hashref;
1171                    $sth->finish;
1172                    return $res->{expire}
1173                },
1174            },
1175            expireText => {
1176                ro => 1,
1177                auto => 1,
1178            },
1179            _expireText => {
1180                ro => 1,
1181                hide => 1,
1182                managed => 1,
1183                get => sub {
1184                    my ($self) = @_;
1185                    my $obj = $self->object;
1186                    my $sth = $obj->db->prepare_cached(
1187                        sprintf(
1188                            q{select to_char(expire, 'YYYY/MM/DD') as expire
1189                            from %s where %s = ?},
1190                            $obj->db->quote_identifier($obj->_object_table),
1191                            $obj->db->quote_identifier($obj->_key_field),
1192                        )
1193                    );
1194                    $sth->execute($obj->id) or $obj->db->rollback;
1195                    my $res = $sth->fetchrow_hashref;
1196                    $sth->finish;
1197                    return $res->{expire}
1198                },
1199            },
1200            krb5ValidEnd => {
1201                ro => 1,
1202                auto => 1,
1203            },
1204            _krb5ValidEnd => {
1205                ro => 1,
1206                managed => 1,
1207                hide => 1,
1208                get => sub {
1209                    my ($self) = @_;
1210                    my $sth = $self->object->db->prepare_cached(
1211                        sprintf(
1212                            q{select date_part('epoch', COALESCE(endcircuit,  expire))::int as expire
1213                            from %s where %s = ?},
1214                            $self->object->db->quote_identifier($self->object->_object_table),
1215                            $self->object->db->quote_identifier($self->object->_key_field),
1216                        )
1217                    );
1218                    $sth->execute($self->object->id) or $self->object->db->rollback;
1219                    my $res = $sth->fetchrow_hashref;
1220                    $sth->finish;
1221                    return $res->{expire}
1222                },
1223            },
1224            cells  => {
1225                ro => 1,
1226                reference => 'group',
1227            },
1228            departments => {
1229                reference => 'group',
1230                delayed => 1,
1231                ro => 1,
1232                label => l('Departments'),
1233            },
1234            arrivalDate => { },
1235            expired => {
1236                ro => 1,
1237                label => l('Expired'),
1238            },
1239            active => {
1240                ro => 1,
1241                label => l('Active'),
1242            },
1243            status => {
1244                ro => 1,
1245                label => l('Statut du compte'),
1246            },
1247            pwdAccountLockedTime => {
1248                auto => 1,
1249                ro => 1,
1250            },
1251            _pwdAccountLockedTime => {
1252                managed => 1,
1253                ro => 1,
1254                hide => 1,
1255                get => sub {
1256                    my ($self) = @_;
1257                    my $obj = $self->object;
1258                    if ($obj->_get_c_field('locked')) {
1259                        return '000001010000Z';
1260                    } else {
1261                        my $sth = $obj->db->prepare_cached(
1262                            sprintf(
1263                                q{select to_char(%s AT TIME ZONE 'Z', 'YYYYMMDDHH24MISSZ') as expire
1264                                from %s where %s = ? and expire < now()},
1265                                $base->config('endCircuitdontExpire') ? 'expire' : 'COALESCE(endcircuit,  expire)',
1266                                $obj->db->quote_identifier($obj->_object_table),
1267                                $obj->db->quote_identifier($obj->_key_field),
1268                            )
1269                        );
1270                        $sth->execute($obj->id);
1271                        my $res = $sth->fetchrow_hashref;
1272                        $sth->finish;
1273                        return $res->{expire}
1274                    }
1275                },
1276            },
1277            userPassword => { readable => 0, },
1278            wWWHomePage => {
1279                label => l('Web Page'),
1280                formopts => { length => 35 },
1281            },
1282            title => { },
1283            snNative => {
1284                label => l('Native name'),
1285            },
1286            givenNameNative => {
1287                label => l('Native first name'),
1288            },
1289            sn => {
1290                label => l('Name'),
1291            },
1292            shadowWarning => { },
1293            shadowMin => { },
1294            shadowMax => { },
1295            shadowLastChange => { },
1296            shadowInactive => { },
1297            shadowFlag => { },
1298            otherTelephone => { },
1299            nickname => {
1300                label => l('Nickname'),
1301            },
1302            mobile => { },
1303            mail => {
1304                label => l('Email'),
1305            },
1306            otherEmail => {
1307                label => l('External mail'),
1308            },
1309            labeledURI => { },
1310            jobType => { },
1311            ipPhone => { },
1312            initials => {
1313                label => l('Initials'),
1314                checkinput => sub {
1315                    $_[0] or return;
1316                    return(length($_[0]) <= 6)
1317                }
1318            },
1319            homePhone => { },
1320            homeDirectory => {
1321                label => l('Home directory'),
1322            },
1323            halReference => {
1324                label => l('HAL id'),
1325            },
1326            grade => { },
1327            givenName => {
1328                label => l('First name'),
1329            },
1330            encryptedPassword => { },
1331            description => {
1332                label => l('Description'),
1333            },
1334            company => {
1335                label => l('Company'),
1336            },
1337            employer => {
1338                label => l('Employer'),
1339            },
1340            comment => {
1341                label => l('Comment'),
1342            },
1343            college => { },
1344            passwordLastSet => {
1345                ro => 1,
1346                label => l('Password set'),
1347            },
1348            oldPassword => {
1349                multiple => 1,
1350            },
1351            bannedPassword => {
1352                multiple => 1,
1353            },
1354            sshPublicKey => {
1355                multiple => 1,
1356                formopts => { length => 45 },
1357            },
1358            sshPublicKeyFilter => {
1359                multiple => 1,
1360                formopts => { length => 45 },
1361            },
1362            delUnknownSshKey => {
1363                formtype => 'CHECKBOX',
1364            },
1365            _authorizedKeys => {
1366                multiple => 1,
1367                ro => 1,
1368                managed => 1,
1369                hide => 1,
1370                get => sub {
1371                    my ($attr) = @_;
1372                    my $self = $attr->object;
1373
1374                    my @keys = $self->_get_attributes('sshPublicKey');
1375
1376                    my @filters = $self->_get_attributes('sshPublicKeyFilter');
1377                    my $delUnknownSshKey = $self->_get_attributes('delUnknownSshKey');
1378
1379                    my %users = ( $self->id => 1 );
1380
1381                    if (@filters) {
1382                        foreach my $user ($self->base->search_objects('user', @filters, 'oalias=NULL')) {
1383                            my $ouser = $self->base->get_object('user', $user) or next;
1384                            $users{ $user } and next;
1385                            $users{ $user } = 1;
1386                            push(@keys, $ouser->_get_attributes('sshPublicKey'));
1387                        }
1388                    }
1389
1390                    return @keys
1391                        ? \@keys
1392                        : (@filters || $delUnknownSshKey
1393                            ? [ '# No key (' . DateTime->now->iso8601 . ')' ]
1394                            : undef);
1395                },
1396            },
1397            authorizedKeys => {
1398                multiple => 1,
1399                ro => 1,
1400            },
1401            currentEmployment => {
1402                managed => 1,
1403                ro => 1,
1404                reference => 'employment',
1405                get => sub {
1406                    my ($attr) = @_;
1407                    my $self = $attr->object;
1408
1409                    my $now = DateTime->now()->iso8601 . 'Z';
1410
1411                    my $sth = $self->base->db->prepare_cached(
1412                        q{
1413                        select name from employment where firstday <= ?::timestamp and
1414                        (lastday is null or lastday >= ?::timestamp - '1 days'::interval) and "user" = ?
1415                        limit 1
1416                        }
1417                    );
1418                    $sth->execute($now, $now, $self->id);
1419                    my $res = $sth->fetchrow_hashref;
1420                    $sth->finish;
1421                    if ($res) {
1422                        return $res->{name}
1423                    } else {
1424                        return;
1425                    }
1426                },
1427            },
1428            nextEmployment => {
1429                managed => 1,
1430                ro => 1,
1431                reference => 'employment',
1432                get => sub {
1433                    my ($attr) = @_;
1434                    my $self = $attr->object;
1435
1436                    my $now = DateTime->now()->iso8601 . 'Z';
1437
1438                    my $sth = $self->base->db->prepare_cached(
1439                        q{
1440                        select name from employment where firstday > ?::timestamp and "user" = ?
1441                        order by firstday asc
1442                        limit 1
1443                        }
1444                    );
1445                    $sth->execute($now, $self->id);
1446                    my $res = $sth->fetchrow_hashref;
1447                    $sth->finish;
1448                    if ($res) {
1449                        return $res->{name}
1450                    } else {
1451                        return;
1452                    }
1453                }
1454            },
1455            activeEmployment => {
1456                managed => 1,
1457                ro => 1,
1458                reference => 'employment',
1459                multiple => 1,
1460                get => sub {
1461                    my ($attr) = @_;
1462                    my $self = $attr->object;
1463
1464                    my $now = DateTime->now()->iso8601 . 'Z';
1465
1466                    my $sth = $self->base->db->prepare_cached(
1467                        q{
1468                        select name from employment where (lastday > ?::timestamp or lastday IS NULL) and "user" = ?
1469                        order by firstday asc
1470                        limit 1
1471                        }
1472                    );
1473                    $sth->execute($now, $self->id);
1474                    my @Res;
1475                    while (my  $res = $sth->fetchrow_hashref) {
1476                        push(@Res, $res->{name});
1477                    }
1478
1479                    return \@Res;
1480                }
1481            },
1482            prevEmployment => {
1483                managed => 1,
1484                ro => 1,
1485                reference => 'employment',
1486                get => sub {
1487                    my ($attr) = @_;
1488                    my $self = $attr->object;
1489
1490                    my $now = DateTime->now()->iso8601 . 'Z';
1491
1492                    my $sth = $self->base->db->prepare_cached(
1493                        q{
1494                        select name from employment where
1495                        (lastday is not null and lastday <= ?::timestamp - '1 days'::interval) and "user" = ?
1496                        order by firstday desc
1497                        limit 1
1498                        }
1499                    );
1500                    $sth->execute($now, $self->id);
1501                    my $res = $sth->fetchrow_hashref;
1502                    $sth->finish;
1503                    if ($res) {
1504                        return $res->{name}
1505                    } else {
1506                        return;
1507                    }
1508                }
1509            },
1510            appliedEmployement => {
1511                hide => 1,
1512                reference => 'employment',
1513            },
1514            contratTypeHistory => {
1515                reference => 'group',
1516                can_values => sub {
1517                    $base->search_objects('group', 'sutype=contrattype')
1518                },
1519                multiple => 1,
1520            },
1521            employmentHistory => {
1522                reference => 'employment',
1523                multiple => 1,
1524                ro => 1,
1525            },
1526            hosted => {
1527                formtype => 'CHECKBOX',
1528                label => l('Hosted'),
1529            },
1530            assigned => {
1531                formtype => 'CHECKBOX',
1532                label => l('Assigned'),
1533            },
1534            createRequestId => {
1535                label => l('Account Request id')
1536            },
1537            requestId => {
1538                label => l('Request id'),
1539            },
1540            nationality => {
1541                label => l('Nationality'),
1542            },
1543            nativeCountry => {
1544                label => l('Native country'),
1545            },
1546            firstAidTrainingValidity => {
1547                formtype => 'DATE',
1548                label => l('Validité formation SST'),
1549            },
1550    };
1551
1552    my $employmentro = sub {
1553        my $setting = $base->config('employment_lock_user') || 'any';
1554
1555        for ($setting) {
1556            /^always$/ and return 1;
1557            /^never$/ and return 0;
1558
1559            $_[0] or return 0;
1560
1561            /^any$/i and return $_[0]->listEmployment ? 1 : 0;
1562            /^active/i and do {
1563                return $_[0]->_get_c_field('currentEmployment')
1564                ? 1
1565                : $_[0]->_get_c_field('nextEmployment') ? 1 : 0;
1566            };
1567            /(\S+)=(\S+)/ and do {
1568                my $attr = $_[0]->_get_c_field($1);
1569                if (defined($attr)) {
1570                    if ($2 eq '*') {
1571                        return 1;
1572                    } elsif($2 eq $attr) {
1573                        return 1;
1574                    } else {
1575                        return 0;
1576                    }
1577                } else {
1578                    return 0;
1579                }
1580            };
1581        }
1582        return $_[0]->listEmployment ? 1 : 0; # default is any!
1583    };
1584
1585    foreach (_reported_atributes(), qw(department managerContact contratTypeHistory)) {
1586        $attrs->{$_}{ro} = $employmentro;
1587    }
1588
1589    $attrs->{expire}{ro} = sub {
1590        my $expireOn = $base->config('expireOn') || '';
1591        if ($expireOn eq 'never') {
1592            return 0;
1593        }
1594
1595        $employmentro->($_[0]);
1596    };
1597
1598    $class->SUPER::_get_attr_schema($base, $attrs)
1599}
1600
1601sub CreateAlias {
1602    my ($class, $base, $name, $for) = @_;
1603
1604    my $stAddAlias = $base->db->prepare_cached(
1605        q{INSERT INTO "user" (name, uidnumber,            gidnumber, oalias, oaliascache) values
1606                             (?,    -nextval('ikey_seq'), ?,         ?,      ?)}
1607    );
1608
1609    my $ref = $base->_derefObject($class->type, $for);
1610    my $res = $stAddAlias->execute($name, -1, $for, $ref ? $ref->id : undef);
1611    return $res ? 1 : 0;
1612}
1613
1614sub _get_state {
1615    my ($self, $state) = @_;
1616    for ($state) {
1617        /^expired$/ and do {
1618            my $attribute = $self->attribute('expire');
1619            $attribute->check_acl('r') or return;
1620            my $sth = $self->db->prepare_cached(
1621                q{ select coalesce(expire < now(), false) as exp from "user"
1622                where "user".name = ?}
1623            );
1624            $sth->execute($self->id);
1625            my $res = $sth->fetchrow_hashref;
1626            $sth->finish;
1627            return $res->{exp} ? 1 : 0;
1628        };
1629    }
1630}
1631
1632sub set_fields {
1633    my ($self, %data) = @_;
1634
1635    my $old;
1636    if (exists($data{department})) {
1637        $old = $self->_get_attributes('department');
1638    }
1639
1640    if (($data{department} || '') eq ($old || '')) {
1641        # We do not remove the group, there is no change
1642        $old = undef;
1643    }
1644
1645    if ($old) {
1646        # If the department is no longer a department
1647        # we do nothing
1648        my @names = $self->base->search_objects('group', 'name=' . $old, 'sutype=dpmt');
1649        if (! @names) {
1650            $old = undef;
1651        }
1652    }
1653
1654    my $res = $self->SUPER::set_fields(%data) or return;
1655
1656    if ($self->base->config('remove_old_dpmt') && $old) {
1657        $self->base->log(LA_DEBUG,
1658            "Removing %s from group %s (department change to %s)",
1659            $self->id,
1660            $old,
1661            $data{department} || '');
1662        $self->_delAttributeValue('memberOf', $old) or return;
1663        $res++;
1664    }
1665
1666    $res
1667}
1668
1669=head2 listEmployment
1670
1671Return the ordered list of contract
1672
1673=cut
1674
1675sub listEmployment {
1676    my ($self) = @_;
1677
1678    my $sth = $self->base->db->prepare_cached(
1679        q{
1680        select name from employment where "user" = ?
1681        order by lastday desc NULLS first
1682        }
1683    );
1684    $sth->execute($self->id);
1685    my @list = ();
1686    while (my $res = $sth->fetchrow_hashref) {
1687        push(@list, $res->{name});
1688    }
1689
1690    @list
1691}
1692
1693sub _reported_atributes { qw(contratType endcircuit hosted assigned requestId company employer) }
1694
1695=head2 applyCurrentEmployment
1696
1697Search the current employment is any and apply paramter to user
1698
1699=cut
1700
1701sub applyCurrentEmployment {
1702    my ($self) = @_;
1703
1704    # Get current employment name
1705    my $currentempl = $self->get_attributes('currentEmployment') || '';
1706
1707    $self->base->log(
1708        LA_DEBUG,
1709        "Applying Employement %s to user %s",
1710        $currentempl || '(none)',
1711        $self->id
1712    );
1713
1714    if (my $currentemployment = $self->base->get_object('employment', $currentempl)) {
1715
1716        # If an employement apply we set the value to the user object
1717
1718        $self->computeEmploymentDate;
1719
1720        my %attrsets = (
1721            appliedEmployement => $currentemployment->id,
1722        );
1723        foreach my $attr (_reported_atributes(), qw(department managerContact)) {
1724            my $uval = $self->get_attributes($attr) || '';
1725            my $cval = $currentemployment->get_attributes($attr) || '';
1726
1727            if ($attr eq 'managerContact') {
1728                if (!$cval) {
1729                    my $dpmt  = $currentemployment->get_attributes('department') or last;
1730                    my $odmpt = $currentemployment->base->get_object('group', $dpmt) or last;
1731                    $cval = $odmpt->get_attributes('managedBy');
1732                }
1733            }
1734
1735            if ($uval ne $cval) {
1736                my $oattr = $currentemployment->base->attribute('user', $attr);
1737                $attrsets{$oattr->iname} = $cval;
1738            }
1739        }
1740
1741        if (keys %attrsets) {
1742            if (my $res = $self->set_fields(%attrsets)) {
1743                $self->ReportChange('Update', 'Attr %s updated to match Employment %s', join(', ', sort keys %attrsets), $currentemployment->id);
1744                return $res;
1745            }
1746        } else {
1747            return 1;
1748        }
1749    } else {
1750        # No current employment, resetting values:
1751
1752        return $self->_resetEmployment;
1753    }
1754
1755}
1756
1757# Reset attribute value set by employment
1758# except managerContact and expire
1759
1760sub _resetEmployment {
1761    my ($self) = @_;
1762
1763    $self->computeEmploymentDate;
1764
1765    my %changes = (
1766        appliedEmployement => undef,
1767    );
1768
1769    my @attributesToReset = (_reported_atributes(), qw(department));
1770
1771    foreach my $attr (@attributesToReset) {
1772        my $default = $self->base->config("unemployment.$attr") || '';
1773        my $old = $self->_get_attributes($attr) || '';
1774
1775        if ($old ne $default) {
1776            $changes{$attr} = $default || undef;
1777        }
1778    }
1779
1780    if(!$self->get_attributes('managerContact')) {
1781        if (my $next = $self->_get_attributes('nextEmployment')) {
1782            my $onext = $self->base->get_object('employment', $next);
1783            $changes{'manager'} = $onext->_get_attributes('managerContact');
1784        }
1785    }
1786
1787    # Managing expire:
1788    # If we found next status apply, keep it for expiration
1789    # Otherwise we reset to previous end of status
1790
1791    if (my $expire = $self->_computeEndEmployment($self->base->config('employment_delay') || 0)) {
1792        $changes{ 'expire' } = $expire;
1793    } elsif (my $prevEmployment = $self->_get_attributes('prevEmployment')) {
1794        my $oprev = $self->base->get_object('employment', $prevEmployment);
1795        $changes{ 'expire' } = $oprev->_get_attributes('lastday');
1796    } elsif (($self->base->config('unemployed_expire') ||'') ne 'no') {
1797        if (my $def = $self->base->{defattr}{'user.expire'}) {
1798            $changes{ 'expire' } = $def;
1799        }
1800    }
1801
1802
1803    if (%changes) {
1804        if ($self->set_fields(%changes)) {
1805            $self->base->log(LA_NOTICE, "Updating user %s to match unemployment", $self->id);
1806            $self->ReportChange('Update', 'Update %s to match unemployment', join(', ', sort keys %changes));
1807            return 1;
1808        } else {
1809            return 0;
1810        }
1811    } else {
1812        return 1;
1813    }
1814
1815}
1816
1817=head2 computeEmploymentDate
1818
1819Compute and copy to user start and end employment date
1820
1821=cut
1822
1823sub computeEmploymentDate {
1824    my ($self) = @_;
1825
1826    my $currentemployment = $self->get_attributes('currentEmployment') || '';
1827
1828    my $expire = str2time($self->_get_attributes('expire') || '1970-01-01T00:00:00');
1829
1830    my %changes;
1831    my @employmentDate = qw(
1832        endEmployment   endStrictEmployment   endCurrentEmployment   endLastEmployment
1833        startEmployment startStrictEmployment startCurrentEmployment startFirstEmployment
1834        arrival departure
1835    );
1836    foreach (@employmentDate) {
1837        my $old = $self->_get_attributes($_) || '';
1838        my $new = $self->_get_attributes("_$_") || '';
1839        if ($old ne $new) {
1840            $changes{$_} = $new || undef;
1841        }
1842    }
1843
1844    # If there is no current employment we try to find any to not let expire
1845    # unset
1846
1847    my $expireOn = $self->base->config('expireOn') || '';
1848    if (!grep { $_ eq $expireOn } (@employmentDate, '', 'never')) {
1849        $self->base->log(LA_ERR, "expireOn set to invalid parameter %s, using endEmployment instead", $expireOn);
1850        $expireOn = undef;
1851    }
1852    $expireOn ||= 'endEmployment';
1853
1854    # We check if matching start exists to know if using end* for expiration is
1855    # safe, even undef
1856    my %end2start = (
1857        endEmployment        => 'startEmployment',
1858        endStrictEmployment  => 'startStrictEmployment',
1859        endCurrentEmployment => 'startCurrentEmployment',
1860        endLastEmployment    => 'startFirstEmployment',
1861    );
1862
1863    # TODO rework this, working code but bloat
1864    if ($expireOn ne 'never') {
1865        my $endemploy = '';
1866        if ($self->_get_attributes("_$end2start{$expireOn}")) {
1867            $endemploy = $self->_get_attributes("_$expireOn") || '';
1868            $endemploy ||= 'UNCHANGED' unless($currentemployment);
1869        } elsif (($self->base->config('unemployed_expire') ||'') eq 'no') {
1870            $endemploy = '';
1871        } else {
1872            # No expiration date apply, don't touch
1873            $endemploy = 'UNCHANGED';
1874        }
1875
1876        if ($endemploy ne 'UNCHANGED') {
1877            my $nextexpire = str2time( $endemploy || '1970-01-01T00:00:00' );
1878
1879            if ($expire != $nextexpire) {
1880                $changes{expire} = $endemploy;
1881            }
1882        }
1883    }
1884
1885    if (keys %changes) {
1886        $self->base->log(LA_DEBUG, 'Applying employment state to user %s for field %s', $self->id, join(', ', keys %changes));
1887        $self->ReportChange('Update', 'Update %s to match employment', join(', ', sort keys %changes));
1888        if (exists($changes{expire})) {
1889            $self->ReportChange('Update', 'Expire update to %s to match employment', ($changes{expire} || '(none)'));
1890            $self->base->log(LA_DEBUG, 'New expiration is %s for user %s', ($changes{expire} || '(none)'), $self->id);
1891        }
1892        $self->set_fields(%changes);
1893    } else {
1894        $self->base->log(LA_DEBUG, 'No employment change for user %s', $self->id);
1895    }
1896
1897    $self->_computeEmploymentHistory();
1898
1899    return 1;
1900}
1901
1902sub _computeStartEmployment {
1903    my ($self, $delay, $any, $workday) = @_;
1904
1905    $delay ||= 0;
1906    my $start;
1907    my $nstart;
1908
1909    if (my $next = $self->_get_attributes('nextEmployment')) {
1910        my $onext = $self->base->get_object('employment', $next);
1911        $nstart = DateTime->from_epoch(epoch => str2time($onext->_get_attributes('firstday')));
1912        $nstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1913    }
1914
1915    my $list_empl = $self->base->db->prepare_cached(q{
1916        SELECT *, (lastday is null or lastday >= now() - '1days'::interval) as "current" FROM employment
1917        WHERE "user" = ? and firstday < now()
1918        order by firstday desc
1919        });
1920    $list_empl->execute($self->id);
1921
1922    while (my $res = $list_empl->fetchrow_hashref) {
1923        if ($res->{current}) {
1924        } elsif ($nstart) {
1925            my $prevend = DateTime->from_epoch(epoch => str2time($res->{lastday}));
1926            $prevend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1927            my $tstart = $nstart->clone;
1928            $tstart->subtract(days => $delay + 1);
1929            if ($tstart->ymd gt $prevend->ymd) {
1930                last;
1931            }
1932        } elsif ((!$res->{current}) && (!$any)) {
1933            last;
1934        }
1935        $nstart = DateTime->from_epoch(epoch => str2time($res->{firstday}));
1936        $nstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1937        $start = $nstart->clone;
1938    }
1939    $list_empl->finish;
1940
1941    $start ||= $nstart if ($any);
1942
1943    if ($start) {
1944        if ($workday) {
1945            my $day_of_week = $start->day_of_week;
1946            $start->add(days =>
1947                $day_of_week == 6 ? 2 :
1948                $day_of_week == 7 ? 1 : 0
1949            );
1950        }
1951    }
1952
1953    return $start ? $start->iso8601 : undef
1954}
1955
1956sub _computeEndEmployment {
1957    my ($self, $delay, $any, $workday) = @_;
1958
1959    $delay ||= 0;
1960    my $end;
1961    my $pend;
1962
1963    if (my $prev = $self->_get_attributes('prevEmployment')) {
1964        my $oprev = $self->base->get_object('employment', $prev);
1965        $pend = DateTime->from_epoch(epoch => str2time($oprev->_get_attributes('lastday')));
1966        $pend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1967        $pend->add(hours => 23, minutes => 59, seconds => 59);
1968    }
1969
1970    my $list_empl = $self->base->db->prepare_cached(q{
1971        SELECT *, firstday <= now() as "current" FROM employment WHERE "user" = ? and
1972        (lastday is null or lastday >= now() - '1 days'::interval)
1973        order by firstday asc
1974        });
1975    $list_empl->execute($self->id);
1976    while (my $res = $list_empl->fetchrow_hashref) {
1977        if (!$res->{lastday}) {
1978            # Ultimate employment.
1979            $list_empl->finish;
1980            return undef;
1981        }
1982        if ($res->{current}) {
1983        } elsif ($end) {
1984            my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday}));
1985            $nextstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1986            my $tend = $end->clone;
1987            $tend->add(days => $delay + 1);
1988            if ($tend->ymd lt $nextstart->ymd) {
1989                last;
1990            }
1991        } elsif ($pend) {
1992            my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday}));
1993            $nextstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1994            my $tend = $pend->clone;
1995            $tend->add(days => $delay + 1);
1996            if ($tend->ymd lt $nextstart->ymd) {
1997                last;
1998            }
1999            $end = $tend
2000        } elsif ((!$res->{current}) && (!$any)) {
2001            last;
2002        }
2003        $end = DateTime->from_epoch(epoch => str2time($res->{lastday}));
2004        $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
2005        $end->add(hours => 23, minutes => 59, seconds => 59);
2006    }
2007    $list_empl->finish;
2008
2009    $end ||= $pend if($any);
2010
2011    if ($end) {
2012        if ($workday) {
2013            my $day_of_week = $end->day_of_week;
2014            $end->subtract(days =>
2015                $day_of_week == 7 ? 2 :
2016                $day_of_week == 6 ? 1 : 0
2017            );
2018        }
2019    }
2020
2021    return $end ? $end->iso8601 : undef
2022}
2023
2024# Compute a summary of employement and store the value
2025# into an attribute
2026
2027sub _computeEmploymentHistory {
2028    my ($self) = @_;
2029
2030    my %changes;
2031
2032    {
2033        my $sth = $self->db->prepare_cached(q{
2034            select employment.name from employment
2035            where "user" = ? and employment.firstday < now()
2036        });
2037        $sth->execute($self->id);
2038        my @values;
2039        while (my $res = $sth->fetchrow_hashref) {
2040            push(@values, $res->{name});
2041        }
2042        $changes{"employmentHistory"} = \@values;
2043    }
2044
2045    foreach my $attribute (qw(contratType)) {
2046        my $sth = $self->db->prepare_cached(q{
2047            select employment_attributes.value from employment
2048            join employment_attributes
2049            on employment.ikey = employment_attributes.okey
2050            where "user" = ? and employment_attributes.attr = ?
2051            and employment.firstday < now()
2052            group by employment_attributes.value
2053            });
2054        $sth->execute($self->id, $attribute);
2055        my @values;
2056        while (my $res = $sth->fetchrow_hashref) {
2057            push(@values, $res->{value});
2058        }
2059        $changes{$attribute . "History"} = \@values;
2060    }
2061
2062    $self->set_fields(%changes);
2063}
2064
2065=head2 storeBannedPassword($epassword)
2066
2067Add an encrypted password to untrust list
2068
2069=cut
2070
2071sub storeBannedPassword {
2072    my ($self, $EncPass) = @_;
2073
2074    my @banned = sort { $b cmp $a } $self->_get_attributes('bannedPassword');
2075    my $now = DateTime->now; 
2076    unshift(@banned, $now->iso8601 . ';' . $EncPass);
2077    $self->set_fields('bannedPassword', [ grep { $_ } @banned ]);
2078
2079}
2080
2081=head2 banCurrentPassword
2082
2083Store the current password as banned
2084
2085=cut
2086
2087sub banCurrentPassword {
2088    my ($self) = @_;
2089   
2090    my $old = $self->get_field('userPassword') or return;
2091    $self->storeBannedPassword($old);
2092}
2093
2094sub check_password {
2095    my ( $self, $password ) = @_;
2096
2097    my $res = $self->SUPER::check_password($password);
2098    if ($res !~ /^ok$/) {
2099        return $res;
2100    }
2101
2102    foreach my $banned ($self->_get_attributes('bannedPassword')) {
2103        my ($date, $oldPassword) = $banned =~ /^([^;]*);(.*)/;
2104        if (crypt($password, $oldPassword) eq $oldPassword) {
2105            return "Banned password, cannot be used anymore";
2106        }
2107    }
2108
2109    return 'ok';
2110}
2111
2112sub _set_password {
2113    my ($self, $clear_pass) = @_;
2114    if (my $attr = $self->base->attribute($self->type, 'userPassword')) {
2115        my $field = $attr->iname;
2116
2117        # Storing as old password
2118        my @olds = sort { $b cmp $a } $self->_get_attributes('oldPassword');
2119        if (my $old = $self->get_field('userPassword')) {
2120            my $now = DateTime->now; 
2121            unshift(@olds, $now->iso8601 . ';' . $old);
2122            $self->set_fields('oldPassword', [ grep { $_ } @olds[0 .. 14] ]);
2123        }
2124
2125        my $res = $self->set_fields($field, $self->base->passCrypt($clear_pass));
2126        if ($res) {
2127            if ($self->base->get_global_value('rsa_public_key')) {
2128                $self->setCryptPassword($clear_pass) or return;
2129            }
2130        }
2131
2132        $self->set_fields('passwordLastSet', DateTime->now->datetime);
2133        $self->base->log(LA_NOTICE,
2134            'Mot de passe changé pour %s',
2135            $self->id
2136        );
2137
2138
2139        return $res;
2140    } else {
2141        $self->log(LA_WARN,
2142            "Cannot set password: userPassword attributes is unsupported");
2143    }
2144}
2145
2146=head2 setCryptPassword($clear_pass)
2147
2148Store password encrypted using RSA encryption.
2149
2150=cut
2151
2152sub setCryptPassword {
2153    my ($self, $clear_pass) = @_;
2154    if (my $serialize = $self->base->get_global_value('rsa_public_key')) {
2155        my $public = Crypt::RSA::Key::Public->new;
2156        $public = $public->deserialize(String => [ $serialize ]);
2157        my $rsa = new Crypt::RSA ES => 'PKCS1v15';
2158        my $rsa_password = $rsa->encrypt (
2159            Message    => $clear_pass,
2160            Key        => $public,
2161            Armour     => 1,
2162        ) || die $rsa->errstr();
2163        if (!$self->_set_c_fields('encryptedPassword', $rsa_password)) {
2164            $self->log(LA_ERR,
2165                "Cannot set 'encryptedPassword' attribute for object %s/%s",
2166                $self->type, $self->id,
2167            );
2168            return;
2169        }
2170    }
2171    $self->ReportChange('Password', 'Password stored using internal key');
2172    return 1;
2173}
2174
2175=head2 _InjectCryptPasswd($cryptpasswd)
2176
2177Inject a password encrypted using standard UNIX method.
2178
2179The passwrod will be used to authenticate user inside the application but it
2180will not be transmit to any other database.
2181
2182=cut
2183
2184sub _InjectCryptPasswd {
2185    my ($self, $cryptpasswd) = @_;
2186
2187    if (my $current = $self->get_field('userPassword')) {
2188        if ($cryptpasswd eq $current) {
2189            return 1;
2190        }
2191    }
2192    my $res = $self->set_fields('userPassword', $cryptpasswd);
2193
2194    if ($res) {
2195        $self->base->log(LA_NOTICE, 'Crypted password injected for %s', $self->id);
2196        return 1;
2197    } else {
2198        $self->base->log(LA_ERR, 'Cannot inject crypted password for %s', $self->id);
2199        return 0;
2200    }
2201}
2202
2203=head2 GenPasswordResetId
2204
2205Return a new id allowing passowrd reset
2206
2207=cut
2208
2209sub GenPasswordResetId {
2210    my ($self) = @_;
2211
2212    my $id = LATMOS::Accounts::Utils::genpassword(length => 32);
2213
2214    my $sth = $self->base->db->prepare_cached(q{
2215        INSERT INTO passwordreset (id, "user") values (?,?)
2216    });
2217
2218    if ($sth->execute($id, $self->id)) {
2219        return $id;
2220    } else {
2221        return;
2222    }
2223}
2224
2225=head2 SendPasswordReset($url)
2226
2227Generate a password reset Id and the to the user.
2228
2229C<$url> is the URL where the password can changed (printf forward, the %s is
2230replaced by the request id)
2231
2232=cut
2233
2234sub SendPasswordReset {
2235    my ($self, $url) = @_;
2236
2237    my $id = $self->GenPasswordResetId;
2238
2239    my $mail = $self->_get_attributes('mail') or do {
2240        $self->base->log(LA_ERR, "Cannot sent reset password mail: no mail found");
2241        return;
2242    };
2243
2244    my $MailSubject = $self->base->la->val('_default_', 'mailSubject', 'LATMOS::Accounts');
2245
2246    my %mail = (
2247        Subject => "$MailSubject: pasword reset",
2248        'X-LATMOS-Reason' => 'Password Reset',
2249        to => $mail,
2250    );
2251
2252    if (my $otherEmail = $self->_get_attributes('otherEmail')) {
2253        $mail{cc} = $otherEmail;
2254    }
2255
2256    my $vars = {
2257        url => sprintf($url, $id),
2258    };
2259    $vars->{id} =  $id;
2260    $vars->{obj} = $self;
2261
2262    my $lamail = LATMOS::Accounts::Mail->new(
2263        $self->base->la,
2264        'passwordreset.mail',
2265    );
2266
2267    if ($lamail->process(\%mail, $vars)) {
2268        $self->base->log(LA_NOTICE,
2269            "Reset password sent to %s for user %s",
2270            $mail{to},
2271            $self->id,
2272        );
2273        return 1;
2274    } else {
2275        return;
2276    }
2277
2278}
2279
2280=head2 CheckPasswordResetId($id)
2281
2282Return True if the reset password ID can be found and is less than one day old
2283
2284=cut
2285
2286sub CheckPasswordResetId {
2287    my ($self, $id) = @_;
2288
2289    my $sth = $self->base->db->prepare_cached(q{
2290        SELECT * FROM passwordreset WHERE
2291            "user" = ? and
2292            id = ? and
2293            "create" >= now() - '1 days'::interval
2294    });
2295    $sth->execute($self->id, $id);
2296
2297    my $res = $sth->fetchrow_hashref;
2298    $sth->finish;
2299
2300    return $res ? 1 : 0;
2301}
2302
2303=head2 DeletePasswordId($id)
2304
2305Delete password reset C<$id> and all expired request
2306
2307=cut
2308
2309sub DeletePasswordId {
2310    my ($self, $id) = @_;
2311
2312    my $sth = $self->base->db->prepare_cached(q{
2313        DELETE FROM passwordreset WHERE
2314        "user" = ? AND (id = ? or "create" < now() - '1 days'::interval)
2315    });
2316
2317    $sth->execute($self->id, $id);
2318}
2319
23201;
2321
2322__END__
2323
2324=head1 SEE ALSO
2325
2326=head1 AUTHOR
2327
2328Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
2329
2330=head1 COPYRIGHT AND LICENSE
2331
2332Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS
2333
2334This library is free software; you can redistribute it and/or modify
2335it under the same terms as Perl itself, either Perl version 5.10.0 or,
2336at your option, any later version of Perl 5 you may have available.
2337
2338=cut
Note: See TracBrowser for help on using the repository browser.