Add forward option

tags/smeserver-expire-accounts-0.1.7-1
Daniel Berteaud 8 years ago
parent c485f53762
commit ab177842ef
  1. 25
      root/sbin/e-smith/expire-accounts

@ -37,7 +37,12 @@ my @lock = ();
my $now = DateTime->now;
foreach my $user ($a->users){
my $date = $user->prop('ExpiresOn') || 'never';
my $pass = $user->prop('PasswordSet') || 'no';
if ($pass ne 'yes'){
print $user->key . ": Account already locked\n" if $debug;
next;
}
my $date = $user->prop('ExpireLockOn') || 'never';
if ($date eq 'never'){
print $user->key . ": No expiration date set\n" if $debug;
next;
@ -65,16 +70,24 @@ foreach my $user ($a->users){
# Lock accounts which need to be locked now
foreach my $u (@lock){
event_signal('user-lock', $u);
$a->del_prop($u, 'ExpiresOn');
$a->del_prop($u, 'ExpirationLastNotified');
event_signal('user-lock', $u);
$a = esmith::AccountsDB->open || die "Couldn't open the AccountsDB\n";
my $rec = $a->get($u);
my $fwd = $rec->prop('ExpireForwardAfterLock') || '';
if ($fwd ne ''){
$rec->set_prop('ForwardAddress', $fwd);
$rec->set_prop('EmailForward', 'forward');
}
$rec->del_prop('ExpireLockOn');
$rec->del_prop('ExpireLastNotifiedOn');
$rec->set_prop('ExpireLockedOn', $now->ymd);
}
# Send a warning for accounts which will be locked soon
my $send_warn_for = {};
foreach my $user (keys %$rem){
my $rec = $a->get($user) || next;
my $last_notif = $rec->prop('ExpirationLastNotified') || 'never';
my $last_notif = $rec->prop('ExpireLastNotifiedOn') || 'never';
if ($last_notif =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})/){
$last_notif = DateTime->new(
year => $1,
@ -107,7 +120,7 @@ foreach my $user (keys %$rem){
close QMAIL;
}
$rec->set_prop('ExpirationLastNotified', $now->ymd);
$rec->set_prop('ExpireLastNotifiedOn', $now->ymd);
# This one will be notified to the admin
$send_warn_for->{$user} = {
remaining => $rem->{$user},

Loading…
Cancel
Save