From: Will Budicm Date: Thu, 26 Nov 2020 00:56:19 +0000 (+1100) Subject: Public access provided for specific categories. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=20fc3714c82e5153f43b4161bc3d0fe205235c09;p=LifeLog.git Public access provided for specific categories. --- diff --git a/Current Development Check List.md b/Current Development Check List.md index 019f893..a95e3cb 100644 --- a/Current Development Check List.md +++ b/Current Development Check List.md @@ -1,16 +1,16 @@ # Branch Development Life Log in Perl -*This page lists current development and issues being worked on in the LifeLog app. Being in the **Sun** stage, means there is a production environment. And usable, used. When, the project reaches **Earth** stage. It will be at its final specification. No data structures or major new features can be added or requested anymore. Only bug fixes, enhancements and efficiency fixes, if any at the **Earth** stage.* +*This page lists current development and issues being worked on in the LifeLog app. Being in the **Sun** stage, means there is a production environment. And usable, and in use. When, the project reaches **Earth** stage. It will be at its final specification. No data structures or major new features can be added or requested anymore. Only bug fixes, enhancements and efficiency fixes, if any at the **Earth** stage.* ## Life Log Development ### v.2.1 SUN STABLE New Features in Works -* Provide office share link for main.inf linked categories, No login required but not log creation or search is possible. -* ✔ Make the dbname uniform across all source types with Settings, as backups use the file format, not the database name. +* Implement mapped provision of named timezones via main.inf, for towns not available in global list. +* ✔ Provide office share public link for main.inf linked categories, No login required but no log creation or search is possible. +* ✔ main.inf - Make the dbname uniform across all source types with Settings, as backups use the file format, not the database name. * Static pages setting for the pages directory. * Search on multiple words should rank by encounter of words specified and display first. (That one is difficult) -* Search button should be an and on previous views settings. Otherwise lists entries of other categories containing an word. * Provide markdown text functionality to html pages. For quick vanilla plain documentation. * Auto collapse/expand on multi line logs by 0-none as default. Setting to 1 or more shows only that number of lines. (That one is difficult) * ✔ Edit button to show if hidden is the log entry section. diff --git a/dbLifeLog/main.cnf b/dbLifeLog/main.cnf index 4b78277..8ad9efc 100644 --- a/dbLifeLog/main.cnf +++ b/dbLifeLog/main.cnf @@ -12,7 +12,7 @@ Credential format:< , don't enable here using AU # ProgresSQL DB driver. Remove -> '!' prefix to tag name, to enable. < -# Set folowing to an database name, if multiple aliases connect to a single log database. +# Set following to an database name, if multiple aliases connect to a single log database. # Users have to be set, and alias is then used for their userid to be able to login. # By default this setting is disabled with 0, making alias, its own log database. < @@ -20,6 +20,12 @@ Credential format:< , don't enable here using AU #Timezoning, if set to 1, country locale setting for timezone in config page is ignored. < +# Public, enabled list of categories. Remove -> '!' prefix to tag name, to enable. Be careful what category you add/enable here. +# Public records view feature only, it doesn't allow new log entries to be added and have pin point searching of all existing. +<#File,System log and Event. +# Following is similar to AUTO_LOGIN setting above, and must be set. +< + < 00|$RELEASE_VER = 2.1`LifeLog Application Version. 01|$REC_LIMIT = 25`Records shown per page. diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index 9e8f141..3f2661f 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -347,14 +347,14 @@ my $frmPASS = qq( my @backups = (); -my ($bck_list) =""; +my ($file, $bck_list) =""; opendir my $dir, &Settings::logPath; -while(my $file = readdir $dir){ +while($file = readdir $dir){ next if $file eq '.' or $file eq '..' or index ($file , 'bck_') == -1; push @backups, $file; } close $dir; -foreach my $file (sort @backups){ +foreach $file (sort @backups){ #my $n = substr $file, length(&Settings::logPath); $bck_list .= "$file
"; } diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index 112868a..ddf03e5 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -131,15 +131,15 @@ sub checkAutologinSet { open(my $fh, '<', Settings::logPath().'main.cnf' ) or LifeLogException->throw("Can't open main.cnf: $!"); while (my $line = <$fh>) { chomp $line; - $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_SOURCE',$line); + $v = Settings::parseAutonom('AUTO_LOGIN',$line); + if($v){@cre = split '/', $v; next} + $v = Settings::parseAutonom('BACKUP_ENABLED',$line); + if($v){$BACKUP_ENABLED = $v; next} + $v = Settings::parseAutonom('DBI_SOURCE',$line); if($v){Settings::dbSrc($v); next} - $v = parseAutonom('AUTO_SET_TIMEZONE',$line); + $v = Settings::parseAutonom('AUTO_SET_TIMEZONE',$line); if($v){$AUTO_SET_TIMEZONE = $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. + last if Settings::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){ @@ -150,27 +150,18 @@ sub checkAutologinSet { $passw = $cre[1] if (!$passw); $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; - Settings::removeOldSessions(); - } + my $st = Settings::selectRecords($db,"SELECT VALUE FROM CONFIG WHERE NAME='AUTO_LOGIN';"); + if($st){my @set = $st->fetchrow_array(); + if($set[0]=="1"){ + $alias = $cre[0]; + $passw = $passw; + Settings::removeOldSessions(); + } + } } } -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; -} sub checkPreparePGDB { my $create =1; diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 94b87c3..eb61699 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -34,13 +34,14 @@ my $sssCDB = $sss->param('cdb'); my ($vmode, $imgw, $imgh ); if ( !$alias || !$passw) { - print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid"); + print $cgi->redirect("alogin_ctr.cgi?CGISESSID=$sid"); exit; } - ### Authenticate session to alias passw &authenticate; # + + my $log_rc = 0; my $log_rc_prev = 0; my $log_cur_id = 0; @@ -62,12 +63,12 @@ my $stmS = $sqlView." WHERE"; my $stmE = ' LIMIT '.&Settings::viewAllLimit.';'; my $stmD = ""; my $sm_reset_all; -my $rec_limit = &Settings::recordLimit; +my $rec_limit = Settings::recordLimit(); ### Page specific settings Here -my $TH_CSS = &Settings::css; -my $BGCOL = &Settings::bgcol; +my $TH_CSS = Settings::css(); +my $BGCOL = Settings::bgcol(); #Set to 1 to get debug help. Switch off with 0. -my $DEBUG = &Settings::debug; +my $DEBUG = Settings::debug(); #END OF SETTINGS my $BUFFER; @@ -204,6 +205,7 @@ else { #defaults my $st; my $sqlCAT = "SELECT ID, NAME, DESCRIPTION FROM CAT ORDER BY ID;"; my $sqlVWL = "$stmS STICKY = true $stmE"; +my $isPUBViewMode = Settings::pub() && Settings::sqlPubors(); toBuf ("## Using db ->". Settings::dsn(). "\n") if $DEBUG; @@ -244,6 +246,8 @@ for my $key ( keys %hshDesc ) { $data_cats .= qq(\n); } } +my $eh; +if($isPUBViewMode){$eh = ""}else{$eh='Edit'} my $log_output = qq(
@@ -252,14 +256,16 @@ qq( - + $eh ); #We use js+perl, trickery to filter by amount type, as well. - if ($prm_aa >0){my $s = $prm_aa - 1;$prm_aa = " AFLAG=$s AND";}else{$prm_aa=""} + if($prm_aa >0){my $s = $prm_aa - 1;$prm_aa = " AFLAG=$s AND";}else{$prm_aa=""} + if($prm_rtf){$stmS .= " ID_RTF>0 AND";} - $stmS .= " ID_RTF>0 AND" if($prm_rtf); - - if ( $rs_keys && $rs_keys ne '*' ) { + if($isPUBViewMode){ + $sqlVWL = $stmS." ".Settings::sqlPubors().$stmE; + } + elsif ( $rs_keys && $rs_keys ne '*' ) { my @keywords = split / /, $rs_keys; if ($prm_vc && $prm_vc != $prm_xc) { @@ -393,7 +399,7 @@ qq( $sqlVWL = "$stmS STICKY = false $stmE"; toBuf $cgi->pre("###2 -> ".$sqlVWL) if $DEBUG; ; - &buildLog(traceDBExe($sqlVWL)); + buildLog(traceDBExe($sqlVWL)); } @@ -651,13 +657,15 @@ sub buildLog { + ); + if(!$isPUBViewMode){$log_output .= qq( ); + )}; if ( $rtf > 0 ) { $log_output .= qq( @@ -727,7 +735,10 @@ if ( $log_rc == 0 ) { }else{ $log_output .= ''} } } +if($isPUBViewMode){ +} +else{ $log_output .= <<_TXT;
Time Log# CategoryEdit
$log $am $ct -
Database is New or Empty!
Show All hidden with ➔ @@ -751,7 +762,7 @@ $log_output .= qq(
); - +}; my ( $sp1, $sp2, $sp3 ); $sp1 = ''; $sp2 = ''; @@ -954,45 +965,56 @@ $log_output .= qq(
View Statistics
+
+); +if($isPUBViewMode){$sideMenu=$frm=$srh=$tail=""}else{ + $sideMenu = qq( + + ); +} + + my $quill = &quill( $cgi->param('submit_is_edit') ); my $help = &help; - ################################## - # Final Page Output from here! # - ################################## +################################## +# Final Page Output from here! # +################################## + toBuf (qq( - -
$frm
-
$srh
- $quill -
$help
-
\n$log_output\n

-
-
- +$sideMenu +
$frm
+
$srh
+$quill +
$help
+
\n$log_output\n

+$tail $data_cats @@ -1182,8 +1204,10 @@ my $dbg = qq(--DEBUG OUTPUT--\n $vmode = "[In Page Mode] "; $vmode = "[In View Mode] " if$isInViewMode; - - if($rec_limit == 0){ + if($isPUBViewMode){ + $log_output .=qq!!; + } + elsif($rec_limit == 0){ $log_output .= qq!
$vmode
$vmode !; diff --git a/htdocs/cgi-bin/system/modules/Settings.pm b/htdocs/cgi-bin/system/modules/Settings.pm index 5bb3e41..2e1173b 100644 --- a/htdocs/cgi-bin/system/modules/Settings.pm +++ b/htdocs/cgi-bin/system/modules/Settings.pm @@ -48,7 +48,7 @@ our $DSN; our $DBFILE; our $IS_PG_DB = 0; -my ($cgi, $sss, $sid, $alias, $pass, $dbname); +my ($cgi, $sss, $sid, $alias, $pass, $dbname, $pub); #Annons here, variables that could be overiden in code or database, per need. @@ -65,7 +65,9 @@ our $DEBUG = 1; #200 -> '^REL_RENUM' : this.$RELEASE_VER (Used in login_ctr.cgi) #201 -> '^EXCLUDES' : 0 (Used in main.cgi) -sub anons {return sort keys %anons} +our $SQL_PUB = ""; + +sub anons {my @ret=sort(keys %anons); return @ret;} #Check call with defined(Settings::anon('my_anon')) sub anon {my $n=shift; return $anons{$n}} @@ -97,6 +99,9 @@ sub dbFile {my $r = shift; if($r) {$DBFILE=$r} return $DBFILE} sub dbName {return $dbname;} sub dsn {return $DSN} sub isProgressDB {return $IS_PG_DB} +sub sqlPubors {return $SQL_PUB} + +sub trim {my $r=shift; $r=~s/^\s+|\s+$//g; return $r} sub fetchDBSettings { try { @@ -107,13 +112,37 @@ try { $dbname = $sss->param('database'); $alias = $sss->param('alias'); $pass = $sss->param('passw'); - if(!$alias||!$dbname){ + $pub = $cgi->param('pub'); + if($pub){#we override session to obtain pub(alias)/pass from config. + open(my $fh, '<', logPath().'main.cnf' ) or LifeLogException->throw("Can't open main.cnf: $!"); + while (my $line = <$fh>) { + chomp $line; + my $v = Settings::parseAutonom('PUBLIC_LOGIN',$line); + if($v){my @cre = split '/', $v; + $alias = $cre[0]; + $pass = uc crypt $cre[1], hex Settings->CIPHER_KEY; + } + $v = Settings::parseAutonom('PUBLIC_CATS',$line); + if($v){my @cats= split(',',$v); + foreach(@cats){ + $SQL_PUB .= "ID_CAT=".trim($_)." OR "; + } + $SQL_PUB =~ s/\s+OR\s+$//; + } + last if Settings::parseAutonom('CONFIG',$line); + } + close $fh; + } + elsif(!$alias||!$dbname){ print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid"); exit; } - my $ret = connectDB($alias, $pass); + + print "a:$alias/p:$pass"; + my $ret = connectDB($alias, $pass); dbSrc($sss->param('db_source')); getConfiguration($ret); + getTheme(); $sss->expire($SESSN_EXPR); return $ret; @@ -128,6 +157,7 @@ sub sid {return $sid} sub dbname {return $dbname} sub alias {return $alias} sub pass {return $pass} +sub pub {return $pub} sub today { my $ret = DateTime->now(); @@ -136,7 +166,7 @@ return $ret; } sub createCONFIGStmt { -if($IS_PG_DB){qq( +if($IS_PG_DB){return qq( CREATE TABLE CONFIG( ID INT NOT NULL UNIQUE GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ), NAME VARCHAR(16) UNIQUE, @@ -283,26 +313,26 @@ sub getConfiguration { $st->execute(); while ( my @r = $st->fetchrow_array() ){ switch ( $r[1] ) { - case "RELEASE_VER" { $RELEASE_VER = $r[2]} - case "TIME_ZONE" { $TIME_ZONE = $r[2]} - case "PRC_WIDTH" { $PRC_WIDTH = $r[2]} - case "SESSN_EXPR" { $SESSN_EXPR = $r[2]} - case "DATE_UNI" { $DATE_UNI = $r[2]} - case "LANGUAGE" { $LANGUAGE = $r[2]} + case "RELEASE_VER" {$RELEASE_VER = $r[2]} + case "TIME_ZONE" {$TIME_ZONE = $r[2]} + case "PRC_WIDTH" {$PRC_WIDTH = $r[2]} + case "SESSN_EXPR" {$SESSN_EXPR = $r[2]} + case "DATE_UNI" {$DATE_UNI = $r[2]} + case "LANGUAGE" {$LANGUAGE = $r[2]} case "LOG_PATH" {} #ommited and code static can't change for now. - case "IMG_W_H" { $IMG_W_H = $r[2]} - case "REC_LIMIT" { $REC_LIMIT = $r[2]} - case "AUTO_WRD_LMT" { $AUTO_WRD_LMT = $r[2]} - case "VIEW_ALL_LMT" { $VIEW_ALL_LMT = $r[2]} - case "DISP_ALL" { $DISP_ALL = $r[2]} - case "FRAME_SIZE" { $FRAME_SIZE = $r[2]} - case "RTF_SIZE" { $RTF_SIZE = $r[2]} - case "THEME" { $THEME = $r[2]} - case "DEBUG" { $DEBUG = $r[2]} - case "KEEP_EXCS" { $KEEP_EXCS = $r[2]} - case "TRACK_LOGINS" { $TRACK_LOGINS = $r[2]} - case "COMPRESS_ENC" { $COMPRESS_ENC = $r[2]} - else { $anons{$r[1]} = $r[2]} + case "IMG_W_H" {$IMG_W_H = $r[2]} + case "REC_LIMIT" {$REC_LIMIT = $r[2]} + case "AUTO_WRD_LMT" {$AUTO_WRD_LMT = $r[2]} + case "VIEW_ALL_LMT" {$VIEW_ALL_LMT = $r[2]} + case "DISP_ALL" {$DISP_ALL = $r[2]} + case "FRAME_SIZE" {$FRAME_SIZE = $r[2]} + case "RTF_SIZE" {$RTF_SIZE = $r[2]} + case "THEME" {$THEME = $r[2]} + case "DEBUG" {$DEBUG = $r[2]} + case "KEEP_EXCS" {$KEEP_EXCS = $r[2]} + case "TRACK_LOGINS" {$TRACK_LOGINS = $r[2]} + case "COMPRESS_ENC" {$COMPRESS_ENC = $r[2]} + else {$anons{$r[1]} = $r[2]} } } #Anons are murky grounds. -- @bud @@ -555,4 +585,16 @@ sub connectDB { LifeLogException->throw(error=>"

Error->$@

", show_trace=>1); } } + +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; +} + 1; \ No newline at end of file