show search archive and burn media CGI interface
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 3 Jan 2011 21:21:04 +0000 (21:21 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 3 Jan 2011 21:21:04 +0000 (21:21 +0000)
cgi-bin/BackupPC_Admin
lib/BackupPC/CGI/BurnMedia.pm [new file with mode: 0644]
lib/BackupPC/CGI/Lib.pm
lib/BackupPC/CGI/SearchArchives.pm [new file with mode: 0644]
lib/BackupPC/Lang/en.pm

index ce057d0..90dfdba 100755 (executable)
@@ -58,6 +58,8 @@ BackupPC::CGI::Lib::NewRequest;
 
 my %ActionDispatch = (
     "summary"                   => "Summary",
 
 my %ActionDispatch = (
     "summary"                   => "Summary",
+    "search"                     => "SearchArchives",
+    "burn"                       => "BurnMedia",    
     "Start_Incr_Backup"          => "StartStopBackup",
     "Start_Full_Backup"          => "StartStopBackup",
     "Stop_Dequeue_Backup"        => "StartStopBackup",
     "Start_Incr_Backup"          => "StartStopBackup",
     "Start_Full_Backup"          => "StartStopBackup",
     "Stop_Dequeue_Backup"        => "StartStopBackup",
diff --git a/lib/BackupPC/CGI/BurnMedia.pm b/lib/BackupPC/CGI/BurnMedia.pm
new file mode 100644 (file)
index 0000000..8f29a07
--- /dev/null
@@ -0,0 +1,150 @@
+package BackupPC::CGI::BurnMedia;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+use BackupPC::SearchLib;
+use Data::Dumper;
+use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
+
+my $dsn = $Conf{SearchDSN};
+my $db_user = $Conf{SearchUser} || '';
+
+sub action() {
+       my $cont = "";
+       my $title;
+       my $subtitle;
+       my @files;
+
+       my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 0 } );
+
+       BackupPC::CGI::Lib::NewRequest();
+#      $cont = Dumper(%In);
+       if (!defined($In{submitBurner})) {
+               $title = eval(q{ ${h1($Lang->{Burn_media})}});
+               $cont = Dumper(%In);
+               $subtitle = eval(q{ ${h2($Lang->{Burn_media_select})}});
+               $cont = <<EOF;
+
+       $title
+       $subtitle
+       
+EOF
+             
+               $cont .= "Backups that have not been archived:<br>";
+               $cont .= BackupPC::SearchLib::displayBackupsGrid( \%In );
+           
+       } else {
+
+               my @selected_backup_ids;
+
+               my $total_size = 0;
+               my $selected = 0;
+
+               my $parts = 1;
+               foreach my $key(keys(%In)) {
+                       if ($key =~ m/^fcb([0-9]+)_([0-9]+)_([0-9]+)$/gi) {
+
+                               my ($host_id, $backup_num, $backup_id) = ($1,$2,$3);
+                               push @selected_backup_ids, $backup_id;
+                               my $currSize = BackupPC::SearchLib::getGzipSizeFromBackupID($backup_id);
+                               my $sth_size = $dbh->prepare(q{select inc_size from backups where id = ?});
+                               $sth_size -> execute( $backup_id );
+                               my $db_size = $sth_size->fetchrow_hashref()->{inc_size};
+
+                               if ($db_size != $currSize) {
+                                       $cont .= "NOT EQUAL!: [fs_size:$currSize, db_size:$db_size, backup_id:$backup_id] <br />";
+                               }
+                               
+                               if ($currSize > 0) {
+                                       $total_size += $currSize;
+                               } 
+                               $selected++;
+
+                               my ($this_part) = $dbh->selectrow_array("select parts from backups where id = ?", undef, $backup_id);
+                               $this_part--;
+                               $parts += $this_part;
+                       } 
+               }
+
+               if ($total_size > ($Conf{MaxArchiveSize} * $parts)) {
+                       $cont .= eval( q{ ${h2(Error)}});
+                       $cont .= "Selected backups size " . sprintf("%1.2f", $total_size / 1024) ." Kb exceed max archive size " . sprintf("%1.2f", $Conf{MaxArchiveSize} / 1024) ." Kb.";
+               } elsif ($total_size == 0) {
+                       $cont .= eval( q{ ${h2(Error)}});
+                       $cont .= "No backups selected.";
+               } else {
+
+                       # create new archive
+                       my $sth = $dbh->prepare(q{
+                               INSERT INTO archive (
+                                       id,
+                                       dvd_nr,
+                                       note,
+                                       username,
+                                       date,
+                                       total_size
+                               ) VALUES (
+                                       nextVal('archive_id_seq'),
+                                       nextVal('dvd_nr'),
+                                       ?,
+                                       ?,
+                                       NOW(),
+                                       ?
+                               )
+                       });
+
+                       $sth->execute($In{'note'}, $User, $total_size);
+
+                       foreach my $backup_id (@selected_backup_ids) {
+
+                               # link backups with archive
+                               my $sth = $dbh->prepare(q{
+                                       INSERT INTO archive_backup (
+                                               archive_id, backup_id
+                                       ) VALUES (
+                                               (SELECT last_value FROM archive_id_seq), ?
+                                       )
+                               });
+
+                               $sth->execute($backup_id);
+
+                               $dbh->commit();
+
+                       }
+
+                       my ($dvd_nr) = $dbh->selectrow_array(qq{
+                               select last_value from dvd_nr
+                       });
+
+                       $dvd_nr ||= 'error';
+
+                       $dbh->commit();
+
+                       my $db_size = 0;
+                       $sth = $dbh->prepare('SELECT SUM(gzip_size) AS suma FROM backups_on_dvds WHERE dvd_nr=?');
+                       $sth->execute($dvd_nr);
+                       $db_size = $sth->fetchrow_hashref()->{suma};
+                       $sth->finish();
+                       
+                       $cont .= q{
+                               Archived following backups:
+                       } . join(", ", @selected_backup_ids) . q{
+                               <br/>with total size of
+                       <b>} . sprintf("%1.2f Mb", $total_size / 1024 / 1024) 
+                       . q{</b>
+                               to media <b>} . $dvd_nr . q{</b>
+                               with following message:
+                               <div style="background-color: #e0e0e0; display: inline; padding: 2px;">
+                       } . $In{'note'} . q{
+                               </div>
+                       };
+               }
+       }
+
+       Header($Lang->{Burn_media}, "", 1, "", $cont);
+
+       Trailer();
+       $dbh->disconnect();
+}
+
+1;
index d55b56c..a1d06aa 100644 (file)
@@ -354,6 +354,10 @@ sub CheckPermission
 
     $Privileged ||= $User eq $Hosts->{$host}{user};
     $Privileged ||= defined($Hosts->{$host}{moreUsers}{$User});
 
     $Privileged ||= $User eq $Hosts->{$host}{user};
     $Privileged ||= defined($Hosts->{$host}{moreUsers}{$User});
+
+    # XXX check against REMOTE_NTGROUP from mod_ntlm
+    $Privileged ||= $Conf{CgiAdminUserGroup} eq $ENV{REMOTE_NTGROUP};
+
     return $Privileged;
 }
 
     return $Privileged;
 }
 
@@ -437,6 +441,11 @@ sub Header
                                            priv => 1},
         { link => "?action=queue",         name => $Lang->{Current_queues},
                                            priv => 1},
                                            priv => 1},
         { link => "?action=queue",         name => $Lang->{Current_queues},
                                            priv => 1},
+       # XXX additional search extensions
+        { link => "?action=search",        name => $Lang->{Search_archive},
+                                           priv => 0},
+        { link => "?action=burn",          name => $Lang->{Burn_media},
+                                           priv => 1},
         @{$Conf{CgiNavBarLinks} || []},
     );
     my $host = $In{host};
         @{$Conf{CgiNavBarLinks} || []},
     );
     my $host = $In{host};
diff --git a/lib/BackupPC/CGI/SearchArchives.pm b/lib/BackupPC/CGI/SearchArchives.pm
new file mode 100644 (file)
index 0000000..3e1ce0a
--- /dev/null
@@ -0,0 +1,96 @@
+####################################################################
+#  SearchArchives.pm - module for searching through archived files #
+#                      via a sqlite database                       #
+####################################################################
+package BackupPC::CGI::SearchArchives;
+
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+use BackupPC::SearchLib;
+use Data::Dumper;
+use HTML::FillInForm;
+use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
+
+sub action() {
+       my $hosts_html = "";
+
+    
+       BackupPC::CGI::Lib::NewRequest();
+       my @hosts = BackupPC::SearchLib::getUnits();
+
+       foreach my $host (@hosts) {
+               $hosts_html .= "<option value=" . $host->{'id'} . "> " . $host->{'share'} . " </option>\n";
+        }
+
+       sub date_from_to_html {
+               my $name = shift || return;
+               return qq{
+                       <input type="text" name="${name}_year_from" size="4">
+                       <input type="text" name="${name}_month_from" size="2">
+                       <input type="text" name="${name}_day_from" size="2">
+                       -
+                       <input type="text" name="${name}_year_to" size="4">
+                       <input type="text" name="${name}_month_to" size="2">
+                       <input type="text" name="${name}_day_to" size="2">
+               };
+       }
+
+        my $form .= qq{
+<form name="searchForm" method="GET" action="$MyURL">
+<p>
+       Filename:
+       <input type="text" name="search_filename" size="50">
+       &nbsp;
+       on share
+       &nbsp;
+       <select name="search_share">$hosts_html</select>
+       &nbsp;show&nbsp;
+       <select name="burned">
+       <option value="">all</a>
+       <option value="burned">burned</a>
+       <option value="pending">pending</a>
+       </select>
+       files
+       &nbsp;&nbsp;&nbsp;
+       <input type="submit" value="Search">
+</p>
+
+<p style="color:gray;">
+       file(s) between:
+       } . date_from_to_html('search') . qq{
+       &nbsp;&nbsp;
+       backups between:
+       } . date_from_to_html('search_backup') . qq{
+       (yyyy-mm-dd)
+</p>
+
+<p style="color: gray;">
+       <input type="checkbox" name="use_hest"> use faster full-text search engine
+</p>
+
+<input type="hidden" value="search" name="action">
+<input type="hidden" value="results" name="search_results">
+</form>
+       };
+
+       my $html = eval(q{ ${h1("Search")}});
+
+       if ( !defined($In{search_results}) ) {
+               $html .= eval(q{ ${h2("Search criteria")}});
+
+               $html .= $form;
+       } else {
+               $html .= eval(q{ ${h2("Search results")}});
+
+               my $fif = new HTML::FillInForm;
+               $html .= $fif->fill(scalarref => \$form, fdat => \%In);
+
+               $html .= BackupPC::SearchLib::displayGrid( \%In );
+       }
+
+       Header( eval("qq{$Lang->{Search_archive}}"), "", 1, "", $html );
+       Trailer();
+}
+
+1;
index 9f1b3bc..9d8f3ec 100644 (file)
@@ -1470,5 +1470,11 @@ $Lang{CfgEdit_Log_Host_Change}
             = "\$User host \$host changed \$key from \$valueOld to \$valueNew\n";
 $Lang{CfgEdit_Log_Host_Add}
             = "\$User added host \$host: \$value\n";
             = "\$User host \$host changed \$key from \$valueOld to \$valueNew\n";
 $Lang{CfgEdit_Log_Host_Add}
             = "\$User added host \$host: \$value\n";
+
+# search extension
+$Lang{Search_archive} = "Search archive";
+$Lang{Burn_media} = "Archive to backup medium";
+$Lang{Burn_media_select} = "Select files to archive to medium";
+$Lang{Burn_media_assign} = "Files assigned to medium $mediumNum";
   
 #end of lang_en.pm
   
 #end of lang_en.pm