]> lifelog.hopto.org Git - LifeLog.git/commitdiff
dev
authorWill Budic <redacted>
Tue, 25 Feb 2020 11:08:58 +0000 (22:08 +1100)
committerWill Budic <redacted>
Tue, 25 Feb 2020 11:08:58 +0000 (22:08 +1100)
htdocs/cgi-bin/config.cgi
htdocs/cgi-bin/data.cgi
htdocs/cgi-bin/system/modules/Settings.pm

index 527b3a8bbfb867bc7682b7996b5c447f94b74586..ca19915b3ec36d7da9cbdbba89927316fc3decdc 100755 (executable)
@@ -78,6 +78,7 @@ my $status = "Ready for change!";
 my $cats;
 my %hshCats = {};
 &cats;
+
 ###############
 &processSubmit;
 ###############
@@ -131,8 +132,10 @@ my  $frmCats = qq(
          <td align="left"><input type="text" name="cade" value="" size="64"/></td>
         </tr>
       <tr class="r1">
-         <td colspan="2"><a href="#bottom">&#x21A1;</a>&nbsp;&nbsp;&nbsp;<input type="submit" value="Add New Category First" onclick="return submitNewCategory()"/> or <input type="submit" value="Change"/></td>
-         <td colspan="1" align="right"><b>Categories Configuration In -> $dbname</b>&nbsp;<input type="submit" value="Change" onclick="return checkConfigCatsChange()"/></td>
+         <td colspan="2"><a href="#bottom">&#x21A1;</a>&nbsp;&nbsp;&nbsp;
+         <input type="submit" value="Add New Category First" onclick="return submitNewCategory()"/> or <input type="submit" value="Change"/></td>
+         <td colspan="1" align="right"><b>Categories Configuration In -> $dbname</b>&nbsp;
+         <input type="submit" value="Change" onclick="return checkConfigCatsChange()"/></td>
         </tr>
         <tr class="r1">
           <td colspan="3"><div style="text-align:left; float"><font color="red">WARNING!</font>
@@ -345,6 +348,26 @@ my  $frmPASS = qq(
         );
 
 
+my @backups = ();
+my ($file,$bck_list) ="";
+opendir my $dir, &Settings::logPath;
+while($file = readdir $dir){
+next if $file eq '.' or $file eq '..' or index ($file , 'bck_') == -1;
+  push @backups, $file;
+}
+close $dir;
+foreach $file (sort @backups){
+    #my $n = substr $file, length(&Settings::logPath);
+    $bck_list .=  "<input name='bck_file' type='radio' value='$file'>$file</input><br>";
+}
+if(length $bck_list == 0){
+$bck_list = '<p>Restore will bring back and merge log entries from the time of backup.</p>';
+}
+else{
+    $bck_list = qq(<p>Tick Select Backup to Restore or Delete</p><p>$bck_list</p>);
+}
+
+
 #
 #  Page printout from here!
 #
@@ -365,8 +388,8 @@ print qq(
                 <tr><td><H3>Backup File Format</H3></td></tr>
                 <tr><td><input type="button" onclick="return fetchBackup();" value="Fetch"/><hr></td></tr>
 
-                <tr><td><p>Restore will bring back and merge log entries from the time of backup.</p><hr></td></tr>
-                <tr><td><input type="file" name="data_bck" /><input type="button" onclick="return restoreBackup();" value="Restore"/><hr></td></tr>
+                <tr><td><div id="div_backups">$bck_list</div><hr></td></tr>
+                <tr><td><input type="button" onclick="return deleteBackup();" value="Delete"/> <input type="file" name="data_bck" /><input type="button" onclick="return restoreBackup();" value="Restore"/><hr></td></tr>
 
 
                 <tr><td><H3>CSV File Format</H3></td></tr>
@@ -908,58 +931,20 @@ sub changeSystemSettings {
     while (my @r=$dbs->fetchrow_array()){
         my $var = $cgi->param('var'.$r[0]);
         if(defined $var){
-            updCnf($r[0],$var);
+            Settings::configProperty($db, $r[0], undef, $var);
             $updated = 1;
         }
     }
     Settings::getConfiguration($db) if($updated);
 }
 
-sub updCnf {
-    my ($id, $val, $s) = @_;
-    $s = "UPDATE CONFIG SET VALUE='".$val."' WHERE ID=".$id.";";
-    try{
-          Settings::selectRecords($db, $s);
-    }
-    catch{
-        print "<font color=red><b>SERVER ERROR</b>->updCnf[$s]</font>:".$_;
-    }
-}
-
-
 sub backup {
 
-   # my $ball2 = qwq(tar -czf - data_*_log.db | openssl enc -e -des-ede3-cfb -out secured.tgz);
-   #openssl enc -d -des-ede3-cfb -in secured.tar.gz | tar xz -C test
 
-   my $ball = $today->strftime('%Y%m%d%H%M%S_')."$dbname.osz";
+   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;
    `$pipe`;
 
-    # my $ball = $today->strftime('%Y%m%d%H%M%S_')."$dbname.tgz";
-    # my $pipe = new IO::File("| openssl enc -k $pass:$userid -e -des-ede3-cfb | gzip -c >".Settings::logPath().$ball);
-    # my @fls =(&Settings::logPath.'main.cnf',$database);
-    # my $tar = Archive::Tar->new();
-    #    $tar-> add_files(@fls);
-    #    $tar->write($pipe);
-    #    $pipe->close;
-
-    # my @tar = qw("tar -czf ");
-    # push @tar, &Settings::logPath. "data_*_log.db";
-    # push @tar, qw(|openssl enc -e -pbkdf2 -out);
-    # push @tar, $ball;
-    # my $res = run @tar;
-
-
-
-
-    # my $tar = Archive::Tar->new();
-    # my @fls =(&Settings::logPath.'main.cnf',$database);
-    #    $tar-> add_files(@fls);
-    #    $tar->write(Settings::logPath().$ball,9);
-
-    # Not allowed following for now
-    #
     print $cgi->header(-type=>"application/octet-stream", -attachment=>"$ball");
     select(STDOUT); $| = 1;   #unbuffer STDOUT
     binmode STDOUT;
@@ -967,7 +952,7 @@ sub backup {
     print <TAR>;
     close TAR;
 
-    LifeLogException->throw("Backup feature currently under development! Serverside created files is -> $ball");
+     #LifeLogException->throw("Backup feature currently under development! Serverside created files is -> $ball");
 
 }
 
index 56b93a0105cd0f86611d0d024cdffdede24bca4b..a306b75c1f12f98307e3fb879c4fb6121bdf5f03 100755 (executable)
@@ -62,9 +62,9 @@ $today->set_time_zone(&Settings::timezone);
 my $tbl_rc =0;
 my ($stm,$st, $rv);
 
-my $tbl = '<form name="frm_log_del" action="data.cgi" onSubmit="return formDelValidation();">
+my $tbl = '<a name="top"></a><form name="frm_log_del" action="data.cgi" onSubmit="return formDelValidation();">
            <table class="tbl_rem" width="'.$PRC_WIDTH.'%">
-           <tr class="hdr" style="text-align:left;"><th>Date</th> <th>Time</th><th>Log</th><th>Category</th></tr>';
+           <tr class="hdr" style="text-align:left;"><th>Date <a href="#bottom">&#x21A1;</a></th> <th>Time</th> <th>Log</th> <th>Category</th></tr>';
 
 
 my $datediff = $cgi->param("datediff");
@@ -135,7 +135,7 @@ sub DisplayDateDiffs{
     }
     $tbl .= '</table>';
 
-print '<center><div>'.$tbl.'</div><br><div><a href="main.cgi">Back to Main Log</a></div></center>';
+print '<a name="top"></a><center><div>'.$tbl.'</div><br><div><a href="main.cgi">Back to Main Log</a></div></center>';
 }
 
 
@@ -236,7 +236,7 @@ sub NotConfirmed {
         $plural = "s";
     }
 
- $tbl = $tbl .  '<tr class="r0"><td colspan="4">
+ $tbl = $tbl .  '<tr class="r0"><td colspan="4"><a name="bottom"></a><a href="#top">&#x219F;</a>
  <center>
  <h2>Please Confirm You Want<br>The Above Record'.$plural.' Deleted?</h2>
  (Or hit you Browsers Back Button!)</center>
index 2b33969dd94bfedb74ee2d963c1d61b195000bd2..6d20be9c421f5722690fef1b31ddf306ddaf94fc 100644 (file)
@@ -325,17 +325,43 @@ sub obtainProperty {
 sub configProperty {
     my($db, $id, $name, $value) = @_;
     $id = '0' if not $id;
-    if(!$db || !$name|| not defined $value){
+    if($db eq undef || $value eq undef){
         SettingsException->throw(
             error => "ERROR Invalid number of arguments in call -> Settings::configProperty('$db',$id,'$name','$value')\n",  show_trace=>$DEBUG
             );
     };
-    my $dbs = selectRecords($db, "SELECT ID, NAME FROM CONFIG WHERE NAME IS '$name';");
-    if($dbs->fetchrow_array()){
-       $db->do("UPDATE CONFIG SET VALUE = '$value' WHERE NAME IS '$name';");
+    if($name eq undef && $id){
+
+        my $sql = "UPDATE CONFIG SET VALUE='".$value."' WHERE ID=".$id.";";
+        try{
+            $db->do($sql);
+        }
+        catch{
+
+            SettingsException->throw(
+                error => "ERROR with $sql -> Settings::configProperty('$db',$id,'$name','$value')\n",
+                show_trace=>$DEBUG
+                );
+        }
     }
     else{
-       $db->do("INSERT INTO CONFIG (ID, NAME, VALUE) VALUES ($id, '$name', '$value');");
+        my $dbs = selectRecords($db, "SELECT ID, NAME FROM CONFIG WHERE NAME IS '$name';");
+        if($dbs->fetchrow_array()){
+            $db->do("UPDATE CONFIG SET VALUE = '$value' WHERE NAME IS '$name';");
+        }
+        else{
+            my $sql = "INSERT INTO CONFIG (ID, NAME, VALUE) VALUES ($id, '$name', '$value');";
+            try{
+                $db->do($sql);
+            }
+            catch{
+
+                SettingsException->throw(
+                    error => "ERROR $@ with $sql -> Settings::configProperty('$db',$id,'$name','$value')\n",
+                    show_trace=>$DEBUG
+                    );
+            }
+        }
     }
 }