From: Will Budic Date: Sun, 2 Feb 2020 10:25:57 +0000 (+1100) Subject: New CNF Development. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=ed0057db2a7aa51cf24bfaa958e87a40a2601e8b;p=LifeLog.git New CNF Development. --- diff --git a/CNF_Specs.md b/CNF_Specs.md new file mode 100644 index 0000000..f90eaec --- /dev/null +++ b/CNF_Specs.md @@ -0,0 +1,82 @@ +# Configuration Network File Format Specifications + + Moon Stage v.1.0 + +## Introduction + +This is a simple and fast file format. That allowes setting an network application with constant values. +SQL database structures and data. It is designed to accomodate an parser to read and parse CNF tags. +These can be of three types, using an textual similar presentation. +And are recognised as constants, anons and sqlites. +## CNF Formatting Rules + +* Text that isn't CNF tagged is ignored in the file and can be used as comments. +* CNF tag begins with an **<<** and ends with an **>>** +* CNF instructions and constants are uppercase. +* CNF instructions are all uppercase and unique, to its processor. +* A CNF constant in its propety name is prefixed with an '**$**' signifier. + * Constants are ususally scripted at the begining of the file, or parsed first in a separate file. + * The instruction processor can use them if signifier $ surounds the constant name. Therefore, replacing it with the contants value if further found in the file. + + <<$APP_PATH=~/MyApplication>> + <$APP_PATH$/module/main>> + * CNF Constant values can't be changed for th life of the application. + * CNF Constant values can be changed in the file itself only. +* A CNF Anon is to similar to constants but a more simpler property and value only pair. + * Anon is not instruction processed. Hence anonymouse in nature for its value. + * Anon has no signifier. + * Anon value is global to the application and its value can be modified. + + <true>> + <MyApplication Title>> + +* CNF supports basic SQL Database structure statment generation. This is done via instruction based CNF tags. Named sqlites. + * Supported is table, view, index and data creation statments. + * Database statments are generic text, that is not further processed. + * There is no database interaction, handling or processing as part of this processing. + +## CNF Tag Formats +### Property Value Tag + <<{name}<{value}>> +### Instruction Value Tag + <<<{instruction} + {value\n...valuen\n}>> +### Full Tag + <<{name}>{instruction} + {value\n...value\n} + >> +**Examples** + + <$HELP + Sorry help is currently. + Not available. + >> + <<> + <> + +## SQL Instruction Formatting + +(section not complete, as of 2020-02-02) + +* SQLites have the following reserved instructions. + * TABLE + * INDEX + * DATA + + <TABLE + ID INT PRIMARY KEY NOT NULL, + ALIAS VCHAR(16), + EMAIL VCHAR(28), + FULL_NAME VCHAR(128) + >> + +*** + + + + Project -> diff --git a/Current Development Check List.md b/Current Development Check List.md index 614b5f4..ef42c69 100644 --- a/Current Development Check List.md +++ b/Current Development Check List.md @@ -8,6 +8,8 @@ This version is not compatible in data structure to prior versions. Data migrati ## LifeLog Development ### v.1.7 Encountered + +* New CNF Development. * ✔ Provide system logs on stats page runs. * ✔ Menus updated in other pages to have button look. * ✔ main.cnf newer versions should have precedence to id and entry name to previously set or stored in db. @@ -54,11 +56,11 @@ This version is not compatible in data structure to prior versions. Data migrati ### v. 1.7 Encountered/Fixed * ✔ Issue 14 Subpages pages links to main, restart main page session counter, making the main page fully usable. - * Not really a bug. Session will expire but time remaining will be displayed wrong on the main page. - * All subpages need either to inherit the counter, and jump user to the login screen if expired. - * Or update main pages timer countdown. Which is not possible if browsers back button is pressed. - * Pressing back button brings the page display to initial time it was loaded from. - * This has been now marked as an complex issue. Not worth much spending time on. + * Not really a bug. Session will expire but time remaining will be displayed wrong on the main page. + * All subpages need either to inherit the counter, and jump user to the login screen if expired. + * Or update main pages timer countdown. Which is not possible if browsers back button is pressed. + * Pressing back button brings the page display to initial time it was loaded from. + * This has been now marked as an complex issue. Not worth much spending time on. * ✔ Bug 13 - Migrated old data, linking to wrong id, db fix in config page seems to fix this. * ✔ Bug 12 - Invalid login only shows db error. diff --git a/dbLifeLog/database.cnf b/dbLifeLog/database.cnf new file mode 100644 index 0000000..0ad6952 --- /dev/null +++ b/dbLifeLog/database.cnf @@ -0,0 +1,74 @@ + +This is the main configuration file for the LifeLog applications settings. +https://github.com/wbudic/LifeLog +This is an Open Source License project -> https://choosealicense.com/licenses/isc/ +The credential format:< , dont enable here using AUTO_LOGIN option bellow, use config in app. +<> +<<> +<> + +<> +<> +<> +<> +<> + +<> + diff --git a/htdocs/cgi-bin/configFileTester.pl b/htdocs/cgi-bin/configFileTester.pl new file mode 100755 index 0000000..11628d6 --- /dev/null +++ b/htdocs/cgi-bin/configFileTester.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl -w +# +# Programed by: Will Budic +# Open Source License -> https://choosealicense.com/licenses/isc/ +# +use strict; +use warnings; +use Try::Tiny; + +use DateTime; +use DateTime::Format::SQLite; +use DateTime::Duration; +use Text::CSV; + +#DEFAULT SETTINGS HERE! +use lib "system/modules"; + +use lib $ENV{'PWD'}.'/htdocs/cgi-bin/system/modules'; +require CNFParser; + +my $cnf = CNFParser->new(); + +$cnf->parse($ENV{'PWD'}."/dbLifeLog/database.cnf"); + +foreach ($cnf->SQLStatments()){ + print "$_\n"; +} +foreach my $p ($cnf->constants()){ + + print "$p=", $cnf->constant($p),"\n"; +} +# foreach (sort keys %ENV) { +# print "$_= $ENV{$_}\n"; +# } + +### CGI END +1; diff --git a/htdocs/cgi-bin/system/modules/CNFParser.pm b/htdocs/cgi-bin/system/modules/CNFParser.pm new file mode 100755 index 0000000..4f8a1ed --- /dev/null +++ b/htdocs/cgi-bin/system/modules/CNFParser.pm @@ -0,0 +1,157 @@ +#!/usr/bin/perl -w +# +# Programed by: Will Budic +# Open Source License -> https://choosealicense.com/licenses/isc/ +# +package CNFParser; + +use strict; +use warnings; +use Try::Tiny; + + +our %anons = (); +our %consts = (); +our @sql = (); + + +sub new { + my $class = shift; + my $self = {}; + bless $self, $class; + return $self; +} + + +sub anons {return %anons} +sub constant {my $s=shift;if(@_ > 0){$s=shift;} return $consts{$s}} +sub constants {return keys %consts} +sub SQLStatments {return @sql} +sub anonsToENV { + # foreach my $prp (keys %anons){ + # print "{{",$prp, '=' , $anons{$prp}, "}}\n"; + # } +} + + +sub parse { + my ($self, $cnf, $content) = @_; + open(my $fh, "<:perlio", $cnf ) or die "Can't open $cnf -> $!"; + read $fh, $content, -s $fh; + close $fh; +try{ + + my @tags = ($content =~ m/<<(\w*<(.*?).*?>>)/gs); + foreach my $tag (@tags){ + next if not $tag; + if(index($tag,'>//; + $_ # return the modified string + } + split /\s*=\s*/, $_; + + my $k; + foreach (@prps){ + if ($k){ + $consts{$k} = $_; + undef $k; + } + else{ + $k = $_; + } + } + } + + } + elsif(index($tag,'CONST<')==0){#multiline constant. + my $i = index $tag, "\n"; + my $k = substr $tag, 6, $i-6; + my $v = substr $tag, $i, (rindex $tag, ">>")-$i; + $consts{$k} = $v; + } + else{ + + my ($st,$v); + my @kv = split />"); + } + else{ + $v = substr $t, $i, (rindex $t, ">>")-$i; + $t = substr $t, 0, $i; + } + + # print "Ins($i): with $e do $t\n"; + if($t eq 'TABLE'){ + $st = "CREATE TABLE $e(\n$v\n);"; + } + elsif($t eq 'INDEX'){ + $st = "CREATE INDEX $v;"; + } + elsif($t eq 'DATA'){ + $st =""; + foreach(split /\n/,$v){ + my $d = $i = ""; + foreach $d (split /\`/, $_){ + $t = substr $d, 0, 1; + if($t eq '$'){ + $v = $d; #capture spected value. + $d =~ s/\$$|\s*$//g; #trim any space and system or constant '$' end marker. + if($v=~m/\$$/){ + $v = $consts{$d} + } + else{ + $v = $d; + } + $i .= "'$v',"; + } + else{ + #First is always ID a number and '#' signifies number. + if(!$i || $t eq "\#") { + $i .= "$d,"; + } + else{ + $i .= "'$d',"; + } + } + } + $i =~ s/,$//; + $st .="INSERT INTO $e VALUES($i);\n" if $i; + } + } + else{ + #Register application statement as an anonymouse one. + $anons{$e} = $v; + next; + } + push @sql, $st;#push application statement as SQL one. + } + } + + # foreach my $prp (keys %consts){ + # print "[[",$prp, '=' , constant($prp), "]]\n"; + # } + # foreach my $prp (keys %anons){ + # print "{{",$prp, '=' , $anons{$prp}, "}}\n"; + # } + # foreach (@sql){ + # print "$_\n"; + # } + +} catch{ + die $_; +} + +} +### CGI END +1; diff --git a/htdocs/cgi-bin/system/modules/Settings.pm b/htdocs/cgi-bin/system/modules/Settings.pm index 3fb7d43..0818d0c 100644 --- a/htdocs/cgi-bin/system/modules/Settings.pm +++ b/htdocs/cgi-bin/system/modules/Settings.pm @@ -1,4 +1,8 @@ #!/usr/bin/perl -w +# +# Programed by: Will Budic +# Open Source License -> https://choosealicense.com/licenses/isc/ +# package Settings; use strict;