From c5e5cba814835feaca554afeb682bbe8af0442f0 Mon Sep 17 00:00:00 2001 From: Will Budicm Date: Sun, 27 Dec 2020 07:05:52 +1100 Subject: [PATCH] Bugg 33, fix. --- dbLifeLog/main.cnf | 2 +- htdocs/cgi-bin/json.cgi | 1 + htdocs/cgi-bin/system/modules/Settings.pm | 25 ++++++--- htdocs/cgi-bin/testSettings.pl | 62 ++++++++++++++++++++++- 4 files changed, 82 insertions(+), 8 deletions(-) diff --git a/dbLifeLog/main.cnf b/dbLifeLog/main.cnf index 92c1a6a..20de50f 100644 --- a/dbLifeLog/main.cnf +++ b/dbLifeLog/main.cnf @@ -53,7 +53,7 @@ America/Texas=America/Chicago 03|$TIME_ZONE = Australia/Sydney`Time zone of your country and city. 05|$PRC_WIDTH = 80`Default presentation width for pages. 08|$LOG_PATH = ../../dbLifeLog/`Path to folder containing data. -10|$SESSN_EXPR = +30m`Login session expiration time setting, can be minutes or hours. +10|$SESSN_EXPR = +30m`Login session expiration time setting, can be seconds, minutes or hours. 12|$DATE_UNI = 0`Setting of how dates are displayed, universal yyyy-mm-dd or local dd-mm-yyyy. 14|$LANGUAGE = English`Default language locale. 18|$IMG_W_H = 210x120`Default embedded image width. diff --git a/htdocs/cgi-bin/json.cgi b/htdocs/cgi-bin/json.cgi index 46f0e9a..8260d22 100755 --- a/htdocs/cgi-bin/json.cgi +++ b/htdocs/cgi-bin/json.cgi @@ -114,6 +114,7 @@ sub processSubmit { $st->execute($zip); $response = "Updated Document (id:$lid)!"; } + } elsif($action eq 'load'){ $st = $db->prepare("SELECT DOC FROM NOTES WHERE LID = $lid;"); diff --git a/htdocs/cgi-bin/system/modules/Settings.pm b/htdocs/cgi-bin/system/modules/Settings.pm index 0693182..beae7a2 100644 --- a/htdocs/cgi-bin/system/modules/Settings.pm +++ b/htdocs/cgi-bin/system/modules/Settings.pm @@ -356,7 +356,7 @@ sub getConfiguration { when ("RELEASE_VER") {$RELEASE_VER = $r[2]} when ("TIME_ZONE") {$TIME_ZONE = $r[2]} when ("PRC_WIDTH") {$PRC_WIDTH = $r[2]} - when ("SESSN_EXPR") {$SESSN_EXPR = timeFormatValue($r[2])} + when ("SESSN_EXPR") {$SESSN_EXPR = timeFormatSessionValue($r[2])} when ("DATE_UNI") {$DATE_UNI = $r[2]} when ("LANGUAGE") {$LANGUAGE = $r[2]} when ("LOG_PATH") {} # Ommited and code static can't change for now. @@ -420,13 +420,26 @@ sub getConfiguration { }; } -sub timeFormatValue { +sub timeFormatSessionValue { my $v = shift; - if(!$v || $v==0){$v="+2m"} - if($v !~ /^\+/){$v='+'.$v.'m'} - return $v; + my $ret = "+2m"; + if(!$v){$v=$ret} + if($v !~ /^\+/){$v='+'.$v.'m'}# Must be positive added time + # Find first match in whatever passed. + my @a = $v =~ m/(\+\d+[shm])/gis; + if(scalar(@a)>0){$v=$a[0]} + # Test acceptable setting, which is any number from 2, having any s,m or h. + if($v =~ m/(\+[2-9]\d*[smh])|(\+[1-9]+\d+[smh])/){ + # Next is actually, the dry booger in the nose. Let's pick it out! + # Someone might try to set in seconds value to be under two minutes. + @a = $v =~ m/(\d[2-9]\d+)/gs; + if(scalar(@a)>0 && int($a[0])<120){return $ret}else{return $v} + } + elsif($v =~ m/\+\d+/){# is passedstill without time unit? Minutetise! + $ret=$v."m" + } + return $ret; } - sub getTheme { given ($THEME){ when ("Sun") { $BGCOL = '#D4AF37'; $TH_CSS = "main_sun.css"; } diff --git a/htdocs/cgi-bin/testSettings.pl b/htdocs/cgi-bin/testSettings.pl index 0670058..d6fb462 100755 --- a/htdocs/cgi-bin/testSettings.pl +++ b/htdocs/cgi-bin/testSettings.pl @@ -83,7 +83,67 @@ my $v3 = $' =~ qr/:/; # $`=DBI # $&=: # $'=Pg:host=elite;name=androi +print $v2.'->'.$`,"\n"; +$v1 =""; + +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="1"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+1m"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+10minutes"; +print "[$v1]->".timeFormatValue($v1),"\n"; +#default +$v1 ="+30m"; +print "[$v1]->".timeFormatValue($v1),"\n"; + +#Let's try sneak in garbage. +$v1 ="+20bitcons"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+20hitcons"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+30hr"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+1hr"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+8.2severe"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+8severe"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+2severe"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+120severe"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+119severe"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+121severe"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+280severe"; +print "[$v1]->".timeFormatValue($v1),"\n"; +$v1 ="+120"; +print "[$v1]->".timeFormatValue($v1),"\n"; + + +sub timeFormatValue { + my $v = shift; + my $ret = "+2m"; + if(!$v){$v=$ret} + if($v !~ /^\+/){$v='+'.$v.'m'}# Must be positive added time + # Find first match in whatever passed. + my @a = $v =~ m/(\+\d+[shm])/gis; + if(scalar(@a)>0){$v=$a[0]} + # Test acceptable setting, which is any number from 2, having any s,m or h. + if($v =~ m/(\+[2-9]\d*[smh])|(\+[1-9]+\d+[smh])/){ + # Next is actually, the dry booger in the nose. Let's pick it out! + # Someone might try to set in seconds value to be under two minutes. + @a = $v =~ m/(\d[2-9]\d+)/gs; + if(scalar(@a)>0 && int($a[0])<120){return $ret}else{return $v} + } + elsif($v =~ m/\+\d+/){# is passedstill without time unit? Minutetise! + $ret=$v."m" + } + return $ret; +} -print $v2.'->'.$`,"\n"; 1; \ No newline at end of file -- 2.34.1