From 826d4865475e09caa00076b1b41063ae8e618cc0 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 --- C4/Auth.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 80cc4773a6..966ad7ba09 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -762,12 +762,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.20.1