[410] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use LATMOS::Accounts::Maintenance; |
---|
[711] | 6 | use LATMOS::Accounts::Log; |
---|
[410] | 7 | use Getopt::Long; |
---|
| 8 | use Pod::Usage; |
---|
| 9 | |
---|
| 10 | =head1 NAME |
---|
| 11 | |
---|
[424] | 12 | la-warn-expire - query expiration of user and send mail |
---|
[410] | 13 | |
---|
| 14 | =head1 SYNOPSIS |
---|
| 15 | |
---|
[594] | 16 | la-warn-expire [options] |
---|
[410] | 17 | |
---|
| 18 | =cut |
---|
| 19 | |
---|
| 20 | GetOptions( |
---|
| 21 | 'c|config=s' => \my $config, |
---|
[413] | 22 | # 'b|base=s' => \my $base, |
---|
[410] | 23 | 'm|mail' => \my $mail, |
---|
| 24 | 'help' => sub { pod2usage(0) }, |
---|
[704] | 25 | 'users|u=s' => \my @users, |
---|
[417] | 26 | 'to=s' => \my $to, |
---|
[704] | 27 | 'at=s' => \my $delay, |
---|
[710] | 28 | 'test' => \my $test, |
---|
[410] | 29 | ) or pod2usage(); |
---|
| 30 | |
---|
| 31 | =head1 OPTIONS |
---|
| 32 | |
---|
| 33 | =over 4 |
---|
| 34 | |
---|
[861] | 35 | =item -c|--config configdir |
---|
[410] | 36 | |
---|
[861] | 37 | Use this configuration directory instead of the default one. |
---|
[410] | 38 | |
---|
[417] | 39 | =item -m|mail |
---|
[410] | 40 | |
---|
[594] | 41 | Send a mail to user(s) concerned by the future expiration of his/her/their account(s). |
---|
[410] | 42 | |
---|
[1959] | 43 | =item -u|user USER |
---|
[410] | 44 | |
---|
[594] | 45 | Send email only to this user if his/her account will expire. Usefull for |
---|
| 46 | testing and not sending hundred of mails. |
---|
[410] | 47 | |
---|
[417] | 48 | Multiple users can be specified by using -u several times |
---|
[410] | 49 | |
---|
[417] | 50 | =item --to MAIL |
---|
[410] | 51 | |
---|
[594] | 52 | Instead sending email to user(s) and eventually his/her/their manager(s), send the mail to |
---|
[417] | 53 | only this email address. |
---|
[410] | 54 | |
---|
[704] | 55 | =item --at DELAY |
---|
| 56 | |
---|
| 57 | Search account expiring in DELAY. Delay must must a number follow by a time |
---|
| 58 | unit. Example: |
---|
| 59 | |
---|
| 60 | 1 month |
---|
| 61 | 2 days |
---|
| 62 | |
---|
[778] | 63 | =item --test |
---|
| 64 | |
---|
| 65 | With -m, do not send mail but tell to who the mail would have been sent |
---|
| 66 | |
---|
[417] | 67 | =back |
---|
[410] | 68 | |
---|
[417] | 69 | =head1 CONFIGURATION |
---|
| 70 | |
---|
[861] | 71 | Some variables are taken from configuration directory: |
---|
[417] | 72 | |
---|
| 73 | =over 4 |
---|
| 74 | |
---|
| 75 | =item mailFrom |
---|
| 76 | |
---|
| 77 | Specify the From address to use in mail |
---|
| 78 | |
---|
| 79 | =item smtp |
---|
| 80 | |
---|
| 81 | The smtp server to use to send mail |
---|
| 82 | |
---|
| 83 | =item alwayscc |
---|
| 84 | |
---|
| 85 | In normal mode (without --to), the mail is also sent this email address. |
---|
| 86 | |
---|
[410] | 87 | =back |
---|
| 88 | |
---|
[417] | 89 | =head1 USERS EMAIL ADDRESSES |
---|
| 90 | |
---|
| 91 | The mail use to send warning to users and manager is taken from 'mail' |
---|
| 92 | attributes. If the attributes is unset, the user will not receive the mail. |
---|
| 93 | |
---|
[410] | 94 | =cut |
---|
| 95 | |
---|
[711] | 96 | if (!$test) { |
---|
| 97 | la_set_log( |
---|
| 98 | syslog => [], |
---|
| 99 | console => undef, |
---|
| 100 | ); |
---|
| 101 | } |
---|
| 102 | |
---|
[410] | 103 | my $LA = LATMOS::Accounts::Maintenance->new($config); |
---|
| 104 | |
---|
| 105 | if ($mail) { |
---|
[704] | 106 | $LA->warn_next_expire_users( |
---|
| 107 | to => $to, |
---|
| 108 | users => (@users ? \@users : undef), |
---|
[710] | 109 | delay => $delay, |
---|
| 110 | test => $test, |
---|
[704] | 111 | ); |
---|
[410] | 112 | } else { |
---|
[704] | 113 | foreach ($LA->find_next_expire_users($delay)) { |
---|
[1762] | 114 | printf("%4s jours: %s (%s)\n", $_->{days}, $_->{obj}->get_c_field('displayName'), |
---|
[410] | 115 | $_->{obj}->id); |
---|
| 116 | } |
---|
| 117 | } |
---|