X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=cgi-bin%2FBackupPC_Admin;h=ac43d85845038463a3a9252bba6fcde0674fa6e4;hb=dcb39df8e33e09eabfb4eae471c2e6447094d0e2;hp=cac9707afff973e4723701bf96737f5013401b53;hpb=2fb1e8b5cee74c72bbb8ecc7722c05256cbdc6bf;p=BackupPC.git
diff --git a/cgi-bin/BackupPC_Admin b/cgi-bin/BackupPC_Admin
index cac9707..ac43d85 100755
--- a/cgi-bin/BackupPC_Admin
+++ b/cgi-bin/BackupPC_Admin
@@ -1,4 +1,4 @@
-#!/bin/perl -T
+#!/bin/perl
#============================================================= -*-perl-*-w
#
# BackupPC_Admin: Apache/CGI interface for BackupPC.
@@ -21,7 +21,7 @@
# Craig Barratt ${HostLink($host)}
- ${UserLink($Hosts->{$host}{user})}
- $fullCnt
- $fullAge
- $fullSize
- $fullRate
- $incrCnt
- $incrAge
- $Lang->{$Status{$host}{state}}
- $Lang->{$Status{$host}{reason}}
-EOF
- if ( @Backups == 0 ) {
- $hostCntNone++;
- $strNone .= $str;
- } else {
- $hostCntGood++;
- $strGood .= $str;
- }
- }
- $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
- $incrSizeTot = sprintf("%.2f", $incrSizeTot / 1000);
- my $now = timeStamp2(time);
-
- Header($Lang->{BackupPC__Server_Summary});
- print eval ("qq{$Lang->{BackupPC_Summary}}");
-
- Trailer();
-}
-
-sub Action_StartStopBackup
-{
- my($str, $reply);
-
- my $start = 1 if ( $In{action} eq $Lang->{Start_Incr_Backup}
- || $In{action} eq $Lang->{Start_Full_Backup} );
- my $doFull = $In{action} eq $Lang->{Start_Full_Backup} ? 1 : 0;
- my $type = $doFull ? "full" : "incremental";
- my $host = $In{host};
- my $Privileged = CheckPermission($host);
-
- if ( !$Privileged ) {
- ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_stop_or_start_backups}}"));
- }
- ServerConnect();
-
- if ( $In{doit} ) {
- if ( $start ) {
- if ( $Hosts->{$host}{dhcp} ) {
- $reply = $bpc->ServerMesg("backup $In{hostIP} $host"
- . " $User $doFull");
- $str = eval("qq{$Lang->{Backup_requested_on_DHCP__host}}");
- } else {
- $reply = $bpc->ServerMesg("backup $host $host $User $doFull");
- $str = eval("qq{$Lang->{Backup_requested_on__host_by__User}}");
- }
- } else {
- $reply = $bpc->ServerMesg("stop $host $User $In{backoff}");
- $str = eval("qq{$Lang->{Backup_stopped_dequeued_on__host_by__User}}");
- }
-
- Header(eval ("qq{$Lang->{BackupPC__Backup_Requested_on__host}}") );
- print (eval ("qq{$Lang->{REPLY_FROM_SERVER}}"));
-
- Trailer();
- } else {
- if ( $start ) {
- my $ipAddr = ConfirmIPAddress($host);
-
- Header(eval("qq{$Lang->{BackupPC__Start_Backup_Confirm_on__host}}"));
- print (eval("qq{$Lang->{Are_you_sure_start}}"));
- } else {
- my $backoff = "";
- GetStatusInfo("host($host)");
- if ( $StatusHost{backoffTime} > time ) {
- $backoff = sprintf("%.1f",
- ($StatusHost{backoffTime} - time) / 3600);
- }
- Header($Lang->{BackupPC__Stop_Backup_Confirm_on__host});
- print (eval ("qq{$Lang->{Are_you_sure_stop}}"));
- }
- Trailer();
- }
-}
-
-sub Action_Queue
-{
- my($strBg, $strUser, $strCmd);
-
- GetStatusInfo("queues");
- my $Privileged = CheckPermission();
-
- if ( !$Privileged ) {
- ErrorExit($Lang->{Only_privileged_users_can_view_queues_});
- }
-
- while ( @BgQueue ) {
- my $req = pop(@BgQueue);
- my($reqTime) = timeStamp2($req->{reqTime});
- $strBg .= < ${HostLink($req->{host})}
- $reqTime
- $req->{user}
-EOF
- }
- while ( @UserQueue ) {
- my $req = pop(@UserQueue);
- my $reqTime = timeStamp2($req->{reqTime});
- $strUser .= < ${HostLink($req->{host})}
- $reqTime
- $req->{user}
-EOF
- }
- while ( @CmdQueue ) {
- my $req = pop(@CmdQueue);
- my $reqTime = timeStamp2($req->{reqTime});
- (my $cmd = $req->{cmd}) =~ s/$BinDir\///;
- $strCmd .= < ${HostLink($req->{host})}
- $reqTime
- $req->{user}
- $cmd
-EOF
- }
- Header($Lang->{BackupPC__Queue_Summary});
-
- print ( eval ( "qq{$Lang->{Backup_Queue_Summary}}") );
-
- Trailer();
-}
-
-sub Action_View
-{
- my $Privileged = CheckPermission($In{host});
- my $compress = 0;
- my $fh;
- my $host = $In{host};
- my $num = $In{num};
- my $type = $In{type};
- my $linkHosts = 0;
- my($file, $comment);
- my $ext = $num ne "" ? ".$num" : "";
-
- ErrorExit(eval("qq{$Lang->{Invalid_number__num}}")) if ( $num ne "" && $num !~ /^\d+$/ );
- if ( $type eq "XferLOG" ) {
- $file = "$TopDir/pc/$host/SmbLOG$ext";
- $file = "$TopDir/pc/$host/XferLOG$ext" if ( !-f $file && !-f "$file.z");
- } elsif ( $type eq "XferLOGbad" ) {
- $file = "$TopDir/pc/$host/SmbLOG.bad";
- $file = "$TopDir/pc/$host/XferLOG.bad" if ( !-f $file && !-f "$file.z");
- } elsif ( $type eq "XferErrbad" ) {
- $file = "$TopDir/pc/$host/SmbLOG.bad";
- $file = "$TopDir/pc/$host/XferLOG.bad" if ( !-f $file && !-f "$file.z");
- $comment = "(Extracting only Errors)";
- } elsif ( $type eq "XferErr" ) {
- $file = "$TopDir/pc/$host/SmbLOG$ext";
- $file = "$TopDir/pc/$host/XferLOG$ext" if ( !-f $file && !-f "$file.z");
- $comment = "(Extracting only Errors)";
- } elsif ( $type eq "RestoreLOG" ) {
- $file = "$TopDir/pc/$host/RestoreLOG$ext";
- } elsif ( $type eq "RestoreErr" ) {
- $file = "$TopDir/pc/$host/RestoreLOG$ext";
- $comment = "(Extracting only Errors)";
- } elsif ( $host ne "" && $type eq "config" ) {
- $file = "$TopDir/pc/$host/config.pl";
- } elsif ( $type eq "docs" ) {
- $file = "$BinDir/../doc/BackupPC.html";
- if ( open(LOG, $file) ) {
- Header($Lang->{BackupPC__Documentation});
- print while ( ";
- if ( $type eq "XferErr" || $type eq "XferErrbad"
- || $type eq "RestoreErr" ) {
- my $skipped;
- while ( 1 ) {
- $_ = $fh->readLine();
- if ( $_ eq "" ) {
- print(eval ("qq{$Lang->{skipped__skipped_lines}}"));
- last;
- }
- if ( /smb: \\>/
- || /^\s*(\d+) \(\s*\d+\.\d kb\/s\) (.*)$/
- || /^tar: dumped \d+ files/
- || /^added interface/i
- || /^restore tar file /i
- || /^restore directory /i
- || /^tarmode is now/i
- || /^Total bytes written/i
- || /^Domain=/i
- || /^Getting files newer than/i
- || /^Output is \/dev\/null/
- || /^\([\d\.]* kb\/s\) \(average [\d\.]* kb\/s\)$/
- || /^\s+directory \\/
- || /^Timezone is/
- || /^\.\//
- || /^ /
- ) {
- $skipped++;
- next;
- }
- print(eval("qq{$Lang->{skipped__skipped_lines}}")) if ( $skipped );
- $skipped = 0;
- print ${EscapeHTML($_)};
- }
- } elsif ( $linkHosts ) {
- while ( 1 ) {
- $_ = $fh->readLine();
- last if ( $_ eq "" );
- my $s = ${EscapeHTML($_)};
- $s =~ s/\b([\w-]+)\b/defined($Hosts->{$1})
- ? ${HostLink($1)} : $1/eg;
- print $s;
- }
- } elsif ( $type eq "config" ) {
- while ( 1 ) {
- $_ = $fh->readLine();
- last if ( $_ eq "" );
- # remove any passwords and user names
- s/(SmbSharePasswd.*=.*['"]).*(['"])/$1$2/ig;
- s/(SmbShareUserName.*=.*['"]).*(['"])/$1$2/ig;
- s/(ServerMesgSecret.*=.*['"]).*(['"])/$1$2/ig;
- print ${EscapeHTML($_)};
- }
- } else {
- while ( 1 ) {
- $_ = $fh->readLine();
- last if ( $_ eq "" );
- print ${EscapeHTML($_)};
- }
- }
- $fh->close();
- } else {
- printf( eval("qq{$Lang->{_pre___Can_t_open_log_file__file}}"));
- }
- print <
$file
- $size
- $mtimeStr
-EOF
- }
- Header($Lang->{BackupPC__Log_File_History});
- print (eval("qq{$Lang->{Log_File_History__hdr}}"));
- Trailer();
-}
-
-sub Action_EmailSummary
-{
- my $Privileged = CheckPermission();
-
- if ( !$Privileged ) {
- ErrorExit($Lang->{Only_privileged_users_can_view_email_summaries});
- }
- GetStatusInfo("hosts");
- ReadUserEmailInfo();
- my(%EmailStr, $str);
- foreach my $u ( keys(%UserEmailInfo) ) {
- next if ( !defined($UserEmailInfo{$u}{lastTime}) );
- my $emailTimeStr = timeStamp2($UserEmailInfo{$u}{lastTime});
- $EmailStr{$UserEmailInfo{$u}{lastTime}} .= <${UserLink($u)}
- ${HostLink($UserEmailInfo{$u}{lastHost})}
- $emailTimeStr
- $UserEmailInfo{$u}{lastSubj}
-EOF
- }
- foreach my $t ( sort({$b <=> $a} keys(%EmailStr)) ) {
- $str .= $EmailStr{$t};
- }
- Header($Lang->{Email_Summary});
- print (eval("qq{$Lang->{Recent_Email_Summary}}"));
- Trailer();
-}
-
-sub Action_Browse
-{
- my $Privileged = CheckPermission($In{host});
- my($i, $dirStr, $fileStr, $attr);
- my $checkBoxCnt = 0;
-
- if ( !$Privileged ) {
- ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_browse_backup_files}}"));
- }
- my $host = $In{host};
- my $num = $In{num};
- my $share = $In{share};
- my $dir = $In{dir};
-
- ErrorExit($Lang->{Empty_host_name}) if ( $host eq "" );
- #
- # Find the requested backup and the previous filled backup
- #
- my @Backups = $bpc->BackupInfoRead($host);
- for ( $i = 0 ; $i < @Backups ; $i++ ) {
- last if ( $Backups[$i]{num} == $num );
- }
- if ( $i >= @Backups ) {
- ErrorExit("Backup number $num for host ${EscapeHTML($host)} does"
- . " not exist.");
- }
- my $backupTime = timeStamp2($Backups[$i]{startTime});
- my $backupAge = sprintf("%.1f", (time - $Backups[$i]{startTime})
- / (24 * 3600));
- my $view = BackupPC::View->new($bpc, $host, \@Backups);
-
- if ( $dir eq "" || $dir eq "." || $dir eq ".." ) {
- $attr = $view->dirAttrib($num, "", "");
- if ( keys(%$attr) > 0 ) {
- $share = (sort(keys(%$attr)))[0];
- $dir = '/';
- } else {
- ErrorExit(eval("qq{$Lang->{Directory___EscapeHTML}}"));
- }
- }
- my $relDir = $dir;
- my $currDir = undef;
-
- #
- # Loop up the directory tree until we hit the top.
- #
- my(@DirStrPrev);
- while ( 1 ) {
- my($fLast, $fLastum, @DirStr);
-
- $attr = $view->dirAttrib($num, $share, $relDir);
- if ( !defined($attr) ) {
- ErrorExit(eval("qq{$Lang->{Can_t_browse_bad_directory_name2}}"));
- }
-
- my $fileCnt = 0; # file counter
- $fLast = $dirStr = "";
-
- #
- # Loop over each of the files in this directory
- #
- foreach my $f ( sort(keys(%$attr)) ) {
- my($dirOpen, $gotDir, $imgStr, $img);
- my $fURI = $f; # URI escaped $f
- my $shareURI = $share; # URI escaped $share
- my $path = "$relDir/$f";
- if ( $shareURI eq "" ) {
- $shareURI = $path;
- $path = "";
- }
- $path =~ s{^/+}{/};
- $path =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
- $fURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
- $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
- $dirOpen = 1 if ( defined($currDir) && $f eq $currDir );
- if ( $attr->{$f}{type} == BPC_FTYPE_DIR ) {
- #
- # Display directory if it exists in current backup.
- # First find out if there are subdirs
- #
- my($bold, $unbold, $BGcolor);
- $img |= 1 << 6;
- $img |= 1 << 5 if ( $attr->{$f}{nlink} > 2 );
- if ( $dirOpen ) {
- $bold = "";
- $unbold = "";
- $img |= 1 << 2;
- $img |= 1 << 3 if ( $attr->{$f}{nlink} > 2 );
- }
- my $imgFileName = sprintf("%07b.gif", $img);
- $imgStr = "";
- if ( "$relDir/$f" eq $dir ) {
- $BGcolor = " bgcolor=\"$Conf{CgiHeaderBgColor}\"";
- } else {
- $BGcolor = "";
- }
- my $dirName = $f;
- $dirName =~ s/ / /g;
- push(@DirStr, {needTick => 1,
- tdArgs => $BGcolor,
- link => <$modeStr
- $a->{backupNum}
- $a->{size}
- $mtimeStr
-
-EOF
- } else {
- $attrStr .= " \n";
- }
- if ( $gotDir ) {
- $fileStr .= < ${EscapeHTML($f)}
-$attrStr
-
-EOF
- } else {
- $fileStr .= < ${EscapeHTML($f)}
-$attrStr
-
-EOF
- }
- $checkBoxCnt++;
- }
- }
- @DirStrPrev = @DirStr;
- last if ( $relDir eq "" && $share eq "" );
- #
- # Prune the last directory off $relDir, or at the very end
- # do the top-level directory.
- #
- if ( $relDir eq "" ) {
- $currDir = $share;
- $share = "";
- } else {
- $relDir =~ s/(.*)\/(.*)/$1/;
- $currDir = $2;
- }
- }
- $share = $currDir;
- my $dirDisplay = "$share/$dir";
- $dirDisplay =~ s{//+}{/}g;
- $dirDisplay =~ s{/+$}{}g;
- my $filledBackup;
-
- if ( (my @mergeNums = @{$view->mergeNums}) > 1 ) {
- shift(@mergeNums);
- my $numF = join(", #", @mergeNums);
- $filledBackup = eval("qq{$Lang->{This_display_is_merged_with_backup}}");
- }
- Header(eval("qq{$Lang->{Browse_backup__num_for__host}}"));
-
- foreach my $d ( @DirStrPrev ) {
- $dirStr .= "
-EOF
- }
- Header(eval("qq{$Lang->{Restore_Confirm_on__host}}"));
- print(eval("qq{$Lang->{Are_you_sure}}"));
- Trailer();
- } elsif ( $In{type} == 4 ) {
- if ( !defined($Hosts->{$In{hostDest}}) ) {
- ErrorExit(eval("qq{$Lang->{Host_doesn_t_exist}}"));
- }
- if ( !CheckPermission($In{hostDest}) ) {
- ErrorExit(eval("qq{$Lang->{You_don_t_have_permission_to_restore_onto_host}}"));
- }
- my $hostDest = $1 if ( $In{hostDest} =~ /(.+)/ );
- my $ipAddr = ConfirmIPAddress($hostDest);
- #
- # Prepare and send the restore request. We write the request
- # information using Data::Dumper to a unique file,
- # $TopDir/pc/$hostDest/restoreReq.$$.n. We use a file
- # in case the list of files to restore is very long.
- #
- my $reqFileName;
- for ( my $i = 0 ; ; $i++ ) {
- $reqFileName = "restoreReq.$$.$i";
- last if ( !-f "$TopDir/pc/$hostDest/$reqFileName" );
- }
- my %restoreReq = (
- # source of restore is hostSrc, #num, path shareSrc/pathHdrSrc
- num => $In{num},
- hostSrc => $host,
- shareSrc => $share,
- pathHdrSrc => $pathHdr,
-
- # destination of restore is hostDest:shareDest/pathHdrDest
- hostDest => $hostDest,
- shareDest => $In{shareDest},
- pathHdrDest => $In{pathHdr},
-
- # list of files to restore
- fileList => \@fileList,
-
- # other info
- user => $User,
- reqTime => time,
- );
- my($dump) = Data::Dumper->new(
- [ \%restoreReq],
- [qw(*RestoreReq)]);
- $dump->Indent(1);
- if ( open(REQ, ">$TopDir/pc/$hostDest/$reqFileName") ) {
- print(REQ $dump->Dump);
- close(REQ);
- } else {
- ErrorExit(eval("qq{$Lang->{Can_t_open_create}}"));
- }
- $reply = $bpc->ServerMesg("restore $ipAddr"
- . " $hostDest $User $reqFileName");
- $str = eval("qq{$Lang->{Restore_requested_to_host__hostDest__backup___num}}");
- Header(eval("qq{$Lang->{Restore_Requested_on__hostDest}}"));
- print (eval("qq{$Lang->{Reply_from_server_was___reply}}"));
- Trailer();
- }
-}
-
-sub Action_RestoreFile
-{
- restoreFile($In{host}, $In{num}, $In{share}, $In{dir});
-}
-
-sub restoreFile
-{
- my($host, $num, $share, $dir, $skipHardLink, $origName) = @_;
- my($Privileged) = CheckPermission($host);
-
- #
- # Some common content (media) types from www.iana.org (via MIME::Types).
- #
- my $Ext2ContentType = {
- 'asc' => 'text/plain',
- 'avi' => 'video/x-msvideo',
- 'bmp' => 'image/bmp',
- 'book' => 'application/x-maker',
- 'cc' => 'text/plain',
- 'cpp' => 'text/plain',
- 'csh' => 'application/x-csh',
- 'csv' => 'text/comma-separated-values',
- 'c' => 'text/plain',
- 'deb' => 'application/x-debian-package',
- 'doc' => 'application/msword',
- 'dot' => 'application/msword',
- 'dtd' => 'text/xml',
- 'dvi' => 'application/x-dvi',
- 'eps' => 'application/postscript',
- 'fb' => 'application/x-maker',
- 'fbdoc'=> 'application/x-maker',
- 'fm' => 'application/x-maker',
- 'frame'=> 'application/x-maker',
- 'frm' => 'application/x-maker',
- 'gif' => 'image/gif',
- 'gtar' => 'application/x-gtar',
- 'gz' => 'application/x-gzip',
- 'hh' => 'text/plain',
- 'hpp' => 'text/plain',
- 'h' => 'text/plain',
- 'html' => 'text/html',
- 'htmlx'=> 'text/html',
- 'htm' => 'text/html',
- 'iges' => 'model/iges',
- 'igs' => 'model/iges',
- 'jpeg' => 'image/jpeg',
- 'jpe' => 'image/jpeg',
- 'jpg' => 'image/jpeg',
- 'js' => 'application/x-javascript',
- 'latex'=> 'application/x-latex',
- 'maker'=> 'application/x-maker',
- 'mid' => 'audio/midi',
- 'midi' => 'audio/midi',
- 'movie'=> 'video/x-sgi-movie',
- 'mov' => 'video/quicktime',
- 'mp2' => 'audio/mpeg',
- 'mp3' => 'audio/mpeg',
- 'mpeg' => 'video/mpeg',
- 'mpg' => 'video/mpeg',
- 'mpp' => 'application/vnd.ms-project',
- 'pdf' => 'application/pdf',
- 'pgp' => 'application/pgp-signature',
- 'php' => 'application/x-httpd-php',
- 'pht' => 'application/x-httpd-php',
- 'phtml'=> 'application/x-httpd-php',
- 'png' => 'image/png',
- 'ppm' => 'image/x-portable-pixmap',
- 'ppt' => 'application/powerpoint',
- 'ppt' => 'application/vnd.ms-powerpoint',
- 'ps' => 'application/postscript',
- 'qt' => 'video/quicktime',
- 'rgb' => 'image/x-rgb',
- 'rtf' => 'application/rtf',
- 'rtf' => 'text/rtf',
- 'shar' => 'application/x-shar',
- 'shtml'=> 'text/html',
- 'swf' => 'application/x-shockwave-flash',
- 'tex' => 'application/x-tex',
- 'texi' => 'application/x-texinfo',
- 'texinfo'=> 'application/x-texinfo',
- 'tgz' => 'application/x-gtar',
- 'tiff' => 'image/tiff',
- 'tif' => 'image/tiff',
- 'txt' => 'text/plain',
- 'vcf' => 'text/x-vCard',
- 'vrml' => 'model/vrml',
- 'wav' => 'audio/x-wav',
- 'wmls' => 'text/vnd.wap.wmlscript',
- 'wml' => 'text/vnd.wap.wml',
- 'wrl' => 'model/vrml',
- 'xls' => 'application/vnd.ms-excel',
- 'xml' => 'text/xml',
- 'xwd' => 'image/x-xwindowdump',
- 'z' => 'application/x-compress',
- 'zip' => 'application/zip',
- %{$Conf{CgiExt2ContentType}}, # add site-specific values
- };
- if ( !$Privileged ) {
- ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_restore_backup_files2}}"));
- }
- ServerConnect();
- ErrorExit($Lang->{Empty_host_name}) if ( $host eq "" );
-
- $dir = "/" if ( $dir eq "" );
- my @Backups = $bpc->BackupInfoRead($host);
- my $view = BackupPC::View->new($bpc, $host, \@Backups);
- my $a = $view->fileAttrib($num, $share, $dir);
- if ( $dir =~ m{(^|/)\.\.(/|$)} || !defined($a) ) {
- ErrorExit("Can't restore bad file ${EscapeHTML($dir)}");
- }
- my $f = BackupPC::FileZIO->open($a->{fullPath}, 0, $a->{compress});
- my $data;
- if ( !$skipHardLink && $a->{type} == BPC_FTYPE_HARDLINK ) {
- #
- # hardlinks should look like the file they point to
- #
- my $linkName;
- while ( $f->read(\$data, 65536) > 0 ) {
- $linkName .= $data;
- }
- $f->close;
- $linkName =~ s/^\.\///;
- my $share = $1 if ( $dir =~ /^\/?(.*?)\// );
- restoreFile($host, $num, $share, $linkName, 1, $dir);
- return;
- }
- $bpc->ServerMesg("log User $User recovered file $host/$num:$share/$dir ($a->{fullPath})");
- $dir = $origName if ( defined($origName) );
- my $ext = $1 if ( $dir =~ /\.([^\/\.]+)$/ );
- my $contentType = $Ext2ContentType->{lc($ext)}
- || "application/octet-stream";
- my $fileName = $1 if ( $dir =~ /.*\/(.*)/ );
- $fileName =~ s/"/\\"/g;
- print "Content-Type: $contentType\n";
- print "Content-Transfer-Encoding: binary\n";
- print "Content-Disposition: attachment; filename=\"$fileName\"\n\n";
- while ( $f->read(\$data, 1024 * 1024) > 0 ) {
- print STDOUT $data;
- }
- $f->close;
-}
-
-sub Action_HostInfo
-{
- my $host = $1 if ( $In{host} =~ /(.*)/ );
- my($statusStr, $startIncrStr);
-
- $host =~ s/^\s+//;
- $host =~ s/\s+$//;
- return Action_GeneralInfo() if ( $host eq "" );
- $host = lc($host)
- if ( !-d "$TopDir/pc/$host" && -d "$TopDir/pc/" . lc($host) );
- if ( $host =~ /\.\./ || !-d "$TopDir/pc/$host" ) {
- #
- # try to lookup by user name
- #
- if ( !defined($Hosts->{$host}) ) {
- foreach my $h ( keys(%$Hosts) ) {
- if ( $Hosts->{$h}{user} eq $host
- || lc($Hosts->{$h}{user}) eq lc($host) ) {
- $host = $h;
- last;
- }
- }
- CheckPermission();
- ErrorExit(eval("qq{$Lang->{Unknown_host_or_user}}"))
- if ( !defined($Hosts->{$host}) );
- }
- $In{host} = $host;
- }
- GetStatusInfo("host($host)");
- $bpc->ConfigRead($host);
- %Conf = $bpc->Conf();
- my $Privileged = CheckPermission($host);
- if ( !$Privileged ) {
- ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_view_information_about}}"));
- }
- ReadUserEmailInfo();
-
- my @Backups = $bpc->BackupInfoRead($host);
- my($str, $sizeStr, $compStr, $errStr, $warnStr);
- for ( my $i = 0 ; $i < @Backups ; $i++ ) {
- my $startTime = timeStamp2($Backups[$i]{startTime});
- my $dur = $Backups[$i]{endTime} - $Backups[$i]{startTime};
- $dur = 1 if ( $dur <= 0 );
- my $duration = sprintf("%.1f", $dur / 60);
- my $MB = sprintf("%.1f", $Backups[$i]{size} / (1024*1024));
- my $MBperSec = sprintf("%.2f", $Backups[$i]{size} / (1024*1024*$dur));
- my $MBExist = sprintf("%.1f", $Backups[$i]{sizeExist} / (1024*1024));
- my $MBNew = sprintf("%.1f", $Backups[$i]{sizeNew} / (1024*1024));
- my($MBExistComp, $ExistComp, $MBNewComp, $NewComp);
- if ( $Backups[$i]{sizeExist} && $Backups[$i]{sizeExistComp} ) {
- $MBExistComp = sprintf("%.1f", $Backups[$i]{sizeExistComp}
- / (1024 * 1024));
- $ExistComp = sprintf("%.1f%%", 100 *
- (1 - $Backups[$i]{sizeExistComp} / $Backups[$i]{sizeExist}));
- }
- if ( $Backups[$i]{sizeNew} && $Backups[$i]{sizeNewComp} ) {
- $MBNewComp = sprintf("%.1f", $Backups[$i]{sizeNewComp}
- / (1024 * 1024));
- $NewComp = sprintf("%.1f%%", 100 *
- (1 - $Backups[$i]{sizeNewComp} / $Backups[$i]{sizeNew}));
- }
- my $age = sprintf("%.1f", (time - $Backups[$i]{startTime}) / (24*3600));
- my $browseURL = "$MyURL?action=browse&host=$host&num=$Backups[$i]{num}";
- my $filled = $Backups[$i]{noFill} ? $Lang->{No} : $Lang->{Yes};
- $filled .= " ($Backups[$i]{fillFromNum}) "
- if ( $Backups[$i]{fillFromNum} ne "" );
- my $ltype;
- if ($Backups[$i]{type} eq "full") { $ltype = $Lang->{full}; }
- else { $ltype = $Lang->{incremental}; }
- $str .= <{tdArgs}>$d->{link}\n";
- }
-
- ### hide checkall button if there are no files
- my ($topCheckAll, $checkAll, $fileHeader);
- if ( $fileStr ) {
- $fileHeader = eval("qq{$Lang->{fileHeader}}");
-
- $checkAll = $Lang->{checkAll};
-
- # and put a checkall box on top if there are at least 20 files
- if ( $checkBoxCnt >= 20 ) {
- $topCheckAll = $checkAll;
- $topCheckAll =~ s{allFiles}{allFilestop}g;
- }
- } else {
- $fileStr = eval("qq{$Lang->{The_directory_is_empty}}");
- }
- my @otherDirs;
- foreach my $i ( $view->backupList($share, $dir) ) {
- next if ( $i == $num );
- my $path = $dir;
- my $shareURI = $share;
- $path =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
- $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
- push(@otherDirs, < $host:/$strippedShare$f $In{hostDest}:/$strippedShareDest$targetFile $Backups[$i]{num}
- $ltype
- $filled
- $startTime
- $duration
- $age
- $TopDir/pc/$host/$Backups[$i]{num}
-EOF
- $sizeStr .= < $Backups[$i]{num}
- $ltype
- $Backups[$i]{nFiles}
- $MB
- $MBperSec
- $Backups[$i]{nFilesExist}
- $MBExist
- $Backups[$i]{nFilesNew}
- $MBNew
-
-EOF
- $Backups[$i]{compress} ||= "off";
- my $is_compress = $Lang->{off};
- if ($Backups[$i]{compress} ne "off") {$is_compress = $Lang->{on}; }
- if (! $ExistComp) { $ExistComp = " "; }
- if (! $MBExistComp) { $MBExistComp = " "; }
- $compStr .= < $Backups[$i]{num}
- $ltype
- $is_compress
- $MBExist
- $MBExistComp
- $ExistComp
- $MBNew
- $MBNewComp
- $NewComp
-
-EOF
- $errStr .= < $Backups[$i]{num}
- $ltype
- XferLOG,
- Errors
- $Backups[$i]{xferErrs}
- $Backups[$i]{xferBadFile}
- $Backups[$i]{xferBadShare}
- $Backups[$i]{tarErrs}
-EOF
- }
-
- my @Restores = $bpc->RestoreInfoRead($host);
- my $restoreStr;
-
- for ( my $i = 0 ; $i < @Restores ; $i++ ) {
- my $startTime = timeStamp2($Restores[$i]{startTime});
- my $dur = $Restores[$i]{endTime} - $Restores[$i]{startTime};
- $dur = 1 if ( $dur <= 0 );
- my $duration = sprintf("%.1f", $dur / 60);
- my $MB = sprintf("%.1f", $Restores[$i]{size} / (1024*1024));
- my $MBperSec = sprintf("%.2f", $Restores[$i]{size} / (1024*1024*$dur));
- my $Restores_Result = $Lang->{failed};
- if ($Restores[$i]{result} ne "failed") { $Restores_Result = $Lang->{success}; }
- $restoreStr .= <$Restores[$i]{num}
- $Restores_Result
- $startTime
- $duration
- $Restores[$i]{nFiles}
- $MB
- $Restores[$i]{tarCreateErrs}
- $Restores[$i]{xferErrs}
-
-EOF
- }
- if ( $restoreStr ne "" ) {
- $restoreStr = eval("qq{$Lang->{Restore_Summary}}");
- }
- if ( @Backups == 0 ) {
- $warnStr = $Lang->{This_PC_has_never_been_backed_up};
- }
- if ( defined($Hosts->{$host}) ) {
- my $user = $Hosts->{$host}{user};
- my @moreUsers = sort(keys(%{$Hosts->{$host}{moreUsers}}));
- my $moreUserStr;
- foreach my $u ( sort(keys(%{$Hosts->{$host}{moreUsers}})) ) {
- $moreUserStr .= ", " if ( $moreUserStr ne "" );
- $moreUserStr .= "${UserLink($u)}";
- }
- if ( $moreUserStr ne "" ) {
- $moreUserStr = " ($Lang->{and} $moreUserStr).\n";
- } else {
- $moreUserStr = ".\n";
- }
- if ( $user ne "" ) {
- $statusStr .= eval("qq{$Lang->{This_PC_is_used_by}$moreUserStr}");
- }
- if ( defined($UserEmailInfo{$user})
- && $UserEmailInfo{$user}{lastHost} eq $host ) {
- my $mailTime = timeStamp2($UserEmailInfo{$user}{lastTime});
- my $subj = $UserEmailInfo{$user}{lastSubj};
- $statusStr .= eval("qq{$Lang->{Last_email_sent_to__was_at___subject}}");
- }
- }
- if ( defined($Jobs{$host}) ) {
- my $startTime = timeStamp2($Jobs{$host}{startTime});
- (my $cmd = $Jobs{$host}{cmd}) =~ s/$BinDir\///g;
- $statusStr .= eval("qq{$Lang->{The_command_cmd_is_currently_running_for_started}}");
- }
- if ( $StatusHost{BgQueueOn} ) {
- $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_background_queue_will_be_backed_up_soon}}");
- }
- if ( $StatusHost{UserQueueOn} ) {
- $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_user_queue__will_be_backed_up_soon}}");
- }
- if ( $StatusHost{CmdQueueOn} ) {
- $statusStr .= eval("qq{$Lang->{A_command_for_host_is_on_the_command_queue_will_run_soon}}");
- }
- my $startTime = timeStamp2($StatusHost{endTime} == 0 ?
- $StatusHost{startTime} : $StatusHost{endTime});
- my $reason = "";
- if ( $StatusHost{reason} ne "" ) {
- $reason = " ($Lang->{$StatusHost{reason}})";
- }
- $statusStr .= eval("qq{$Lang->{Last_status_is_state_StatusHost_state_reason_as_of_startTime}}");
-
- if ( $StatusHost{error} ne "" ) {
- $statusStr .= eval("qq{$Lang->{Last_error_is____EscapeHTML_StatusHost_error}}");
- }
- my $priorStr = "Pings";
- if ( $StatusHost{deadCnt} > 0 ) {
- $statusStr .= eval("qq{$Lang->{Pings_to_host_have_failed_StatusHost_deadCnt__consecutive_times}}");
- $priorStr = $Lang->{Prior_to_that__pings};
- }
- if ( $StatusHost{aliveCnt} > 0 ) {
- $statusStr .= eval("qq{$Lang->{priorStr_to_host_have_succeeded_StatusHostaliveCnt_consecutive_times}}");
-
- if ( $StatusHost{aliveCnt} >= $Conf{BlackoutGoodCnt}
- && $Conf{BlackoutGoodCnt} >= 0 && $Conf{BlackoutHourBegin} >= 0
- && $Conf{BlackoutHourEnd} >= 0 ) {
- my(@days) = qw(Sun Mon Tue Wed Thu Fri Sat);
- my($days) = join(", ", @days[@{$Conf{BlackoutWeekDays}}]);
- my($t0) = sprintf("%d:%02d", $Conf{BlackoutHourBegin},
- 60 * ($Conf{BlackoutHourBegin}
- - int($Conf{BlackoutHourBegin})));
- my($t1) = sprintf("%d:%02d", $Conf{BlackoutHourEnd},
- 60 * ($Conf{BlackoutHourEnd}
- - int($Conf{BlackoutHourEnd})));
- $statusStr .= eval("qq{$Lang->{Because__host_has_been_on_the_network_at_least__Conf_BlackoutGoodCnt_consecutive_times___}}");
- }
- }
- if ( $StatusHost{backoffTime} > time ) {
- my $hours = sprintf("%.1f", ($StatusHost{backoffTime} - time) / 3600);
- $statusStr .= eval("qq{$Lang->{Backups_are_deferred_for_hours_hours_change_this_number}}");
-
- }
- if ( @Backups ) {
- # only allow incremental if there are already some backups
- $startIncrStr = < ${HostLink($host)}
- $Jobs{$host}{type}
- ${UserLink($Hosts->{$host}{user})}
- $startTime
- $cmd
- $Jobs{$host}{pid}
- $Jobs{$host}{xferPid}
-EOF
- if ( $Jobs{$host}{tarPid} > 0 ) {
- $jobStr .= " $Jobs{$host}{tarPid} \n";
- $tarPidHdr ||= " tar PID \n";
- }
- $jobStr .= "\n";
- }
- foreach my $host ( sort(keys(%Status)) ) {
- next if ( $Status{$host}{reason} ne "Reason_backup_failed" );
- my $startTime = timeStamp2($Status{$host}{startTime});
- my($errorTime, $XferViewStr);
- if ( $Status{$host}{errorTime} > 0 ) {
- $errorTime = timeStamp2($Status{$host}{errorTime});
- }
- if ( -f "$TopDir/pc/$host/SmbLOG.bad"
- || -f "$TopDir/pc/$host/SmbLOG.bad.z"
- || -f "$TopDir/pc/$host/XferLOG.bad"
- || -f "$TopDir/pc/$host/XferLOG.bad.z"
- ) {
- $XferViewStr = < ${HostLink($host)}
- $Status{$host}{type}
- ${UserLink($Hosts->{$host}{user})}
- $startTime
- $XferViewStr
- $errorTime
- ${EscapeHTML($shortErr)}
-EOF
- }
- my $now = timeStamp2(time);
- my $nextWakeupTime = timeStamp2($Info{nextWakeup});
- my $DUlastTime = timeStamp2($Info{DUlastValueTime});
- my $DUmaxTime = timeStamp2($Info{DUDailyMaxTime});
- my $numBgQueue = $QueueLen{BgQueue};
- my $numUserQueue = $QueueLen{UserQueue};
- my $numCmdQueue = $QueueLen{CmdQueue};
- my $serverStartTime = timeStamp2($Info{startTime});
- my $poolInfo = genPoolInfo("pool", \%Info);
- my $cpoolInfo = genPoolInfo("cpool", \%Info);
- if ( $Info{poolFileCnt} > 0 && $Info{cpoolFileCnt} > 0 ) {
- $poolInfo = <
-$poolInfo
-
-
-$cpoolInfo
-
-EOF
- } elsif ( $Info{cpoolFileCnt} > 0 ) {
- $poolInfo = $cpoolInfo;
- }
-
- Header($Lang->{H_BackupPC_Server_Status});
- #Header("H_BackupPC_Server_Status");
- print (eval ("qq{$Lang->{BackupPC_Server_Status}}"));
-
- #Header($Lang->{BackupPC_Server_Status});
-
- #my $trans_text = $Lang->{BackupPC_Server_Status};
- #print eval ("qq{$trans_text}");
- Trailer();
-}
-
-sub Action_RestoreInfo
-{
- my $Privileged = CheckPermission($In{host});
- my $host = $1 if ( $In{host} =~ /(.*)/ );
- my $num = $In{num};
- my $i;
-
- if ( !$Privileged ) {
- ErrorExit($Lang->{Only_privileged_users_can_view_restore_information});
- }
- #
- # Find the requested restore
- #
- my @Restores = $bpc->RestoreInfoRead($host);
- for ( $i = 0 ; $i < @Restores ; $i++ ) {
- last if ( $Restores[$i]{num} == $num );
- }
- if ( $i >= @Restores ) {
- ErrorExit(eval("qq{$Lang->{Restore_number__num_for_host__does_not_exist}}"));
- }
-
- %RestoreReq = ();
- do "$TopDir/pc/$host/RestoreInfo.$Restores[$i]{num}"
- if ( -f "$TopDir/pc/$host/RestoreInfo.$Restores[$i]{num}" );
-
- my $startTime = timeStamp2($Restores[$i]{startTime});
- my $reqTime = timeStamp2($RestoreReq{reqTime});
- my $dur = $Restores[$i]{endTime} - $Restores[$i]{startTime};
- $dur = 1 if ( $dur <= 0 );
- my $duration = sprintf("%.1f", $dur / 60);
- my $MB = sprintf("%.1f", $Restores[$i]{size} / (1024*1024));
- my $MBperSec = sprintf("%.2f", $Restores[$i]{size} / (1024*1024*$dur));
-
- my $fileListStr = "";
- foreach my $f ( @{$RestoreReq{fileList}} ) {
- my $targetFile = $f;
- (my $strippedShareSrc = $RestoreReq{shareSrc}) =~ s/^\///;
- (my $strippedShareDest = $RestoreReq{shareDest}) =~ s/^\///;
- substr($targetFile, 0, length($RestoreReq{pathHdrSrc}))
- = $RestoreReq{pathHdrDest};
- $fileListStr .= <$RestoreReq{hostSrc}:/$strippedShareSrc$f $RestoreReq{hostDest}:/$strippedShareDest$targetFile
-EOF
- }
-
- Header(eval("qq{$Lang->{Restore___num_details_for__host}}"));
- print(eval("qq{$Lang->{Restore___num_details_for__host2 }}"));
- Trailer();
-}
-
-###########################################################################
-# Miscellaneous subroutines
-###########################################################################
-
-sub timeStamp2
-{
- my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
- = localtime($_[0] == 0 ? time : $_[0] );
- $year += 1900;
- $mon++;
- if ( $Conf{CgiDateFormatMMDD} ) {
- return sprintf("$mon/$mday %02d:%02d", $hour, $min);
- } else {
- return sprintf("$mday/$mon %02d:%02d", $hour, $min);
- }
-}
-
-sub HostLink
-{
- my($host) = @_;
- my($s);
- if ( defined($Hosts->{$host}) || defined($Status{$host}) ) {
- $s = "$host";
- } else {
- $s = $host;
- }
- return \$s;
-}
-
-sub UserLink
-{
- my($user) = @_;
- my($s);
-
- return \$user if ( $user eq ""
- || $Conf{CgiUserUrlCreate} eq "" );
- if ( $Conf{CgiUserHomePageCheck} eq ""
- || -f sprintf($Conf{CgiUserHomePageCheck}, $user, $user, $user) ) {
- $s = "$user";
- } else {
- $s = $user;
- }
- return \$s;
-}
-
-sub EscapeHTML
-{
- my($s) = @_;
- $s =~ s/&/&/g;
- $s =~ s/\"/"/g;
- $s =~ s/>/>/g;
- $s =~ s/</g;
- $s =~ s{([^[:print:]])}{sprintf("&\#x%02X", ord($1));}eg;
- return \$s;
-}
-
-##sub URIEncode
-##{
-## my($s) = @_;
-## $s =~ s{(['"&%[:^print:]])}{sprintf("%%%02X", ord($1));}eg;
-## return \$s;
-##}
-
-sub ErrorExit
-{
- my(@mesg) = @_;
- my($head) = shift(@mesg);
- my($mesg) = join("
", @mesg);
- $Conf{CgiHeaderFontType} ||= "arial";
- $Conf{CgiHeaderFontSize} ||= "3";
- $Conf{CgiNavBarBgColor} ||= "#ddeeee";
- $Conf{CgiHeaderBgColor} ||= "#99cc33";
-
- $bpc->ServerMesg("log User $User (host=$In{host}) got CGI error: $head")
- if ( defined($bpc) );
- if ( !defined($Lang->{Error}) ) {
- Header("BackupPC: Error");
- print <
-EOF
- NavSectionTitle("BackupPC");
- print " \n";
- if ( defined($In{host}) && defined($Hosts->{$In{host}}) ) {
- my $host = $In{host};
- NavSectionTitle( eval("qq{$Lang->{Host_Inhost}}") );
- NavSectionStart();
- NavLink("?host=$host", $Lang->{Home});
- NavLink("?action=view&type=LOG&host=$host", $Lang->{LOG_file});
- NavLink("?action=LOGlist&host=$host", $Lang->{Old_LOGs});
- if ( -f "$TopDir/pc/$host/SmbLOG.bad"
- || -f "$TopDir/pc/$host/SmbLOG.bad.z"
- || -f "$TopDir/pc/$host/XferLOG.bad"
- || -f "$TopDir/pc/$host/XferLOG.bad.z" ) {
- NavLink("?action=view&type=XferLOGbad&host=$host",
- $Lang->{Last_bad_XferLOG});
- NavLink("?action=view&type=XferErrbad&host=$host",
- $Lang->{Last_bad_XferLOG_errors_only});
- }
- if ( -f "$TopDir/pc/$host/config.pl" ) {
- NavLink("?action=view&type=config&host=$host", $Lang->{Config_file});
- }
- NavSectionEnd();
- }
- NavSectionTitle($Lang->{Hosts});
- if ( defined($Hosts) && %$Hosts > 0 ) {
- NavSectionStart(0);
- foreach my $host ( GetUserHosts() ) {
- NavLink("?host=$host", $host);
- }
- NavSectionEnd();
- }
- print <$Lang->{Host_or_User_name} |
- |