From 0c7a2fd24c67fe5d646feaab4c8d77c40f1cd112 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 27 Jan 2016 18:48:20 +0100 Subject: [PATCH] Separate active and inactive users Also display more info like days left before lock or delete --- root/etc/e-smith/web/functions/expireaccounts | 6 ++ .../esmith/FormMagick/Panel/expireaccounts.pm | 100 ++++++++++++++++++--- 2 files changed, 95 insertions(+), 11 deletions(-) diff --git a/root/etc/e-smith/web/functions/expireaccounts b/root/etc/e-smith/web/functions/expireaccounts index 08e241c..0f0f7ba 100755 --- a/root/etc/e-smith/web/functions/expireaccounts +++ b/root/etc/e-smith/web/functions/expireaccounts @@ -66,6 +66,12 @@ __DATA__ MODIFY_USER_DESC + + + DESC_LOCK_ON_DATE diff --git a/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/expireaccounts.pm b/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/expireaccounts.pm index c8805c1..0b8b758 100644 --- a/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/expireaccounts.pm +++ b/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/expireaccounts.pm @@ -38,6 +38,7 @@ our @EXPORT = qw( print_save_button print_custom_button print_section_bar + print_user_locked_warning ); our $a = esmith::AccountsDB->open || die "Couldn't open AccountsDB"; @@ -67,28 +68,93 @@ sub print_user_table { print $q->Tr($q->td($self->localise('NO_USER_ACCOUNTS'))); return ""; } - print " \n \n "; - print $q->start_table ({-CLASS => "sme-border"}),"\n "; + print " "; + print $q->start_table ({-CLASS => "sme-border"}); print $q->Tr( - esmith::cgi::genSmallCell($q, $self->localise('ACCOUNT'), "header"), - esmith::cgi::genSmallCell($q, $self->localise('USER_NAME'), "header"), - esmith::cgi::genSmallCell($q, $self->localise('ACTION'), "header") + esmith::cgi::genSmallCell($q, $self->localise('ACTIVE_ACCOUNT'), "header"), + esmith::cgi::genSmallCell($q, $self->localise('USER_NAME'), "header"), + esmith::cgi::genSmallCell($q, $self->localise('FORWARD'), "header"), + esmith::cgi::genSmallCell($q, $self->localise('DAYS_BEFORE_LOCK'), "header"), + esmith::cgi::genSmallCell($q, $self->localise('ACTION'), "header") ); my $scriptname = basename($0); + my $now = DateTime->now; foreach my $u (@users) { - my $username = $u->key(); - my $first = $u->prop('FirstName'); - my $last = $u->prop('LastName'); + my $username = $u->key(); + next unless (($u->prop('PasswordSet') || 'no') eq 'yes'); + my $first = $u->prop('FirstName') || ''; + my $last = $u->prop('LastName') || ''; + my $lock_date = $u->prop('ExpireLockOn') || ''; + my $delivery = $u->prop('EmailForward') || 'local'; + my $fwd = $u->prop('ForwardAddress') || ''; + my $action = "" . + $self->localise('MODIFY') . ""; + my $days_left = ''; + if ($lock_date =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/){ + my $lock_on = eval { + DateTime->new( + year => $1, + month => $2, + day => $3 + ); + }; + $days_left = ($lock_on - $now)->in_units('days') if ($lock_on); + } + my $addr = ($delivery eq 'local') ? '' : $fwd; - my $action = (($u->prop('PasswordSet') || 'no') eq 'yes') ? "" . - $self->localise('MODIFY') . "" : $self->localise('LOCKED'); + print $q->Tr( + esmith::cgi::genSmallCell($q, $username, "normal"), + esmith::cgi::genSmallCell($q, "$first $last", "normal"), + esmith::cgi::genSmallCell($q, $addr, "normal"), + esmith::cgi::genSmallCell($q, $days_left, "normal"), + esmith::cgi::genSmallCell($q, $action, "normal") + ); + } + + # Now, same for locked accounts + print $q->Tr( + esmith::cgi::genSmallCell($q, $self->localise('INACTIVE_ACCOUNT'), "header"), + esmith::cgi::genSmallCell($q, $self->localise('USER_NAME'), "header"), + esmith::cgi::genSmallCell($q, $self->localise('FORWARD'), "header"), + esmith::cgi::genSmallCell($q, $self->localise('DAYS_BEFORE_DELETE'), "header"), + esmith::cgi::genSmallCell($q, $self->localise('ACTION'), "header") + ); + + foreach my $u (@users) { + my $username = $u->key(); + next unless (($u->prop('PasswordSet') || 'no') ne 'yes'); + my $first = $u->prop('FirstName') || ''; + my $last = $u->prop('LastName') || ''; + my $delete_in = $u->prop('ExpireDeleteAfterLock') || ''; + my $locked_on = $u->prop('ExpireLockedOn') || ''; + my $delivery = $u->prop('EmailForward') || ''; + my $fwd = $u->prop('ForwardAddress') || ''; + my $action = "" . + $self->localise('MODIFY') . ""; + my $days_left = ''; + if ($delete_in =~ m/^\d+$/ && $locked_on =~ m/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/){ + my $locked_date = eval { + DateTime->new( + year => $1, + month => $2, + day => $3 + ); + }; + if ($locked_date){ + my $delete_on = $locked_date->add(days => $delete_in); + $days_left = ($delete_on - $now)->in_units('days'); + } + } + my $addr = ($delivery eq 'local') ? '' : $fwd; print $q->Tr( esmith::cgi::genSmallCell($q, $username, "normal"), esmith::cgi::genSmallCell($q, "$first $last", "normal"), - esmith::cgi::genSmallCell($q, "$action", "normal") + esmith::cgi::genSmallCell($q, $addr, "normal"), + esmith::cgi::genSmallCell($q, $days_left, "normal"), + esmith::cgi::genSmallCell($q, $action, "normal") ); } @@ -97,6 +163,18 @@ sub print_user_table { return ""; } +sub print_user_locked_warning { + my ($self) = @_; + my $u = $self->{cgi}->param('acctName'); + my $user = $a->get($u); + return $self->localise('USER_NOT_FOUND') unless ($user); + my $type = $user->prop('type'); + return $self->localise('ERROR_OCCURRED') unless ($type && $type eq 'user'); + my $pass = $user->prop('PasswordSet') || 'no'; + return $self->localise('USER_LOCKED') if ($pass eq 'no'); + return ""; +} + sub print_save_button { my ($self) = @_; $self->print_button("SAVE");