From: Will Budicm Date: Thu, 17 Sep 2020 00:15:28 +0000 (+1000) Subject: Initial multi driver support settings, added. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=a2373054274c42a8c68f95970337e494de99190f;p=LifeLog.git Initial multi driver support settings, added. --- diff --git a/dbLifeLog/main.cnf b/dbLifeLog/main.cnf index d5a4b35..69d3d28 100644 --- a/dbLifeLog/main.cnf +++ b/dbLifeLog/main.cnf @@ -3,10 +3,12 @@ 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/ -Credential format:< , dont enable here using AUTO_LOGIN option bellow, use config in app. +Credential format:< , don't enable here using AUTO_LOGIN option bellow, use config in app. < # BACKUP_ENABLED -> Enable (1), disable (0) backups to be restored from config page. < +# Default database driver prefix, is SQLite. +< < 00|$RELEASE_VER = 2.1`LifeLog Application Version. 01|$REC_LIMIT = 25`Records shown per page. @@ -27,6 +29,7 @@ Credential format:< , dont enable here using AUT 34|$VIEW_ALL_LMT=1000`Limit of all records displayed for large logs. Set to 0, for unlimited. 36|$TRACK_LOGINS=1`Create system logs on login/logout of Life Log. 38|$COMPRESS_ENC=0`Compress Encode pages, default -> 0=false, 1=true. +40|$SUBPAGEDIR =docs`Directory to scan for subpages like documents. < 01|Unspecified `For quick uncategorised entries. 03|File System `Operating file system/Application short log. diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index 709e775..3d3c552 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -20,7 +20,7 @@ use DateTime::Duration; use Date::Language; use Text::CSV; use Scalar::Util qw(looks_like_number); -use Sys::Syslog qw(:DEFAULT :standard :macros); +use Sys::Syslog qw(:DEFAULT :standard :macros); #openLog, closelog macros #DEFAULT SETTINGS HERE! use lib "system/modules"; @@ -44,9 +44,7 @@ if(!$userid||!$dbname){ exit; } -my $database = &Settings::logPath.$dbname; -my $dsn= "DBI:SQLite:dbname=$database"; -my $db = DBI->connect($dsn, $userid, $pass, { RaiseError => 1 }) or die "

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

"; +my $db = Settings::connectDB($userid, $pass); ### Fetch settings Settings::getConfiguration($db); @@ -600,7 +598,7 @@ if($passch){ } } - openlog($dsn, 'cons,pid', "user"); + openlog(Settings::dsn(), 'cons,pid', "user"); syslog('info', 'Status:%s', $status); syslog('info', 'Password change request for %s', $$userid); closelog(); @@ -780,7 +778,7 @@ catch{ } - openlog($dsn, 'cons,pid', "user"); + openlog(Settings::dsn(), 'cons,pid', "user"); syslog('info', 'Status:%s', $status); syslog('err', '%s', $ERROR) if ($ERROR); closelog(); @@ -863,7 +861,7 @@ try{ $db->do('COMMIT;'); $db->disconnect(); - $db = DBI->connect($dsn, $userid, $pass, { RaiseError => 1 }) or LifeLogException->throw($DBI::errstri); + $db =Settings::connectDB($userid, $pass); $dbs = $db->do("VACUUM;"); @@ -1022,7 +1020,7 @@ try{ sub backup { my $ball = 'bck__'.$today->strftime('%Y%m%d%H%M%S_')."$dbname.osz"; - my $pipe = "tar czf - ".&Settings::logPath.'main.cnf' ." $database | openssl enc -k $pass:$userid -e -des-ede3-cfb -out ".Settings::logPath().$ball." 2>/dev/null"; + my $pipe = "tar czf - ".Settings::logPath().'main.cnf' ." ". Settings::dbFile()." | openssl enc -k $pass:$userid -e -des-ede3-cfb -out ".Settings::logPath().$ball." 2>/dev/null"; my $rez = `$pipe`; #print $cgi->header; diff --git a/htdocs/cgi-bin/data.cgi b/htdocs/cgi-bin/data.cgi index 1d5a1be..7a52bdd 100755 --- a/htdocs/cgi-bin/data.cgi +++ b/htdocs/cgi-bin/data.cgi @@ -41,9 +41,8 @@ if(!$userid||!$dbname){ # $userid = "admin"; # $password= "admin"; -my $database = Settings::logPath().$dbname; -my $dsn= "DBI:SQLite:dbname=$database"; -my $db = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or LifeLogException->throw($DBI::errstri); + +my $db = Settings::connectDB($userid, $password); #Fetch settings my $imgw = 210; diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index ef4f4fd..8bd061d 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -29,7 +29,7 @@ my $sssCreatedDB = $session->param("cdb"); my $sid=$session->id(); my $cookie = $cgi->cookie(CGISESSID => $sid); - +my $db; my $alias = $cgi->param('alias'); my $passw = $cgi->param('passw'); my ($debug,$frm) = ""; @@ -127,47 +127,47 @@ sub processSubmit { return 0; } -sub checkAutologinSet { +sub parseAutonom { #Parses autonom tag for its crest value, returns undef if tag not found or wrong for passed line. + my $t = '<<'.shift.'<'; + my $line = shift; + if(rindex ($line, $t, 0)==0){#@TODO change the following to regex parsing: + my $l = length $t; + my $e = index $line, ">", $l + 1; + return substr $line, $l, $e - $l; + } + return undef; +} - #We don't need to slurp as it is expected setting in header. - my (@cre, $end,$crest); +sub checkAutologinSet { + my (@cre, $v); + # We don't need to slurp whole file as next are expected settings in begining of the config file. open(my $fh, '<', &Settings::logPath.'main.cnf' ) or LifeLogException->throw("Can't open main.cnf: $!"); while (my $line = <$fh>) { chomp $line; - if(rindex ($line, "<", 14; - $crest = substr $line, 13, $end - 13; - @cre = split '/', $crest; - next; - } - elsif(rindex ($line, "<", 18; - $BACKUP_ENABLED = substr $line, 17, $end - 17; - last; #we expect as last anon to be set. - } - elsif(rindex ($line, "<1){##TODO we already connected here to the db, why do it again later? + if(@cre &&scalar(@cre)>1){ - if($alias && $passw && $alias ne $cre[0]){ # Is this an new alias login attempt? + if($alias && $passw && $alias ne $cre[0]){ # Is this an new alias login attempt? If so, autologin is of the agenda. return; # Note, we do assign entered password even passw as autologin is set. Not entering one bypasses this. } # If stricter access is required set it to zero in main.cnf, or disable in config. $passw = $cre[1] if (!$passw); - my $database = &Settings::logPath.'data_'.$cre[0].'_log.db'; - my $dsn= "DBI:SQLite:dbname=$database"; - my $db = DBI->connect($dsn, $cre[0], $cre[1], { RaiseError => 1 }) - or LifeLogException->throw("

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

"); - #check if enabled. - my $st = $db->prepare("SELECT VALUE FROM CONFIG WHERE NAME='AUTO_LOGIN';"); - $st->execute(); - my @set = $st->fetchrow_array(); - if(@set && $set[0]=="1"){ + $db = Settings::connectDB($alias, $passw); + #check if autologin enabled. + my $st = Settings::selectRecords($db,"SELECT VALUE FROM CONFIG WHERE NAME='AUTO_LOGIN';"); + my @set = $st->fetchrow_array() if $st; + if($set[0]=="1"){ $alias = $cre[0]; - $passw = $passw; #same as entered, by the not knowing to leave it blank. + $passw = $passw; &Settings::removeOldSessions; - } - $db->disconnect(); + } } } @@ -176,10 +176,8 @@ sub checkCreateTables { my $today = DateTime->now; $today-> set_time_zone( &Settings::timezone ); - my $database = &Settings::logPath.'data_'.$alias.'_log.db'; - my $dsn= "DBI:SQLite:dbname=$database"; - my $db = DBI->connect($dsn, $alias, $passw, { RaiseError => 1 }) or LifeLogException->throw($DBI::errstri); my ($pst, $sql,$rv, $changed) = 0; + $db = Settings::connectDB($alias, $passw) if !$db; # We live check database for available tables now only once. # If brand new database, this sill returns fine an empty array. $pst = Settings::selectRecords($db,"SELECT name FROM sqlite_master WHERE type='table' or type='view';"); diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 66825be..02fa597 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -43,11 +43,7 @@ if ( !$userid || !$dbname ) { print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid"); exit; } - -my $database = &Settings::logPath . $dbname; -my $dsn = "DBI:SQLite:dbname=$database"; -my $db = DBI->connect( $dsn, $userid, $password, { PrintError => 0, RaiseError => 1 } ) - or LifeLogException->throw("Connection failed [$DBI::errstri]"); +my $db = Settings::connectDB($userid, $password); my ( $imgw, $imgh ); #Fetch settings Settings::getConfiguration($db); @@ -220,7 +216,7 @@ my $st; my $sqlCAT = "SELECT ID, NAME, DESCRIPTION FROM CAT ORDER BY ID;"; my $sqlVWL = "$stmS STICKY = 1 $stmE"; -toBuf (qq(## Using db -> $dsn\n)) if $DEBUG; +toBuf ("## Using db ->". Settings::dsn(). "\n") if $DEBUG; $st = $db->prepare($sqlCAT); $st->execute() or LifeLogException->throw($DBI::errstri); @@ -1065,7 +1061,7 @@ try { toBuf $stm if $DEBUG; # - my $dbUpd = DBI->connect( $dsn, $userid, $password, { RaiseError => 1 } ) or LifeLogException->throw("Execute failed [$DBI::errstri]"); + my $dbUpd = DBI->connect(Settings::dsn(), $userid, $password, { RaiseError => 1 } ) or LifeLogException->throw("Execute failed [$DBI::errstri]"); traceDBExe($stm); return; } @@ -1163,7 +1159,7 @@ my $pwd = `pwd`; $pwd =~ s/\s*$//; my $dbg = qq(--DEBUG OUTPUT--\n - DSN:$dsn + DSN:) . Settings::dsn(). qq( stm:$stm \@DB::args:@DB::args \$DBI::err:$DBI::errstr