#!/usr/bin/perl -w
#---------------------------------------------------------------------
# Copyright (C) 2016 Firewall-Services
# daniel@firewall-services.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#----------------------------------------------------------------------
package esmith::FormMagick::Panel::expireaccounts;
use strict;
use esmith::FormMagick;
use esmith::AccountsDB;
use esmith::ConfigDB;
use esmith::cgi;
use DateTime;
use File::Basename;
use Exporter;
use Carp qw(verbose);
our @ISA = qw(esmith::FormMagick Exporter);
our @EXPORT = qw(
print_user_table
print_save_button
print_custom_button
print_section_bar
);
our $a = esmith::AccountsDB->open || die "Couldn't open AccountsDB";
our $c = esmith::ConfigDB->open || die "Couldn't open ConfigDB";
our %defaults = (
ExpireAutoReply => 'enabled',
ExpireDeleteAfterLock => 'never',
WarnUsers => 'enabled'
);
sub new {
shift;
my $self = esmith::FormMagick->new();
$self->{calling_package} = (caller)[0];
bless $self;
return $self;
}
sub print_user_table {
my $self = shift;
my $q = $self->{cgi};
my @users = $a->users;
unless ( scalar @users ) {
print $q->Tr($q->td($self->localise('NO_USER_ACCOUNTS')));
return "";
}
print "
";
print $q->start_table ({-CLASS => "sme-border"});
print $q->Tr(
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();
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;
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, $addr, "normal"),
esmith::cgi::genSmallCell($q, $days_left, "normal"),
esmith::cgi::genSmallCell($q, $action, "normal")
);
}
print qq( |
\n);
return "";
}
sub print_save_button {
my ($self) = @_;
$self->print_button("SAVE");
}
sub print_section_bar{
my $self = shift;
print "