From 78e8c65bf5fa8db6b9a8e8f3313359a4f295c00d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 30 Jul 2020 15:15:46 +0200 Subject: [PATCH] Bug 20804: Add support for "days" to the timeout syspref If the timeout syspref did not contain an integer, or was not matching integer.'d|D', then it "fallback" to 0 We can easily add support for hours and fallback to 600 if the value is not correct. It will prevent the session to timeout immediately Test plan: 0. Do not apply the patches 1. Fill the timeout syspref with "5h" 2. Login 3. Click somewhere => Notice that the session timed out 4. Apply the patches, restart_all 5. Login 6. Click somewhere => You have 5 hours to enjoy Koha 7. Fill the pref with an incorrect value ("5x" for instance) 8. Logout, login 9. There is a warning in the log, and you have 10 minutes (600 secondes) to enjoy Koha Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit 97b9eab178f0b45b38662747a4e009e71d8b73ff) Signed-off-by: Lucas Gass --- C4/Auth.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index eda9c32956..7fe23a211f 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -761,12 +761,22 @@ sub _session_log { } sub _timeout_syspref { - my $timeout = C4::Context->preference('timeout') || 600; + my $default_timeout = 600; + my $timeout = C4::Context->preference('timeout') || $default_timeout; # value in days, convert in seconds - if ( $timeout =~ /(\d+)[dD]/ ) { + if ( $timeout =~ /^(\d+)[dD]$/ ) { $timeout = $1 * 86400; } + # value in hours, convert in seconds + elsif ( $timeout =~ /^(\d+)[hH]$/ ) { + $timeout = $1 * 3600; + } + elsif ( $timeout !~ m/^\d+$/ ) { + warn "The value of the system preference 'timeout' is not correct, defaulting to $default_timeout"; + $timeout = $default_timeout; + } + return $timeout; } -- 2.39.5