From: Will Budicm Date: Fri, 27 Nov 2020 05:58:12 +0000 (+1100) Subject: impl. TZ mapping. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=ee603ef843b75eb2657531924b8307fd36d68797;p=LifeLog.git impl. TZ mapping. --- diff --git a/dbLifeLog/main.cnf b/dbLifeLog/main.cnf index 8ad9efc..c110aad 100644 --- a/dbLifeLog/main.cnf +++ b/dbLifeLog/main.cnf @@ -25,6 +25,12 @@ Credential format:< , don't enable here using AU <#File,System log and Event. # Following is similar to AUTO_LOGIN setting above, and must be set. < +<> + < 00|$RELEASE_VER = 2.1`LifeLog Application Version. @@ -40,7 +46,7 @@ Credential format:< , don't enable here using AU 22|$AUTO_LOGIN = 0`Autologin option, that expires only if login out. Enter Credentials in main.cnf. 24|$FRAME_SIZE = 0`Youtube frame size settings, 0 - Large, 1 - Medium, 2- Small. 26|$RTF_SIZE = 2`RTF Document height, 0 - Large, 1 - Medium, 2- Small. -28|$THEME = Standard`Theme to applay, Standard, Sun, Moon, Earth. +28|$THEME = Standard`Theme to apply, Standard, Sun, Moon, Earth. 30|$DEBUG = 0`Development page additional debug output, off (default) or on. 32|$KEEP_EXCS = 0`Cache excludes between sessions, off (default) or on. 34|$VIEW_ALL_LMT=1000`Limit of all records displayed for large logs. Set to 0, for unlimited. @@ -49,7 +55,7 @@ Credential format:< , don't enable here using AU 40|$SUBPAGEDIR =docs`Directory to scan for subpages like documents. 42|$DISP_ALL = 1`Display whole log entry, default -> 1=true, 0=false for display single line only. < -01|Unspecified `For quick uncategorised entries. +01|Unspecified `For quick uncategorized entries. 03|File System `Operating file system/Application short log. 06|System Log `Operating system important log. 09|Event `Event that occurred, meeting, historically important. @@ -63,7 +69,7 @@ Credential format:< , don't enable here using AU 55|Cars `Car(s) related entry. 60|Online `Online purchases (ebay, or received/ordered from online source). 88|Diary `Diary specific log and entry. Your daily yaddi-yadda that have decided to place here. -90|Fitness `Fitness steps, news, info, and usefull links. Ammount is steps. +90|Fitness `Fitness steps, news, info, and useful links. Amount is steps. < NOTES|DROP TABLE NOTES;' ver. 1.5 fts4 virtual tables have been scratched as they require special SQLite compilation. LOG<5>|Run Query ' ver. 1.5 diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index 3f2661f..2960ad7 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -3,9 +3,9 @@ # Programed by: Will Budic # Open Source License -> https://choosealicense.com/licenses/isc/ # +use v5.10; use strict; use warnings; -use Switch; use CGI; use CGI::Carp qw ( fatalsToBrowser ); diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index ddf03e5..58db360 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -138,7 +138,7 @@ sub checkAutologinSet { $v = Settings::parseAutonom('DBI_SOURCE',$line); if($v){Settings::dbSrc($v); next} $v = Settings::parseAutonom('AUTO_SET_TIMEZONE',$line); - if($v){$AUTO_SET_TIMEZONE = $v; next} + if($v){$AUTO_SET_TIMEZONE = $v; next} last if Settings::parseAutonom('CONFIG',$line); #By specs the config tag, is not an autonom, if found we stop reading. So better be last one spec. in file. } close $fh; diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index fde31f2..6f4d22e 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -40,8 +40,6 @@ if ( !$alias || !$passw) { ### Authenticate session to alias passw &authenticate; # - - my $log_rc = 0; my $log_rc_prev = 0; my $log_cur_id = 0; diff --git a/htdocs/cgi-bin/stats.cgi b/htdocs/cgi-bin/stats.cgi index 9372e34..a961395 100755 --- a/htdocs/cgi-bin/stats.cgi +++ b/htdocs/cgi-bin/stats.cgi @@ -2,10 +2,10 @@ # Programed by: Will Budic # Open Source License -> https://choosealicense.com/licenses/isc/ # +use v5.10; use strict; use warnings; #no warnings 'uninitialized'; -use Switch; use CGI; use CGI::Pretty ":standard"; #Influde style subroutine for inline CSS diff --git a/htdocs/cgi-bin/system/modules/CNFParser.pm b/htdocs/cgi-bin/system/modules/CNFParser.pm old mode 100755 new mode 100644 index 794592c..ba5d4d5 --- a/htdocs/cgi-bin/system/modules/CNFParser.pm +++ b/htdocs/cgi-bin/system/modules/CNFParser.pm @@ -4,14 +4,10 @@ # Open Source License -> https://choosealicense.com/licenses/isc/ # package CNFParser; - use strict; use warnings; use Exception::Class ('CNFParserException'); use Try::Tiny; -use Switch; - - our %anons = (); our %consts = (); @@ -20,6 +16,7 @@ our @sql = (); our @files = (); our %tables = (); our %data = (); +our %lists = (); sub new { @@ -46,10 +43,10 @@ sub anons { } return $ret; } - return %anons; + return \%anons; } sub constant {my $s=shift;if(@_ > 0){$s=shift;} return $consts{$s}} -sub constants {return sort keys %consts} +sub constants {my @ret = sort keys %consts; return @ret} sub SQLStatments {return @sql} sub dataFiles {return @files} sub tables {return keys %tables} @@ -57,6 +54,23 @@ sub tableSQL {my $t=shift;if(@_ > 0){$t=shift;} return $tables{$t}} sub dataKeys {return keys %data} sub data {my $t=shift;if(@_ > 0){$t=shift;} return @{$data{$t}}} sub migrations {return %mig;} +sub lists {return \%lists} +sub list {my $t=shift;if(@_ > 0){$t=shift;} return @{$lists{$t}}} +sub listDelimit { + my ($this, $d , $t)=@_; + my @p = @{$lists{$t}}; + if(@p&&$d){ + my @ret = (); + foreach (@p){ + my @s = split $d, $_; + push @ret, @s; + } + $lists{$t}=\@ret; + return @{$lists{$t}}; + } + return; + + } # Adds a list of environment expected list of variables. # This is optional and ideally to be called before parse. @@ -117,9 +131,10 @@ sub parse { close $fh; try{ - my @tags = ($content =~ m/<<(\$*\w*<(.*?).*?>>)/gs); - foreach my $tag (@tags){ - next if not $tag; + my @tags = ($content =~ m/<<(\$*\w*\$*<(.*?).*?>+)/gs); + + foreach my $tag (@tags){ + next if not $tag; if(index($tag,'do("select count(*) from SYS_CNF_CONFIG;"); diff --git a/htdocs/cgi-bin/system/modules/Settings.pm b/htdocs/cgi-bin/system/modules/Settings.pm index 9e8c0a5..cc219ec 100644 --- a/htdocs/cgi-bin/system/modules/Settings.pm +++ b/htdocs/cgi-bin/system/modules/Settings.pm @@ -4,6 +4,7 @@ # Open Source License -> https://choosealicense.com/licenses/isc/ # package Settings; + use v5.10; use strict; use warnings; @@ -17,6 +18,7 @@ use DateTime::Format::SQLite; use DateTime::Duration; use DBI; +use experimental qw( switch ); #This is the default developer release key, replace on istallation. As it is not secure. use constant CIPHER_KEY => '95d7a85ba891da'; @@ -51,7 +53,8 @@ my ($cgi, $sss, $sid, $alias, $pass, $dbname, $pub); #Annons here, variables that could be overiden in code or database, per need. -my %anons = (); +our %anons = (); +our %tz_map; ### Page specific settings Here our $TH_CSS = 'main.css'; @@ -69,6 +72,7 @@ our $SQL_PUB = undef; sub anons {my @ret=sort(keys %anons); return @ret;} #Check call with defined(Settings::anon('my_anon')) sub anon {my $n=shift; return $anons{$n}} +sub anonsSet {my $a = shift;%anons=%{$a}} sub release {return $RELEASE_VER} sub logPath {return $LOG_PATH} @@ -112,7 +116,7 @@ try { $alias = $sss->param('alias'); $pass = $sss->param('passw'); $pub = $cgi->param('pub'); - if($pub){#we override session to obtain pub(alias)/pass from config. + if($pub){#we override session to obtain pub(alias)/pass from file main config. open(my $fh, '<', logPath().'main.cnf' ) or LifeLogException->throw("Can't open main.cnf: $!"); while (my $line = <$fh>) { chomp $line; @@ -159,8 +163,29 @@ sub pub {return $pub} sub today { my $ret = DateTime->now(); - $ret -> set_time_zone(Settings::timezone()) if(!anon('auto_set_timezone')); -return $ret; + if(!$anons{'auto_set_timezone'}){ + setTimezone($ret); + } + return $ret; +} + +sub setTimezone { + my $ret = shift; + my $v= $anons{'TIME_ZONE_MAP'}; + if($v){ + if(!%tz_map){ + %tz_map={}; chomp($v); + foreach (split('\n')){ + my @p = split('=', $_); + $tz_map{trim($p[0])} = trim($p[1]); + } + } + $v = $tz_map{$TIME_ZONE}; #will be set in config to either valid or mapped. + if($v){$TIME_ZONE=$v} + } + $ret = DateTime->now() if(!$ret); + $ret -> set_time_zone($TIME_ZONE) ; + return $ret; } sub createCONFIGStmt { @@ -483,7 +508,6 @@ sub countRecordsIn { } sub getCurrentSQLTimeStamp { - my $dt; if(anon('auto_set_timezone')){$dt = DateTime->from_epoch(epoch => time())} else{ $dt = DateTime->from_epoch(epoch => time(), time_zone=> $TIME_ZONE)} @@ -590,7 +614,7 @@ sub parseAutonom { #Parses autonom tag for its crest value, returns undef if tag my $e = index $line, ">", $l + 1; return substr $line, $l, $e - $l; } - return undef; + return; } 1; \ No newline at end of file diff --git a/htdocs/cgi-bin/testPGDB.pl b/htdocs/cgi-bin/testPGDB.pl index cf0ce52..aff7e2d 100644 --- a/htdocs/cgi-bin/testPGDB.pl +++ b/htdocs/cgi-bin/testPGDB.pl @@ -80,11 +80,11 @@ foreach (@data_sources){ } - $db->disconnect(); +$db->disconnect(); - $db = DBI->connect("DBI:Pg:host=localhost;dbname=admin3", "admin3", "admin3", {AutoCommit => 1, RaiseError => 1, PrintError => 0}); - my @tbls = $db->tables(undef, 'public'); - foreach (@tbls){ - print uc substr($_,7) ,"\n"; - } \ No newline at end of file +$db = DBI->connect("DBI:Pg:host=localhost;dbname=admin3", "admin3", "admin3", {AutoCommit => 1, RaiseError => 1, PrintError => 0}); + my @tbls = $db->tables(undef, 'public'); + foreach (@tbls){ + print uc substr($_,7) ,"\n"; + } \ No newline at end of file diff --git a/htdocs/cgi-bin/testSettings.pl b/htdocs/cgi-bin/testSettings.pl new file mode 100644 index 0000000..09ea8d7 --- /dev/null +++ b/htdocs/cgi-bin/testSettings.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl -w +# +# Programed by: Will Budic +# Open Source License -> https://choosealicense.com/licenses/isc/ +# +use experimental qw( switch ); +use v5.10; +use strict; +use warnings; +use lib "system/modules"; +# Settings are used in static context throughout. +require Settings; + +use lib $ENV{'PWD'}.'/htdocs/cgi-bin/system/modules'; +require CNFParser; + +# Settings obtains from file escalated for anons to database configuration +# Currently we don't have an database set, and don't need it for this tester script. +# So we read and process the main.cnf file in via parser and transfer into Settings; +my $cnf = CNFParser->new($ENV{'PWD'}.'/dbLifeLog/main.cnf'); +my $ptr = $cnf->anons(); +Settings::anonsSet($ptr); + +my $time = Settings::today(); +my $a = Settings::anon('TIME_ZONE_MAP'); + + +print $time, $a , "\n"; + +1; \ No newline at end of file diff --git a/htdocs/cgi-bin/time_zones.cgi b/htdocs/cgi-bin/time_zones.cgi index 434fbb8..0abbde6 100755 --- a/htdocs/cgi-bin/time_zones.cgi +++ b/htdocs/cgi-bin/time_zones.cgi @@ -5,7 +5,7 @@ # use Try::Tiny; -use Switch; +use strict; use CGI; use CGI::Session '-ip_match'; @@ -41,7 +41,7 @@ print $cgi->start_html(-title => "Personal Log", -BGCOLOR=>"$BGCOL", #TODO my %countries = {}; my @states; -foreach $zone (sort @zones){ +foreach my $zone (sort @zones){ $zone =~ s/\"//g; my @p = split /\//, $zone; my $country = $p[0]; @@ -68,7 +68,7 @@ foreach $zone (sort @zones){ print "
"; print "

World Time Zone Strings

\n"; -foreach $key (sort keys %countries){ +foreach my $key (sort keys %countries){ $states = $countries{$key}; if( length($states)>0 ){ print "
$key
\n";