From b6d9c5657ca678b2adc4853e4f4b474cdf933d97 Mon Sep 17 00:00:00 2001 From: Will Budic Date: Tue, 25 Feb 2020 22:08:58 +1100 Subject: [PATCH] dev --- htdocs/cgi-bin/config.cgi | 75 +++++++++-------------- htdocs/cgi-bin/data.cgi | 8 +-- htdocs/cgi-bin/system/modules/Settings.pm | 36 +++++++++-- 3 files changed, 65 insertions(+), 54 deletions(-) diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index 527b3a8..ca19915 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -78,6 +78,7 @@ my $status = "Ready for change!"; my $cats; my %hshCats = {}; &cats; + ############### &processSubmit; ############### @@ -131,8 +132,10 @@ my $frmCats = qq( -     or - Categories Configuration In -> $dbname  +     + or + Categories Configuration In -> $dbname  +
WARNING! @@ -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 .= "$file
"; +} +if(length $bck_list == 0){ +$bck_list = '

Restore will bring back and merge log entries from the time of backup.

'; +} +else{ + $bck_list = qq(

Tick Select Backup to Restore or Delete

$bck_list

); +} + + # # Page printout from here! # @@ -365,8 +388,8 @@ print qq(

Backup File Format


-

Restore will bring back and merge log entries from the time of backup.


-
+
$bck_list

+

CSV File Format

@@ -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 "SERVER ERROR->updCnf[$s]:".$_; - } -} - - 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 ; 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"); } diff --git a/htdocs/cgi-bin/data.cgi b/htdocs/cgi-bin/data.cgi index 56b93a0..a306b75 100755 --- a/htdocs/cgi-bin/data.cgi +++ b/htdocs/cgi-bin/data.cgi @@ -62,9 +62,9 @@ $today->set_time_zone(&Settings::timezone); my $tbl_rc =0; my ($stm,$st, $rv); -my $tbl = '
+my $tbl = ' - '; + '; my $datediff = $cgi->param("datediff"); @@ -135,7 +135,7 @@ sub DisplayDateDiffs{ } $tbl .= '
Date TimeLogCategory
Date Time Log Category
'; -print '
'.$tbl.'

'; +print '
'.$tbl.'

'; } @@ -236,7 +236,7 @@ sub NotConfirmed { $plural = "s"; } - $tbl = $tbl . ' + $tbl = $tbl . '

Please Confirm You Want
The Above Record'.$plural.' Deleted?

(Or hit you Browsers Back Button!)
diff --git a/htdocs/cgi-bin/system/modules/Settings.pm b/htdocs/cgi-bin/system/modules/Settings.pm index 2b33969..6d20be9 100644 --- a/htdocs/cgi-bin/system/modules/Settings.pm +++ b/htdocs/cgi-bin/system/modules/Settings.pm @@ -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 + ); + } + } } } -- 2.34.1