]> lifelog.hopto.org Git - LifeLog.git/commitdiff
Implemented new Tick config file spec.
authorMetabox <redacted>
Wed, 15 May 2019 22:58:54 +0000 (08:58 +1000)
committerMetabox <redacted>
Wed, 15 May 2019 22:58:54 +0000 (08:58 +1000)
htdocs/cgi-bin/login_ctr.cgi
htdocs/cgi-bin/main.cnf
htdocs/cgi-bin/tempCodeRunnerFile.cgi

index 85793322372198fa758c91b705ba984f5055accf..4b0dc61be2970d58db4f410441bd727d1de0d9c6 100755 (executable)
@@ -191,11 +191,14 @@ try{
                                                                                CREATE TABLE CONFIG(
                                                                                                ID TINY PRIMARY KEY NOT NULL,
                                                                                                NAME VCHAR(16),
-                                                                                               VALUE VCHAR(64)
+                                                                                               VALUE VCHAR(28),
+                                                                                               DESCRIPTION VCHAR(128)
                                                                                );
                );
                $rv = $db->do($stmt);
+               $st->finish();
        }
+       #PRAGMA table_info(CONFIG); <-To check current structure
   populateConfig($db);
        $db->disconnect();
 }
@@ -210,7 +213,14 @@ sub populateConfig{
 
                open(my $fh, '<', './main.cnf' ) or die "Can't open main.cnf: $!";
                my $db = shift;
-               my ($did,$name, $value);
+               my ($did,$name, $value, $desc);
+               my $inData = 0;
+               my $err = "";
+               my %vars = {};
+
+#TODO Check if script id is unique to database? If not script prevails to database entry. 
+#So, if user settings from a previous release, must be migrated later.
+
 
                my $st = $db->prepare("SELECT count(*) FROM CONFIG;");
                   $st->execute();
@@ -218,35 +228,59 @@ sub populateConfig{
                if($cnt != 0){
                         return;
                }
-try{           
+try{
+         $st->finish();
+               my $insert = $db->prepare('INSERT INTO CONFIG VALUES (?,?,?,?)');               
     while (my $line = <$fh>) {
-                                       chomp $line;                            
-                                       my %hsh = $line =~ m[(\S+)\s*=\s*(\S+)]g;
-                                       for my $key (keys %hsh) {
-                                                               my %nash = $key =~ m[(\S+)\s*\|\$\s*(\S+)]g;                                                                    
-                                                               
-                                               for my $id (keys %nash) {
-                                                           $did = $id;
-                                                                 $name  = $nash{$id};
-                                                                 $value = $hsh{$key};
-                                                        my $st = $db->prepare("SELECT * FROM CONFIG WHERE NAME LIKE '$name';");
-                                                                       $st->execute();                                                         
-                                                        if(!$st->fetchrow_array()){
-                                                                       #TODO Check if script id is unique to database? If not script prevails to database entry. 
-                                                                       #if user setting from previous release, must be migrated later.
-                                                                       $st = $db->prepare('INSERT INTO CONFIG VALUES (?,?,?)');
-                                                                       $did = $id;
-                                                                       $st->execute($id, $name,$value);                  
-                                                               }
-                                                       }
+                                       chomp $line;
+                                       my @tick = split("`",$line);
+                                       if(scalar(@tick)==2){
+                                                                       my %hsh = $tick[0] =~ m[(\S+)\s*=\s*(\S+)]g;
+                                                                       if(scalar(%hsh)==1){                                                                            
+                                                                                       for my $key (keys %hsh) {
+
+                                                                                                       my %nash = $key =~ m[(\S+)\s*\|\$\s*(\S+)]g;
+                                                                                                       if(scalar(%nash)==1){
+                                                                                                                       for my $id (keys %nash) {
+                                                                                                                               my $name  = $nash{$id};
+                                                                                                                               my $value = $hsh{$key};
+                                                                                                                               if($vars{$id}){
+                                                       $err .= "UID{$id} taken by $vars{$id}-> $line\n";
+                                                                                                                               }
+                                                                                                                               else{
+                                                                                                                                                       my $st = $db->prepare("SELECT * FROM CONFIG WHERE NAME LIKE '$name';");
+                                                                                                                                                               $st->execute();
+                                                                                                                                                               $inData = 1;
+                                                                                                                                                       if(!$st->fetchrow_array()){
+                                                                                                                                                                       $insert->execute($id,$name,$value,$tick[1]);                                                                                                    
+                                                                                                                                                       }
+                                                                                                                               }
+                                                                                                                       }
+                                                                                                       }else{
+                                                       $err .= "Invalid, spec'ed {uid}|{setting}`{description}-> $line\n";
+                                                                                                       }
+
+                                                                                       }#rof
+                                                                       }
+                                                                       else{
+                                                       $err .= "Invalid, speced entry -> $line\n";
+                                                                       }
+
+                                       }elsif($inData && length($line)>0){
+                                   if(scalar(@tick)==1){
+                                                        $err .= "Corrupt Entry, no description supplied -> $line\n";
+                                               }
+                                               else{   
+                                                  $err .= "Corrupt Entry -> $line\n";
+                                               }
                                        }
-               }      
-    
-    close $fh; 
+               }    
+               die "Configuration script './main.cnf' [$fh] contains errors." if $err;
+               close $fh;
  } catch{              
          close $fh;    
          print $cgi->header;
-               print "<font color=red><b>SERVER ERROR</b></font> [$did, $name,$value]:".$_;
+               print "<font color=red><b>SERVER ERROR!</b></font><br> ".$_."<br><pre>$err</pre>";
     print $cgi->end_html;
                exit;
  }
index 6d8870d103797aabbe75f8ac0f103ba411a1a9e3..edad5570a2e3ee50be1871f419e6efe79d506658 100644 (file)
@@ -1,13 +1,17 @@
 
-00|$RELEASE_VER = 1.3
-01|$REC_LIMIT   = 25
-03|$TIME_ZONE   = Australia/Sydney
-05|$PRC_WIDTH   = 75
-08|$LOG_PATH    = ../../dbLifeLog/
-10|$SESSN_EXPR  = +30m
-12|$DATE_UNI    = 0
-14|$LANGUAGE   = English
-18|$IMG_W_H     = 210x120
-20|$AUTO_WRD_LMT= 200
+This the main configuration file for the LifeLog application settings.
+https://github.com/wbudic/LifeLog
+This is an Open Source License project -> https://choosealicense.com/licenses/isc/
+
+00|$RELEASE_VER = 1.3`LifeLog Application Version.
+01|$REC_LIMIT   = 25`Records shown per page.
+03|$TIME_ZONE   = Australia/Sydney`Time zone of your country.
+05|$PRC_WIDTH   = 75`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.
 
 
index c14c4af787309602f0c059bb349d468baa4321fe..e9c08661b2941bfdae6394b87385f2157eeb9715 100644 (file)
@@ -6,22 +6,50 @@
 use strict;
 use warnings;
 
-
-       open(my $fh, '<', '/home/will/dev/LifeLog/htdocs/cgi-bin/main.cnf' ) or die "Can't open main.cnf: $!";
-       
+    my $fh;
+       my $inData = 0;
+       open($fh, '<', '/home/will/dev/LifeLog/htdocs/cgi-bin/main.cnf' ) or die "Can't open main.cnf: $!";
+       my %vars = {};
     while (my $line = <$fh>) {
            chomp $line;
 
-                       my %hsh = $line =~ m[(\S+)\s*=\s*(\S+)]g;
-                   for my $key (keys %hsh) {
-                               my %nash = $key =~ m[(\S+)\s*\|\$\s*(\S+)]g;                            
-                               for my $id (keys %nash) {
-                                       my $name  = $nash{$id};
-                                       my $value = $hsh{$key};
-                                       print "[$id]->$name:$value\n";
+                   my @tick = split("`",$line);
+
+                       if(scalar(@tick)==2){
+                               my %hsh = $tick[0] =~ m[(\S+)\s*=\s*(\S+)]g;
+                               if(scalar(%hsh)==1){
+                               for my $key (keys %hsh) {
+                                       my %nash = $key =~ m[(\S+)\s*\|\s*(\S+)]g;
+                                       if(scalar(%nash)==1){
+                                               for my $id (keys %nash) {
+                                                       my $name  = $nash{$id};
+                                                       my $value = $hsh{$key};
+                                                       if($vars{$id}){
+                                                               print "4Corrupt Entry -> $line\n";
+                                                       }
+                                                       else{
+                                                       $vars{$id}=$name;
+                                                       print "[$id]->$name:$value -> $tick[1]\n";
+                                                       $inData = 1;
+                                                       }
+                                               }
+                                       }
+                                       else{
+                                               print "3Corrupt Entry -> $line\n";
+                                       }
                                }
-
-                               # print $nar[0].'='.$nar[1]."\n";
+                               }
+                               else{
+                                       print "2Corrupt Entry -> $line\n";
+                               }
+                       }
+                       elsif($inData && length($line)>0){
+                                   if(scalar(@tick)==1){
+                                               print "Corrupt Entry, no description supplied -> $line\n";
+                                       }
+                                       else{   
+                                               print "1Corrupt Entry -> $line\n";
+                                       }
                        }