Use a new user-expire-account event

tags/smeserver-expire-accounts-0.1.7-1
Daniel Berteaud 9 years ago
parent c94cd7589b
commit c589fa01a4
  1. 9
      createlinks
  2. 18
      root/etc/e-smith/events/actions/user-expire-account
  3. 12
      root/sbin/e-smith/expire-accounts

@ -2,6 +2,9 @@
use esmith::Build::CreateLinks qw(:all);
event_link("user-reset-expired", 'password-modify', "80");
event_link("expire-update-auto-reply", "user-lock", "80");
event_link("qmail-update-user", "user-lock", "20");
event_link("user-reset-expired", "password-modify", "80");
event_link("user-expire-account", "user-expire-account", "20");
event_link("user-lock-passwd", "user-expire-account", "30");
event_link("count-active-user-accounts", "user-expire-account", "40");
event_link("ldap-update-simple", "user-expire-account", "50");
event_link("qmail-update-user", "user-expire-account", "60");

@ -4,6 +4,7 @@ use strict;
use esmith::ConfigDB;
use esmith::AccountsDB;
use esmith::templates;
use DateTime;
use User::pwent;
my $a = esmith::AccountsDB->open_ro or
@ -23,6 +24,8 @@ else{
@users = ( $a->users );
}
my $now = DateTime->now;
foreach my $user (@users){
my $userName = $user->key;
@ -32,6 +35,21 @@ foreach my $user (@users){
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);
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');
}
# Remove expiration settings now that the account is locked
$user->delete_prop('ExpireLockOn');
$user->delete_prop('ExpireLastNotifiedOn');
my $home = getpwnam($userName)->dir;
mkdir $home . '/.lock-auto-reply' unless -d $home . '/.lock-auto-reply';
esmith::templates::processTemplate ({

@ -70,17 +70,7 @@ foreach my $user ($a->users){
# Lock accounts which need to be locked now
foreach my $u (@lock){
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->delete_prop('ExpireLockOn');
$rec->delete_prop('ExpireLastNotifiedOn');
$rec->set_prop('ExpireLockedOn', $now->ymd);
event_signal('user-expire-account', $u);
}
# Send a warning for accounts which will be locked soon

Loading…
Cancel
Save