]> lifelog.hopto.org Git - LifeLog.git/commitdiff
DBI_MULTI_USER_DB implementation.
authorWill Budicm <redacted>
Wed, 16 Dec 2020 03:01:16 +0000 (14:01 +1100)
committerWill Budicm <redacted>
Wed, 16 Dec 2020 03:01:16 +0000 (14:01 +1100)
Current Development Check List.md
dbLifeLog/main.cnf
htdocs/cgi-bin/config.cgi
htdocs/cgi-bin/data.cgi
htdocs/cgi-bin/login_ctr.cgi
htdocs/cgi-bin/stats.cgi
htdocs/cgi-bin/system/modules/Settings.pm

index 9c42805da3f939015d7d9581e4b1bb2c6220fefb..d6d095efc41ba3ac7d643f6f4d3a794923a6d8f1 100644 (file)
 * &#10004; Multi db driver type support. Earth stage requires same SQL related code to work on at least one more DBMS type other than SQLight.
   * PostgreSQL is the candidate as MySQL is not easy to install and bulky for all systems.
   * Developing and adopting to MySQL or any other system is not prerogative, as it works well as it is with inbuilt simplicity.
+* &#10004; Single database, multi-user login.
 * 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)
 * Provide markdown text functionality to html pages. For quick vanilla plain documentation.
+* Search on multiple words should rank by encounter of words specified and display first. (That one is difficult)
 * 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)
 
 ### v.2.0 SUN RC2 Encountered
index 272368fd19d68714c55bc7ec6268c0a98db6e49f..fb785a8ef066e05ad9db78eb0f35aba71456fbfe 100644 (file)
@@ -10,19 +10,20 @@ Credential format:<<AUTO_LOGIN <{alias}/{password}> , don't enable here using AU
 # Default database driver prefix, is SQLite.
 <<DBI_SOURCE<DBI:SQLite:>
 # ProgresSQL DB driver. Remove -> '!' prefix to tag name, to enable, and override the above SQLite one.
-<<!DBI_SOURCE<DBI:Pg:host=localhost;>
+<<DBI_SOURCE<DBI:Pg:host=localhost;>
 # LOG actual variable size limit, - 1024 default, 128 minimum value. 
-#<<DBI_LOG_VAR_SIZE<1024>
-# 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.
-<<DBI_MULTI_USER_DB<0>
+<<!DBI_LOG_VAR_SIZE<1024>
+
+# Set the following to an database name, with external managed multiple users, that are to connect to a single database.
+# Users have to be externally set, and alias is then used for their userid to be able to login. (Add user roles to AUTH table).
+# By default this setting is disabled with 0, making alias name, its own log database, per user.
+<<DBI_MULTI_USER_DB<>
 
 #Timezoning, if set to 1, country locale setting for timezone in config page is ignored.
 <<AUTO_SET_TIMEZONE<0>
 
 
-# Public, enabled list of categories. Remove -> '!' prefix to tag name, to enable. Be careful what category you add/enable here.
+# Public, enabled list of categories. Remove -> '!' prefix before 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.
 <<!PUBLIC_CATS<03,06,09>#File,System log and Event.
 # Following is similar to AUTO_LOGIN setting above, and must be set.
@@ -38,7 +39,7 @@ America/Texas=America/Chicago
 <<CONFIG<4>
 00|$RELEASE_VER = 2.1`LifeLog Application Version.
 01|$REC_LIMIT   = 25`Records shown per page.
-03|$TIME_ZONE   = Australia/Sydney`Time zone of your country.
+03|$TIME_ZONE   = Australia/Sydney`Time zone of your country and city.
 05|$PRC_WIDTH   = 80`Default presentation width for pages.
 08|$LOG_PATH    = ../../dbLifeLog/`Path to folder containing data.
 10|$SESSN_EXPR  = +30m`Login session expiration time setting, can be minutes or hours.
index c11eef50af2f95ce715964575c7068ddd33f0e18..dc46db0cd1ed7b6c18ebc56df5fd52a5aa416c78 100755 (executable)
@@ -29,7 +29,7 @@ my $sys     = `uname -n`;
 my $db      = Settings::fetchDBSettings();
 my $cgi     = Settings->cgi();
 my $sid     = Settings::sid(); 
-my $dbname  = Settings::dbname();
+my $dbname  = Settings::dbName();
 my $alias   = Settings::alias();
 my $rv;
 my $dbs;
index 0c041b8e0e6093e23847e4272b962bd131c9177e..c701c3ef748a975554eb0d7566321ae770f3001f 100755 (executable)
@@ -18,7 +18,7 @@ require Settings;
 
 my $db        = Settings::fetchDBSettings();
 my $cgi       = Settings->cgi();
-my $dbname    = Settings::dbname();
+my $dbname    = Settings::dbName();
 my $imgw      = 210;
 my $imgh      = 120;
 my $human     = DateTime::Format::Human::Duration->new();
index bc40b85a08c5d39a6b9606e94c5de2469b242191..9fce9092553d35ec71b4c38554dd1b17091f5dea 100755 (executable)
@@ -32,6 +32,7 @@ my $SCRIPT_RELEASE = Settings::release();
 my $BACKUP_ENABLED = 0;
 my $AUTO_SET_TIMEZONE = 0;
 my $TIME_ZONE_MAP = 0;
+my $DB_NAME;
 
 try{
     checkAutologinSet();
@@ -110,7 +111,7 @@ sub processSubmit {
                 $session->param('passw', $passw);
                 $session->param('db_source', Settings::dbSrc());
                 $session->param('db_file',   Settings::dbFile());
-                $session->param('database',  Settings::dbname());                
+                $session->param('database',  Settings::dbName());                
                 $session->flush();
                 ### To MAIN PAGE
                 print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie, -location=>"main.cgi");
@@ -141,6 +142,9 @@ sub checkAutologinSet {
         if($v){$AUTO_SET_TIMEZONE = $v; next}
         $v = Settings::parseAutonom('DBI_LOG_VAR_SIZE',$line);
         if($v){Settings::dbVLSZ($v); next}
+        # From here are config file only autonoms. Don't need or harm being in database configuration.
+        $v = Settings::parseAutonom('DBI_MULTI_USER_DB',$line);
+        if($v){$DB_NAME=$v;Settings::dbName($v);next}
         if($line =~ /<<TIME_ZONE_MAP</){
             $TIME_ZONE_MAP = substr($line,16);
             while ($line = <$fh>) {
@@ -159,7 +163,7 @@ sub checkAutologinSet {
                 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);
-            $db = Settings::connectDB($alias, $passw);            
+            $db = Settings::connectDB($DB_NAME, $alias, $passw);            
             #check if autologin enabled.
             my $st = Settings::selectRecords($db,"SELECT VALUE FROM CONFIG WHERE NAME='AUTO_LOGIN';");                        
             if($st){my @set = $st->fetchrow_array();
@@ -178,7 +182,7 @@ sub checkAutologinSet {
 
 sub checkPreparePGDB {
     my $create =1;
-    $passw = $cgi->param('passw'); #PG handles password encryption itself.
+    $passw = $cgi->param('passw'); #We let PG handles password encryption (security) itself.
     my @data_sources = DBI->data_sources("Pg");
     foreach my $ln (@data_sources){
             my $i = rindex $ln, '=';
@@ -227,9 +231,9 @@ try{
     # If brand new database, this sill returns fine an empty array.
     my %curr_tables = ();
 
-    if(Settings::isProgressDB()){
+    if(Settings::isProgressDB()){        
         $changed = checkPreparePGDB();
-        $db = Settings::connectDB($alias, $passw); 
+        $db = Settings::connectDB($DB_NAME, $alias, $passw); 
         my @tbls = $db->tables(undef, 'public');
         foreach (@tbls){
             my $t = uc substr($_,7);
@@ -237,7 +241,7 @@ try{
         }
     }
     else{
-        $db = Settings::connectDB($alias, $passw); 
+        $db = Settings::connectDB($DB_NAME, $alias, $passw); 
         $pst = Settings::selectRecords($db,"SELECT name FROM sqlite_master WHERE type='table' or type='view';");        
         while(my @r = $pst->fetchrow_array()){
             $curr_tables{$r[0]} = 1;
@@ -353,7 +357,7 @@ try{
         $db->do('DROP VIEW VW_LOG;');delete($curr_tables{'VW_LOG'});
         delete($curr_tables{'VW_LOG'});
         $changed = 1;
-    }
+    }elsif($SCRIPT_RELEASE > $DB_VERSION){$changed = 1;}
 
     if(!$hasLogTbl) {
 
@@ -579,8 +583,8 @@ sub logout {
         $alias = $session->param('alias');
         $passw = $session->param('passw');
         if($alias){
-            my $db = Settings::connectDB($alias, $passw);
-            Settings::toLog($db, "Log properly loged out by $alias.");
+            my $db = Settings::connectDB($DB_NAME, $alias, $passw);
+            Settings::toLog($db, "Log has properly been loged out by $alias.");
             $db->disconnect();
         }
     }catch{
index 358769cbff086bdf7291856043b992a717b96cb4..7e4ec2892d6459ae7a3b524541ffff7f8f6e04c4 100755 (executable)
@@ -25,7 +25,7 @@ my $cgi     = CGI->new();
 my $db      = Settings::fetchDBSettings($cgi);
 my $sss     = Settings::session();
 my $sid     = Settings::sid(); 
-my $dbname  = Settings::dbname();
+my $dbname  = Settings::dbName();
 my $alias   = Settings::alias();
 my $passw   = Settings::pass();
 
index cd0c4ee522ff3b1a07ab2ddc2ac8ee8533d1b1a9..08e5a41ce32009b588887d08a38062d1bafad4fc 100644 (file)
@@ -101,7 +101,7 @@ sub dbSrc          {my $r = shift; if($r) {$DBI_SOURCE=$r; $IS_PG_DB = 1 if(inde
                     return $DBI_SOURCE}
 sub dbVLSZ         {my $r = shift; if(!$r){$r = $DBI_LVAR_SZ}else{$r=128 if($r<128);$DBI_LVAR_SZ=$r}  return $r}
 sub dbFile         {my $r = shift; if($r) {$DBFILE=$r} return $DBFILE}
-sub dbName         {return $dbname}
+sub dbName         {my $r = shift; if($r) {$dbname=$r} return $dbname}
 sub dsn            {return $DSN}
 sub isProgressDB   {return $IS_PG_DB}
 sub sqlPubors      {return $SQL_PUB}
@@ -109,7 +109,6 @@ sub sqlPubors      {return $SQL_PUB}
 sub cgi     {return $cgi}
 sub session {return $sss}
 sub sid     {return $sid}
-sub dbname  {return $dbname}
 sub alias   {return $alias}
 sub pass    {return $pass}
 sub pub     {return $pub}
@@ -154,11 +153,11 @@ try {
     # if(!$alias){
     #     $alias = "admin"; $pass  = $alias; dbSrc('dbi:Pg:host=localhost;');
     # }
-     if(!$alias){
+    if(!$alias){
         print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid");
         exit;
-    }
-    my $ret  = connectDB($alias, $pass);
+    }    
+    my $ret  = connectDB($dbname, $alias, $pass);
     getConfiguration($ret);    
     getTheme();
     $sss->expire($SESSN_EXPR);
@@ -611,18 +610,20 @@ sub configProperty {
 }
 
 sub connectDB {
-    my ($a,$p) = @_;
-    $a = $alias if(!$a);
+    my ($d,$u,$p) = @_;
+    $u = $alias if(!$u);
     $p = $alias if(!$p);
-    $dbname = 'data_'.$a.'_log.db';
-    $DBFILE = $LOG_PATH.$dbname if(!$DBFILE);    
-    if ($IS_PG_DB)  {
-        $DSN = $DBI_SOURCE .'dbname='.$a; $DBFILE = $a;        
-    }else{
-        $DSN = $DBI_SOURCE .'dbname='.$DBFILE;        
-    }
+    my $db =$u;
+    if(!$d){$db = 'data_'.$u.'_log.db';}
+    else{   $db = 'data_'.$d.'_log.db';}
+    $DBFILE = $LOG_PATH.'/'.$db;
+        if ($IS_PG_DB)  {
+            $DSN = $DBI_SOURCE .'dbname='.$d;
+        }else{
+            $DSN = $DBI_SOURCE .'dbname='.$DBFILE;        
+        }    
     try{
-        return DBI->connect($DSN, $a, $p, {AutoCommit => 1, RaiseError => 1, PrintError => 0, show_trace=>1});
+        return DBI->connect($DSN, $u, $p, {AutoCommit => 1, RaiseError => 1, PrintError => 0, show_trace=>1});
     }catch{           
        LifeLogException->throw(error=>"<p>Error->$@</p>",  show_trace=>1);
     }