]> lifelog.hopto.org Git - LifeLog.git/commitdiff
New CNF Development.
authorWill Budic <redacted>
Sun, 2 Feb 2020 10:25:57 +0000 (21:25 +1100)
committerWill Budic <redacted>
Sun, 2 Feb 2020 10:25:57 +0000 (21:25 +1100)
CNF_Specs.md [new file with mode: 0644]
Current Development Check List.md
dbLifeLog/database.cnf [new file with mode: 0644]
htdocs/cgi-bin/configFileTester.pl [new file with mode: 0755]
htdocs/cgi-bin/system/modules/CNFParser.pm [new file with mode: 0755]
htdocs/cgi-bin/system/modules/Settings.pm

diff --git a/CNF_Specs.md b/CNF_Specs.md
new file mode 100644 (file)
index 0000000..f90eaec
--- /dev/null
@@ -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.
+
+        <<<CONST>$APP_PATH=~/MyApplication>>
+        <<app_path>$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.
+
+        <<USE_SWITCH>true>>
+        <<DIALOG_TITLE_EN>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**
+
+    <<CONST>$HELP
+        Sorry help is currently.
+        Not available.
+    >>
+    <<<CONST
+        $RELEASE_VER = 1.8
+        $SYS_1 =    10
+        $SYS_2 = 20
+        $SYS_3 =      "   Some Nice Text!   "
+    >>
+    <<PRINT_TO_HELP<true>>
+
+## SQL Instruction Formatting
+
+(section not complete, as of 2020-02-02)
+
+* SQLites have the following reserved instructions.
+  * TABLE
+  * INDEX
+  * DATA
+
+        <<MyAliasTable>TABLE
+            ID INT PRIMARY KEY NOT NULL,
+            ALIAS VCHAR(16),
+            EMAIL VCHAR(28),
+            FULL_NAME VCHAR(128)
+        >>
+
+***
+
+
+
+     Project ->  <https://github.com/wbudic/LifeLog/>
index 614b5f47b299443f3e8354631f45dabbae6873fc..ef42c69e494be72ab0d351c1a5f79ad8e3fcb8fc 100644 (file)
@@ -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.
 * &#10004; Provide system logs on stats page runs.
 * &#10004; Menus updated in other pages to have button look.
 * &#10004; 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
 
 * &#10004; 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.
 
 * &#10004; Bug 13 - Migrated old data, linking to wrong id, db fix in config page seems to fix this.
 * &#10004; Bug 12 - Invalid login only shows db error.
diff --git a/dbLifeLog/database.cnf b/dbLifeLog/database.cnf
new file mode 100644 (file)
index 0000000..0ad6952
--- /dev/null
@@ -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:<<AUTO_LOGIN <{alias}/{password}> , dont enable here using AUTO_LOGIN option bellow, use config in app.
+<<AUTO_LOGIN<>>
+<<<CONST
+$RELEASE_VER = 1.8
+$SYS_1 =    10
+$SYS_2 = 20
+$SYS_3 =      "   Some Nice Text!   "
+>>
+<<CONST<$SYS_HELP
+Multiple lines
+in this txt
+is placed as a const.
+>>
+
+<<LOG<TABLE
+    ID_CAT TINY NOT NULL,
+    DATE DATETIME  NOT NULL,
+    LOG VCHAR(128) NOT NULL,
+    AMOUNT INTEGER DEFAULT 0,
+    AFLAG TINY DEFAULT 0,
+    RTF BOOL DEFAULT 0,
+    STICKY BOOL DEFAULT 0
+>>
+<<LOG<DATA
+01`@2014-11-13 13:48:05`Test Entry\nmulti\nlined
+>>
+<<CONFIG<TABLE
+    ID TINY PRIMARY KEY NOT NULL,
+    NAME VCHAR(16),
+    VALUE VCHAR(28),
+    DESCRIPTION VCHAR(128)
+   >>
+<<CONFIG<INDEX
+    idx_config_name ON CONFIG (NAME);
+>>
+<<CONFIG<DATA
+00`$RELEASE_VER `$RELEASE_VER$`LifeLog Application Version.
+01`$REC_LIMIT   `25`Records shown per page.
+03`$TIME_ZONE   `Australia/Sydney`Time zone of your country.
+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.
+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.
+20`$AUTO_WRD_LMT`200`Autocomplete word gathering limit.
+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.
+30`$DEBUG       `0`Development page additional debug output, off (default) or on.
+32`$KEEP_EXCS   `0`Cache excludes between sessions, off (default) or on.
+>>
+
+<<CAT<DATA
+01`Unspecified`For quick uncategorised 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.
+28`Personal`Personal log of historical importance, diary type.
+32`Expense`Significant yearly expense.
+35`Income`Significant yearly income.
+40`Work`Work related entry, worth monitoring.
+45`Food`Quick \`reference\` to recipes, observations.
+50`Music`Music reference of interest. Youtube embbed.
+52`Sport/Club`Sport or Social related entry.
+55`Cars`Car(s) related entry.
+60`Online`Online purchases (ebay, or received/ordered from online source).
+>>
+
diff --git a/htdocs/cgi-bin/configFileTester.pl b/htdocs/cgi-bin/configFileTester.pl
new file mode 100755 (executable)
index 0000000..11628d6
--- /dev/null
@@ -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 (executable)
index 0000000..4f8a1ed
--- /dev/null
@@ -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,'<CONST')==0){#constant
+
+            foreach  (split '\n', $tag){
+                my @prps = map {
+                    s/^\s+\s+$//;  # strip unwanted spaces
+                    s/^\"//;      # strip start quote
+                    s/\"$//;      # strip end quote
+                    s/<const\s//i; # strip  identifier
+                    s/\s>>//;
+                    $_             # 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 /</,$tag;
+            my $e = $kv[0];
+            my $t = $kv[1];
+            my $i = index $t, "\n";
+            if($i==-1){
+               $t = $v = substr $t, 0, (rindex $t, ">>");
+            }
+            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;
index 3fb7d431fac3a50ff3dbd8cde0f24ceedc447d4d..0818d0c08d5c700ae2ecd8eb599a20d0617a56df 100644 (file)
@@ -1,4 +1,8 @@
 #!/usr/bin/perl -w
+#
+# Programed by: Will Budic
+# Open Source License -> https://choosealicense.com/licenses/isc/
+#
 package Settings;
 
 use strict;