From: Metabox Date: Wed, 15 May 2019 22:58:54 +0000 (+1000) Subject: Implemented new Tick config file spec. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=636a24d583bd3cfd8f802abed9afa7acf1e5c5f1;p=LifeLog.git Implemented new Tick config file spec. --- diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index 8579332..4b0dc61 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -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 "SERVER ERROR [$did, $name,$value]:".$_; + print "SERVER ERROR!
".$_."
$err
"; print $cgi->end_html; exit; } diff --git a/htdocs/cgi-bin/main.cnf b/htdocs/cgi-bin/main.cnf index 6d8870d..edad557 100644 --- a/htdocs/cgi-bin/main.cnf +++ b/htdocs/cgi-bin/main.cnf @@ -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. diff --git a/htdocs/cgi-bin/tempCodeRunnerFile.cgi b/htdocs/cgi-bin/tempCodeRunnerFile.cgi index c14c4af..e9c0866 100644 --- a/htdocs/cgi-bin/tempCodeRunnerFile.cgi +++ b/htdocs/cgi-bin/tempCodeRunnerFile.cgi @@ -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"; + } }