Code cleanup

tags/smeserver-expire-accounts-0.1.7-1
Daniel Berteaud 9 years ago
parent ab7648d9c0
commit 40cfe05301
  1. 22
      root/sbin/e-smith/expire-accounts

@ -61,7 +61,7 @@ my $now = DateTime->now;
foreach my $user ($a->users){
my $pass = $user->prop('PasswordSet') || 'no';
if ($pass ne 'yes'){
if ( $pass ne 'yes' ){
print $user->key . ": Account already locked\n" if $debug;
my $delete = $user->prop('ExpireDeleteAfterLock') || 'never';
my $locked_date = $user->prop('ExpireLockedOn') || '';
@ -80,11 +80,11 @@ foreach my $user ($a->users){
next;
}
my $lock_date = $user->prop('ExpireLockOn') || 'never';
if ($lock_date eq 'never'){
if ( $lock_date eq 'never' ){
print $user->key . ": No expiration date set\n" if $debug;
next;
}
elsif ($lock_date !~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/){
elsif ( $lock_date !~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/ ){
print $user->key . ": Invalide expiration date ($lock_date)\n" if $debug;
next;
}
@ -94,7 +94,7 @@ foreach my $user ($a->users){
day => $3,
);
if ($exp < $now){
if ( $exp < $now ){
print $user->key . ": Expiration date is passed, account must be locked\n" if $debug;
push @lock, $user->key;
}
@ -113,7 +113,7 @@ foreach my $u (@lock){
# Accounts to be deleted
foreach my $u (@delete){
my $user = $a->get($u);
if (!$user || !$user->prop('type') || $user->prop('type') ne 'user'){
if ( !$user || !$user->prop('type') || $user->prop('type') ne 'user' ){
print $u . ": This is not a user account\n";
next;
}
@ -122,7 +122,7 @@ foreach my $u (@delete){
next;
}
my $archive = $user->prop('ExpireArchiveBeforeDelete') || 'yes';
if ($archive =~ m/^yes|enabled|1|on$/){
if ( $archive =~ m/^yes|enabled|1|on$/ ){
my $tar = $archive_path . '/' . $u . '-' . $now->ymd . '.' . $archive_ext;
my $res = system(
'tar',
@ -134,9 +134,9 @@ foreach my $u (@delete){
getpwnam($u)->dir,
getpwnam($u)->dir
);
if ($res == 0){
if ( $res == 0 ){
print $u . ": Data archived as $tar. The user account will now be deleted\n" if ($debug);
$user->set_prop(type => 'user-deleted');
$user->set_prop( type => 'user-deleted' );
event_signal('user-delete', $u);
$a = esmith::AccountsDB->open || die "Couldn't open AccountsDB\n";
$a->get($u)->delete;
@ -150,13 +150,13 @@ foreach my $user (keys %$rem){
my $rec = $a->get($user) || next;
my $last_notif = $rec->prop('ExpireLastNotifiedOn') || 'never';
my $warn_user = $rec->prop('ExpireWarnUser') || 'disabled';
if ($last_notif =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})/){
if ( $last_notif =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})/ ){
$last_notif = DateTime->new(
year => $1,
month => $2,
day => $3,
);
if (($last_notif - $now)->in_units('days') < $days_between_warn){
if ( ($last_notif - $now)->in_units('days') < $days_between_warn ){
next;
}
}
@ -166,7 +166,7 @@ foreach my $user (keys %$rem){
# Use templates-custom version by preference if it exists
-f "${templates}-custom${source}" and $templates .= "-custom";
if ($warn_user =~ m/^enabled|yes|on|1$/){
if ( $warn_user =~ m/^enabled|yes|on|1$/ ){
my $t = new Text::Template(TYPE => 'FILE',
SOURCE => "${templates}${source}");

Loading…
Cancel
Save