1 | package LATMOS::Accounts::Task::Unexportexpired; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base qw(LATMOS::Accounts::Task); |
---|
6 | use LATMOS::Accounts; |
---|
7 | use LATMOS::Accounts::Log; |
---|
8 | use LATMOS::Accounts::Utils; |
---|
9 | use DateTime; |
---|
10 | |
---|
11 | =head1 NAME |
---|
12 | |
---|
13 | LATMOS::Accounts::Task::Refreshexpired - Task to disable expired users |
---|
14 | |
---|
15 | =head1 DESCRIPTION |
---|
16 | |
---|
17 | Some base doesn't handle accounts expiration. One way to do it is to synchronize |
---|
18 | user with value denying login (wrong UNIX shell, password entry set to false, |
---|
19 | ...). |
---|
20 | |
---|
21 | For performance issue, objects are not written at each synchronisation, only |
---|
22 | when they changes. |
---|
23 | |
---|
24 | This module find expired user and refresh modification time to ensure |
---|
25 | propagation to other database. |
---|
26 | |
---|
27 | =cut |
---|
28 | |
---|
29 | # Every 10 minutes |
---|
30 | sub runDelay { 20 * 60 } |
---|
31 | |
---|
32 | sub init { |
---|
33 | my ($self) = @_; |
---|
34 | my $LA = LATMOS::Accounts->new($self->{config}, noacl => 1); |
---|
35 | my $labase = $self->{base} ? $LA->base($self->{base}) : $LA->base; |
---|
36 | $labase && $labase->load or die "Cannot load base"; |
---|
37 | |
---|
38 | $self->{_la} = $LA; |
---|
39 | $self->{_base} = $labase; |
---|
40 | |
---|
41 | 1; |
---|
42 | } |
---|
43 | |
---|
44 | sub run { |
---|
45 | my ($self) = @_; |
---|
46 | |
---|
47 | my $now = DateTime->now(); |
---|
48 | my $nowtext = $now->iso8601(); |
---|
49 | |
---|
50 | foreach my $otype (qw(Aliases Nethost Address)) { |
---|
51 | |
---|
52 | foreach my $name ( |
---|
53 | $self->{_base}->search_objects($otype, 'exported=t', "expire<$nowtext")) { |
---|
54 | my $obj = $self->{_base}->get_object($otype, $name); |
---|
55 | la_log(LA_NOTICE, "Unexport %s/%s object due to expire (%s)", $otype, $name, $obj->_get_attributes('expire') ||''); |
---|
56 | $obj->_set_c_fields(unexported => 1); |
---|
57 | $self->{_base}->commit; |
---|
58 | } |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | 1; |
---|
63 | } |
---|
64 | |
---|
65 | 1; |
---|
66 | |
---|
67 | __END__ |
---|
68 | |
---|
69 | =head1 SEE ALSO |
---|
70 | |
---|
71 | L<LATMOS::Accounts>, L<LATMOS::Accounts::Task> |
---|
72 | |
---|
73 | =head1 AUTHOR |
---|
74 | |
---|
75 | Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt> |
---|
76 | |
---|
77 | =head1 COPYRIGHT AND LICENSE |
---|
78 | |
---|
79 | Copyright (C) 2012 CNRS SA/CETP/LATMOS |
---|
80 | |
---|
81 | This library is free software; you can redistribute it and/or modify |
---|
82 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
83 | at your option, any later version of Perl 5 you may have available. |
---|
84 | |
---|
85 | =cut |
---|
86 | |
---|