[1737] | 1 | package LATMOS::Accounts::Task::Unexportexpired; |
---|
[861] | 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; |
---|
[1737] | 9 | use DateTime; |
---|
[861] | 10 | |
---|
[1023] | 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 | |
---|
[1880] | 29 | # Every 10 minutes |
---|
| 30 | sub runDelay { 20 * 60 } |
---|
[1737] | 31 | |
---|
[861] | 32 | sub init { |
---|
| 33 | my ($self) = @_; |
---|
[2439] | 34 | my $LA = $self->LA; |
---|
[1085] | 35 | my $labase = $self->{base} ? $LA->base($self->{base}) : $LA->base; |
---|
[861] | 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 | |
---|
[1737] | 47 | my $now = DateTime->now(); |
---|
| 48 | my $nowtext = $now->iso8601(); |
---|
| 49 | |
---|
[1865] | 50 | foreach my $otype (qw(Aliases Nethost Address)) { |
---|
[1737] | 51 | |
---|
| 52 | foreach my $name ( |
---|
[1746] | 53 | $self->{_base}->search_objects($otype, 'exported=t', "expire<$nowtext")) { |
---|
[1737] | 54 | my $obj = $self->{_base}->get_object($otype, $name); |
---|
[1801] | 55 | la_log(LA_NOTICE, "Unexport %s/%s object due to expire (%s)", $otype, $name, $obj->_get_attributes('expire') ||''); |
---|
[1737] | 56 | $obj->_set_c_fields(unexported => 1); |
---|
| 57 | $self->{_base}->commit; |
---|
[861] | 58 | } |
---|
[1737] | 59 | |
---|
[861] | 60 | } |
---|
| 61 | |
---|
| 62 | 1; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | 1; |
---|
[1023] | 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 | |
---|