From 4bce7467f600d5d6ea9145fd0cee1d833ce949f3 Mon Sep 17 00:00:00 2001
From: Brian Read
Date: Thu, 2 Oct 2025 08:08:52 +0100
Subject: [PATCH] * Wed Oct 01 2025 Brian Read
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]
---
.../lib/SrvMngr/Controller/Uservacations.pm | 90 +++++++++++++++----
.../{en.pm => uservacations_en.lex} | 20 +----
.../I18N/Modules/Uservacations/vac_en.lex | 45 ++++++++++
smeserver-vacation.spec | 8 +-
4 files changed, 125 insertions(+), 38 deletions(-)
rename root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/{en.pm => uservacations_en.lex} (90%)
create mode 100644 root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/vac_en.lex
diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm
index 1068c15..e9bd663 100644
--- a/root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm
+++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Uservacations.pm
@@ -24,11 +24,12 @@ use SrvMngr qw(theme_list init_session);
use Data::Dumper;
use esmith::util;
-use esmith::HostsDB;
+#use esmith::HostsDB::UTF8;
use esmith::AccountsDB;
+use esmith::ConfigDB::UTF8;
-our $db = esmith::ConfigDB->open();
-our $adb = esmith::AccountsDB->open();
+my $db;
+my $adb;
our $PanelUser = $ENV{'REMOTE_USER'} ||'';
$PanelUser = $1 if ($PanelUser =~ /^([a-z][\.\-a-z0-9]*)$/);
@@ -43,11 +44,33 @@ sub main {
my $c = shift;
$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 $title = $c->l('vac_FORM_TITLE');
my $modul = '';
- $vac_datas{trt} = 'LIST';
+ 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';
+ }
my @vacations = get_vacation_table($c);
my $empty = (scalar @vacations == 0);
@@ -69,6 +92,9 @@ sub do_display {
my $c = shift;
$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 $trt = ( $c->param('trt') || 'LIST' );
@@ -89,9 +115,9 @@ sub do_display {
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(account=>$account,
- username=>$username,
+ $c->stash(username=>$username,
EmailVacation=>$EmailVacation,
EmailVacationFrom=>$EmailVacationFrom,
EmailVacationTo=>$EmailVacationTo,
@@ -103,10 +129,29 @@ sub do_display {
#Add or edit vacation message.
my $ret = add_vac_message($c);
#Return to list page if success
+ # unless in user panel, in which case return to vacation msg display
if ($ret eq "OK") {
- $trt = "LIST";
- $vac_datas{success} = "vac_SUCCESS";
-
+ 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";
+ $vac_datas{success} = "vac_SUCCESS";
+ }
} else {
my $account = $c->param("account");
my $user = $adb->get($account);
@@ -209,13 +254,19 @@ sub get_vacation_table
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);
+sub showDate {
+ my $strDate = shift;
+
+ # Try to capture Year, Month, Day from the string
+ my ($Year, $Month, $Day) = ($strDate =~ /(\d{4})(\d{2})(\d{2})/);
+
+ # 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";
-}
+}
sub modify_link
@@ -240,8 +291,7 @@ sub get_vacation_text
{
my $q = shift;
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") . " " .
$adb->get_prop($user, "LastName");
@@ -258,6 +308,10 @@ sub get_vacation_text
my $ExistingMessage = "$from $fullname \<$user\@$domain\>\n"."$Subject $return\n".
"\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 (( -e $vfile ) && (! -z $vfile ))
@@ -381,4 +435,4 @@ sub add_vac_message
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
-1;
+1;
\ No newline at end of file
diff --git a/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/en.pm b/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/uservacations_en.lex
similarity index 90%
rename from root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/en.pm
rename to root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/uservacations_en.lex
index f03b4d5..6e77c52 100644
--- a/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/en.pm
+++ b/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/uservacations_en.lex
@@ -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_Vacation Message' =>'Vacation Message',
'vac_FORM_TITLE' =>'Change user vacation settings',
@@ -51,13 +42,4 @@ my %lexicon = (
The dates in the two fields must not be the same.
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.
-
'
-);
-
-our %Lexicon = (
- %{ SrvMngr::I18N::Modules::General::en::Lexicon },
- %lexicon
-);
-
-
-1;
+
'
\ No newline at end of file
diff --git a/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/vac_en.lex b/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/vac_en.lex
new file mode 100644
index 0000000..6e77c52
--- /dev/null
+++ b/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Uservacations/vac_en.lex
@@ -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
(YYYY-MM-DD)',
+'vac_VACATION_TO' =>'Vacation finishes on
(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' =>'
+
+ 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.
+
+
+ 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.
+
+ 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.
+
+
+ The dates in the two fields must not be the same.
+ 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.
+
'
\ No newline at end of file
diff --git a/smeserver-vacation.spec b/smeserver-vacation.spec
index 7493487..29259c6 100644
--- a/smeserver-vacation.spec
+++ b/smeserver-vacation.spec
@@ -4,7 +4,7 @@
%define name smeserver-vacation
%define version 11.0.0
-%define release 1
+%define release 2
Summary: SME Server enhancement to enable vacation messages for users.
Name: %{name}
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
%changelog
+* Wed Oct 01 2025 Brian Read 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 11.0.0-1.sme
- Fix call to $config-> to config-> in default panel [SME: 12908]