User account expiration control panel for SME Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

#!/usr/bin/perl -w
use strict;
use esmith::ConfigDB;
use esmith::AccountsDB;
use esmith::templates;
use DateTime;
use User::pwent;
my $a = esmith::AccountsDB->open_ro or
die "Could not open AccountsDB\n";
my $event = shift;
my $userName = shift;
my @users;
if (defined $userName){
my $user = $a->get($userName);
die "Account $userName is not a user account; can't update the auto-reply message.\n"
unless $user && $user->prop('type') eq "user";
@users = ($user);
}
else{
@users = ( $a->users );
}
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') || '';
9 years ago
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 ({
MORE_DATA => { USERNAME => $userName },
TEMPLATE_PATH => "/.lock-auto-reply/message.txt",
TEMPLATE_EXPAND_QUEUE =>
[
"/etc/e-smith/templates-user-custom",
"/etc/e-smith/templates-user",
],
OUTPUT_PREFIX => "$home",
PERMS => 0644,
});
}
exit (0);