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

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

Fix otheraddress attribute issue

  • 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                multiple => 1,
1073                reference => 'address',
1074                get => sub {
1075                    my ($self) = @_;
1076                    my $sth = $self->base->db->prepare_cached(q{
1077                        select name from address left join address_attributes
1078                        on address.ikey = address_attributes.okey and
1079                        address_attributes.attr = 'isMainAddress'
1080                        where "user" = ?
1081                        } . ($self->base->{wexported} ? '' : ' and "address".exported = true') . q{
1082                        order by address_attributes.attr
1083                        } );
1084                    $sth->execute($self->object->id);
1085                    my @values;
1086                    while (my $res = $sth->fetchrow_hashref) {
1087                        push(@values, $res->{name});
1088                    }
1089                    return \@values;
1090                },
1091            },
1092            mainaddress => { auto => 1 },
1093            _mainaddress => {
1094                hide => 1,
1095                ro => 1,
1096                reference => 'address',
1097                get => sub {
1098                    my ($self) = @_;
1099                    my $sth = $self->base->db->prepare_cached(q{
1100                        select name from address join address_attributes on ikey = okey
1101                        where "user" = ? and attr = 'isMainAddress'
1102                        } . ($self->base->{wexported} ? '' : ' and "address".exported = true'));
1103                    $sth->execute($self->object->id);
1104                    my $res = $sth->fetchrow_hashref;
1105                    $sth->finish;
1106                    return $res->{name};
1107                },
1108            },
1109            postalAddress => {
1110                auto => 1,
1111            },
1112            _postalAddress => {
1113                hide => 1,
1114                ro => 1,
1115                get => sub {
1116                    my ($self) = @_;
1117                    if (my $fmainaddress = $self->object->_get_c_field('mainaddress')) {
1118                        $self->base->get_object('address', $fmainaddress)
1119                            ->_get_c_field($self->name);
1120                    } else {
1121                        return;
1122                    }
1123                },
1124                label => l('Postal Address'),
1125            },
1126            facsimileTelephoneNumber => {
1127                ro => 1,
1128                label => l('Fax number'),
1129            },
1130            allsite   => {
1131                ro => 1,
1132                reference => 'site',
1133            },
1134            managerContact => {
1135                delayed => 1,
1136                can_values => sub {
1137                    my %uniq = map { $_ => 1 } grep { $_ }
1138                    (($_[1] ? $_[1]->get_attributes('managerContact') : ()),
1139                    $base->search_objects('user', 'active=1'));
1140                    sort keys %uniq;
1141                },
1142                reference => 'user',
1143                monitored => 1,
1144                iname => 'manager',
1145                label => l('Manager'),
1146            },
1147            expireTextEC => {
1148                ro => 1,
1149                auto => 1,
1150            },
1151            _expireTextEC => {
1152                ro => 1,
1153                managed => 1,
1154                hide => 1,
1155                get => sub {
1156                    my ($self) = @_;
1157                    my $obj = $self->object;
1158                    my $sth = $obj->db->prepare_cached(
1159                        sprintf(
1160                            q{select to_char(%s, 'YYYY/MM/DD') as expire
1161                            from %s where %s = ?},
1162                            $base->config('endCircuitdontExpire') ? 'expire' : 'COALESCE(endcircuit,  expire)',
1163                            $obj->db->quote_identifier($obj->_object_table),
1164                            $obj->db->quote_identifier($obj->_key_field),
1165                        )
1166                    );
1167                    $sth->execute($obj->id) or $obj->db->rollback;
1168                    my $res = $sth->fetchrow_hashref;
1169                    $sth->finish;
1170                    return $res->{expire}
1171                },
1172            },
1173            expireText => {
1174                ro => 1,
1175                auto => 1,
1176            },
1177            _expireText => {
1178                ro => 1,
1179                hide => 1,
1180                managed => 1,
1181                get => sub {
1182                    my ($self) = @_;
1183                    my $obj = $self->object;
1184                    my $sth = $obj->db->prepare_cached(
1185                        sprintf(
1186                            q{select to_char(expire, 'YYYY/MM/DD') as expire
1187                            from %s where %s = ?},
1188                            $obj->db->quote_identifier($obj->_object_table),
1189                            $obj->db->quote_identifier($obj->_key_field),
1190                        )
1191                    );
1192                    $sth->execute($obj->id) or $obj->db->rollback;
1193                    my $res = $sth->fetchrow_hashref;
1194                    $sth->finish;
1195                    return $res->{expire}
1196                },
1197            },
1198            krb5ValidEnd => {
1199                ro => 1,
1200                auto => 1,
1201            },
1202            _krb5ValidEnd => {
1203                ro => 1,
1204                managed => 1,
1205                hide => 1,
1206                get => sub {
1207                    my ($self) = @_;
1208                    my $sth = $self->object->db->prepare_cached(
1209                        sprintf(
1210                            q{select date_part('epoch', COALESCE(endcircuit,  expire))::int as expire
1211                            from %s where %s = ?},
1212                            $self->object->db->quote_identifier($self->object->_object_table),
1213                            $self->object->db->quote_identifier($self->object->_key_field),
1214                        )
1215                    );
1216                    $sth->execute($self->object->id) or $self->object->db->rollback;
1217                    my $res = $sth->fetchrow_hashref;
1218                    $sth->finish;
1219                    return $res->{expire}
1220                },
1221            },
1222            cells  => {
1223                ro => 1,
1224                reference => 'group',
1225            },
1226            departments => {
1227                reference => 'group',
1228                delayed => 1,
1229                ro => 1,
1230                label => l('Departments'),
1231            },
1232            arrivalDate => { },
1233            expired => {
1234                ro => 1,
1235                label => l('Expired'),
1236            },
1237            active => {
1238                ro => 1,
1239                label => l('Active'),
1240            },
1241            status => {
1242                ro => 1,
1243                label => l('Statut du compte'),
1244            },
1245            pwdAccountLockedTime => {
1246                auto => 1,
1247                ro => 1,
1248            },
1249            _pwdAccountLockedTime => {
1250                managed => 1,
1251                ro => 1,
1252                hide => 1,
1253                get => sub {
1254                    my ($self) = @_;
1255                    my $obj = $self->object;
1256                    if ($obj->_get_c_field('locked')) {
1257                        return '000001010000Z';
1258                    } else {
1259                        my $sth = $obj->db->prepare_cached(
1260                            sprintf(
1261                                q{select to_char(%s AT TIME ZONE 'Z', 'YYYYMMDDHH24MISSZ') as expire
1262                                from %s where %s = ? and expire < now()},
1263                                $base->config('endCircuitdontExpire') ? 'expire' : 'COALESCE(endcircuit,  expire)',
1264                                $obj->db->quote_identifier($obj->_object_table),
1265                                $obj->db->quote_identifier($obj->_key_field),
1266                            )
1267                        );
1268                        $sth->execute($obj->id);
1269                        my $res = $sth->fetchrow_hashref;
1270                        $sth->finish;
1271                        return $res->{expire}
1272                    }
1273                },
1274            },
1275            userPassword => { readable => 0, },
1276            wWWHomePage => {
1277                label => l('Web Page'),
1278                formopts => { length => 35 },
1279            },
1280            title => { },
1281            snNative => {
1282                label => l('Native name'),
1283            },
1284            givenNameNative => {
1285                label => l('Native first name'),
1286            },
1287            sn => {
1288                label => l('Name'),
1289            },
1290            shadowWarning => { },
1291            shadowMin => { },
1292            shadowMax => { },
1293            shadowLastChange => { },
1294            shadowInactive => { },
1295            shadowFlag => { },
1296            otherTelephone => { },
1297            nickname => {
1298                label => l('Nickname'),
1299            },
1300            mobile => { },
1301            mail => {
1302                label => l('Email'),
1303            },
1304            otherEmail => {
1305                label => l('External mail'),
1306            },
1307            labeledURI => { },
1308            jobType => { },
1309            ipPhone => { },
1310            initials => {
1311                label => l('Initials'),
1312                checkinput => sub {
1313                    $_[0] or return;
1314                    return(length($_[0]) <= 6)
1315                }
1316            },
1317            homePhone => { },
1318            homeDirectory => {
1319                label => l('Home directory'),
1320            },
1321            halReference => {
1322                label => l('HAL id'),
1323            },
1324            grade => { },
1325            givenName => {
1326                label => l('First name'),
1327            },
1328            encryptedPassword => { },
1329            description => {
1330                label => l('Description'),
1331            },
1332            company => {
1333                label => l('Company'),
1334            },
1335            employer => {
1336                label => l('Employer'),
1337            },
1338            comment => {
1339                label => l('Comment'),
1340            },
1341            college => { },
1342            passwordLastSet => {
1343                ro => 1,
1344                label => l('Password set'),
1345            },
1346            oldPassword => {
1347                multiple => 1,
1348            },
1349            bannedPassword => {
1350                multiple => 1,
1351            },
1352            sshPublicKey => {
1353                multiple => 1,
1354                formopts => { length => 45 },
1355            },
1356            sshPublicKeyFilter => {
1357                multiple => 1,
1358                formopts => { length => 45 },
1359            },
1360            delUnknownSshKey => {
1361                formtype => 'CHECKBOX',
1362            },
1363            _authorizedKeys => {
1364                multiple => 1,
1365                ro => 1,
1366                managed => 1,
1367                hide => 1,
1368                get => sub {
1369                    my ($attr) = @_;
1370                    my $self = $attr->object;
1371
1372                    my @keys = $self->_get_attributes('sshPublicKey');
1373
1374                    my @filters = $self->_get_attributes('sshPublicKeyFilter');
1375                    my $delUnknownSshKey = $self->_get_attributes('delUnknownSshKey');
1376
1377                    my %users = ( $self->id => 1 );
1378
1379                    if (@filters) {
1380                        foreach my $user ($self->base->search_objects('user', @filters, 'oalias=NULL')) {
1381                            my $ouser = $self->base->get_object('user', $user) or next;
1382                            $users{ $user } and next;
1383                            $users{ $user } = 1;
1384                            push(@keys, $ouser->_get_attributes('sshPublicKey'));
1385                        }
1386                    }
1387
1388                    return @keys
1389                        ? \@keys
1390                        : (@filters || $delUnknownSshKey
1391                            ? [ '# No key (' . DateTime->now->iso8601 . ')' ]
1392                            : undef);
1393                },
1394            },
1395            authorizedKeys => {
1396                multiple => 1,
1397                ro => 1,
1398            },
1399            currentEmployment => {
1400                managed => 1,
1401                ro => 1,
1402                reference => 'employment',
1403                get => sub {
1404                    my ($attr) = @_;
1405                    my $self = $attr->object;
1406
1407                    my $now = DateTime->now()->iso8601 . 'Z';
1408
1409                    my $sth = $self->base->db->prepare_cached(
1410                        q{
1411                        select name from employment where firstday <= ?::timestamp and
1412                        (lastday is null or lastday >= ?::timestamp - '1 days'::interval) and "user" = ?
1413                        limit 1
1414                        }
1415                    );
1416                    $sth->execute($now, $now, $self->id);
1417                    my $res = $sth->fetchrow_hashref;
1418                    $sth->finish;
1419                    if ($res) {
1420                        return $res->{name}
1421                    } else {
1422                        return;
1423                    }
1424                },
1425            },
1426            nextEmployment => {
1427                managed => 1,
1428                ro => 1,
1429                reference => 'employment',
1430                get => sub {
1431                    my ($attr) = @_;
1432                    my $self = $attr->object;
1433
1434                    my $now = DateTime->now()->iso8601 . 'Z';
1435
1436                    my $sth = $self->base->db->prepare_cached(
1437                        q{
1438                        select name from employment where firstday > ?::timestamp and "user" = ?
1439                        order by firstday asc
1440                        limit 1
1441                        }
1442                    );
1443                    $sth->execute($now, $self->id);
1444                    my $res = $sth->fetchrow_hashref;
1445                    $sth->finish;
1446                    if ($res) {
1447                        return $res->{name}
1448                    } else {
1449                        return;
1450                    }
1451                }
1452            },
1453            activeEmployment => {
1454                managed => 1,
1455                ro => 1,
1456                reference => 'employment',
1457                multiple => 1,
1458                get => sub {
1459                    my ($attr) = @_;
1460                    my $self = $attr->object;
1461
1462                    my $now = DateTime->now()->iso8601 . 'Z';
1463
1464                    my $sth = $self->base->db->prepare_cached(
1465                        q{
1466                        select name from employment where (lastday > ?::timestamp or lastday IS NULL) and "user" = ?
1467                        order by firstday asc
1468                        limit 1
1469                        }
1470                    );
1471                    $sth->execute($now, $self->id);
1472                    my @Res;
1473                    while (my  $res = $sth->fetchrow_hashref) {
1474                        push(@Res, $res->{name});
1475                    }
1476
1477                    return \@Res;
1478                }
1479            },
1480            prevEmployment => {
1481                managed => 1,
1482                ro => 1,
1483                reference => 'employment',
1484                get => sub {
1485                    my ($attr) = @_;
1486                    my $self = $attr->object;
1487
1488                    my $now = DateTime->now()->iso8601 . 'Z';
1489
1490                    my $sth = $self->base->db->prepare_cached(
1491                        q{
1492                        select name from employment where
1493                        (lastday is not null and lastday <= ?::timestamp - '1 days'::interval) and "user" = ?
1494                        order by firstday desc
1495                        limit 1
1496                        }
1497                    );
1498                    $sth->execute($now, $self->id);
1499                    my $res = $sth->fetchrow_hashref;
1500                    $sth->finish;
1501                    if ($res) {
1502                        return $res->{name}
1503                    } else {
1504                        return;
1505                    }
1506                }
1507            },
1508            appliedEmployement => {
1509                hide => 1,
1510                reference => 'employment',
1511            },
1512            contratTypeHistory => {
1513                reference => 'group',
1514                can_values => sub {
1515                    $base->search_objects('group', 'sutype=contrattype')
1516                },
1517                multiple => 1,
1518            },
1519            employmentHistory => {
1520                reference => 'employment',
1521                multiple => 1,
1522                ro => 1,
1523            },
1524            hosted => {
1525                formtype => 'CHECKBOX',
1526                label => l('Hosted'),
1527            },
1528            assigned => {
1529                formtype => 'CHECKBOX',
1530                label => l('Assigned'),
1531            },
1532            createRequestId => {
1533                label => l('Account Request id')
1534            },
1535            requestId => {
1536                label => l('Request id'),
1537            },
1538            nationality => {
1539                label => l('Nationality'),
1540            },
1541            nativeCountry => {
1542                label => l('Native country'),
1543            },
1544            firstAidTrainingValidity => {
1545                formtype => 'DATE',
1546                label => l('Validité formation SST'),
1547            },
1548    };
1549
1550    my $employmentro = sub {
1551        my $setting = $base->config('employment_lock_user') || 'any';
1552
1553        for ($setting) {
1554            /^always$/ and return 1;
1555            /^never$/ and return 0;
1556
1557            $_[0] or return 0;
1558
1559            /^any$/i and return $_[0]->listEmployment ? 1 : 0;
1560            /^active/i and do {
1561                return $_[0]->_get_c_field('currentEmployment')
1562                ? 1
1563                : $_[0]->_get_c_field('nextEmployment') ? 1 : 0;
1564            };
1565            /(\S+)=(\S+)/ and do {
1566                my $attr = $_[0]->_get_c_field($1);
1567                if (defined($attr)) {
1568                    if ($2 eq '*') {
1569                        return 1;
1570                    } elsif($2 eq $attr) {
1571                        return 1;
1572                    } else {
1573                        return 0;
1574                    }
1575                } else {
1576                    return 0;
1577                }
1578            };
1579        }
1580        return $_[0]->listEmployment ? 1 : 0; # default is any!
1581    };
1582
1583    foreach (_reported_atributes(), qw(department managerContact contratTypeHistory)) {
1584        $attrs->{$_}{ro} = $employmentro;
1585    }
1586
1587    $attrs->{expire}{ro} = sub {
1588        my $expireOn = $base->config('expireOn') || '';
1589        if ($expireOn eq 'never') {
1590            return 0;
1591        }
1592
1593        $employmentro->($_[0]);
1594    };
1595
1596    $class->SUPER::_get_attr_schema($base, $attrs)
1597}
1598
1599sub CreateAlias {
1600    my ($class, $base, $name, $for) = @_;
1601
1602    my $stAddAlias = $base->db->prepare_cached(
1603        q{INSERT INTO "user" (name, uidnumber,            gidnumber, oalias, oaliascache) values
1604                             (?,    -nextval('ikey_seq'), ?,         ?,      ?)}
1605    );
1606
1607    my $ref = $base->_derefObject($class->type, $for);
1608    my $res = $stAddAlias->execute($name, -1, $for, $ref ? $ref->id : undef);
1609    return $res ? 1 : 0;
1610}
1611
1612sub _get_state {
1613    my ($self, $state) = @_;
1614    for ($state) {
1615        /^expired$/ and do {
1616            my $attribute = $self->attribute('expire');
1617            $attribute->check_acl('r') or return;
1618            my $sth = $self->db->prepare_cached(
1619                q{ select coalesce(expire < now(), false) as exp from "user"
1620                where "user".name = ?}
1621            );
1622            $sth->execute($self->id);
1623            my $res = $sth->fetchrow_hashref;
1624            $sth->finish;
1625            return $res->{exp} ? 1 : 0;
1626        };
1627    }
1628}
1629
1630sub set_fields {
1631    my ($self, %data) = @_;
1632
1633    my $old;
1634    if (exists($data{department})) {
1635        $old = $self->_get_attributes('department');
1636    }
1637
1638    if (($data{department} || '') eq ($old || '')) {
1639        # We do not remove the group, there is no change
1640        $old = undef;
1641    }
1642
1643    if ($old) {
1644        # If the department is no longer a department
1645        # we do nothing
1646        my @names = $self->base->search_objects('group', 'name=' . $old, 'sutype=dpmt');
1647        if (! @names) {
1648            $old = undef;
1649        }
1650    }
1651
1652    my $res = $self->SUPER::set_fields(%data) or return;
1653
1654    if ($self->base->config('remove_old_dpmt') && $old) {
1655        $self->base->log(LA_DEBUG,
1656            "Removing %s from group %s (department change to %s)",
1657            $self->id,
1658            $old,
1659            $data{department} || '');
1660        $self->_delAttributeValue('memberOf', $old) or return;
1661        $res++;
1662    }
1663
1664    $res
1665}
1666
1667=head2 listEmployment
1668
1669Return the ordered list of contract
1670
1671=cut
1672
1673sub listEmployment {
1674    my ($self) = @_;
1675
1676    my $sth = $self->base->db->prepare_cached(
1677        q{
1678        select name from employment where "user" = ?
1679        order by lastday desc NULLS first
1680        }
1681    );
1682    $sth->execute($self->id);
1683    my @list = ();
1684    while (my $res = $sth->fetchrow_hashref) {
1685        push(@list, $res->{name});
1686    }
1687
1688    @list
1689}
1690
1691sub _reported_atributes { qw(contratType endcircuit hosted assigned requestId company employer) }
1692
1693=head2 applyCurrentEmployment
1694
1695Search the current employment is any and apply paramter to user
1696
1697=cut
1698
1699sub applyCurrentEmployment {
1700    my ($self) = @_;
1701
1702    # Get current employment name
1703    my $currentempl = $self->get_attributes('currentEmployment') || '';
1704
1705    $self->base->log(
1706        LA_DEBUG,
1707        "Applying Employement %s to user %s",
1708        $currentempl || '(none)',
1709        $self->id
1710    );
1711
1712    if (my $currentemployment = $self->base->get_object('employment', $currentempl)) {
1713
1714        # If an employement apply we set the value to the user object
1715
1716        $self->computeEmploymentDate;
1717
1718        my %attrsets = (
1719            appliedEmployement => $currentemployment->id,
1720        );
1721        foreach my $attr (_reported_atributes(), qw(department managerContact)) {
1722            my $uval = $self->get_attributes($attr) || '';
1723            my $cval = $currentemployment->get_attributes($attr) || '';
1724
1725            if ($attr eq 'managerContact') {
1726                if (!$cval) {
1727                    my $dpmt  = $currentemployment->get_attributes('department') or last;
1728                    my $odmpt = $currentemployment->base->get_object('group', $dpmt) or last;
1729                    $cval = $odmpt->get_attributes('managedBy');
1730                }
1731            }
1732
1733            if ($uval ne $cval) {
1734                my $oattr = $currentemployment->base->attribute('user', $attr);
1735                $attrsets{$oattr->iname} = $cval;
1736            }
1737        }
1738
1739        if (keys %attrsets) {
1740            if (my $res = $self->set_fields(%attrsets)) {
1741                $self->ReportChange('Update', 'Attr %s updated to match Employment %s', join(', ', sort keys %attrsets), $currentemployment->id);
1742                return $res;
1743            }
1744        } else {
1745            return 1;
1746        }
1747    } else {
1748        # No current employment, resetting values:
1749
1750        return $self->_resetEmployment;
1751    }
1752
1753}
1754
1755# Reset attribute value set by employment
1756# except managerContact and expire
1757
1758sub _resetEmployment {
1759    my ($self) = @_;
1760
1761    $self->computeEmploymentDate;
1762
1763    my %changes = (
1764        appliedEmployement => undef,
1765    );
1766
1767    my @attributesToReset = (_reported_atributes(), qw(department));
1768
1769    foreach my $attr (@attributesToReset) {
1770        my $default = $self->base->config("unemployment.$attr") || '';
1771        my $old = $self->_get_attributes($attr) || '';
1772
1773        if ($old ne $default) {
1774            $changes{$attr} = $default || undef;
1775        }
1776    }
1777
1778    if(!$self->get_attributes('managerContact')) {
1779        if (my $next = $self->_get_attributes('nextEmployment')) {
1780            my $onext = $self->base->get_object('employment', $next);
1781            $changes{'manager'} = $onext->_get_attributes('managerContact');
1782        }
1783    }
1784
1785    # Managing expire:
1786    # If we found next status apply, keep it for expiration
1787    # Otherwise we reset to previous end of status
1788
1789    if (my $expire = $self->_computeEndEmployment($self->base->config('employment_delay') || 0)) {
1790        $changes{ 'expire' } = $expire;
1791    } elsif (my $prevEmployment = $self->_get_attributes('prevEmployment')) {
1792        my $oprev = $self->base->get_object('employment', $prevEmployment);
1793        $changes{ 'expire' } = $oprev->_get_attributes('lastday');
1794    } elsif (($self->base->config('unemployed_expire') ||'') ne 'no') {
1795        if (my $def = $self->base->{defattr}{'user.expire'}) {
1796            $changes{ 'expire' } = $def;
1797        }
1798    }
1799
1800
1801    if (%changes) {
1802        if ($self->set_fields(%changes)) {
1803            $self->base->log(LA_NOTICE, "Updating user %s to match unemployment", $self->id);
1804            $self->ReportChange('Update', 'Update %s to match unemployment', join(', ', sort keys %changes));
1805            return 1;
1806        } else {
1807            return 0;
1808        }
1809    } else {
1810        return 1;
1811    }
1812
1813}
1814
1815=head2 computeEmploymentDate
1816
1817Compute and copy to user start and end employment date
1818
1819=cut
1820
1821sub computeEmploymentDate {
1822    my ($self) = @_;
1823
1824    my $currentemployment = $self->get_attributes('currentEmployment') || '';
1825
1826    my $expire = str2time($self->_get_attributes('expire') || '1970-01-01T00:00:00');
1827
1828    my %changes;
1829    my @employmentDate = qw(
1830        endEmployment   endStrictEmployment   endCurrentEmployment   endLastEmployment
1831        startEmployment startStrictEmployment startCurrentEmployment startFirstEmployment
1832        arrival departure
1833    );
1834    foreach (@employmentDate) {
1835        my $old = $self->_get_attributes($_) || '';
1836        my $new = $self->_get_attributes("_$_") || '';
1837        if ($old ne $new) {
1838            $changes{$_} = $new || undef;
1839        }
1840    }
1841
1842    # If there is no current employment we try to find any to not let expire
1843    # unset
1844
1845    my $expireOn = $self->base->config('expireOn') || '';
1846    if (!grep { $_ eq $expireOn } (@employmentDate, '', 'never')) {
1847        $self->base->log(LA_ERR, "expireOn set to invalid parameter %s, using endEmployment instead", $expireOn);
1848        $expireOn = undef;
1849    }
1850    $expireOn ||= 'endEmployment';
1851
1852    # We check if matching start exists to know if using end* for expiration is
1853    # safe, even undef
1854    my %end2start = (
1855        endEmployment        => 'startEmployment',
1856        endStrictEmployment  => 'startStrictEmployment',
1857        endCurrentEmployment => 'startCurrentEmployment',
1858        endLastEmployment    => 'startFirstEmployment',
1859    );
1860
1861    # TODO rework this, working code but bloat
1862    if ($expireOn ne 'never') {
1863        my $endemploy = '';
1864        if ($self->_get_attributes("_$end2start{$expireOn}")) {
1865            $endemploy = $self->_get_attributes("_$expireOn") || '';
1866            $endemploy ||= 'UNCHANGED' unless($currentemployment);
1867        } elsif (($self->base->config('unemployed_expire') ||'') eq 'no') {
1868            $endemploy = '';
1869        } else {
1870            # No expiration date apply, don't touch
1871            $endemploy = 'UNCHANGED';
1872        }
1873
1874        if ($endemploy ne 'UNCHANGED') {
1875            my $nextexpire = str2time( $endemploy || '1970-01-01T00:00:00' );
1876
1877            if ($expire != $nextexpire) {
1878                $changes{expire} = $endemploy;
1879            }
1880        }
1881    }
1882
1883    if (keys %changes) {
1884        $self->base->log(LA_DEBUG, 'Applying employment state to user %s for field %s', $self->id, join(', ', keys %changes));
1885        $self->ReportChange('Update', 'Update %s to match employment', join(', ', sort keys %changes));
1886        if (exists($changes{expire})) {
1887            $self->ReportChange('Update', 'Expire update to %s to match employment', ($changes{expire} || '(none)'));
1888            $self->base->log(LA_DEBUG, 'New expiration is %s for user %s', ($changes{expire} || '(none)'), $self->id);
1889        }
1890        $self->set_fields(%changes);
1891    } else {
1892        $self->base->log(LA_DEBUG, 'No employment change for user %s', $self->id);
1893    }
1894
1895    $self->_computeEmploymentHistory();
1896
1897    return 1;
1898}
1899
1900sub _computeStartEmployment {
1901    my ($self, $delay, $any, $workday) = @_;
1902
1903    $delay ||= 0;
1904    my $start;
1905    my $nstart;
1906
1907    if (my $next = $self->_get_attributes('nextEmployment')) {
1908        my $onext = $self->base->get_object('employment', $next);
1909        $nstart = DateTime->from_epoch(epoch => str2time($onext->_get_attributes('firstday')));
1910        $nstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1911    }
1912
1913    my $list_empl = $self->base->db->prepare_cached(q{
1914        SELECT *, (lastday is null or lastday >= now() - '1days'::interval) as "current" FROM employment
1915        WHERE "user" = ? and firstday < now()
1916        order by firstday desc
1917        });
1918    $list_empl->execute($self->id);
1919
1920    while (my $res = $list_empl->fetchrow_hashref) {
1921        if ($res->{current}) {
1922        } elsif ($nstart) {
1923            my $prevend = DateTime->from_epoch(epoch => str2time($res->{lastday}));
1924            $prevend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1925            my $tstart = $nstart->clone;
1926            $tstart->subtract(days => $delay + 1);
1927            if ($tstart->ymd gt $prevend->ymd) {
1928                last;
1929            }
1930        } elsif ((!$res->{current}) && (!$any)) {
1931            last;
1932        }
1933        $nstart = DateTime->from_epoch(epoch => str2time($res->{firstday}));
1934        $nstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1935        $start = $nstart->clone;
1936    }
1937    $list_empl->finish;
1938
1939    $start ||= $nstart if ($any);
1940
1941    if ($start) {
1942        if ($workday) {
1943            my $day_of_week = $start->day_of_week;
1944            $start->add(days =>
1945                $day_of_week == 6 ? 2 :
1946                $day_of_week == 7 ? 1 : 0
1947            );
1948        }
1949    }
1950
1951    return $start ? $start->iso8601 : undef
1952}
1953
1954sub _computeEndEmployment {
1955    my ($self, $delay, $any, $workday) = @_;
1956
1957    $delay ||= 0;
1958    my $end;
1959    my $pend;
1960
1961    if (my $prev = $self->_get_attributes('prevEmployment')) {
1962        my $oprev = $self->base->get_object('employment', $prev);
1963        $pend = DateTime->from_epoch(epoch => str2time($oprev->_get_attributes('lastday')));
1964        $pend->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1965        $pend->add(hours => 23, minutes => 59, seconds => 59);
1966    }
1967
1968    my $list_empl = $self->base->db->prepare_cached(q{
1969        SELECT *, firstday <= now() as "current" FROM employment WHERE "user" = ? and
1970        (lastday is null or lastday >= now() - '1 days'::interval)
1971        order by firstday asc
1972        });
1973    $list_empl->execute($self->id);
1974    while (my $res = $list_empl->fetchrow_hashref) {
1975        if (!$res->{lastday}) {
1976            # Ultimate employment.
1977            $list_empl->finish;
1978            return undef;
1979        }
1980        if ($res->{current}) {
1981        } elsif ($end) {
1982            my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday}));
1983            $nextstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1984            my $tend = $end->clone;
1985            $tend->add(days => $delay + 1);
1986            if ($tend->ymd lt $nextstart->ymd) {
1987                last;
1988            }
1989        } elsif ($pend) {
1990            my $nextstart = DateTime->from_epoch(epoch => str2time($res->{firstday}));
1991            $nextstart->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
1992            my $tend = $pend->clone;
1993            $tend->add(days => $delay + 1);
1994            if ($tend->ymd lt $nextstart->ymd) {
1995                last;
1996            }
1997            $end = $tend
1998        } elsif ((!$res->{current}) && (!$any)) {
1999            last;
2000        }
2001        $end = DateTime->from_epoch(epoch => str2time($res->{lastday}));
2002        $end->set_time_zone( DateTime::TimeZone->new( name => 'local' ) );
2003        $end->add(hours => 23, minutes => 59, seconds => 59);
2004    }
2005    $list_empl->finish;
2006
2007    $end ||= $pend if($any);
2008
2009    if ($end) {
2010        if ($workday) {
2011            my $day_of_week = $end->day_of_week;
2012            $end->subtract(days =>
2013                $day_of_week == 7 ? 2 :
2014                $day_of_week == 6 ? 1 : 0
2015            );
2016        }
2017    }
2018
2019    return $end ? $end->iso8601 : undef
2020}
2021
2022# Compute a summary of employement and store the value
2023# into an attribute
2024
2025sub _computeEmploymentHistory {
2026    my ($self) = @_;
2027
2028    my %changes;
2029
2030    {
2031        my $sth = $self->db->prepare_cached(q{
2032            select employment.name from employment
2033            where "user" = ? and employment.firstday < now()
2034        });
2035        $sth->execute($self->id);
2036        my @values;
2037        while (my $res = $sth->fetchrow_hashref) {
2038            push(@values, $res->{name});
2039        }
2040        $changes{"employmentHistory"} = \@values;
2041    }
2042
2043    foreach my $attribute (qw(contratType)) {
2044        my $sth = $self->db->prepare_cached(q{
2045            select employment_attributes.value from employment
2046            join employment_attributes
2047            on employment.ikey = employment_attributes.okey
2048            where "user" = ? and employment_attributes.attr = ?
2049            and employment.firstday < now()
2050            group by employment_attributes.value
2051            });
2052        $sth->execute($self->id, $attribute);
2053        my @values;
2054        while (my $res = $sth->fetchrow_hashref) {
2055            push(@values, $res->{value});
2056        }
2057        $changes{$attribute . "History"} = \@values;
2058    }
2059
2060    $self->set_fields(%changes);
2061}
2062
2063=head2 storeBannedPassword($epassword)
2064
2065Add an encrypted password to untrust list
2066
2067=cut
2068
2069sub storeBannedPassword {
2070    my ($self, $EncPass) = @_;
2071
2072    my @banned = sort { $b cmp $a } $self->_get_attributes('bannedPassword');
2073    my $now = DateTime->now; 
2074    unshift(@banned, $now->iso8601 . ';' . $EncPass);
2075    $self->set_fields('bannedPassword', [ grep { $_ } @banned ]);
2076
2077}
2078
2079=head2 banCurrentPassword
2080
2081Store the current password as banned
2082
2083=cut
2084
2085sub banCurrentPassword {
2086    my ($self) = @_;
2087   
2088    my $old = $self->get_field('userPassword') or return;
2089    $self->storeBannedPassword($old);
2090}
2091
2092sub check_password {
2093    my ( $self, $password ) = @_;
2094
2095    my $res = $self->SUPER::check_password($password);
2096    if ($res !~ /^ok$/) {
2097        return $res;
2098    }
2099
2100    foreach my $banned ($self->_get_attributes('bannedPassword')) {
2101        my ($date, $oldPassword) = $banned =~ /^([^;]*);(.*)/;
2102        if (crypt($password, $oldPassword) eq $oldPassword) {
2103            return "Banned password, cannot be used anymore";
2104        }
2105    }
2106
2107    return 'ok';
2108}
2109
2110sub _set_password {
2111    my ($self, $clear_pass) = @_;
2112    if (my $attr = $self->base->attribute($self->type, 'userPassword')) {
2113        my $field = $attr->iname;
2114
2115        # Storing as old password
2116        my @olds = sort { $b cmp $a } $self->_get_attributes('oldPassword');
2117        if (my $old = $self->get_field('userPassword')) {
2118            my $now = DateTime->now; 
2119            unshift(@olds, $now->iso8601 . ';' . $old);
2120            $self->set_fields('oldPassword', [ grep { $_ } @olds[0 .. 14] ]);
2121        }
2122
2123        my $res = $self->set_fields($field, $self->base->passCrypt($clear_pass));
2124        if ($res) {
2125            if ($self->base->get_global_value('rsa_public_key')) {
2126                $self->setCryptPassword($clear_pass) or return;
2127            }
2128        }
2129
2130        $self->set_fields('passwordLastSet', DateTime->now->datetime);
2131        $self->base->log(LA_NOTICE,
2132            'Mot de passe changé pour %s',
2133            $self->id
2134        );
2135
2136
2137        return $res;
2138    } else {
2139        $self->log(LA_WARN,
2140            "Cannot set password: userPassword attributes is unsupported");
2141    }
2142}
2143
2144=head2 setCryptPassword($clear_pass)
2145
2146Store password encrypted using RSA encryption.
2147
2148=cut
2149
2150sub setCryptPassword {
2151    my ($self, $clear_pass) = @_;
2152    if (my $serialize = $self->base->get_global_value('rsa_public_key')) {
2153        my $public = Crypt::RSA::Key::Public->new;
2154        $public = $public->deserialize(String => [ $serialize ]);
2155        my $rsa = new Crypt::RSA ES => 'PKCS1v15';
2156        my $rsa_password = $rsa->encrypt (
2157            Message    => $clear_pass,
2158            Key        => $public,
2159            Armour     => 1,
2160        ) || die $rsa->errstr();
2161        if (!$self->_set_c_fields('encryptedPassword', $rsa_password)) {
2162            $self->log(LA_ERR,
2163                "Cannot set 'encryptedPassword' attribute for object %s/%s",
2164                $self->type, $self->id,
2165            );
2166            return;
2167        }
2168    }
2169    $self->ReportChange('Password', 'Password stored using internal key');
2170    return 1;
2171}
2172
2173=head2 _InjectCryptPasswd($cryptpasswd)
2174
2175Inject a password encrypted using standard UNIX method.
2176
2177The passwrod will be used to authenticate user inside the application but it
2178will not be transmit to any other database.
2179
2180=cut
2181
2182sub _InjectCryptPasswd {
2183    my ($self, $cryptpasswd) = @_;
2184
2185    if (my $current = $self->get_field('userPassword')) {
2186        if ($cryptpasswd eq $current) {
2187            return 1;
2188        }
2189    }
2190    my $res = $self->set_fields('userPassword', $cryptpasswd);
2191
2192    if ($res) {
2193        $self->base->log(LA_NOTICE, 'Crypted password injected for %s', $self->id);
2194        return 1;
2195    } else {
2196        $self->base->log(LA_ERR, 'Cannot inject crypted password for %s', $self->id);
2197        return 0;
2198    }
2199}
2200
2201=head2 GenPasswordResetId
2202
2203Return a new id allowing passowrd reset
2204
2205=cut
2206
2207sub GenPasswordResetId {
2208    my ($self) = @_;
2209
2210    my $id = LATMOS::Accounts::Utils::genpassword(length => 32);
2211
2212    my $sth = $self->base->db->prepare_cached(q{
2213        INSERT INTO passwordreset (id, "user") values (?,?)
2214    });
2215
2216    if ($sth->execute($id, $self->id)) {
2217        return $id;
2218    } else {
2219        return;
2220    }
2221}
2222
2223=head2 SendPasswordReset($url)
2224
2225Generate a password reset Id and the to the user.
2226
2227C<$url> is the URL where the password can changed (printf forward, the %s is
2228replaced by the request id)
2229
2230=cut
2231
2232sub SendPasswordReset {
2233    my ($self, $url) = @_;
2234
2235    my $id = $self->GenPasswordResetId;
2236
2237    my $mail = $self->_get_attributes('mail') or do {
2238        $self->base->log(LA_ERR, "Cannot sent reset password mail: no mail found");
2239        return;
2240    };
2241
2242    my $MailSubject = $self->base->la->val('_default_', 'mailSubject', 'LATMOS::Accounts');
2243
2244    my %mail = (
2245        Subject => "$MailSubject: pasword reset",
2246        'X-LATMOS-Reason' => 'Password Reset',
2247        to => $mail,
2248    );
2249
2250    if (my $otherEmail = $self->_get_attributes('otherEmail')) {
2251        $mail{cc} = $otherEmail;
2252    }
2253
2254    my $vars = {
2255        url => sprintf($url, $id),
2256    };
2257    $vars->{id} =  $id;
2258    $vars->{obj} = $self;
2259
2260    my $lamail = LATMOS::Accounts::Mail->new(
2261        $self->base->la,
2262        'passwordreset.mail',
2263    );
2264
2265    if ($lamail->process(\%mail, $vars)) {
2266        $self->base->log(LA_NOTICE,
2267            "Reset password sent to %s for user %s",
2268            $mail{to},
2269            $self->id,
2270        );
2271        return 1;
2272    } else {
2273        return;
2274    }
2275
2276}
2277
2278=head2 CheckPasswordResetId($id)
2279
2280Return True if the reset password ID can be found and is less than one day old
2281
2282=cut
2283
2284sub CheckPasswordResetId {
2285    my ($self, $id) = @_;
2286
2287    my $sth = $self->base->db->prepare_cached(q{
2288        SELECT * FROM passwordreset WHERE
2289            "user" = ? and
2290            id = ? and
2291            "create" >= now() - '1 days'::interval
2292    });
2293    $sth->execute($self->id, $id);
2294
2295    my $res = $sth->fetchrow_hashref;
2296    $sth->finish;
2297
2298    return $res ? 1 : 0;
2299}
2300
2301=head2 DeletePasswordId($id)
2302
2303Delete password reset C<$id> and all expired request
2304
2305=cut
2306
2307sub DeletePasswordId {
2308    my ($self, $id) = @_;
2309
2310    my $sth = $self->base->db->prepare_cached(q{
2311        DELETE FROM passwordreset WHERE
2312        "user" = ? AND (id = ? or "create" < now() - '1 days'::interval)
2313    });
2314
2315    $sth->execute($self->id, $id);
2316}
2317
23181;
2319
2320__END__
2321
2322=head1 SEE ALSO
2323
2324=head1 AUTHOR
2325
2326Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
2327
2328=head1 COPYRIGHT AND LICENSE
2329
2330Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS
2331
2332This library is free software; you can redistribute it and/or modify
2333it under the same terms as Perl itself, either Perl version 5.10.0 or,
2334at your option, any later version of Perl 5 you may have available.
2335
2336=cut
Note: See TracBrowser for help on using the repository browser.