]> lifelog.hopto.org Git - LifeLog.git/commitdiff
CGI, DB session moved into settings. DBName.
authorWill Budicm <redacted>
Sat, 31 Oct 2020 16:58:51 +0000 (03:58 +1100)
committerWill Budicm <redacted>
Sat, 31 Oct 2020 16:58:51 +0000 (03:58 +1100)
Current Development Check List.md
htdocs/cgi-bin/config.cgi
htdocs/cgi-bin/login_ctr.cgi
htdocs/cgi-bin/main.cgi
htdocs/cgi-bin/stats.cgi
htdocs/cgi-bin/system/modules/Settings.pm

index 7bdde8803d1344a4eb55e6fb72903b6eb4f155fd..810f6a0eacc96794c1feeccf6a7e5b692eb462b0 100644 (file)
@@ -6,7 +6,7 @@
 
 ### v.2.1 SUN STABLE New Features in Works
 
-* Make the dbname uniform across all source types with Settings, as backups use the file format, not the database name.
+* &#10004; 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 multiwords should rank by encounter of words specified and display first. (That one is difficult)
 * Provide markdown text functionality to html pages. For quick vanila plain documentation.
@@ -18,8 +18,9 @@
 
 ### v.2.0 SUN RC2 Encountered
 
-* Multiple search views and their settings, should be preserved as last preset. Maybe even have named multiple ones in a dropdown or part of the page menu.
 * Sub users list with passwords in config to be provided, with access and category, permissions settings. Default enabled permission is Event view category.
+* [Scrapt] Multiple search views and their settings, should be preserved as last preset. Maybe even have named multiple ones in a dropdown or part of the page menu.
+  * Scrapt -> as view display is different to actual time based normal page display of records. Maybe in the future.
 * [Scrapt] Multiple category assignment to be enabled, where the first selected is the primary, others put in a separate cross reference table, parseed as hashtags maybe.
   * Scrapt -> as many categories per log complex and not necessary as many categories per view is already there.
 * &#10004; Export to CVS button on selected logs.
index 0fbae05d9fe75bf7f8dc0cdd69d6e7f989b10eb1..29e7db86ea33e8ea21722bfc81df81329a45da4a 100755 (executable)
@@ -8,7 +8,6 @@ use warnings;
 use Switch;
 
 use CGI;
-use CGI::Session '-ip_match';
 use CGI::Carp qw ( fatalsToBrowser );
 use DBI;
 use Exception::Class ('LifeLogException');
@@ -30,35 +29,19 @@ require Settings;
 #15mg data post limit
 $CGI::POST_MAX = 1024 * 15000;
 my ($LOGOUT,$ERROR) = (0,"");
-my $cgi     = CGI->new;
-my $sss     = new CGI::Session("driver:File", $cgi, {Directory=>&Settings::logPath});
-my $sid     = $sss->id();
-my $dbname  = $sss->param('database');
-my $userid  = $sss->param('alias');
-my $pass    = $sss->param('passw');
+my $cgi     = CGI->new();
 my $sys     = `uname -n`;
-#my $acumululator="";
-
-if(!$userid||!$dbname){
-    print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid");
-    exit;
-}
-
-Settings::dbSrc( $sss->param('db_source'));
-Settings::dbFile($sss->param('database'));
-### Fetch settings
-    my $db = Settings::connectDB($userid, $pass);
-    Settings::getConfiguration($db);
-    Settings::getTheme();
-###
-
+my $db      = Settings::fetchDBSettings($cgi);
+my $sid     = Settings::sid(); 
+my $dbname  = Settings::dbname();
+my $alias   = Settings::alias();
 my $rv;
 my $dbs;
-my $lang   = Date::Language->new(&Settings::language);
-my $today  = DateTime->now;
+my $lang    = Date::Language->new(&Settings::language);
+my $today   = DateTime->now;
    $today->set_time_zone( &Settings::timezone );
-my $tz     = $cgi->param('tz');
-my $csvp   = $cgi->param('csv');
+my $tz      = $cgi->param('tz');
+my $csvp    = $cgi->param('csv');
 
 &exportToCSV if ($csvp);
 
@@ -74,15 +57,14 @@ my $stmtCat = 'SELECT * FROM CAT ORDER BY ID;';
 my $status = "Ready for change!";
 my $cats;
 my %hshCats = {};
-&cats;
+cats();
 ###############
-&processSubmit;
+processSubmit();
 ###############
 Settings::getTheme();
-$sss->param("theme", &Settings::css);
-$sss->param("bgcolor", &Settings::bgcol);
-
-&getHeader;
+Settings::session()->param("theme", Settings::css());
+Settings::session()->param("bgcolor", Settings::bgcol());
+getHeader();
 
  if ($ERROR){&error;}else{
 print qq(<div id="menu" title="To close this menu click on its heart, and wait.">
@@ -121,7 +103,7 @@ while(my @row = $dbs->fetchrow_array()) {
     }
  }
 
-my  $frmCats = qq(
+my $frmCats = qq(
      <form id="frm_config" action="config.cgi">).$tbl.qq(
       <tr class="r1">
          <td><input type="text" name="caid" value="" size="3"/></td>
@@ -154,7 +136,7 @@ $tbl = qq(<table id="cnf_sys" class="tbl" border="1" width=").&Settings::pagePrc
        );
 my $stm = 'SELECT ID, NAME, VALUE, DESCRIPTION FROM CONFIG ORDER BY NAME;';
    $dbs = Settings::selectRecords($db, $stm);
-my $REL ="";
+my $REL = "";
 while(my @row = $dbs->fetchrow_array()) {
 
          my $n = $row[1]; next if($n =~ m/^\^/); #skip private tagged settings
@@ -348,7 +330,7 @@ my  $frmPASS = qq(
         <tr class="r1" align="left"><td>New:</td><td><input type="pass" name="new" value="" size="12"/></td></tr>
         <tr class="r1" align="left"><td>Confirmation:</td><td><input type="pass" name="confirm" value="" size="12"/></td></tr>
         <tr class="r1">
-         <td colspan="2" align="right"><b>Pass change for -> $userid</b>&nbsp;<input type="submit" value="Change"/></td>
+         <td colspan="2" align="right"><b>Pass change for -> $alias</b>&nbsp;<input type="submit" value="Change"/></td>
         </tr>
         </table><input type="hidden" name="pass_change" value="1"/></form><br>
         );
@@ -437,23 +419,26 @@ print qq(
     <p><ol>
         <li><h3>Backup Rules</h3>
             <ol>
-                <li>Backup provides a compressed archive of the current logged in aliased database only.</li>
-                <li>Backup should be uploaded to client to restore.</li>
+                <li>Backup provides an compressed archive of only the current logged in database.</li>
+                <li>Backup should and can be uploaded to local client to later restore.</li>
                 <li>Issuing backup always creates on the server an copy.</li>
                 <li>Backups are issued manually and are interactive.</li>
+                <li>Backups are server side encrypted.</li>
+                <li>Backups can be particularly server specific, therefore not suitable for restoration on new or different hardware.</li>
+                <li>Backup uses OpenSSL, wich under different versions can be uncompatible in the implemented type of encryption.</li>
             </ol>
         </li>
         <li><h3>Restore Rules</h3>
             <ol>
-                <li>The restoring is only possible if logged into the current by alias application version.</li>
-                <li>Restoration is of found missing in current log data.</li>
+                <li>The restoring is only possible if logged into current database the backup belongs.</li>
+                <li>Restoration is of only logs found missing in current log.</li>
                 <li>Restoration is not removing entries in existing current log data.</li>
-                <li>Restoration is most likelly not possible after application upgrade.</li>
+                <li>Restoration might not be possible after an server application upgrade.</li>
                 <li>Restoration of old backups is not made possible or is safe, on new stable application releases.
-                 <ul><li><i>Upgrade your application after restoring it first, as an upgrade will migrate structure and data.</i></li></ul></li>
+                 <ul><li><i>Upgrade your application after restoring it first, as an upgrade will/might migrate structure and data.</i></li></ul></li>
                 <li>                
-                Restoration will import on an previous date backuped data in case when recreating a new aliased for it database, but of the same application version
-                    <ul><li>For example: If the database file has been deleted or is blank on login, you than can run a restore, if you have an backup.</li></ul>
+                Restoration will import on an previous date backuped data, in case when recreating a newly created same alias database
+                    <ul><li>For example: If the database file has been deleted or is blank on login, you than can run a restore, if you have an backup, for given server.</li></ul>
                 </li>
                 
                 
@@ -461,10 +446,10 @@ print qq(
         </li>
         <li><h3>Purpose</h3>
             <ol>
-                    <li>Provides direct safeguard, besides any external backup procedures.</li>
-                    <li>Provides before snapshot, if venturing into major log modifications.</li>
+                    <li>Provides direct safeguard, besides any external backup procedures.</li>
+                    <li>Provides before snapshot, if venturing into major log modifications.</li>
                     <li>Encourages experimentation, with data deletion and modification.</li>
-                    <li>Required if downgrading from an failed application upgrade, or found missuesed and corrupted current data state.</li>
+                    <li>Required if downgrading from an failed application upgrade, or found a missuesed or corrupted state of current data.</li>
             </ol>
         </li>
     </ol></p>
@@ -594,14 +579,14 @@ if($passch){
              $status = "Pass Has Been Changed";
         }
         else{
-            $status = "Wrong existing pass was entered, are you user by alias: $userid ?";
+            $status = "Wrong existing pass was entered, are you user by alias: $alias ?";
             print "<center><div><p><font color=red>Client Error</font>: $status</p></div></center>";
         }
     }
 
     openlog(Settings::dsn(), 'cons,pid', "user");
         syslog('info', 'Status:%s', $status);
-        syslog('info', 'Password change request for %s', $$userid);
+        syslog('info', 'Password change request for %s', $alias);
     closelog();
 
 
@@ -788,7 +773,7 @@ catch{
 sub confirmExistingPass {
         my $pass = $_[0];
         my $crypt = encryptPassw($pass);
-        my $sql = "SELECT ALIAS, PASSW from AUTH WHERE ALIAS='$userid' AND PASSW='$crypt';";
+        my $sql = "SELECT ALIAS, PASSW from AUTH WHERE ALIAS='$alias' AND PASSW='$crypt';";
     #          print "<center><div><p><font color=red><b>DEBUG</b></font>:[$pass]<br>$sql</p></div></center>";
         $dbs = Settings::selectRecords($db, $stmtCat );
         if($dbs->fetchrow_array()){
@@ -798,7 +783,7 @@ sub confirmExistingPass {
 }
 sub changePass {
       my $pass = encryptPassw($_[0]);
-        $dbs = Settings::selectRecords($db, "UPDATE AUTH SET PASSW='$pass' WHERE ALIAS='$userid';");
+        $dbs = Settings::selectRecords($db, "UPDATE AUTH SET PASSW='$pass' WHERE ALIAS='$alias';");
         if($dbs->fetchrow_array()){
             return 1;
         }
@@ -862,7 +847,7 @@ try{
 
         $db->do('COMMIT;');
         $db->disconnect();
-        $db =Settings::connectDB($userid, $pass);
+        $db  = Settings::connectDB();
         $dbs = $db->do("VACUUM;");
 
 
@@ -975,8 +960,8 @@ try{
 }
 
 sub logout {
-    $sss->delete();
-    $sss->flush();
+    Settings::session()->delete();
+    Settings::session()->flush();
     print $cgi->redirect("login_ctr.cgi");
     exit;
 }
@@ -1000,7 +985,7 @@ sub backupDelete {
     my $f = &Settings::logPath.$n;
 try{
     if (-e $f) {
-         LifeLogException->throw("File -> <i>[$n]</i> is not a backup file or it doesn't belong to $userid (you)!") if(index ($file , /bck_\d+$userid\_log/) == -1 );
+         LifeLogException->throw("File -> <i>[$n]</i> is not a backup file or it doesn't belong to $alias (you)!") if(index ($file , /bck_\d+$alias\_log/) == -1 );
          unlink($f) or LifeLogException->throw("Failed to delete $n! -> $!");
          print $cgi->redirect("config.cgi?CGISESSID=$sid");
     exit;
@@ -1019,9 +1004,9 @@ try{
 };
 }
 sub backup {
-
-   my $ball = 'bck__'.$today->strftime('%Y%m%d%H%M%S_')."$dbname.osz";
-   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 $pass = Settings::pass();
+   my $ball = 'bck_'.$today->strftime('%Y%m%d%H%M%S_')."_$dbname.osz";
+   my $pipe = "tar czf - ".Settings::logPath().'main.cnf' ." ". Settings::dbFile()." | openssl enc -e -des-ede3-cfb -salt -S ".Settings->CIPHER_KEY." -pass pass:$pass-$alias -out ".Settings::logPath().$ball." 2>/dev/null";
    my $rez = `$pipe`;
 
     #print $cgi->header;
@@ -1041,25 +1026,25 @@ sub restore {
 
     my $hndl = $cgi->upload("data_bck");
     my ($pipe,@br);
+    my $pass = Settings::pass();
     try{
 
-
-        &getHeader;
+        getHeader();
         print $cgi->start_html;
         print "<pre>Reading->$hndl</pre>";
         my $dbck = &Settings::logPath."bck/"; `mkdir $dbck` if (!-d $dbck);
         my $tar = $dbck.$hndl; $tar =~ s/osz$/tar/;
         my $pipe;
-        open ($pipe,  "| openssl enc -k $pass:$userid -d -des-ede3-cfb -in /dev/stdin 2>/dev/null > $tar"); #| tar zt");#1>/dev/null");
+        open ($pipe,  "| openssl enc -d -des-ede3-cfb -salt -S ".Settings->CIPHER_KEY." -pass pass:$pass-$alias -in /dev/stdin 2>/dev/null > $tar");
             while(<$hndl>){print $pipe $_;};
         close $pipe;
 
         print "<pre>\n";
         my $m1 = "it is not permitted to restore another aliases log backup.";
-        $m1= "has your log password changed?" if ($tar=~/_data_$userid/);
+        $m1= "has your log password changed?" if ($tar=~/_data_$alias/);
 
         my $cmd = `tar tvf $tar 2>/dev/null` 
-         or die qq(, possible an security issue, $m1\nBACKUP FILE INVALID! $tar\nYour data alias is: <b>$userid</b>\nYour LifeLog version is:), &Settings::release ."\n";
+         or die qq(, possible an security issue, $m1\nBACKUP FILE INVALID! $tar\nYour data alias is: <b>$alias</b>\nYour LifeLog version is:), Settings::release()."\n";
 
         print "Contents->".$cmd."\n\n";
         $cmd = `tar xzvf $tar -C $dbck --strip-components 1 2>/dev/null` or die "Failed extracting $tar";
@@ -1067,7 +1052,7 @@ sub restore {
 
         my $b_base = $dbck.$dbname;
         my $dsn= "DBI:SQLite:dbname=$b_base";
-        my $b_db = DBI->connect($dsn, $userid, $pass, { RaiseError => 1 }) or LifeLogException->throw(error=>"Invalid database! $dsn->$hndl [$@]", show_trace=>&Settings::debug);
+        my $b_db = DBI->connect($dsn, $alias, $pass, { RaiseError => 1 }) or LifeLogException->throw(error=>"Invalid database! $dsn->$hndl [$@]", show_trace=>&Settings::debug);
         print "Connected to -> $dsn\n";
 
         print "Merging from backup categories table...\n";
@@ -1124,7 +1109,7 @@ sub restore {
         print "Done!";
     }
     catch{
-        $ERROR = "<font color='red'><b>Restore Failed!</b></font> hndl->$hndl $@ \n";
+        $ERROR = "<font color='red'><b>Restore Failed!</b></font>hndl->$hndl $@ \n";
         $ERROR = "br:[@br]" if(@br);
     };
 
index 3759f8d924c6a7fb1b3c2b9de911d2ac2f1b40ab..01fef9ad23adc45159f1c83200061f0d2ad17bf4 100755 (executable)
@@ -22,7 +22,7 @@ use lib "system/modules";
 require Settings;
 my $BACKUP_ENABLED = 0;
 
-my $cgi = CGI->new;
+my $cgi = CGI->new();
 my $session = new CGI::Session("driver:File",$cgi, {Directory=>&Settings::logPath});
    $session->expire(&Settings::sessionExprs);
 my $sssCreatedDB = $session->param("cdb");
@@ -36,10 +36,9 @@ my ($debug,$frm) = "";
 #Codebase release version. Release in the created db or existing one can be different, through time.
 my $SCRIPT_RELEASE = Settings::release();
 
-if($cgi->param('logout')){&logout}
-
 try{
-    &checkAutologinSet;
+    logout() if($cgi->param('logout'));
+    checkAutologinSet();
     if(&processSubmit==0){
 
         print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie);
@@ -82,7 +81,7 @@ try{
                                 <a href="https://github.com/wbudic/LifeLog" target="_blank">Get latest version of this application here!</a><br>
                             </center><div>);
 
-    Settings::printDebugHTML($debug) if (&Settings::debug);
+    Settings::printDebugHTML($debug) if (Settings::debug());
     print $cgi->end_html;
 
     }
@@ -113,7 +112,8 @@ sub processSubmit {
                 $session->param('alias', $alias);
                 $session->param('passw', $passw);
                 $session->param('db_source', Settings::dbSrc());
-                $session->param('database',  Settings::dbFile());                
+                $session->param('db_file',   Settings::dbFile());
+                $session->param('database',  Settings::dbname());                
                 $session->flush();
                 ### To MAIN PAGE
                 print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie, -location=>"main.cgi");
@@ -142,7 +142,7 @@ sub parseAutonom { #Parses autonom tag for its crest value, returns undef if tag
 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: $!");
+    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);
@@ -546,16 +546,15 @@ return "SELECT name FROM sqlite_master WHERE type='view' AND name='$name';"
 
 sub logout {
 
-    if(&Settings::trackLogins){
+    if(Settings::trackLogins()){
     try{
         $alias = $session->param('alias');
         $passw = $session->param('passw');
-        Settings::dbSrc( $session->param('db_source'));
-        Settings::dbFile($session->param('database'));
-
-        my $db = Settings::connectDB($alias, $passw);
-        Settings::toLog($db, "Log properly loged out by $alias.");
-        $db->disconnect();
+        if($alias){
+            my $db = Settings::connectDB($alias, $passw);
+            Settings::toLog($db, "Log properly loged out by $alias.");
+            $db->disconnect();
+        }
     }catch{
         my $err = $@;
         my $dbg = "" ;
index 62379d86833626478712ff66dd40a3de17cc3871..f016951d095c13cfe036726ea1ae7e6d57e6a845 100755 (executable)
@@ -9,9 +9,6 @@ use Exception::Class ('LifeLogException');
 use Syntax::Keyword::Try;
 use Switch;
 
-use CGI;
-use CGI::Session '-ip_match';
-use CGI::Carp qw ( fatalsToBrowser );
 use DBI;
 
 use DateTime;
@@ -24,38 +21,29 @@ use Time::localtime;
 use Regexp::Common qw /URI/;
 use List::MoreUtils qw(uniq);
 use Gzip::Faster;
+use Data::Dumper;
 
 #DEFAULT SETTINGS HERE!
 use lib "system/modules";
 require Settings;
-$CGI::POST_MAX = 1024 * 1024 * 5;  # max 5GB file post size limit.
 
-my $cgi     = CGI->new;
-my $sss     = new CGI::Session( "driver:File", $cgi, { Directory => &Settings::logPath } );
-my $sid     = $sss->id();
+my $db      = Settings::fetchDBSettings();
+my $cgi     = Settings::cgi();
+my $sss     = Settings::session();
+my $sid     = Settings::sid(); 
+my $dbname  = Settings::dbname();
+my $alias   = Settings::alias();
+my $passw   = Settings::pass();
 
-my $alias   = $sss->param('alias');
-my $passw   = $sss->param('passw');
 my $sssCDB  = $sss->param('cdb');
-my $vmode;
-
-Settings::dbSrc( $sss->param('db_source'));
-Settings::dbFile($sss->param('database'));
-use Data::Dumper;
-
+my ($vmode, $imgw, $imgh );
 
 if ( !$alias ||  !$passw) {
     print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid");
     exit;
 }
-# print $cgi->header, '<pre>dbFile:'.Settings::dbFile()."\n". Dumper(\$sss).'</pre>';
-# exit;
-my $db = Settings::connectDB($alias, $passw);
-my ( $imgw, $imgh );
-#Fetch settings
- Settings::getConfiguration($db);
- Settings::getTheme();
-### Authenticate sss to alias passw
+
+### Authenticate session to alias passw
     &authenticate;
 #
 my $log_rc      = 0;
index 7718bb95e0926ceeed5c2b90847d4ae59ec54838..bd70b24a0f1b38fe2940d80d6c85248be795cc87 100755 (executable)
@@ -23,18 +23,18 @@ use lib $ENV{'PWD'}.'/htdocs/cgi-bin/system/modules';
 require Settings;
 
 my $cgi     = CGI->new();
-my $sss     = new CGI::Session("driver:File",$cgi, {Directory=>&Settings::logPath});
-my $sid     = $sss->id();
-my $dbname  = $sss->param('database');
-my $userid  = $sss->param('alias');
-my $pass    = $sss->param('passw');
-my $db;
-
-if(!$userid||!$dbname){
+my $db      = Settings::fetchDBSettings($cgi);
+my $sss     = Settings::session();
+my $sid     = Settings::sid(); 
+my $dbname  = Settings::dbname();
+my $alias   = Settings::alias();
+my $passw   = Settings::pass();
+
+if(!$alias||!$dbname){
     if (Settings::debug()){
-        $userid ="admin";
+        $alias  ="admin";
         $dbname = "data_admin_log.db";
-        $pass   = "admin";
+        $passw  = "admin";
     }
     else{
         print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid");
@@ -43,13 +43,6 @@ if(!$userid||!$dbname){
 }
 try{
 
-Settings::dbSrc( $sss->param('db_source'));
-Settings::dbFile($sss->param('database'));
-### Fetch settings
-    $db = Settings::connectDB($userid, $pass);
-    Settings::getConfiguration($db);
-    Settings::getTheme();
-###
 my $today = DateTime->now;
 $today->set_time_zone(&Settings::timezone);
 
index 06e8a904422dbcb948d68b1d63e0e79a69171094..beafd0bfe6409c92eb71a72d819b587338275118 100644 (file)
@@ -10,6 +10,10 @@ use warnings;
 use Switch;
 use Exception::Class ('SettingsException');
 use Syntax::Keyword::Try;
+use CGI;
+use CGI::Session '-ip_match';
+use CGI::Carp qw ( fatalsToBrowser );
+
 
 use DBI;
 
@@ -41,6 +45,8 @@ our $DSN;
 our $DBFILE;
 our $IS_PG_DB     = 0;
 
+my ($cgi, $sss, $sid, $alias, $pass, $dbname);
+
 
 #Annons here, variables that could be overiden in  code or database, per need.
 my %anons = ();
@@ -84,9 +90,40 @@ sub debug          {my $r = shift; if(!$r){$r = $DEBUG}else{$DEBUG=$r}  return $
 sub dbSrc          {my $r = shift; if($r) {$DBI_SOURCE=$r; $IS_PG_DB = 1 if(index (uc $r, 'DBI:PG') ==0)}  
                     return $DBI_SOURCE}
 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 fetchDBSettings {
+try {
+    $CGI::POST_MAX = 1024 * 1024 * 5;  # max 5GB file post size limit.
+    $cgi     = CGI->new();    
+    $sss     = new CGI::Session("driver:File", $cgi, {Directory=>$LOG_PATH});
+    $sid     = $sss->id();
+    $dbname  = $sss->param('database');
+    $alias   = $sss->param('alias');
+    $pass    = $sss->param('passw');
+    if(!$alias||!$dbname){
+        print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid&alias=$alias&dbname=$dbname");
+        exit;
+    }
+    my $ret  = connectDB($alias, $pass);
+    dbSrc($sss->param('db_source'));    
+    getConfiguration($ret);
+    getTheme();
+    $sss->expire($SESSN_EXPR);
+    return $ret;
+}catch{
+    SettingsException->throw(error=>$@, show_trace=>$DEBUG);
+    exit;
+}
+}
+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 createCONFIGStmt {
 if($IS_PG_DB){qq(
@@ -490,11 +527,14 @@ sub configProperty {
 
 sub connectDB {
     my ($a,$p) = @_;
-    $DBFILE = $LOG_PATH.'data_'.$a.'_log.db' if(!$DBFILE);    
+    $a = $alias if(!$a);
+    $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
+        $DSN = $DBI_SOURCE .'dbname='.$DBFILE;        
     }
     try{
         return DBI->connect($DSN, $a, $p, {AutoCommit => 1, RaiseError => 1, PrintError => 0, show_trace=>1});