initial commit of file from CVS for smeserver-vacation on Sat Sep 7 21:13:49 AEST 2024
This commit is contained in:
@@ -0,0 +1,463 @@
|
||||
#----------------------------------------------------------------------
|
||||
# uservacations.pm
|
||||
# support@dungog.net
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
package esmith::FormMagick::Panel::uservacations;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use esmith::util;
|
||||
use esmith::FormMagick;
|
||||
use esmith::AccountsDB;
|
||||
use esmith::ConfigDB;
|
||||
|
||||
use Exporter;
|
||||
use Carp qw(verbose);
|
||||
|
||||
use HTML::Tabulate;
|
||||
|
||||
our @ISA = qw(esmith::FormMagick Exporter);
|
||||
|
||||
our @EXPORT = qw();
|
||||
|
||||
our $db = esmith::ConfigDB->open();
|
||||
our $adb = esmith::AccountsDB->open();
|
||||
|
||||
our $PanelUser = $ENV{'REMOTE_USER'} ||'';
|
||||
$PanelUser = $1 if ($PanelUser =~ /^([a-z][\.\-a-z0-9]*)$/);
|
||||
|
||||
our %delegatedVacations;
|
||||
|
||||
sub new {
|
||||
shift;
|
||||
my $self = esmith::FormMagick->new(filename => '/etc/e-smith/web/functions/uservacations');
|
||||
$self->{calling_package} = (caller)[0];
|
||||
bless $self;
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
#server-manager functions
|
||||
sub user_accounts_exist
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
#return scalar $adb->users;
|
||||
if (scalar $adb->users)
|
||||
{ return $self->localise('DESCRIPTION'); }
|
||||
}
|
||||
|
||||
sub print_vacation_table
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
#We want to retrieve granted group from DB, and retrieve users of groups
|
||||
my $record = $adb->get($PanelUser);
|
||||
my $dg=$record->prop('delegatedVacations')||'';
|
||||
$dg =~ s/ //g;
|
||||
my @g = split(/,/, $dg);
|
||||
my @visiblemembers = ();
|
||||
|
||||
foreach my $g (@g) {
|
||||
my $members = $adb->get_prop("$g",'Members');
|
||||
next unless defined $members;
|
||||
$members =~ s/ //g;
|
||||
my @members = split(/,/, $members);
|
||||
push @visiblemembers , @members ;
|
||||
}
|
||||
|
||||
foreach my $k ( @visiblemembers )
|
||||
{
|
||||
$delegatedVacations{$k}=1;
|
||||
}
|
||||
|
||||
|
||||
my @users = $adb->users;
|
||||
return $self->localise("ACCOUNT_USER_NONE") if (@users == 0);
|
||||
return $self->localise("NO_USERS_IN_GRANTED_GROUPS") if (@visiblemembers == 0 && $dg ne '');
|
||||
|
||||
my $vacation_table =
|
||||
{
|
||||
title => $self->localise('USER_LIST_CURRENT'),
|
||||
|
||||
stripe => '#D4D0C8',
|
||||
|
||||
fields => [ qw(User FullName status Modify) ],
|
||||
|
||||
labels => 1,
|
||||
|
||||
field_attr => {
|
||||
User => { label_escape => 0, escape => 0 , label => $self->localise('ACCOUNT') },
|
||||
|
||||
FullName => { label_escape => 0, escape => 0 , label => $self->localise('USER_NAME') },
|
||||
|
||||
status => { label_escape => 0, escape => 0 , label => $self->localise('LABEL_VACATION') },
|
||||
|
||||
Modify => { label_escape => 0,
|
||||
label => $self->localise('MODIFY'),
|
||||
link => \&modify_link
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
my @data = ();
|
||||
|
||||
for my $user (@users)
|
||||
{
|
||||
next if %delegatedVacations and not $delegatedVacations{$user->key};
|
||||
# make it clearer which uses have vacation
|
||||
my $EmailVacation = $user->prop('EmailVacation') || '';
|
||||
my $EmailVacationFrom = $user->prop('EmailVacationFrom') || '';
|
||||
my $EmailVacationTo = $user->prop('EmailVacationTo') || '';
|
||||
my $status = $user->prop('EmailVacation') || '';
|
||||
if ($status eq 'yes') { $status = 'YES'; } else { $status = ''; }
|
||||
|
||||
push @data,
|
||||
{ User => $user->key,
|
||||
FullName => $user->prop('FirstName') . " " .
|
||||
$user->prop('LastName'),
|
||||
status => $self->localise($status),
|
||||
EmailVacation => $EmailVacation,
|
||||
EmailVacationFrom => $EmailVacationFrom,
|
||||
EmailVacationTo => $EmailVacationTo,
|
||||
Modify => $self->localise('MODIFY'),
|
||||
}
|
||||
}
|
||||
|
||||
my $t = HTML::Tabulate->new($vacation_table);
|
||||
|
||||
$t->render(\@data, $vacation_table);
|
||||
}
|
||||
|
||||
sub modify_link
|
||||
{
|
||||
my ($data_item, $row, $field) = @_;
|
||||
|
||||
return "uservacations?" .
|
||||
join("&",
|
||||
"page=0",
|
||||
"page_stack=",
|
||||
"Next=Next",
|
||||
"User=" . $row->{User},
|
||||
"FullName=" . $row->{FullName},
|
||||
"EmailVacation=" . $row->{EmailVacation},
|
||||
"EmailVacationFrom=" . $row->{EmailVacationFrom},
|
||||
"EmailVacationTo=" . $row->{EmailVacationTo},
|
||||
"wherenext=VACATION_PAGE_MODIFY");
|
||||
}
|
||||
|
||||
# this formats the text to display on screen
|
||||
sub get_vacation_text
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
my $domain = $db->get_value('DomainName');
|
||||
my $user = $q->param('User');
|
||||
|
||||
my $fullname = $adb->get_prop($user, "FirstName") . " " .
|
||||
$adb->get_prop($user, "LastName");
|
||||
|
||||
my $vfile = "/home/e-smith/files/users/$user/.vacation.msg";
|
||||
|
||||
my $from = 'From:';
|
||||
my $away = $self->localise('AWAY_FROM_MAIL');
|
||||
my $return = $self->localise('ANSWER_TO_OBJECT_SENDER');
|
||||
|
||||
my $ExistingMessage = "$from $fullname <\;$user\@$domain>\;\n"."Subject: $return\n".
|
||||
"\n$away\n"."\n--\n$fullname";
|
||||
|
||||
# if exists and is not empty
|
||||
if (( -e $vfile ) && (! -z $vfile ))
|
||||
{
|
||||
open (VACATION, "<$vfile")
|
||||
or die "Error: Could not open file: $vfile\n";
|
||||
my @vacationTemp;
|
||||
|
||||
#reformat so email address isn't hidden inside < >
|
||||
while (<VACATION>)
|
||||
{
|
||||
$_ =~ s/</<\;/;
|
||||
$_ =~ s/>/>\;/;
|
||||
push (@vacationTemp, $_);
|
||||
}
|
||||
|
||||
$ExistingMessage = join ("", @vacationTemp);
|
||||
|
||||
close VACATION;
|
||||
}
|
||||
my $start = '<tr>
|
||||
<td class="sme-noborders-label">' . $self->localise('MESSAGE') . '
|
||||
<td class="sme-noborders-content"><TEXTAREA NAME="new_message" ROWS="10" COLS="60">';
|
||||
|
||||
my $end = '</TEXTAREA></td>
|
||||
</tr>';
|
||||
|
||||
return $start . $ExistingMessage . $end;
|
||||
}
|
||||
|
||||
# saves the text to .vacation.msg
|
||||
sub change_settings
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
my $domain = $db->get_value('DomainName');
|
||||
my $user = $q->param('User');
|
||||
|
||||
my $EmailVacation = $q->param('EmailVacation');
|
||||
my $EmailVacationFrom = $q->param('EmailVacationFrom');
|
||||
my $EmailVacationTo = $q->param('EmailVacationTo');
|
||||
my $new_message = $q->param('new_message');
|
||||
my $vfile = "/home/e-smith/files/users/$user/.vacation.msg";
|
||||
|
||||
my $fullname = $adb->get_prop($user, "FirstName") . " " .
|
||||
$adb->get_prop($user, "LastName");
|
||||
|
||||
my $from = 'From:';
|
||||
my $away = $self->localise('AWAY_FROM_MAIL');
|
||||
my $return = $self->localise('ANSWER_TO_OBJECT_SENDER');
|
||||
|
||||
my $vacation_text = "$from $fullname \<$user\@$domain\>\n"."Subject: $return\n".
|
||||
"\n$away \n"."\n--\n$fullname";
|
||||
|
||||
my $reset = $vacation_text;
|
||||
|
||||
# if exists and is not empty
|
||||
if (( -e $vfile ) && (! -z $vfile ))
|
||||
{
|
||||
open (VACATION, "<$vfile")
|
||||
or die "Error: Could not open file: $vfile\n";
|
||||
my @vacationTemp = <VACATION>;
|
||||
$vacation_text = join ("", @vacationTemp);
|
||||
|
||||
close VACATION;
|
||||
}
|
||||
|
||||
chomp $new_message;
|
||||
|
||||
# reset msg to default,
|
||||
if ($new_message =~ /reset/)
|
||||
{ $vacation_text = $reset; }
|
||||
else
|
||||
{
|
||||
#or save new_message
|
||||
unless ($new_message eq "")
|
||||
{ $vacation_text = $new_message; }
|
||||
}
|
||||
|
||||
# Strip out DOS Carriage Returns (CR)
|
||||
$vacation_text =~ s/\r//g;
|
||||
|
||||
unlink $vfile;
|
||||
open (VACATION, ">$vfile")
|
||||
or die ("Error opening vacation message.\n");
|
||||
|
||||
print VACATION "$vacation_text";
|
||||
close VACATION;
|
||||
|
||||
esmith::util::chownFile($user, $user,
|
||||
"/home/e-smith/files/users/$user/.vacation.msg");
|
||||
|
||||
$adb->set_prop($user, 'EmailVacation', $EmailVacation);
|
||||
$adb->set_prop($user, 'EmailVacationFrom', $EmailVacationFrom);
|
||||
$adb->set_prop($user, 'EmailVacationTo', $EmailVacationTo);
|
||||
|
||||
#the first is more correct but is slower
|
||||
#system ("/sbin/e-smith/signal-event", "email-update", $user) == 0
|
||||
system ("/etc/e-smith/events/actions/qmail-update-user event $user") == 0
|
||||
or die ("Error occurred updating .qmail\n");
|
||||
|
||||
if (($EmailVacation eq 'no') && ( -e "/home/e-smith/files/users/$user/.vacation"))
|
||||
{
|
||||
system ("/bin/rm /home/e-smith/files/users/$user/.vacation") == 0
|
||||
or die ("Error resetting vacation db.\n");
|
||||
}
|
||||
|
||||
return $self->success("SUCCESS");
|
||||
}
|
||||
|
||||
#userpanel functions ######################################################
|
||||
sub get_panel_user
|
||||
{
|
||||
return $PanelUser;
|
||||
}
|
||||
|
||||
sub get_full_name
|
||||
{
|
||||
return $adb->get_prop($PanelUser, "FirstName") . " " .
|
||||
$adb->get_prop($PanelUser, "LastName");
|
||||
}
|
||||
|
||||
sub get_vacation_status
|
||||
{
|
||||
return $adb->get_prop($PanelUser, "EmailVacation");
|
||||
}
|
||||
|
||||
sub get_vacation_date_from
|
||||
{
|
||||
return $adb->get_prop($PanelUser, "EmailVacationFrom");
|
||||
}
|
||||
|
||||
sub get_vacation_date_to
|
||||
{
|
||||
return $adb->get_prop($PanelUser, "EmailVacationTo");
|
||||
}
|
||||
|
||||
# this formats the text to display on screen
|
||||
sub userpanel_get_vacation_text
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
my $domain = $db->get_value('DomainName');
|
||||
|
||||
# single difference in userpanel function
|
||||
my $user = $PanelUser;
|
||||
|
||||
my $fullname = $adb->get_prop($user, "FirstName") . " " .
|
||||
$adb->get_prop($user, "LastName");
|
||||
my $vfile = "/home/e-smith/files/users/$user/.vacation.msg";
|
||||
|
||||
my $from = 'From:';
|
||||
my $away = $self->localise('AWAY_FROM_MAIL');
|
||||
my $return = $self->localise('ANSWER_TO_OBJECT_SENDER');
|
||||
|
||||
my $ExistingMessage = "$from $fullname <\;$user\@$domain>\;\n"."Subject: $return\n".
|
||||
"\n$away"."\n--\n$fullname";
|
||||
|
||||
# if exists and is not empty
|
||||
if (( -e $vfile ) && (! -z $vfile ))
|
||||
{
|
||||
open (VACATION, "<$vfile")
|
||||
or die "Error: Could not open file: $vfile\n";
|
||||
my @vacationTemp;
|
||||
|
||||
#reformat so email address isn't hidden inside < >
|
||||
while (<VACATION>)
|
||||
{
|
||||
$_ =~ s/</<\;/;
|
||||
$_ =~ s/>/>\;/;
|
||||
push (@vacationTemp, $_);
|
||||
}
|
||||
|
||||
$ExistingMessage = join ("", @vacationTemp);
|
||||
|
||||
close VACATION;
|
||||
}
|
||||
my $start = '<tr>
|
||||
<td class="sme-noborders-label">' . $self->localise('MESSAGE') . '
|
||||
<td class="sme-noborders-content"><TEXTAREA NAME="new_message" ROWS="10" COLS="60">';
|
||||
|
||||
my $end = '</TEXTAREA></td>
|
||||
</tr>';
|
||||
|
||||
return $start . $ExistingMessage . $end;
|
||||
}
|
||||
|
||||
# saves the text to .vacation.msg
|
||||
sub userpanel_change_settings
|
||||
{
|
||||
my $self = shift;
|
||||
my $q = $self->{cgi};
|
||||
|
||||
my $domain = $db->get_value('DomainName');
|
||||
|
||||
# single difference in userpanel function
|
||||
my $user = $PanelUser;
|
||||
|
||||
my $EmailVacation = $q->param('EmailVacation');
|
||||
my $new_message = $q->param('new_message');
|
||||
my $EmailVacationFrom = $q->param('EmailVacationFrom');
|
||||
my $EmailVacationTo = $q->param('EmailVacationTo');
|
||||
my $vfile = "/home/e-smith/files/users/$user/.vacation.msg";
|
||||
|
||||
my $fullname = $adb->get_prop($user, "FirstName") . " " .
|
||||
$adb->get_prop($user, "LastName");
|
||||
|
||||
my $from = 'From:';
|
||||
my $away = $self->localise('AWAY_FROM_MAIL');
|
||||
my $return = $self->localise('ANSWER_TO_OBJECT_SENDER');
|
||||
|
||||
my $vacation_text = "$from $fullname \<$user\@$domain\>\n"."Subject: $return\n".
|
||||
"\n$away \n"."\n--\n$fullname";
|
||||
|
||||
my $reset = $vacation_text;
|
||||
|
||||
# if exists and is not empty
|
||||
if (( -e $vfile ) && (! -z $vfile ))
|
||||
{
|
||||
open (VACATION, "<$vfile")
|
||||
or die "Error: Could not open file: $vfile\n";
|
||||
my @vacationTemp = <VACATION>;
|
||||
$vacation_text = join ("", @vacationTemp);
|
||||
|
||||
close VACATION;
|
||||
}
|
||||
|
||||
chomp $new_message;
|
||||
|
||||
# reset msg to default,
|
||||
if ($new_message =~ /reset/)
|
||||
{ $vacation_text = $reset; }
|
||||
else
|
||||
{
|
||||
#or save new_message
|
||||
unless ($new_message eq "")
|
||||
{ $vacation_text = $new_message; }
|
||||
}
|
||||
|
||||
# Strip out DOS Carriage Returns (CR)
|
||||
$vacation_text =~ s/\r//g;
|
||||
|
||||
unlink $vfile;
|
||||
# for the next lines to avoid race condition vulnerability, we switch the effective user to
|
||||
# the one needed see SME #9073 . Those 4 lines are for explanation of the used variables.
|
||||
#$< - real user id (uid); unique value
|
||||
#$> - effective user id (euid); unique value
|
||||
#$( - real group id (gid); list (separated by spaces) of groups
|
||||
#$) - effective group id (egid); list (separated by spaces) of groups
|
||||
|
||||
# remember the UID of the user currently running this script
|
||||
my $original_uid = $>;
|
||||
my $original_gid = $);
|
||||
|
||||
# switch effective UID running this script to $user
|
||||
# in order to prevent race condition vulnerability
|
||||
my $uid = getpwnam($user) or die "Could not get UID for $user\n";
|
||||
my $gid = getgrnam($user) or die "Could not get GID for $user\n";
|
||||
$) = $gid;# should be switched first while still root!
|
||||
$> = $uid;
|
||||
|
||||
open (VACATION, ">$vfile")
|
||||
or die ("Error opening vacation message.\n");
|
||||
|
||||
print VACATION "$vacation_text";
|
||||
close VACATION;
|
||||
|
||||
# switch effective UID and GID back to original user
|
||||
$> = $original_uid;
|
||||
$) = $original_gid;
|
||||
|
||||
$adb->set_prop($user, 'EmailVacation', $EmailVacation);
|
||||
$adb->set_prop($user, 'EmailVacationFrom', $EmailVacationFrom);
|
||||
$adb->set_prop($user, 'EmailVacationTo', $EmailVacationTo);
|
||||
|
||||
#the first is more correct but is slower
|
||||
#system ("/sbin/e-smith/signal-event", "email-update", $user) == 0
|
||||
system ("/etc/e-smith/events/actions/qmail-update-user event $user") == 0
|
||||
or die ("Error occurred updating .qmail\n");
|
||||
|
||||
if (($EmailVacation eq 'no') && ( -e "/home/e-smith/files/users/$user/.vacation"))
|
||||
{
|
||||
system ("/bin/rm /home/e-smith/files/users/$user/.vacation") == 0
|
||||
or die ("Error resetting vacation db.\n");
|
||||
}
|
||||
|
||||
return $self->success("SUCCESS");
|
||||
}
|
||||
|
||||
1;
|
384
root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm
Normal file
384
root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm
Normal file
@@ -0,0 +1,384 @@
|
||||
package SrvMngr::Controller::Uservacations;
|
||||
#----------------------------------------------------------------------
|
||||
# heading : User management
|
||||
# description : User Vacations
|
||||
# navigation : 2000 150
|
||||
#
|
||||
# name : Uservacationsget, method : get, url : /uservacations, ctlact : Uservacations#main
|
||||
# name : Uservacationspost,method : post, url : /Uservacations, ctlact : Uservacations#do_display
|
||||
# name : Uservacations1, method : get, url : /Uservacations1, ctlact : Uservacations#do_display
|
||||
# name : Uservacations2, method : post, url : /Uservacations2, ctlact : Uservacations#do_display
|
||||
# routes : end
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
#use DateTime; #Not part of SME10 mix
|
||||
use POSIX;
|
||||
|
||||
use Locale::gettext;
|
||||
use SrvMngr::I18N;
|
||||
use SrvMngr qw(theme_list init_session);
|
||||
|
||||
use Data::Dumper;
|
||||
use esmith::util;
|
||||
use esmith::HostsDB;
|
||||
use esmith::AccountsDB;
|
||||
|
||||
our $db = esmith::ConfigDB->open();
|
||||
our $adb = esmith::AccountsDB->open();
|
||||
|
||||
our $PanelUser = $ENV{'REMOTE_USER'} ||'';
|
||||
$PanelUser = $1 if ($PanelUser =~ /^([a-z][\.\-a-z0-9]*)$/);
|
||||
|
||||
our %delegatedVacations;
|
||||
|
||||
use constant FALSE => 0;
|
||||
use constant TRUE => 1;
|
||||
|
||||
sub main {
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info( $c->log_req );
|
||||
|
||||
my %vac_datas = ();
|
||||
my $title = $c->l('vac_FORM_TITLE');
|
||||
my $modul = '';
|
||||
|
||||
$vac_datas{trt} = 'LIST';
|
||||
|
||||
my @vacations = get_vacation_table($c);
|
||||
my $empty = (scalar @vacations == 0);
|
||||
|
||||
$vac_datas{"first"} = 'vac_MODIFY_DESCRIPTION';
|
||||
|
||||
$c->stash(
|
||||
title => $title,
|
||||
modul => $modul,
|
||||
vac_datas => \%vac_datas,
|
||||
vacations =>\@vacations,
|
||||
empty => $empty
|
||||
);
|
||||
$c->render( template => 'uservacations' );
|
||||
}
|
||||
|
||||
sub do_display {
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info( $c->log_req );
|
||||
|
||||
my $rt = $c->current_route;
|
||||
my $trt = ( $c->param('trt') || 'LIST' );
|
||||
|
||||
$trt = 'ADD' if ( $rt eq 'Uservacations1' );
|
||||
$trt = 'ADD1' if ( $rt eq 'Uservacations2' );
|
||||
|
||||
my %vac_datas = ();
|
||||
my $title = $c->l('vac_FORM_TITLE');
|
||||
my $modul = '';
|
||||
|
||||
|
||||
if ( $trt eq 'ADD' ) {
|
||||
# Add or change a vacation message - called from the list panel
|
||||
# Get the data and pass it across.
|
||||
my $account = $c->param("account");
|
||||
my $user = $adb->get($account);
|
||||
my $username = $user->prop("FirstName")." ".$user->prop("LastName");
|
||||
my $EmailVacation = $user->prop('EmailVacation') || '';
|
||||
my $EmailVacationFrom = $user->prop('EmailVacationFrom') || '';
|
||||
my $EmailVacationTo = $user->prop('EmailVacationTo') || '';
|
||||
my $VacText = get_vacation_text($c);
|
||||
$c->stash(account=>$account,
|
||||
username=>$username,
|
||||
EmailVacation=>$EmailVacation,
|
||||
EmailVacationFrom=>$EmailVacationFrom,
|
||||
EmailVacationTo=>$EmailVacationTo,
|
||||
VacText=>$VacText
|
||||
);
|
||||
}
|
||||
|
||||
if ( $trt eq 'ADD1' ) {
|
||||
#Add or edit vacation message.
|
||||
my $ret = add_vac_message($c);
|
||||
#Return to list page if success
|
||||
if ($ret eq "OK") {
|
||||
$trt = "LIST";
|
||||
$vac_datas{success} = "vac_SUCCESS";
|
||||
|
||||
} else {
|
||||
my $account = $c->param("account");
|
||||
my $user = $adb->get($account);
|
||||
my $username = $user->prop("FirstName")." ".$user->prop("LastName");
|
||||
my $EmailVacationFrom = $c->param('EmailVacationFrom') || '';
|
||||
my $EmailVacationTo = $c->param('EmailVacationTo') || '';
|
||||
my $EmailVacation = $c->param('EmailVacation') || '';
|
||||
my $VacText = $c->param("VacText");
|
||||
$c->stash(account=>$account,
|
||||
username=>$username,
|
||||
EmailVacation=>$EmailVacation,
|
||||
EmailVacationFrom=>$EmailVacationFrom,
|
||||
EmailVacationTo=>$EmailVacationTo,
|
||||
VacText=>$VacText
|
||||
);
|
||||
#Error - return to Add page
|
||||
$trt = "ADD";
|
||||
$vac_datas{error} = $ret;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $trt eq 'LIST' ) {
|
||||
|
||||
#List all the users and vacation message details.
|
||||
my @vacations = get_vacation_table($c);
|
||||
my $empty = (scalar @vacations == 0);
|
||||
$c->stash(
|
||||
empty => $empty,
|
||||
vacations =>\@vacations
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$vac_datas{'trt'} = $trt;
|
||||
$c->stash( title => $title, modul => $modul, vac_datas => \%vac_datas );
|
||||
$c->render( template => 'uservacations' );
|
||||
}
|
||||
|
||||
sub user_accounts_exist
|
||||
{
|
||||
my $q = shift;
|
||||
#return scalar $adb->users;
|
||||
if (scalar $adb->users)
|
||||
{ return $q->l('vac_DESCRIPTION'); }
|
||||
}
|
||||
|
||||
sub get_vacation_table
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
#We want to retrieve granted group from DB, and retrieve users of groups
|
||||
my $record = $adb->get($PanelUser);
|
||||
my $dg;
|
||||
if ($record) {$dg=$record->prop('delegatedVacations')||'';}
|
||||
else {$dg = '';}
|
||||
$dg =~ s/ //g;
|
||||
my @g = split(/,/, $dg);
|
||||
my @visiblemembers = ();
|
||||
|
||||
foreach my $g (@g) {
|
||||
my $members = $adb->get_prop("$g",'Members');
|
||||
next unless defined $members;
|
||||
$members =~ s/ //g;
|
||||
my @members = split(/,/, $members);
|
||||
push @visiblemembers , @members ;
|
||||
}
|
||||
|
||||
foreach my $k ( @visiblemembers )
|
||||
{
|
||||
$delegatedVacations{$k}=1;
|
||||
}
|
||||
|
||||
|
||||
my @users = $adb->users;
|
||||
return () if (@users == 0); ##$self->l("ACCOUNT_USER_NONE")
|
||||
return () if (@visiblemembers == 0 && $dg ne '');#; #$self->l("NO_USERS_IN_GRANTED_GROUPS")
|
||||
|
||||
my @data = ();
|
||||
|
||||
for my $user (@users)
|
||||
{
|
||||
next if %delegatedVacations and not $delegatedVacations{$user->key};
|
||||
# make it clearer which uses have vacation
|
||||
my $EmailVacation = $user->prop('EmailVacation') || '';
|
||||
my $EmailVacationFrom = $user->prop('EmailVacationFrom') || '';
|
||||
my $EmailVacationTo = $user->prop('EmailVacationTo') || '';
|
||||
my $status = $user->prop('EmailVacation') || '';
|
||||
if ($status eq 'yes') { $status = 'YES'; } else { $status = ''; }
|
||||
|
||||
push @data,
|
||||
{ User => $user->key,
|
||||
FullName => $user->prop('FirstName') . " " .$user->prop('LastName'),
|
||||
status => $self->l($status),
|
||||
EmailVacation => $EmailVacation,
|
||||
EmailVacationFrom => showDate($EmailVacationFrom),
|
||||
EmailVacationTo => showDate($EmailVacationTo),
|
||||
Modify => $self->l('vac_MODIFY'),
|
||||
}
|
||||
}
|
||||
return @data;
|
||||
}
|
||||
|
||||
sub showDate
|
||||
{
|
||||
my $strDate = shift;
|
||||
my ($Year,$Month,$Day) = ($strDate =~ /(\d{4})(\d{2})(\d{2})/);
|
||||
#my $Unix = mktime(0,0,0,$Day,$Month,$Year);
|
||||
return "$Year-$Month-$Day";
|
||||
}
|
||||
|
||||
|
||||
sub modify_link
|
||||
{
|
||||
my ($data_item, $row, $field) = @_;
|
||||
|
||||
return "uservacations?" .
|
||||
join("&",
|
||||
"page=0",
|
||||
"page_stack=",
|
||||
"Next=Next",
|
||||
"User=" . $row->{User},
|
||||
"FullName=" . $row->{FullName},
|
||||
"EmailVacation=" . $row->{EmailVacation},
|
||||
"EmailVacationFrom=" . $row->{EmailVacationFrom},
|
||||
"EmailVacationTo=" . $row->{EmailVacationTo},
|
||||
"wherenext=VACATION_PAGE_MODIFY");
|
||||
}
|
||||
|
||||
# this formats the text to display on screen
|
||||
sub get_vacation_text
|
||||
{
|
||||
my $q = shift;
|
||||
my $domain = $db->get_value('DomainName');
|
||||
my $user = $q->param('account');
|
||||
|
||||
my $fullname = $adb->get_prop($user, "FirstName") . " " .
|
||||
$adb->get_prop($user, "LastName");
|
||||
|
||||
my $vfile = "/home/e-smith/files/users/$user/.vacation.msg";
|
||||
|
||||
my $from = $q->l('vac_FROM');
|
||||
my $Subject = $q->l('vac_SUBJECT');
|
||||
my $away = $q->l('vac_AWAY_FROM_MAIL');
|
||||
my $return = $q->l('vac_ANSWER_TO_OBJECT_SENDER');
|
||||
|
||||
#my $ExistingMessage = "$from $fullname <\;$user\@$domain>\;\n"."$Subject $return\n".
|
||||
# "\n$away\n"."\n--\n$fullname";
|
||||
|
||||
my $ExistingMessage = "$from $fullname \<$user\@$domain\>\n"."$Subject $return\n".
|
||||
"\n$away\n"."\n--\n$fullname";
|
||||
|
||||
|
||||
# if exists and is not empty
|
||||
if (( -e $vfile ) && (! -z $vfile ))
|
||||
{
|
||||
open (VACATION, "<$vfile")
|
||||
or die "Error: Could not open file: $vfile\n";
|
||||
my @vacationTemp;
|
||||
|
||||
#reformat so email address isn't hidden inside < >
|
||||
while (<VACATION>)
|
||||
{
|
||||
$_ =~ s/</<\;/;
|
||||
$_ =~ s/>/>\;/;
|
||||
push (@vacationTemp, $_);
|
||||
}
|
||||
|
||||
$ExistingMessage = join ("", @vacationTemp);
|
||||
|
||||
close VACATION;
|
||||
}
|
||||
return $ExistingMessage;
|
||||
}
|
||||
|
||||
# saves the text to .vacation.msg
|
||||
sub add_vac_message
|
||||
{
|
||||
my $q = shift;
|
||||
|
||||
my $domain = $db->get_value('DomainName');
|
||||
my $user = $q->param('account');
|
||||
|
||||
my $EmailVacation = $q->param('EmailVacation')||"no";
|
||||
#die($EmailVacation);
|
||||
#if ($EmailVacation eq "yes") {$EmailVacation = "yes";} else {$EmailVacation = "no";}
|
||||
|
||||
#Decode To and FROM to standard format - comes over in html5 iso format yyyy-mm-dd
|
||||
my $EmailVacationFrom = trim($q->param('EmailVacationFrom'));
|
||||
my ($fromYear,$fromMonth,$fromDay) = ($EmailVacationFrom =~ /(\d{4})-(\d{2})-(\d{2})/);
|
||||
$EmailVacationFrom = $fromYear.$fromMonth.$fromDay;
|
||||
if ($EmailVacationFrom !~ m/^2[0-9]{3}[0|1][0-9][0-3][0-9]$/ and $EmailVacationFrom ne "") {return "vac_FROM_DATE_INCORRECT";}
|
||||
my $EmailVacationTo = trim($q->param('EmailVacationTo'));
|
||||
my ($toYear,$toMonth,$toDay) = ($EmailVacationTo =~ /(\d{4})-(\d{2})-(\d{2})/);
|
||||
$EmailVacationTo = $toYear.$toMonth.$toDay;
|
||||
# $EmailVacationTo =~ s/-//g; #Just take out "-".
|
||||
if ($EmailVacationTo !~ m/^2[0-9]{3}[0|1][0-9][0-3][0-9]$/ and $EmailVacationFrom ne "") {return "vac_TO_DATE_INCORRECT";}
|
||||
#Check not the same or From follows To.
|
||||
if ($EmailVacationTo ne "" and $EmailVacationTo eq $EmailVacationFrom) {return "vac_DATES_THE_SAME";}
|
||||
my $UnixFrom = mktime(0,0,0,$fromDay,$fromMonth,$fromYear);
|
||||
my $UnixTo = mktime(0,0,0,$toDay,$toMonth,$toYear);
|
||||
if ($UnixTo < $UnixFrom) {return "vac_TO_DATE_MUST_BE_LATER";}
|
||||
|
||||
|
||||
my $new_message = $q->param('VacText');
|
||||
my $vfile = "/home/e-smith/files/users/$user/.vacation.msg";
|
||||
|
||||
my $fullname = $adb->get_prop($user, "FirstName") . " " .
|
||||
$adb->get_prop($user, "LastName");
|
||||
|
||||
my $from = 'From:';
|
||||
my $away = $q->l('vac_AWAY_FROM_MAIL');
|
||||
my $return = $q->l('vac_ANSWER_TO_OBJECT_SENDER');
|
||||
|
||||
my $vacation_text = "$from $fullname \<$user\@$domain\>\n"."Subject: $return\n".
|
||||
"\n$away \n"."\n--\n$fullname";
|
||||
|
||||
my $reset = $vacation_text;
|
||||
|
||||
# if exists and is not empty
|
||||
if (( -e $vfile ) && (! -z $vfile ))
|
||||
{
|
||||
open (VACATION, "<$vfile")
|
||||
or die "Error: Could not open file: $vfile\n";
|
||||
my @vacationTemp = <VACATION>;
|
||||
$vacation_text = join ("", @vacationTemp);
|
||||
|
||||
close VACATION;
|
||||
}
|
||||
|
||||
chomp $new_message;
|
||||
|
||||
# reset msg to default,
|
||||
if ($new_message =~ /reset/)
|
||||
{ $vacation_text = $reset; }
|
||||
else
|
||||
{
|
||||
#or save new_message
|
||||
unless ($new_message eq "")
|
||||
{ $vacation_text = $new_message; }
|
||||
}
|
||||
|
||||
# Strip out DOS Carriage Returns (CR)
|
||||
$vacation_text =~ s/\r//g;
|
||||
|
||||
unlink $vfile;
|
||||
open (VACATION, ">$vfile")
|
||||
or die ("Error opening vacation message.\n");
|
||||
|
||||
print VACATION "$vacation_text";
|
||||
close VACATION;
|
||||
|
||||
esmith::util::chownFile($user, $user,
|
||||
"/home/e-smith/files/users/$user/.vacation.msg");
|
||||
|
||||
$adb->set_prop($user, 'EmailVacation', $EmailVacation);
|
||||
$adb->set_prop($user, 'EmailVacationFrom', $EmailVacationFrom);
|
||||
$adb->set_prop($user, 'EmailVacationTo', $EmailVacationTo);
|
||||
|
||||
#the first is more correct but is slower
|
||||
#system ("/sbin/e-smith/signal-event", "email-update", $user) == 0
|
||||
system ("/etc/e-smith/events/actions/qmail-update-user event $user") == 0
|
||||
or die ("Error occurred updating .qmail\n");
|
||||
|
||||
if (($EmailVacation eq 'no') && ( -e "/home/e-smith/files/users/$user/.vacation"))
|
||||
{
|
||||
system ("/bin/rm /home/e-smith/files/users/$user/.vacation") == 0
|
||||
or die ("Error resetting vacation db.\n");
|
||||
}
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
|
||||
|
||||
1;
|
@@ -0,0 +1,63 @@
|
||||
package SrvMngr::I18N::Modules::Uservacations::en;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use Mojo::Base 'SrvMngr::I18N';
|
||||
|
||||
use SrvMngr::I18N::Modules::General::en;
|
||||
|
||||
my %lexicon = (
|
||||
'vac_User vacations' =>'User vacations',
|
||||
'vac_Vacation Message' =>'Vacation Message',
|
||||
'vac_FORM_TITLE' =>'Change user vacation settings',
|
||||
'vac_DESCRIPTION' =>' You can modify a users vacation message by clicking
|
||||
on the link to the right of their name below.
|
||||
',
|
||||
'vac_LABEL_VACATION' =>'Vacation',
|
||||
'vac_NO_FORWARDS'=>'No users found for forwarding',
|
||||
'vac_VACATION_FROM' =>'Vacation starts on <br>(YYYY-MM-DD)',
|
||||
'vac_VACATION_TO' =>'Vacation finishes on <br>(YYYY-MM-DD)',
|
||||
'vac_VACATION_FROM1' =>'Vacation starts on',
|
||||
'vac_VACATION_TO1' =>'Vacation finishes on',
|
||||
'vac_MESSAGE' =>'Vacation message',
|
||||
'vac_VACATION_STATUS' =>'Enable vacation messages',
|
||||
'vac_FROM' =>'From:',
|
||||
'vac_SUBJECT' =>'Subject:',
|
||||
'vac_AWAY_FROM_MAIL' =>'I will not be reading my mail for a while. Your mail regarding $SUBJECT will be read when I return.',
|
||||
'vac_NO_USERS_IN_GRANTED_GROUPS' =>'There are no users in the group(s) that you are granted to manage.',
|
||||
'vac_ANSWER_TO_OBJECT_SENDER' => 'Re: $SUBJECT - Away from my email ',
|
||||
'vac_FROM_DATE_INCORRECT'=>'From date must have YYYYMMDD format',
|
||||
'vac_TO_DATE_INCORRECT'=>'To date must have YYYYMMDD format',
|
||||
'vac_DATES_THE_SAME'=>"The Start and Finish dates cannot be the same",
|
||||
'vac_TO_DATE_MUST_BE_LATER'=>"The Finish dates cannot be earlier than the Start date",
|
||||
'vac_SUCCESS'=>'Vacation message saved sucessfully',
|
||||
'vac_MODIFY_DESCRIPTION' =>'
|
||||
<p>
|
||||
Enter a vacation message here. You can use $SUBJECT
|
||||
anywhere in the text to be replaced with the subject line
|
||||
from the email that activated the auto-reply.</p>
|
||||
|
||||
<p>
|
||||
This message must be composed of two parts separated by a blank line.
|
||||
The first will be integrated into the headings of the email reply,
|
||||
you must thus ensure you leave at least a blank line before typing your message.
|
||||
The primary domain is added to the address automatically,or you can insert a virtual domain by replacing the domain part of the sender address
|
||||
in the first line of the message with the virtual domain name (eg. replace the default From: user@primary.domain with From: user@virtual.domain).
|
||||
To change the vacation message back to the default type reset.</p>
|
||||
<p>
|
||||
You can also fill out the Enable vacation on and Disable vacation on fields in order to
|
||||
automatically enable and disable sending of the vacation message for this user account on the given dates.
|
||||
</p>
|
||||
<p>
|
||||
The dates in the two fields must not be the same.<br>
|
||||
If you want to use this functionality, leave the Enable vacation messages setting at No - it will be automatically activated based on the date given.
|
||||
</p>'
|
||||
);
|
||||
|
||||
our %Lexicon = (
|
||||
%{ SrvMngr::I18N::Modules::General::en::Lexicon },
|
||||
%lexicon
|
||||
);
|
||||
|
||||
|
||||
1;
|
@@ -0,0 +1,55 @@
|
||||
<div id='vac_add'>
|
||||
|
||||
% my $btn = l('ADD');
|
||||
|
||||
% if ($config->{debug} == 1) {
|
||||
<p>
|
||||
%= dumper $c->current_route
|
||||
%= dumper $EmailVacation
|
||||
</p>
|
||||
% }
|
||||
|
||||
%= form_for '/Uservacations2' => (method => 'POST') => begin
|
||||
|
||||
<span class=label>
|
||||
%=l 'ACCOUNT'
|
||||
</span><span class=data>
|
||||
%= $account
|
||||
</span><br>
|
||||
<span class=label>
|
||||
%=l 'USER_NAME'
|
||||
</span><span class=data>
|
||||
%=$username
|
||||
</span><br>
|
||||
<span class=label>
|
||||
%=$c->render_to_string(inline =>$c->l('vac_VACATION_FROM1'))
|
||||
</span>
|
||||
<span class=data>
|
||||
%=date_field 'EmailVacationFrom' =>$EmailVacationFrom
|
||||
</span><br>
|
||||
<span class=label>
|
||||
%=$c->render_to_string(inline =>$c->l('vac_VACATION_TO1'))
|
||||
</span>
|
||||
<span class=data>
|
||||
%=date_field 'EmailVacationTo' =>$EmailVacationTo
|
||||
</span><br>
|
||||
<span class=label>
|
||||
%=l 'vac_MESSAGE'
|
||||
</span>
|
||||
<span class=data>
|
||||
% $VacText = b("$VacText");
|
||||
%=text_area 'VacText' => $VacText, cols=>40, rows=>15
|
||||
</span><br>
|
||||
<span class=label>
|
||||
%=l 'vac_VACATION_STATUS'
|
||||
</span>
|
||||
<span class=data>
|
||||
% param EmailVacation => "$EmailVacation";
|
||||
%=select_field EmailVacation =>[['Yes'=>'yes'],['No'=>'no']]
|
||||
</span><br>
|
||||
%= hidden_field 'account' => $account
|
||||
|
||||
%= submit_button "$btn", class => 'action'
|
||||
%end
|
||||
|
||||
</div>
|
@@ -0,0 +1,51 @@
|
||||
<div id='vac_list'>
|
||||
|
||||
%# my $btn = l('vac_CREATE_RULE');
|
||||
|
||||
%= form_for '/Uservacations1' => (method => 'POST') => begin
|
||||
<br><br>
|
||||
|
||||
% if ($empty){
|
||||
<br>
|
||||
%=l 'vac_NO_FORWARDS'
|
||||
% } else {
|
||||
<table class="sme-border TableSort"><thead>
|
||||
<tr>
|
||||
<th class='sme-border'>
|
||||
%=l 'ACCOUNT'
|
||||
</th>
|
||||
<th class='sme-border'>
|
||||
%=l 'USER_NAME'
|
||||
</th>
|
||||
<th class='sme-border'>
|
||||
%=l 'vac_LABEL_VACATION'
|
||||
</th>
|
||||
|
||||
<th class='sme-border'>
|
||||
%=$c->render_to_string(inline =>l('vac_VACATION_FROM'))
|
||||
</th>
|
||||
<th class='sme-border'>
|
||||
%=$c->render_to_string(inline =>l('vac_VACATION_TO'))
|
||||
</th>
|
||||
<th class='sme-border' '>
|
||||
%=l 'ACTION'
|
||||
</th>
|
||||
</tr>
|
||||
</thead><tbody>
|
||||
% foreach my $vacation (@$vacations) {
|
||||
<tr>
|
||||
%= t td => (class => 'sme-border') => $vacation->{"User"}
|
||||
%= t td => (class => 'sme-border') => $vacation->{"FullName"}
|
||||
%= t td => (class => 'sme-border') => $vacation->{"status"}
|
||||
%= t td => (class => 'sme-border') => $vacation->{"EmailVacationFrom"}
|
||||
%= t td => (class => 'sme-border') => $vacation->{"EmailVacationTo"}
|
||||
<td>
|
||||
<a href="/smanager/Uservacations1?trt=ADD&account=<%= $vacation->{"User"}%>"><%=l 'MODIFY'%></a>
|
||||
</td>
|
||||
</tr>
|
||||
%}
|
||||
</tbody>
|
||||
</table>
|
||||
%}
|
||||
% end
|
||||
</div>
|
@@ -0,0 +1,42 @@
|
||||
% layout 'default', title => "Sme server 2 - User Vacations", share_dir => './';
|
||||
|
||||
% content_for 'module' => begin
|
||||
<div id="module" class="module vacation-panel">
|
||||
|
||||
% if ($config->{debug} == 1) {
|
||||
<p>
|
||||
%= dumper $c->current_route
|
||||
</p>
|
||||
% }
|
||||
|
||||
<h1><%=$title%></h1>
|
||||
%= $modul
|
||||
|
||||
%if ($vac_datas->{first}) {
|
||||
<br>
|
||||
%=$c->render_to_string(inline =>$c->l($vac_datas->{first}))
|
||||
|
||||
%} elsif ($vac_datas->{success}) {
|
||||
<div class='"success"'>
|
||||
<h2> Operation Status Report</h2>
|
||||
%= $c->l($vac_datas->{success});
|
||||
</div>
|
||||
|
||||
%} elsif ($vac_datas->{error}) {
|
||||
<div class='sme-error'>
|
||||
<h2> Operation Status Report - error</h2>
|
||||
%= $c->l($vac_datas->{error});
|
||||
</div>
|
||||
%}
|
||||
|
||||
|
||||
% if ($vac_datas->{trt} eq 'ADD') {
|
||||
%= include 'partials/_vac_add'
|
||||
%} elsif ($vac_datas->{trt} eq 'ADD1') {
|
||||
%= include 'partials/_vac_add'
|
||||
%} else {
|
||||
%= include 'partials/_vac_list'
|
||||
%}
|
||||
|
||||
</div>
|
||||
%end
|
Reference in New Issue
Block a user