]> lifelog.hopto.org Git - LifeLog.git/commitdiff
impl. TZ mapping.
authorWill Budicm <redacted>
Fri, 27 Nov 2020 05:58:12 +0000 (16:58 +1100)
committerWill Budicm <redacted>
Fri, 27 Nov 2020 05:58:12 +0000 (16:58 +1100)
dbLifeLog/main.cnf
htdocs/cgi-bin/config.cgi
htdocs/cgi-bin/login_ctr.cgi
htdocs/cgi-bin/main.cgi
htdocs/cgi-bin/stats.cgi
htdocs/cgi-bin/system/modules/CNFParser.pm [changed mode: 0755->0644]
htdocs/cgi-bin/system/modules/Settings.pm
htdocs/cgi-bin/testPGDB.pl
htdocs/cgi-bin/testSettings.pl [new file with mode: 0644]
htdocs/cgi-bin/time_zones.cgi

index 8ad9efc7ecf8de2b5d8f64de50796c0bad3d2869..c110aad59c1ebbaf086a7df4e215e28a3b45fae1 100644 (file)
@@ -25,6 +25,12 @@ Credential format:<<AUTO_LOGIN <{alias}/{password}> , don't enable here using AU
 <<!PUBLIC_CATS<03,06,09>#File,System log and Event.
 # Following is similar to AUTO_LOGIN setting above, and must be set.
 <<!PUBLIC_LOGIN<admin/admin>
+<<TIME_ZONE_MAP<
+Marsfield=Australia/Sydney
+Bondi=Australia/Sydney
+America/Texas=America/Chicago
+>>
+
 
 <<CONFIG<4>
 00|$RELEASE_VER = 2.1`LifeLog Application Version.
@@ -40,7 +46,7 @@ Credential format:<<AUTO_LOGIN <{alias}/{password}> , 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:<<AUTO_LOGIN <{alias}/{password}> , 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.
 <<CAT<3>
-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:<<AUTO_LOGIN <{alias}/{password}> , 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.
 <<MIG<>
 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
index 3f2661fdf0c3cf6ca6a8de2545509d0793501fe2..2960ad70ae89164f613e872cb4424214ba0f8156 100755 (executable)
@@ -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 );
index ddf03e536d5e70c9fee51347eeaf6f6a48b28039..58db360fae47749018170ac36920c303e378f140 100755 (executable)
@@ -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;
index fde31f2397ea2a69265dbe56907d1404f3ec0d18..6f4d22ed922207980a425c5029907873d092feef 100755 (executable)
@@ -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;
index 9372e34a429a56756241b605a7b867a9ec0d3554..a961395336617e830449e1f2ad6bd727b74bf6cb 100755 (executable)
@@ -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
old mode 100755 (executable)
new mode 100644 (file)
index 794592c..ba5d4d5
@@ -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,'<CONST')==0){#constant multiple properties.
 
             foreach  (split '\n', $tag){
@@ -196,7 +211,9 @@ try{
                $t = substr $t, 0, $i;
             }
 
-           # print "Ins($i): with $e do $t|\n";
+          # print "Ins($i): with $e do $t|\n";
+
+
            if($t eq 'CONST'){#Single constant with mulit-line value;
                $v =~ s/^\s//;
                $consts{$e} = $v if not $consts{$e};
@@ -336,8 +353,19 @@ try{
                 $mig{$e} = [@m];
             }
             else{
-                #Register application statement as an anonymouse one.
-                $anons{$e} = $v;
+                #Register application statement as either an anonymouse one. Or since v.1.2 an listing type tag.   
+                #print "Reg($e): $v\n";
+                if($e !~ /\$\$$/){ $anons{$e} = $v }
+                else{
+                    $e = substr $e, 0, (rindex $e, "$$")-1;
+                    # Following is confusing as hell. We look to store in the hash an array reference.
+                    # But must convert back and fort via an scalar, since actual arrays returned from an hash are copies in perl.
+                    my $a = $lists{$e};
+                    if(!$a){$a=();$lists{$e} = \@{$a};}
+                    push @{$a}, $v;
+                    #print "Reg($e): $v [$a]\n";                  
+                    
+                }
                 next;
             }
             push @sql, $st;#push as application statement.
@@ -349,12 +377,11 @@ try{
 };
 }
 
+my @resw =("DATA", "FILE", "TABLE", "INDEX", "VIEW", "SQL", "MIGRATE");
+
 sub isReservedWord {
     my $word = shift;
-    switch($word){
-        case "DATA" { return 1; } case "FILE"  { return 1; } case "TABLE" { return 1; } case "INDEX"  { return 1; }
-        case "VIEW" { return 1; } case "SQL" { return 1; } case "MIGRATE" { return 1; }
-    }
+    foreach(@resw){if($word eq $_){return 1}}
     return 0;
 }
 
@@ -362,7 +389,7 @@ sub isReservedWord {
 # Required to be called when using CNF with an database based storage.
 #
 sub initiDatabase {
-    my($self,$db,$st,$dbver)=@_;
+    my ($self,$db,$st,$dbver) = @_;
 #Check and set SYS_CNF_CONFIG
 try{
     $st=$db->do("select count(*) from SYS_CNF_CONFIG;");
index 9e8c0a51d7ebf7d601aaba5ed87c8056d87eb3bd..cc219ec49ff0e63863500591f552dc21bcceeb11 100644 (file)
@@ -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
index cf0ce52c207ce0d369456a14b030e46469a0d249..aff7e2d3ed6093ed0a20a6baf4446cec3760be2b 100644 (file)
@@ -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 (file)
index 0000000..09ea8d7
--- /dev/null
@@ -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
index 434fbb85dac38060759ec7cfb750ee54c3850d3e..0abbde6940b5d5c574ccfe4630aa8ff980c4858d 100755 (executable)
@@ -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 "<center>";
 print "<h2 class='rz' style='text-align:center;border-bottom: 0px cornflowerblue;'>World Time Zone Strings</h2>\n";
-foreach $key (sort keys %countries){   
+foreach my $key (sort keys %countries){   
     $states = $countries{$key}; 
     if( length($states)>0 ){
         print "<div class='rz' style='text-align:left;border-bottom: 0px cornflowerblue;'><b>$key</b></div>\n";