From: Metabox Date: Sun, 21 Apr 2019 08:52:32 +0000 (+1000) Subject: Updated log configuration and added background color to pages. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=8f71c079d3b1db92aecf94470da07abb51b9b1ab;p=LifeLog.git Updated log configuration and added background color to pages. --- diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index b74d748..8742769 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -18,23 +18,23 @@ use DateTime::Duration; use Text::CSV; #DEFAULT SETTINGS HERE! -our $REC_LIMIT = 25; -our $TIME_ZONE = 'Australia/Sydney'; -our $PRC_WIDTH = '60'; -#END OF DEFAULT SETTINGS - - -my $q = CGI->new; -my $session = new CGI::Session(undef, $q); - -my $dbname=$session->param('database'); -my $userid=$session->param('alias'); +our $REC_LIMIT = 25; +our $TIME_ZONE = 'Australia/Sydney'; +our $PRC_WIDTH = '60'; +our $LOG_PATH = '../../dbLifeLog/'; +our $SESSN_EXPR = '+2m'; +our $RELEASE_VER = '1.3'; +#END OF SETTINGS + +my $cgi = CGI->new; +my $session = new CGI::Session("driver:File",$cgi, {Directory=>$LOG_PATH}); +my $sid=$session->id(); +my $dbname =$session->param('database'); +my $userid =$session->param('alias'); my $password=$session->param('passw'); -### Authenticate session to alias password -# -if(!$userid || !$dbname){ - print $q->redirect('login_ctr.cgi'); +if(!$userid||!$dbname){ + print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid"); exit; } @@ -45,42 +45,38 @@ my $db = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die "

my $rv; my $dbs; my $today = DateTime->now; -$today->set_time_zone( $TIME_ZONE ); + ##################### &getConfiguration; ##################### - +$today->set_time_zone( $TIME_ZONE ); -print $q->header(-expires=>"+6os", -charset=>"UTF-8"); - -print $q->start_html(-title => "Personal Log", - -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'}, - -style =>{-type => 'text/css', -src => 'wsrc/main.css'}, -# -onload => "loadedBody('".$rs_keys."');" - ); +print $cgi->header(-expires=>"+6s", -charset=>"UTF-8"); +print $cgi->start_html(-title => "Personal Log", -BGCOLOR=>"#c8fff8", + -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'}, + -style =>{-type => 'text/css', -src => 'wsrc/main.css'}, + ); -my $stmtCat = "SELECT * FROM CAT ORDER BY ID;"; +my $stmtCat = 'SELECT * FROM CAT ORDER BY ID;'; $dbs = $db->prepare( $stmtCat ); $rv = $dbs->execute() or die or die "

Error->"& $DBI::errstri &"

"; - ############### &processSubmit; ############### - # -my $cats = ' - + +my $tbl = '
* CATEGORIES CONFIGURATION *
+ -'; + '; while(my @row = $dbs->fetchrow_array()) { - if($row[0]>0){ - $cats = $cats. + $tbl = $tbl. ' @@ -91,34 +87,64 @@ my $cats = '
* CATEGORIES CONFIGURATION *
IDCategoryDescription
'.$row[0].'
my $frm = qq( - ).$cats.qq( - + ).$tbl.qq( + - + - -
WARNING! - Removing and changing categories is permanent! Adding one must have unique ID. - Blanking an category will seek and change LOG records to Unspecified! Also ONLY the category Unspecified You can't CHANGE!
If changing here things? Make a backup! (copy existing db file)

); +
WARNING! + Removing and changing categories is permanent! Adding one must have unique ID.
+ Blanking an category will seek and change LOG records to Unspecified!
+ Also ONLY the category Unspecified You can't CHANGE!
If changing here things? + Make a backup! (copy existing db file)
+ + + +
); +$tbl = ' + + + '; +my $stm = 'SELECT NAME, VALUE FROM CONFIG;'; +$dbs = $db->prepare( $stm ); +$rv = $dbs->execute() or die or die "

Error->"& $DBI::errstri &"

"; + +while(my @row = $dbs->fetchrow_array()) { + $tbl = $tbl. + ' + + + '; +} + +my $frmVars = qq( + ).$tbl.qq( + + + +
* SYSTEM CONFIGURATION *
VariableValue
'.$row[0].'

); + # #Page printout from here! # -print "
"; - print "\n
\n" . $frm ."\n
\n
"; +print '
'; +print "

Log Configuration In -> $dbname

"; + print "\n
\n" . $frm ."\n
\n
"; + print "\n
\n" . $frmVars."\n
\n
"; print '
Back to Main Log
'; -print "
"; +print '
'; -print $q->end_html; +print $cgi->end_html; $db->disconnect(); exit; @@ -126,7 +152,7 @@ exit; sub processSubmit { -my $change = $q->param("cchg"); +my $change = $cgi->param("cchg"); my $s; my $d; @@ -141,8 +167,8 @@ if ($change == 1){ my $cds = $row[2]; - my $pnm = $q->param('nm'.$cid); - my $pds = $q->param('ds'.$cid); + my $pnm = $cgi->param('nm'.$cid); + my $pds = $cgi->param('ds'.$cid); if($cid!=1 && $pnm ne $cnm || $pds ne $cds){ @@ -179,9 +205,9 @@ if ($change == 1){ if($change > 1){ #UNDER DEVELOPMENT! - my $caid = $q->param('caid'); - my $canm = $q->param('canm'); - my $cade = $q->param('cade'); + my $caid = $cgi->param('caid'); + my $canm = $cgi->param('canm'); + my $cade = $cgi->param('cade'); my $valid = 1; while(my @row = $dbs->fetchrow_array()) { @@ -233,7 +259,8 @@ sub getConfiguration{ case "REC_LIMIT" {$REC_LIMIT=$r[2]} case "TIME_ZONE" {$TIME_ZONE=$r[2]} - case "PRC_WIDTH" {$PRC_WIDTH=$r[2]} + case "PRC_WIDTH" {$PRC_WIDTH=$r[2]} + case "SESSN_EXPR" {$SESSN_EXPR=$r[2]} else {print "Unknow variable setting: ".$r[1]. " == ". $r[2]} } diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index 2f15953..620f013 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -1,8 +1,9 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # # Programed in vim by: Will Budic # Open Source License -> https://choosealicense.com/licenses/isc/ # +package main; use strict; use warnings; use Try::Tiny; @@ -26,9 +27,10 @@ our $SESSN_EXPR = '+2m'; our $RELEASE_VER = '1.3'; #END OF SETTINGS + my $cgi = CGI->new; my $session = new CGI::Session("driver:File",$cgi, {Directory=>$LOG_PATH}); -$session->expire($SESSN_EXPR); + $session->expire($SESSN_EXPR); my $sid=$session->id(); my $cookie = $cgi->cookie(CGISESSID => $sid); @@ -45,7 +47,7 @@ my $cipher = new Crypt::CBC({key => $cipher_key, cipher => 'IDEA'}); if(&processSubmit==0){ print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie); - print $cgi->start_html(-title => "Personal Log Login", + print $cgi->start_html(-title => "Personal Log Login", -BGCOLOR=>"#c8fff8", -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'}, -style =>{-type => 'text/css', -src => 'wsrc/main.css'}, ); @@ -181,22 +183,22 @@ try{ if(!$st->fetchrow_array()) { my $stmt = qq( CREATE TABLE CONFIG( - ID INT PRIMARY KEY NOT NULL, + ID TINY PRIMARY KEY NOT NULL, NAME VCHAR(16), VALUE VCHAR(64) ); ); $rv = $db->do($stmt); - - $st = $db->prepare('INSERT INTO CONFIG VALUES (?,?)'); - $st->execute(0,"RELEASE_VER",$RELEASE_VER); - $st->execute(1,"REC_LIMIT", $REC_LIMIT); - $st->execute(3,"TIME_ZONE", $TIME_ZONE); - $st->execute(5,"PRC_WIDTH", $PRC_WIDTH); - $st->execute(8,"SESSN_EXPR", $SESSN_EXPR); + populateConfig($db); + } else{ #TODO Check table and update existing table for subsequent releases with new settings. + $st = $db->prepare('SELECT * FROM CONFIG'); + $st->execute(); + if(!$st->fetchrow_array()) { + populateConfig($db); + } } } catch{ @@ -212,6 +214,14 @@ sub selSQLTbl{ return "SELECT name FROM sqlite_master WHERE type='table' AND name='$name';" } -### CGI END - +sub populateConfig{ + my $db = shift; + my $st = $db->prepare('INSERT INTO CONFIG VALUES (?,?,?)'); + $st->execute(0,"RELEASE_VER",$RELEASE_VER); + $st->execute(1,"REC_LIMIT", $REC_LIMIT); + $st->execute(3,"TIME_ZONE", $TIME_ZONE); + $st->execute(5,"PRC_WIDTH", $PRC_WIDTH); + $st->execute(8,"SESSN_EXPR", $SESSN_EXPR); +} +### CGI END \ No newline at end of file diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 1ab84e6..62b7b96 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -34,8 +34,6 @@ my $sid=$session->id(); my $dbname =$session->param('database'); my $userid =$session->param('alias'); my $password=$session->param('passw'); -$session->expire('+2m'); - if(!$userid||!$dbname){ print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid"); @@ -75,7 +73,7 @@ my $toggle =""; if($rs_keys||$rs_cat_idx||$stmD){$toggle=1;}; $session->expire($SESSN_EXPR); print $cgi->header(-expires=>"0s", -charset=>"UTF-8"); -print $cgi->start_html(-title => "Personal Log", +print $cgi->start_html(-title => "Personal Log", -BGCOLOR=>"#c8fff8", -script=>{-type => 'text/javascript',-src => 'wsrc/main.js'}, -style =>{-type => 'text/css', -src => 'wsrc/main.css'}, -onload => "loadedBody('".$toggle."');" @@ -501,24 +499,6 @@ sub buildNavigationButtons{ $tbl = $tbl .''; } -sub getConfiguration{ - my $st = $_[0]->prepare("SELECT * FROM CONFIG;"); - $st->execute(); - while (my @r=$st->fetchrow_array()){ - - switch ($r[1]) { - - case "REC_LIMIT" {$REC_LIMIT=$r[2]} - case "TIME_ZONE" {$TIME_ZONE=$r[2]} - case "PRC_WIDTH" {$PRC_WIDTH=$r[2]} - else {print "Unknow variable setting: ".$r[1]. " == ". $r[2]} - - } - - } -} - - sub authenticate{ try { @@ -551,4 +531,22 @@ try { print $cgi->end_html; exit; } +} + + +sub getConfiguration{ + my $st = $_[0]->prepare("SELECT * FROM CONFIG;"); + $st->execute(); + while (my @r=$st->fetchrow_array()){ + + switch ($r[1]) { + + case "REC_LIMIT" {$REC_LIMIT=$r[2]} + case "TIME_ZONE" {$TIME_ZONE=$r[2]} + case "PRC_WIDTH" {$PRC_WIDTH=$r[2]} + else {print "Unknow variable setting: ".$r[1]. " == ". $r[2]} + + } + + } } \ No newline at end of file diff --git a/htdocs/cgi-bin/stats.cgi b/htdocs/cgi-bin/stats.cgi index 2320fa5..b4aa5d6 100755 --- a/htdocs/cgi-bin/stats.cgi +++ b/htdocs/cgi-bin/stats.cgi @@ -1,21 +1,38 @@ -#!/usr/bin/perl - +#!/usr/bin/perl -w +# +# Programed in vim by: Will Budic +# Open Source License -> https://choosealicense.com/licenses/isc/ +# use strict; use warnings; -use DBI; use CGI; +use CGI::Session '-ip_match'; +use DBI; use DateTime; use DateTime::Format::SQLite; use Number::Bytes::Human qw(format_bytes); -my $driver = "SQLite"; -my $database = "../../dbLifeLog/data_log.db"; -my $dsn = "DBI:$driver:dbname=$database"; -my $userid = ""; -my $password = ""; -my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) - or die "

Error->"& $DBI::errstri &"

"; +our $LOG_PATH = '../../dbLifeLog/'; + +my $cgi = CGI->new; +my $session = new CGI::Session("driver:File",$cgi, {Directory=>$LOG_PATH}); +my $sid=$session->id(); +my $dbname =$session->param('database'); +my $userid =$session->param('alias'); +my $password=$session->param('passw'); + +if(!$userid||!$dbname){ + print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid"); + exit; +} + +my $database = '../../dbLifeLog/'.$dbname; +my $dsn= "DBI:SQLite:dbname=$database"; +my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die "

Error->". $DBI::errstri ."

"; + + + my @stat = stat $database; @@ -32,10 +49,10 @@ my $q = CGI->new; print $q->header(-expires=>"+6os", -charset=>"UTF-8"); -print $q->start_html(-title => "Log Data Stats", - -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'}, - -style =>{-type => 'text/css', -src => 'wsrc/main.css'}, - -onload => "loadedBody();" +print $q->start_html(-title => "Log Data Stats", -BGCOLOR=>"#c8fff8", + -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'}, + -style =>{-type => 'text/css', -src => 'wsrc/main.css'}, + -onload => "loadedBody();" );