<<!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.
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.
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.
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
# 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 );
$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;
### Authenticate session to alias passw
&authenticate;
#
-
-
my $log_rc = 0;
my $log_rc_prev = 0;
my $log_cur_id = 0;
# 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
# 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 = ();
our @files = ();
our %tables = ();
our %data = ();
+our %lists = ();
sub new {
}
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}
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.
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){
$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};
$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.
};
}
+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;
}
# 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;");
# Open Source License -> https://choosealicense.com/licenses/isc/
#
package Settings;
+
use v5.10;
use strict;
use warnings;
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';
#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';
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}
$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;
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 {
}
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)}
my $e = index $line, ">", $l + 1;
return substr $line, $l, $e - $l;
}
- return undef;
+ return;
}
1;
\ No newline at end of file
}
- $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
--- /dev/null
+#!/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
#
use Try::Tiny;
-use Switch;
+use strict;
use CGI;
use CGI::Session '-ip_match';
#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];
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";