From 4cf9d64d19383ab24e2cdbeba26405529c6eacfc Mon Sep 17 00:00:00 2001 From: Metabox Date: Fri, 31 May 2019 13:18:01 +1000 Subject: [PATCH] AUTO_LOGIN --- Current Development Check List.md | 1 + htdocs/cgi-bin/login_ctr.cgi | 38 ++++++++++++++++++++++++--- htdocs/cgi-bin/main.cnf | 2 ++ htdocs/cgi-bin/tempCodeRunnerFile.cgi | 18 +++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Current Development Check List.md b/Current Development Check List.md index 33e29d7..331a646 100644 --- a/Current Development Check List.md +++ b/Current Development Check List.md @@ -1,5 +1,6 @@ # Current Branch Development Moon-Stable-1.4 ## Urgent +* Autologin feature, that expires on logout. *✔ Data/Login control updated to read the configuration file. >> Configuration file to be updated to carry also categories. * ✔ Configuration page to be updated, system variables description field to be implemented. diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index 1c3288a..27bf2b3 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -29,6 +29,7 @@ our $RELEASE_VER = '1.4'; our $AUTHORITY = ''; our $IMG_W_H = '210x120'; our $AUTO_WRD_LMT= 200; +our $AUTO_LOGIN = 0; #END OF SETTINGS @@ -93,6 +94,7 @@ exit; sub processSubmit{ try{ + &checkAutologinSet; if($alias&&$passw){ $passw = uc crypt $passw, hex $cipher_key; @@ -101,7 +103,7 @@ try{ $session->param('alias', $alias); $session->param('passw', $passw); $session->param('database', 'data_'.$alias.'_log.db'); - $session->flush(); + $session->flush(); print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie, -location=>"main.cgi"); return 1; } @@ -117,7 +119,37 @@ return 0; } } -sub checkCreateTables{ +sub checkAutologinSet { + #We don't need to slurp as it is expected setting in header. + my @cre; + open(my $fh, '<', './main.cnf' ) or die "Can't open main.cnf: $!"; + while (my $line = <$fh>) { + chomp $line; + if(rindex ($line, "<", 14; + my $crest = substr $line, 13, $end - 13; + @cre = split '/', $crest; + last; + } + } + close $fh; + if(@cre &&scalar(@cre)>1){ + my $database = $LOG_PATH.'data_'.$cre[0].'_log.db'; + my $dsn= "DBI:SQLite:dbname=$database"; + my $db = DBI->connect($dsn, $cre[0], $cre[1], { RaiseError => 1 }) + or die "

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

"; + #check if enabled. + my $st = $db->prepare("SELECT NAME, VALUE FROM CONF WHERE NAME='$AUTO_LOGIN';"); + $st->execute(); + my @set = $st->fetchrow_array(); + if(@set && $set[0]=="1"){ + $alias = $cre[0]; + $passw = $cre[1]; + } + } +} + +sub checkCreateTables { try{ my $today = DateTime->now; $today->set_time_zone( $TIME_ZONE ); @@ -373,7 +405,7 @@ sub insertDefCats { my $st = $_[0]->prepare('INSERT INTO CAT VALUES (?,?,?)'); $st->execute(1, "Unspecified", "For quick uncategorised entries."); - $st->execute(3, "File System", "Operating file system short log."); + $st->execute(3, "File", "Operating file system short log."); $st->execute(6, "System Log", "Operating system important log."); $st->execute(9, "Event", "Event that occured, meeting, historically important."); $st->execute(28,"Personal", "Personal log of historical importance, diary type."); diff --git a/htdocs/cgi-bin/main.cnf b/htdocs/cgi-bin/main.cnf index 589669d..a3d6064 100644 --- a/htdocs/cgi-bin/main.cnf +++ b/htdocs/cgi-bin/main.cnf @@ -2,6 +2,7 @@ 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. @@ -13,6 +14,7 @@ This is an Open Source License project -> https://choosealicense.com/licenses/is 14|$LANGUAGE = English`Default language locale. 18|$IMG_W_H = 210x120`Default embedded image width. 20|$AUTO_WRD_LMT= 200`Autocomplete word gathering limit. +22|$AUTO_LOGIN = 0`Autologin option, that expires only if login out. Enter Credentials in main.cnf. < 01|Unspecified `For quick uncategorised entries. 03|File System `Operating file system short log. diff --git a/htdocs/cgi-bin/tempCodeRunnerFile.cgi b/htdocs/cgi-bin/tempCodeRunnerFile.cgi index 2299039..494187f 100644 --- a/htdocs/cgi-bin/tempCodeRunnerFile.cgi +++ b/htdocs/cgi-bin/tempCodeRunnerFile.cgi @@ -6,6 +6,23 @@ use strict; use warnings; + + + open(my $fh, '<', '/home/will/dev/LifeLog/htdocs/cgi-bin/main.cnf' ) or die "Can't open main.cnf: $!"; + while (my $line = <$fh>) { + chomp $line; + if(rindex ($line, "<", 14; + my $crest = substr $line, 13, $end - 13; + my @cre = split '/', $crest; + if(@cre &&scalar(@cre)>1){ + print @cre; + } + + } + } + close $fh; +=Comm my $fh; my $inData = 0; open( $fh, "<:perlio", '/home/will/dev/LifeLog/htdocs/cgi-bin/main.cnf' ) @@ -77,6 +94,7 @@ foreach my $line (@lines) { } close $fh; +=cut =comment -- 2.34.1