Fixes in user-expire-account script

tags/smeserver-expire-accounts-0.1.7-1
Daniel Berteaud 9 years ago
parent c589fa01a4
commit 134168e141
  1. 19
      root/etc/e-smith/events/actions/user-expire-account

@ -4,10 +4,11 @@ use strict;
use esmith::ConfigDB;
use esmith::AccountsDB;
use esmith::templates;
use esmith::event;
use DateTime;
use User::pwent;
my $a = esmith::AccountsDB->open_ro or
my $a = esmith::AccountsDB->open or
die "Could not open AccountsDB\n";
my $event = shift;
@ -29,26 +30,22 @@ my $now = DateTime->now;
foreach my $user (@users){
my $userName = $user->key;
my $pass = $user->prop('PasswordSet') || 'no';
next if $pass eq 'yes';
my $expired = $user->prop('ExpireLockedOn') || '';
next if $expired !~ /^\d{4}\-\d{1,2}\-\d{1,2}$/;
# Remove user from all its groups
my @groups = $a->user_group_list($u) || ();
$a->remove_user_from_groups($u, @groups);
my @groups = $a->user_group_list($userName);
$a->remove_user_from_groups($userName, @groups);
event_signal('group-modify', @groups) if (scalar @groups);
# Set forward if needed
my $fwd = $user->prop('ExpireForwardAfterLock') || '';
if ($fwd ne ''){
$rec->set_prop('ForwardAddress', $fwd);
$rec->set_prop('EmailForward', 'forward');
$user->set_prop('ForwardAddress', $fwd);
$user->set_prop('EmailForward', 'forward');
}
# Remove expiration settings now that the account is locked
$user->delete_prop('ExpireLockOn');
$user->delete_prop('ExpireLastNotifiedOn');
# Set the expiration date
$user->set_prop('ExpireLockedOn', $now->ymd);
my $home = getpwnam($userName)->dir;
mkdir $home . '/.lock-auto-reply' unless -d $home . '/.lock-auto-reply';

Loading…
Cancel
Save