* Wed Oct 01 2025 Brian Read <brianr@koozali.org> 11.0.0-2.sme

- Restore missing lex file  [SME: 13208]
- Make front end work for user panel as well as admin panel [SME:  13208]
- Fix possible DB caching problems [SME: 13208]
- Add in UTF8 fix for DB access [SME: 13208]
This commit is contained in:
2025-10-02 08:08:52 +01:00
parent 602bec8cb1
commit 4bce7467f6
4 changed files with 125 additions and 38 deletions

View File

@@ -24,11 +24,12 @@ use SrvMngr qw(theme_list init_session);
use Data::Dumper; use Data::Dumper;
use esmith::util; use esmith::util;
use esmith::HostsDB; #use esmith::HostsDB::UTF8;
use esmith::AccountsDB; use esmith::AccountsDB;
use esmith::ConfigDB::UTF8;
our $db = esmith::ConfigDB->open(); my $db;
our $adb = esmith::AccountsDB->open(); my $adb;
our $PanelUser = $ENV{'REMOTE_USER'} ||''; our $PanelUser = $ENV{'REMOTE_USER'} ||'';
$PanelUser = $1 if ($PanelUser =~ /^([a-z][\.\-a-z0-9]*)$/); $PanelUser = $1 if ($PanelUser =~ /^([a-z][\.\-a-z0-9]*)$/);
@@ -43,11 +44,33 @@ sub main {
my $c = shift; my $c = shift;
$c->app->log->info( $c->log_req ); $c->app->log->info( $c->log_req );
$db = esmith::ConfigDB::UTF8->open() || die("Couldn't open config db");
$adb = esmith::AccountsDB->open() || die("Couldn't open accounts db");
my %vac_datas = (); my %vac_datas = ();
my $title = $c->l('vac_FORM_TITLE'); my $title = $c->l('vac_FORM_TITLE');
my $modul = ''; my $modul = '';
if (! $c->is_admin) {
#Here it is in user panel mode and needs the current user data loaded up
$vac_datas{trt} = 'ADD';
my $account = $c->session('username'); #TESTING from somewhere ....#$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') || '';
$c->stash(account=>$account);
my $VacText = get_vacation_text($c);
$c->stash(username=>$username,
EmailVacation=>$EmailVacation,
EmailVacationFrom=>$EmailVacationFrom,
EmailVacationTo=>$EmailVacationTo,
VacText=>$VacText
);
} else {
$vac_datas{trt} = 'LIST'; $vac_datas{trt} = 'LIST';
}
my @vacations = get_vacation_table($c); my @vacations = get_vacation_table($c);
my $empty = (scalar @vacations == 0); my $empty = (scalar @vacations == 0);
@@ -69,6 +92,9 @@ sub do_display {
my $c = shift; my $c = shift;
$c->app->log->info( $c->log_req ); $c->app->log->info( $c->log_req );
$db = esmith::ConfigDB::UTF8->open() || die("Couldn't open config db");
$adb = esmith::AccountsDB->open() || die("Couldn't open accounts db");
my $rt = $c->current_route; my $rt = $c->current_route;
my $trt = ( $c->param('trt') || 'LIST' ); my $trt = ( $c->param('trt') || 'LIST' );
@@ -89,9 +115,9 @@ sub do_display {
my $EmailVacation = $user->prop('EmailVacation') || ''; my $EmailVacation = $user->prop('EmailVacation') || '';
my $EmailVacationFrom = $user->prop('EmailVacationFrom') || ''; my $EmailVacationFrom = $user->prop('EmailVacationFrom') || '';
my $EmailVacationTo = $user->prop('EmailVacationTo') || ''; my $EmailVacationTo = $user->prop('EmailVacationTo') || '';
$c->stash(account=>$account);
my $VacText = get_vacation_text($c); my $VacText = get_vacation_text($c);
$c->stash(account=>$account, $c->stash(username=>$username,
username=>$username,
EmailVacation=>$EmailVacation, EmailVacation=>$EmailVacation,
EmailVacationFrom=>$EmailVacationFrom, EmailVacationFrom=>$EmailVacationFrom,
EmailVacationTo=>$EmailVacationTo, EmailVacationTo=>$EmailVacationTo,
@@ -103,10 +129,29 @@ sub do_display {
#Add or edit vacation message. #Add or edit vacation message.
my $ret = add_vac_message($c); my $ret = add_vac_message($c);
#Return to list page if success #Return to list page if success
# unless in user panel, in which case return to vacation msg display
if ($ret eq "OK") { if ($ret eq "OK") {
if (! $c->is_admin){
$trt = "ADD";
#my $fred = 1/0;
my $account = $c->session('username'); #TESTING from somewhere ....#$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
);
} else {
$trt = "LIST"; $trt = "LIST";
$vac_datas{success} = "vac_SUCCESS"; $vac_datas{success} = "vac_SUCCESS";
}
} else { } else {
my $account = $c->param("account"); my $account = $c->param("account");
my $user = $adb->get($account); my $user = $adb->get($account);
@@ -209,11 +254,17 @@ sub get_vacation_table
return @data; return @data;
} }
sub showDate sub showDate {
{
my $strDate = shift; my $strDate = shift;
# Try to capture Year, Month, Day from the string
my ($Year, $Month, $Day) = ($strDate =~ /(\d{4})(\d{2})(\d{2})/); my ($Year, $Month, $Day) = ($strDate =~ /(\d{4})(\d{2})(\d{2})/);
#my $Unix = mktime(0,0,0,$Day,$Month,$Year);
# Provide default values if regex capture fails or any part is undefined
$Year = defined $Year ? $Year : '0000';
$Month = defined $Month ? $Month : '00';
$Day = defined $Day ? $Day : '00';
return "$Year-$Month-$Day"; return "$Year-$Month-$Day";
} }
@@ -240,8 +291,7 @@ sub get_vacation_text
{ {
my $q = shift; my $q = shift;
my $domain = $db->get_value('DomainName'); my $domain = $db->get_value('DomainName');
my $user = $q->param('account'); my $user = $q->param('account') || $q->stash('account') || "unknown";
my $fullname = $adb->get_prop($user, "FirstName") . " " . my $fullname = $adb->get_prop($user, "FirstName") . " " .
$adb->get_prop($user, "LastName"); $adb->get_prop($user, "LastName");
@@ -258,6 +308,10 @@ sub get_vacation_text
my $ExistingMessage = "$from $fullname \<$user\@$domain\>\n"."$Subject $return\n". my $ExistingMessage = "$from $fullname \<$user\@$domain\>\n"."$Subject $return\n".
"\n$away\n"."\n--\n$fullname"; "\n$away\n"."\n--\n$fullname";
$q->app->log->info( "DEBUG: File path is $vfile\n");
$q->app->log->info( "DEBUG: File exists? ", -e $vfile, "\n");
$q->app->log->info( "DEBUG: File empty? ", -z $vfile, "\n");
# if exists and is not empty # if exists and is not empty
if (( -e $vfile ) && (! -z $vfile )) if (( -e $vfile ) && (! -z $vfile ))

View File

@@ -1,12 +1,3 @@
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_User vacations' =>'User vacations',
'vac_Vacation Message' =>'Vacation Message', 'vac_Vacation Message' =>'Vacation Message',
'vac_FORM_TITLE' =>'Change user vacation settings', 'vac_FORM_TITLE' =>'Change user vacation settings',
@@ -52,12 +43,3 @@ my %lexicon = (
The dates in the two fields must not be the same.<br> 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. 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>' </p>'
);
our %Lexicon = (
%{ SrvMngr::I18N::Modules::General::en::Lexicon },
%lexicon
);
1;

View File

@@ -0,0 +1,45 @@
'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>'

View File

@@ -4,7 +4,7 @@
%define name smeserver-vacation %define name smeserver-vacation
%define version 11.0.0 %define version 11.0.0
%define release 1 %define release 2
Summary: SME Server enhancement to enable vacation messages for users. Summary: SME Server enhancement to enable vacation messages for users.
Name: %{name} Name: %{name}
Version: %{version} Version: %{version}
@@ -30,6 +30,12 @@ Optionally provides a user-manager panel where users can
enable vacation for themselves and to modify their own message enable vacation for themselves and to modify their own message
%changelog %changelog
* Wed Oct 01 2025 Brian Read <brianr@koozali.org> 11.0.0-2.sme
- Restore missing lex file [SME: 13208]
- Make front end work for user panel as well as admin panel [SME: 13208]
- Fix possible DB caching problems [SME: 13208]
- Add in UTF8 fix for DB access [SME: 13208]
* Sat May 17 2025 Brian Read <brianr@koozali.org> 11.0.0-1.sme * Sat May 17 2025 Brian Read <brianr@koozali.org> 11.0.0-1.sme
- Fix call to $config-> to config-> in default panel [SME: 12908] - Fix call to $config-> to config-> in default panel [SME: 12908]