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:<<AUTO_LOGIN <{alias}/{password}> , dont enable here using AUTO_LOGIN option bellow, use config in app.
+Credential format:<<AUTO_LOGIN <{alias}/{password}> , don't enable here using AUTO_LOGIN option bellow, use config in app.
<<AUTO_LOGIN</>
# BACKUP_ENABLED -> Enable (1), disable (0) backups to be restored from config page.
<<BACKUP_ENABLED<1>
+# Default database driver prefix, is SQLite.
+<<DBI_DRV_PRFIX<DBI:SQLite:dbname=>
<<CONFIG<4>
00|$RELEASE_VER = 2.1`LifeLog Application Version.
01|$REC_LIMIT = 25`Records shown per page.
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.
<<CAT<3>
01|Unspecified `For quick uncategorised entries.
03|File System `Operating file system/Application short log.
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";
exit;
}
-my $database = &Settings::logPath.$dbname;
-my $dsn= "DBI:SQLite:dbname=$database";
-my $db = DBI->connect($dsn, $userid, $pass, { RaiseError => 1 }) or die "<p>Error->"& $DBI::errstri &"</p>";
+my $db = Settings::connectDB($userid, $pass);
### Fetch settings
Settings::getConfiguration($db);
}
}
- 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();
}
- openlog($dsn, 'cons,pid', "user");
+ openlog(Settings::dsn(), 'cons,pid', "user");
syslog('info', 'Status:%s', $status);
syslog('err', '%s', $ERROR) if ($ERROR);
closelog();
$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;");
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;
# $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;
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) = "";
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, "<<AUTO_LOGIN<", 0)==0){
- $end = index $line, ">", 14;
- $crest = substr $line, 13, $end - 13;
- @cre = split '/', $crest;
- next;
- }
- elsif(rindex ($line, "<<BACKUP_ENABLED<", 0)==0){
- $end = index $line, ">", 18;
- $BACKUP_ENABLED = substr $line, 17, $end - 17;
- last; #we expect as last anon to be set.
- }
- elsif(rindex ($line, "<<CONFIG<",0) == 0){last;}
+ $v = parseAutonom('AUTO_LOGIN',$line);
+ if($v){ @cre = split '/', $v; next}
+ $v = parseAutonom('BACKUP_ENABLED',$line);
+ if($v){ $BACKUP_ENABLED = $v; next}
+ $v = parseAutonom('DBI_DRV_PRFIX',$line);
+ if($v){Settings::DBIPrefix($v); next}
+ last if parseAutonom('CONFIG',$line); #By specs the config tag, is not an autonom, if found we stop reading. So better be last one spec. in file.
}
close $fh;
- if(@cre &&scalar(@cre)>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("<p>Error->"& $DBI::errstri &"</p>");
- #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();
+ }
}
}
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';");
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);
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);
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;
}
$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