1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use LATMOS::Accounts::Maintenance; |
---|
6 | use LATMOS::Accounts::Log; |
---|
7 | use Getopt::Long; |
---|
8 | use Pod::Usage; |
---|
9 | |
---|
10 | =head1 NAME |
---|
11 | |
---|
12 | la-warn-expire - query expiration of user and send mail |
---|
13 | |
---|
14 | =head1 SYNOPSIS |
---|
15 | |
---|
16 | la-warn-expire [options] |
---|
17 | |
---|
18 | =cut |
---|
19 | |
---|
20 | GetOptions( |
---|
21 | 'c|config=s' => \my $config, |
---|
22 | # 'b|base=s' => \my $base, |
---|
23 | 'm|mail' => \my $mail, |
---|
24 | 'help' => sub { pod2usage(0) }, |
---|
25 | 'users|u=s' => \my @users, |
---|
26 | 'to=s' => \my $to, |
---|
27 | 'at=s' => \my $delay, |
---|
28 | 'test' => \my $test, |
---|
29 | ) or pod2usage(); |
---|
30 | |
---|
31 | =head1 OPTIONS |
---|
32 | |
---|
33 | =over 4 |
---|
34 | |
---|
35 | =item -c|--config configdir |
---|
36 | |
---|
37 | Use this configuration directory instead of the default one. |
---|
38 | |
---|
39 | =item -m|mail |
---|
40 | |
---|
41 | Send a mail to user(s) concerned by the future expiration of his/her/their account(s). |
---|
42 | |
---|
43 | =item u|user USER |
---|
44 | |
---|
45 | Send email only to this user if his/her account will expire. Usefull for |
---|
46 | testing and not sending hundred of mails. |
---|
47 | |
---|
48 | Multiple users can be specified by using -u several times |
---|
49 | |
---|
50 | =item --to MAIL |
---|
51 | |
---|
52 | Instead sending email to user(s) and eventually his/her/their manager(s), send the mail to |
---|
53 | only this email address. |
---|
54 | |
---|
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 | |
---|
63 | =item --test |
---|
64 | |
---|
65 | With -m, do not send mail but tell to who the mail would have been sent |
---|
66 | |
---|
67 | =back |
---|
68 | |
---|
69 | =head1 CONFIGURATION |
---|
70 | |
---|
71 | Some variables are taken from configuration directory: |
---|
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 | |
---|
87 | =back |
---|
88 | |
---|
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 | |
---|
94 | =cut |
---|
95 | |
---|
96 | if (!$test) { |
---|
97 | la_set_log( |
---|
98 | syslog => [], |
---|
99 | console => undef, |
---|
100 | ); |
---|
101 | } |
---|
102 | |
---|
103 | my $LA = LATMOS::Accounts::Maintenance->new($config); |
---|
104 | |
---|
105 | if ($mail) { |
---|
106 | $LA->warn_next_expire_users( |
---|
107 | to => $to, |
---|
108 | users => (@users ? \@users : undef), |
---|
109 | delay => $delay, |
---|
110 | test => $test, |
---|
111 | ); |
---|
112 | } else { |
---|
113 | foreach ($LA->find_next_expire_users($delay)) { |
---|
114 | printf("%-10s %s (%s)\n", $_->{delay}, $_->{obj}->get_c_field('displayName'), |
---|
115 | $_->{obj}->id); |
---|
116 | } |
---|
117 | } |
---|