Changeset 417


Ignore:
Timestamp:
09/03/09 17:31:29 (15 years ago)
Author:
nanardon
Message:
  • add testing options to la-warn-expire
Location:
LATMOS-Accounts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/bin/la-warn-expire

    r413 r417  
    2222    'm|mail'     => \my $mail, 
    2323    'help'       => sub { pod2usage(0) }, 
     24    'users|u=s'    => \my @users, 
     25    'to=s'       => \my $to, 
    2426) or pod2usage(); 
    2527 
     
    3234Use this cofngiuration file instead the default one 
    3335 
    34 =item -b|--base basename 
     36=item -m|mail 
    3537 
    36 Query this specific base instead default. 
     38Send a mail to user concerned by the futur expiration of their account 
    3739 
    38 =item -o|object object_type 
     40=item u|user USER 
    3941 
    40 Query should be performed on this objects. Default is to user 'User' object. 
     42Send email only to this user(s) if their account will expire. Usefull for 
     43testing and not sending hundred of mail. 
    4144 
    42 =item -e|--empty 
     45Multiple users can be specified by using -u several times 
    4346 
    44 Include also unset attributes 
     47=item --to MAIL 
    4548 
    46 =item --ro 
    47  
    48 Include also read-only attributes as comment  
     49Instead sending email to user and eventually their manager, send the mail to 
     50only this email address. 
    4951 
    5052=back 
     53 
     54=head1 CONFIGURATION 
     55 
     56Some variables are take from configuration file: 
     57 
     58=over 4 
     59 
     60=item mailFrom 
     61 
     62Specify the From address to use in mail 
     63 
     64=item smtp 
     65 
     66The smtp server to use to send mail 
     67 
     68=item alwayscc 
     69 
     70In normal mode (without --to), the mail is also sent this email address. 
     71 
     72=back 
     73 
     74=head1 USERS EMAIL ADDRESSES 
     75 
     76The mail use to send warning to users and manager is taken from 'mail' 
     77attributes. If the attributes is unset, the user will not receive the mail. 
    5178 
    5279=cut 
     
    5582 
    5683if ($mail) { 
    57     $LA->warn_next_expire_users; 
     84    $LA->warn_next_expire_users(to => $to, users => (@users ? \@users : undef)); 
    5885} else { 
    5986    foreach ($LA->find_next_expire_users()) { 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Maintenance.pm

    r413 r417  
    4040} 
    4141 
     42=head2 warn_next_expire_users(%options) 
     43 
     44Send a mail to user having account expiring soon 
     45 
     46C<%options are> 
     47 
     48=over 4 
     49 
     50=item users => [] 
     51 
     52Warn only this users (if need) 
     53 
     54=item to 
     55 
     56Send the only to this person. 
     57 
     58=back 
     59 
     60=cut 
     61 
    4262sub warn_next_expire_users { 
    43     my ($self) = @_; 
     63    my ($self, %options) = @_; 
    4464 
    4565    require Mail::Sendmail; 
     
    5272    ); 
    5373    foreach my $user ($self->find_next_expire_users) { 
     74        if ($options{users} && ! grep { $_ eq $user->{name} } @{$options{users}}) { 
     75            next; 
     76        } 
    5477        my %mail = ( 
    5578            From => ($self->val('_default_', 'mailFrom') || 
     
    6992        my ($to, @cc) = grep { $_ } ($mail, $managermail, $self->val('_default_', 
    7093            'allwayscc')); 
    71         $mail{to} = 'nanardon@nanardon.zarb.org'; 
    72  
     94        if ($options{to}) { 
     95            $mail{to} = $options{to}; 
     96        } else { 
     97            $mail{to} = $to; 
     98            $mail{cc} = join(', ', @cc); 
     99        } 
     100        $mail{to} or next; 
    73101        my $message; 
    74102        $template->process('account_expire.mail', $user, \$message) 
    75103            or die $template->error(); 
     104 
    76105        if (Mail::Sendmail::sendmail( 
    77106            %mail, 
    78107            Message => $message, 
    79108        )) { 
    80             warn "mail sent to " . ($to || '') . " cc " . (join(', ', @cc) || '') . "\n"; 
     109            printf("Mail normally set to %s; cc to %s\n", 
     110                $to, (join(', ', @cc) || '')); 
    81111        } else { 
    82112            warn $Mail::Sendmail::error 
Note: See TracChangeset for help on using the changeset viewer.