2 #============================================================= -*-perl-*-w
4 # BackupPC_Admin: Apache/CGI interface for BackupPC.
7 # BackupPC_Admin provides a flexible web interface for BackupPC.
8 # It is a CGI script that runs under Apache.
10 # It requires that Apache pass in $ENV{SCRIPT_NAME} and
11 # $ENV{REMOTE_USER}. The latter requires .ht_access style
12 # authentication. Replace the code below if you are using some other
13 # type of authentication, and have a different way of getting the
16 # Also, this script needs to run as the BackupPC user. To accomplish
17 # this the script is typically installed as setuid to the BackupPC user.
20 # Craig Barratt <cbarratt@users.sourceforge.net>
23 # Copyright (C) 2001 Craig Barratt
25 # This program is free software; you can redistribute it and/or modify
26 # it under the terms of the GNU General Public License as published by
27 # the Free Software Foundation; either version 2 of the License, or
28 # (at your option) any later version.
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 #========================================================================
41 # Version 1.5.0_CVS, released 2 Aug 2002.
43 # See http://backuppc.sourceforge.net.
45 #========================================================================
49 use lib "/usr/local/BackupPC/lib";
51 use BackupPC::FileZIO;
52 use BackupPC::Attrib qw(:all);
55 use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
56 use vars qw(%Status %Info %Jobs @BgQueue @UserQueue @CmdQueue
57 %QueueLen %StatusHost);
58 use vars qw($Hosts $HostsMTime $ConfigMTime $PrivAdmin);
59 use vars qw(%UserEmailInfo $UserEmailInfoMTime %RestoreReq);
67 # We require that Apache pass in $ENV{SCRIPT_NAME} and $ENV{REMOTE_USER}.
68 # The latter requires .ht_access style authentication. Replace this
69 # code if you are using some other type of authentication, and have
70 # a different way of getting the user name.
72 $MyURL = $ENV{SCRIPT_NAME};
73 $User = $ENV{REMOTE_USER};
75 if ( !defined($bpc) ) {
76 ErrorExit($Lang->{BackupPC__Lib__new_failed__check_apache_error_log})
77 if ( !($bpc = BackupPC::Lib->new) );
78 $TopDir = $bpc->TopDir();
79 $BinDir = $bpc->BinDir();
82 $ConfigMTime = $bpc->ConfigMTime();
83 } elsif ( $bpc->ConfigMTime() != $ConfigMTime ) {
86 $ConfigMTime = $bpc->ConfigMTime();
91 # Clean up %ENV for taint checking
93 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
94 $ENV{PATH} = $Conf{MyPath};
97 # Verify we are running as the correct user
99 if ( $Conf{BackupPCUserVerify}
100 && $> != (my $uid = (getpwnam($Conf{BackupPCUser}))[2]) ) {
101 ErrorExit(eval("qq{$Lang->{Wrong_user__my_userid_is___}}"));
104 if ( !defined($Hosts) || $bpc->HostsMTime() != $HostsMTime ) {
105 $HostsMTime = $bpc->HostsMTime();
106 $Hosts = $bpc->HostInfoRead();
108 # turn operators list into a hash for quick lookups
109 foreach my $host (keys %$Hosts) {
110 $Hosts->{$host}{moreUsers} =
111 {map {$_, 1} split(",", $Hosts->{$host}{moreUsers}) }
115 my %ActionDispatch = (
116 "summary" => \&Action_Summary,
117 $Lang->{Start_Incr_Backup} => \&Action_StartStopBackup,
118 $Lang->{Start_Full_Backup} => \&Action_StartStopBackup,
119 $Lang->{Stop_Dequeue_Backup} => \&Action_StartStopBackup,
120 "queue" => \&Action_Queue,
121 "view" => \&Action_View,
122 "LOGlist" => \&Action_LOGlist,
123 "emailSummary" => \&Action_EmailSummary,
124 "browse" => \&Action_Browse,
125 $Lang->{Restore} => \&Action_Restore,
126 "RestoreFile" => \&Action_RestoreFile,
127 $Lang->{hostInfo} => \&Action_HostInfo,
128 "generalInfo" => \&Action_GeneralInfo,
129 "restoreInfo" => \&Action_RestoreInfo,
133 # Set default actions, then call sub handler
135 $In{action} ||= $Lang->{hostInfo} if ( defined($In{host}) );
136 $In{action} = "generalInfo" if ( !defined($ActionDispatch{$In{action}}) );
137 $ActionDispatch{$In{action}}();
140 ###########################################################################
141 # Action handling subroutines
142 ###########################################################################
146 my($fullTot, $fullSizeTot, $incrTot, $incrSizeTot, $str,
147 $strNone, $strGood, $hostCntGood, $hostCntNone);
149 $hostCntGood = $hostCntNone = 0;
150 GetStatusInfo("hosts");
151 my $Privileged = CheckPermission();
153 if ( !$Privileged ) {
154 ErrorExit($Lang->{Only_privileged_users_can_view_PC_summaries} );
156 foreach my $host ( sort(keys(%Status)) ) {
157 my($fullDur, $incrCnt, $incrAge, $fullSize, $fullRate);
158 my @Backups = $bpc->BackupInfoRead($host);
159 my $fullCnt = $incrCnt = 0;
160 my $fullAge = $incrAge = -1;
161 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
162 if ( $Backups[$i]{type} eq "full" ) {
164 if ( $fullAge < 0 || $Backups[$i]{startTime} > $fullAge ) {
165 $fullAge = $Backups[$i]{startTime};
166 $fullSize = $Backups[$i]{size} / (1024 * 1024);
167 $fullDur = $Backups[$i]{endTime} - $Backups[$i]{startTime};
169 $fullSizeTot += $Backups[$i]{size} / (1024 * 1024);
172 if ( $incrAge < 0 || $Backups[$i]{startTime} > $incrAge ) {
173 $incrAge = $Backups[$i]{startTime};
175 $incrSizeTot += $Backups[$i]{size} / (1024 * 1024);
178 if ( $fullAge < 0 ) {
182 $fullAge = sprintf("%.1f", (time - $fullAge) / (24 * 3600));
183 $fullRate = sprintf("%.2f",
184 $fullSize / ($fullDur <= 0 ? 1 : $fullDur));
186 if ( $incrAge < 0 ) {
189 $incrAge = sprintf("%.1f", (time - $incrAge) / (24 * 3600));
191 $fullTot += $fullCnt;
192 $incrTot += $incrCnt;
193 $fullSize = sprintf("%.2f", $fullSize / 1000);
194 if (! $incrAge) { $incrAge = " "; }
196 <tr><td> ${HostLink($host)} </td>
197 <td align="center"> ${UserLink($Hosts->{$host}{user})} </td>
198 <td align="center"> $fullCnt </td>
199 <td align="center"> $fullAge </td>
200 <td align="center"> $fullSize </td>
201 <td align="center"> $fullRate </td>
202 <td align="center"> $incrCnt </td>
203 <td align="center"> $incrAge </td>
204 <td align="center"> $Status{$host}{state} </td>
205 <td> $Status{$host}{reason} </td></tr>
207 if ( @Backups == 0 ) {
215 $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
216 $incrSizeTot = sprintf("%.2f", $incrSizeTot / 1000);
217 my $now = timeStamp2(time);
219 Header($Lang->{BackupPC__Server_Summary});
220 print eval ("qq{$Lang->{BackupPC_Summary}}");
225 sub Action_StartStopBackup
229 my $start = 1 if ( $In{action} eq $Lang->{Start_Incr_Backup}
230 || $In{action} eq $Lang->{Start_Full_Backup} );
231 my $doFull = $In{action} eq $Lang->{Start_Full_Backup} ? 1 : 0;
232 my $type = $doFull ? "full" : "incremental";
233 my $host = $In{host};
234 my $Privileged = CheckPermission($host);
236 if ( !$Privileged ) {
237 ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_stop_or_start_backups}}"));
243 if ( $Hosts->{$host}{dhcp} ) {
244 $reply = $bpc->ServerMesg("backup $In{hostIP} $host"
246 $str = eval("qq{$Lang->{Backup_requested_on_DHCP__host}}");
248 $reply = $bpc->ServerMesg("backup $host $host $User $doFull");
249 $str = eval("qq{$Lang->{Backup_requested_on__host_by__User}}");
252 $reply = $bpc->ServerMesg("stop $host $User $In{backoff}");
253 $str = eval("qq{$Lang->{Backup_stopped_dequeued_on__host_by__User}}");
256 Header(eval ("qq{$Lang->{BackupPC__Backup_Requested_on__host}}") );
257 print (eval ("qq{$Lang->{REPLY_FROM_SERVER}}"));
262 my $ipAddr = ConfirmIPAddress($host);
264 Header(eval("qq{$Lang->{BackupPC__Start_Backup_Confirm_on__host}}"));
265 print (eval("qq{$Lang->{Are_you_sure_start}}"));
268 GetStatusInfo("host($host)");
269 if ( $StatusHost{backoffTime} > time ) {
270 $backoff = sprintf("%.1f",
271 ($StatusHost{backoffTime} - time) / 3600);
273 Header($Lang->{BackupPC__Stop_Backup_Confirm_on__host});
274 print (eval ("qq{$Lang->{Are_you_sure_stop}}"));
282 my($strBg, $strUser, $strCmd);
284 GetStatusInfo("queues");
285 my $Privileged = CheckPermission();
287 if ( !$Privileged ) {
288 ErrorExit($Lang->{Only_privileged_users_can_view_queues_});
292 my $req = pop(@BgQueue);
293 my($reqTime) = timeStamp2($req->{reqTime});
295 <tr><td> ${HostLink($req->{host})} </td>
296 <td align="center"> $reqTime </td>
297 <td align="center"> $req->{user} </td></tr>
300 while ( @UserQueue ) {
301 my $req = pop(@UserQueue);
302 my $reqTime = timeStamp2($req->{reqTime});
304 <tr><td> ${HostLink($req->{host})} </td>
305 <td align="center"> $reqTime </td>
306 <td align="center"> $req->{user} </td></tr>
309 while ( @CmdQueue ) {
310 my $req = pop(@CmdQueue);
311 my $reqTime = timeStamp2($req->{reqTime});
312 (my $cmd = $req->{cmd}) =~ s/$BinDir\///;
314 <tr><td> ${HostLink($req->{host})} </td>
315 <td align="center"> $reqTime </td>
316 <td align="center"> $req->{user} </td>
320 Header($Lang->{BackupPC__Queue_Summary});
322 print ( eval ( "qq{$Lang->{Backup_Queue_Summary}}") );
329 my $Privileged = CheckPermission($In{host});
332 my $host = $In{host};
334 my $type = $In{type};
337 my $ext = $num ne "" ? ".$num" : "";
339 ErrorExit(eval("qq{$Lang->{Invalid_number__num}}")) if ( $num ne "" && $num !~ /^\d+$/ );
340 if ( $type eq "XferLOG" ) {
341 $file = "$TopDir/pc/$host/SmbLOG$ext";
342 $file = "$TopDir/pc/$host/XferLOG$ext" if ( !-f $file && !-f "$file.z");
343 } elsif ( $type eq "XferLOGbad" ) {
344 $file = "$TopDir/pc/$host/SmbLOG.bad";
345 $file = "$TopDir/pc/$host/XferLOG.bad" if ( !-f $file && !-f "$file.z");
346 } elsif ( $type eq "XferErrbad" ) {
347 $file = "$TopDir/pc/$host/SmbLOG.bad";
348 $file = "$TopDir/pc/$host/XferLOG.bad" if ( !-f $file && !-f "$file.z");
349 $comment = "(Extracting only Errors)";
350 } elsif ( $type eq "XferErr" ) {
351 $file = "$TopDir/pc/$host/SmbLOG$ext";
352 $file = "$TopDir/pc/$host/XferLOG$ext" if ( !-f $file && !-f "$file.z");
353 $comment = "(Extracting only Errors)";
354 } elsif ( $type eq "RestoreLOG" ) {
355 $file = "$TopDir/pc/$host/RestoreLOG$ext";
356 } elsif ( $type eq "RestoreErr" ) {
357 $file = "$TopDir/pc/$host/RestoreLOG$ext";
358 $comment = "(Extracting only Errors)";
359 } elsif ( $host ne "" && $type eq "config" ) {
360 $file = "$TopDir/pc/$host/config.pl";
361 } elsif ( $type eq "docs" ) {
362 $file = "$BinDir/../doc/BackupPC.html";
363 if ( open(LOG, $file) ) {
364 Header($Lang->{BackupPC__Documentation});
365 print while ( <LOG> );
369 ErrorExit(eval("qq{$Lang->{Unable_to_open__file__configuration_problem}}"));
372 } elsif ( $type eq "config" ) {
373 $file = "$TopDir/conf/config.pl";
374 } elsif ( $type eq "hosts" ) {
375 $file = "$TopDir/conf/hosts";
376 } elsif ( $host ne "" ) {
377 $file = "$TopDir/pc/$host/LOG$ext";
379 $file = "$TopDir/log/LOG$ext";
382 if ( !$Privileged ) {
383 ErrorExit($Lang->{Only_privileged_users_can_view_log_or_config_files});
385 if ( !-f $file && -f "$file.z" ) {
389 Header(eval("qq{$Lang->{Backup_PC__Log_File__file}}") );
390 print( eval ("qq{$Lang->{Log_File__file__comment}}"));
391 if ( defined($fh = BackupPC::FileZIO->open($file, 0, $compress)) ) {
392 my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
394 print ( eval ("qq{$Lang->{Contents_of_log_file}}"));
397 if ( $type eq "XferErr" || $type eq "XferErrbad"
398 || $type eq "RestoreErr" ) {
401 $_ = $fh->readLine();
403 print(eval ("qq{$Lang->{skipped__skipped_lines}}"));
407 || /^\s*(\d+) \(\s*\d+\.\d kb\/s\) (.*)$/
408 || /^tar: dumped \d+ files/
409 || /^added interface/i
410 || /^restore tar file /i
411 || /^restore directory /i
412 || /^tarmode is now/i
413 || /^Total bytes written/i
415 || /^Getting files newer than/i
416 || /^Output is \/dev\/null/
417 || /^\([\d\.]* kb\/s\) \(average [\d\.]* kb\/s\)$/
418 || /^\s+directory \\/
425 print(eval("qq{$Lang->{skipped__skipped_lines}}")) if ( $skipped );
427 print ${EscapeHTML($_)};
429 } elsif ( $linkHosts ) {
431 $_ = $fh->readLine();
432 last if ( $_ eq "" );
433 my $s = ${EscapeHTML($_)};
434 $s =~ s/\b([\w-]+)\b/defined($Hosts->{$1})
435 ? ${HostLink($1)} : $1/eg;
438 } elsif ( $type eq "config" ) {
440 $_ = $fh->readLine();
441 last if ( $_ eq "" );
442 # remove any passwords and user names
443 s/(SmbSharePasswd.*=.*['"]).*(['"])/$1$2/ig;
444 s/(SmbShareUserName.*=.*['"]).*(['"])/$1$2/ig;
445 s/(ServerMesgSecret.*=.*['"]).*(['"])/$1$2/ig;
446 print ${EscapeHTML($_)};
450 $_ = $fh->readLine();
451 last if ( $_ eq "" );
452 print ${EscapeHTML($_)};
457 printf( eval("qq{$Lang->{_pre___Can_t_open_log_file__file}}"));
467 my $Privileged = CheckPermission($In{host});
469 if ( !$Privileged ) {
470 ErrorExit($Lang->{Only_privileged_users_can_view_log_files});
472 my $host = $In{host};
473 my($url0, $hdr, $root, $str);
475 $root = "$TopDir/pc/$host/LOG";
476 $url0 = "&host=$host";
477 $hdr = "for host $host";
479 $root = "$TopDir/log/LOG";
483 for ( my $i = -1 ; ; $i++ ) {
490 $file .= ".z" if ( !-f $file && -f "$file.z" );
491 last if ( !-f $file );
492 my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
493 my $size = (stat($file))[7];
495 <tr><td> <a href="$MyURL?action=view&type=LOG$url0$url1"><tt>$file</tt></a> </td>
496 <td align="right"> $size </td>
497 <td> $mtimeStr </td></tr>
500 Header($Lang->{BackupPC__Log_File_History});
501 print (eval("qq{$Lang->{Log_File_History__hdr}}"));
505 sub Action_EmailSummary
507 my $Privileged = CheckPermission();
509 if ( !$Privileged ) {
510 ErrorExit($Lang->{Only_privileged_users_can_view_email_summaries});
512 GetStatusInfo("hosts");
515 foreach my $u ( keys(%UserEmailInfo) ) {
516 next if ( !defined($UserEmailInfo{$u}{lastTime}) );
517 my $emailTimeStr = timeStamp2($UserEmailInfo{$u}{lastTime});
518 $EmailStr{$UserEmailInfo{$u}{lastTime}} .= <<EOF;
519 <tr><td>${UserLink($u)} </td>
520 <td>${HostLink($UserEmailInfo{$u}{lastHost})} </td>
521 <td>$emailTimeStr </td>
522 <td>$UserEmailInfo{$u}{lastSubj} </td></tr>
525 foreach my $t ( sort({$b <=> $a} keys(%EmailStr)) ) {
526 $str .= $EmailStr{$t};
528 Header($Lang->{Email_Summary});
529 print (eval("qq{$Lang->{Recent_Email_Summary}}"));
535 my $Privileged = CheckPermission($In{host});
536 my($i, $dirStr, $fileStr, $mangle);
537 my($numF, $compressF, $mangleF, $fullDirF);
538 my $checkBoxCnt = 0; # checkbox counter
540 if ( !$Privileged ) {
541 ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_browse_backup_files}}"));
543 my $host = $In{host};
547 ErrorExit($Lang->{Empty_host_name});
550 # Find the requested backup and the previous filled backup
552 my @Backups = $bpc->BackupInfoRead($host);
553 for ( $i = 0 ; $i < @Backups ; $i++ ) {
554 if ( !$Backups[$i]{noFill} ) {
555 $numF = $Backups[$i]{num};
556 $mangleF = $Backups[$i]{mangle};
557 $compressF = $Backups[$i]{compress};
559 last if ( $Backups[$i]{num} == $num );
561 if ( $i >= @Backups ) {
562 ErrorExit("Backup number $num for host ${EscapeHTML($host)} does"
565 if ( !$Backups[$i]{noFill} ) {
566 # no need to back-fill a filled backup
567 $numF = $mangleF = $compressF = undef;
569 my $backupTime = timeStamp2($Backups[$i]{startTime});
570 my $backupAge = sprintf("%.1f", (time - $Backups[$i]{startTime})
572 $mangle = $Backups[$i]{mangle};
573 if ( $dir eq "" || $dir eq "." || $dir eq ".." ) {
574 if ( !opendir(DIR, "$TopDir/pc/$host/$num") ) {
575 ErrorExit(eval("qq{$Lang->{Can_t_browse_bad_directory_name}}"));
578 # Read this directory and find the first directory
580 foreach my $f ( readdir(DIR) ) {
581 next if ( $f eq "." || $f eq ".." );
582 if ( -d "$TopDir/pc/$host/$num/$f" ) {
588 if ( $dir eq "" || $dir eq "." || $dir eq ".." ) {
589 ErrorExit(eval("qq{$Lang->{Directory___EscapeHTML}}"));
593 my $fullDir = "$TopDir/pc/$host/$num/$relDir";
594 if ( defined($numF) ) {
595 # get full path to filled backup
596 if ( $mangle && !$mangleF ) {
597 $fullDirF = "$TopDir/pc/$host/$numF/"
598 . $bpc->fileNameUnmangle($relDir);
600 $fullDirF = "$TopDir/pc/$host/$numF/$relDir";
605 # Read attributes for the directory and optionally for the filled backup
607 my $attr = BackupPC::Attrib->new({ compress => $Backups[$i]{compress}});
608 my $attrF = BackupPC::Attrib->new({ compress => $compressF})
609 if ( defined($numF) );
610 $attr->read($fullDir) if ( -f $attr->fileName($fullDir) );
611 if ( defined($numF) && -f $attrF->fileName($fullDirF)
612 && $attrF->read($fullDirF) ) {
613 $attr->merge($attrF);
616 # Loop up the directory tree until we hit the top.
620 my($fLast, $fum, $fLastum, @DirStr);
622 if ( $fullDir =~ m{(^|/)\.\.(/|$)} || !opendir(DIR, $fullDir) ) {
623 ErrorExit(eval("qq{$Lang->{Can_t_browse_bad_directory_name2}}"));
626 # Read this directory and optionally the corresponding filled directory
628 my @Dir = readdir(DIR);
630 if ( defined($numF) && opendir(DIR, $fullDirF) ) {
631 if ( $mangle == $mangleF ) {
632 @Dir = (@Dir, readdir(DIR));
634 foreach my $f ( readdir(DIR) ) {
635 next if ( $f eq "." || $f eq ".." );
636 push(@Dir, $bpc->fileNameMangle($f));
641 my $fileCnt = 0; # file counter
642 $fLast = $dirStr = "";
644 # Loop over each of the files in this directory
647 foreach my $f ( sort({uc($a) cmp uc($b)} @Dir) ) {
648 next if ( $f eq "." || $f eq ".."
649 || $f eq $fLast || ($mangle && $f eq "attrib") );
653 while ( defined(my $f = shift(@DirUniq)) ) {
654 my $path = "$relDir/$f";
655 my($dirOpen, $gotDir, $imgStr, $img);
656 $fum = $mangle ? $bpc->fileNameUnmangle($f) : $f; # unmangled $f
657 my $fumURI = $fum; # URI escaped $f
659 $path =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
660 $fumURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
661 $dirOpen = 1 if ( defined($currDir) && $f eq $currDir );
662 if ( -d "$fullDir/$f" ) {
664 # Display directory if it exists in current backup.
665 # First find out if there are subdirs
667 my @s = (defined($numF) && -d "$fullDirF/$f")
668 ? stat("$fullDirF/$f")
669 : stat("$fullDir/$f");
670 my($bold, $unbold, $BGcolor);
672 $img |= 1 << 5 if ( $s[3] > 2 );
677 $img |= 1 << 3 if ( $s[3] > 2 );
679 my $imgFileName = sprintf("%07b.gif", $img);
680 $imgStr = "<img src=\"$Conf{CgiImageDirURL}/$imgFileName\" align=\"absmiddle\" width=\"9\" height=\"19\" border=\"0\">";
681 if ( "$relDir/$f" eq $dir ) {
682 $BGcolor = " bgcolor=\"$Conf{CgiHeaderBgColor}\"";
687 $dirName =~ s/ / /g;
688 push(@DirStr, {needTick => 1,
691 <a href="$MyURL?action=browse&host=$host&num=$num&dir=$path">$imgStr</a><a href="$MyURL?action=browse&host=$host&num=$num&dir=$path" style="font-size:13px;font-family:arial;text-decoration:none;line-height:15px"> $bold$dirName$unbold</a></td></tr>
696 my($lastTick, $doneLastTick);
697 foreach my $d ( @DirStrPrev ) {
698 $lastTick = $d if ( $d->{needTick} );
700 $doneLastTick = 1 if ( !defined($lastTick) );
701 foreach my $d ( @DirStrPrev ) {
703 if ( $d->{needTick} ) {
706 if ( $d == $lastTick ) {
709 } elsif ( !$doneLastTick ) {
710 $img |= 1 << 3 | 1 << 4;
712 my $imgFileName = sprintf("%07b.gif", $img);
713 $imgStr = "<img src=\"$Conf{CgiImageDirURL}/$imgFileName\" align=\"absmiddle\" width=\"9\" height=\"19\" border=\"0\">";
714 push(@DirStr, {needTick => 0,
715 tdArgs => $d->{tdArgs},
716 link => $imgStr . $d->{link}
721 if ( $relDir eq $dir ) {
723 # This is the selected directory, so display all the files
726 if ( defined($a = $attr->get($fum)) ) {
727 my $mtimeStr = $bpc->timeStamp($a->{mtime});
728 my $typeStr = $attr->fileType2Text($a->{type});
729 my $modeStr = sprintf("0%o", $a->{mode} & 07777);
731 <td align="center">$typeStr</td>
732 <td align="right">$modeStr</td>
733 <td align="right">$a->{size}</td>
734 <td align="right">$mtimeStr</td>
738 $attrStr .= "<td colspan=\"4\" align=\"center\"> </td>\n";
742 <tr bgcolor="#ffffcc"><td><input type="checkbox" name="fcb$checkBoxCnt" value="$path"> <a href="$MyURL?action=browse&host=$host&num=$num&dir=$path">${EscapeHTML($fum)}</a></td>
748 <tr bgcolor="#ffffcc"><td><input type="checkbox" name="fcb$checkBoxCnt" value="$path"> <a href="$MyURL?action=RestoreFile&host=$host&num=$num&dir=$path">${EscapeHTML($fum)}</a></td>
756 @DirStrPrev = @DirStr;
757 last if ( $relDir eq "" );
759 # Prune the last directory off $relDir
761 $relDir =~ s/(.*)\/(.*)/$1/;
763 $fullDir = "$TopDir/pc/$host/$num/$relDir";
764 $fullDirF = "$TopDir/pc/$host/$numF/$relDir" if ( defined($numF) );
766 my $dirDisplay = $mangle ? $bpc->fileNameUnmangle($dir) : $dir;
767 $dirDisplay =~ s{//}{/}g;
769 if ( defined($numF) ) {
770 $filledBackup = eval("qq{$Lang->{This_display_is_merged_with_backup}}");
772 Header(eval("qq{$Lang->{Browse_backup__num_for__host}}"));
774 foreach my $d ( @DirStrPrev ) {
775 $dirStr .= "<tr><td$d->{tdArgs}>$d->{link}\n";
778 ### hide checkall button if there are no files
779 my ($topCheckAll, $checkAll, $fileHeader);
781 $fileHeader = eval("qq{$Lang->{fileHeader}}");
783 $checkAll = $Lang->{checkAll};
785 # and put a checkall box on top if there are at least 20 files
786 if ( $checkBoxCnt >= 20 ) {
787 $topCheckAll = $checkAll;
788 $topCheckAll =~ s{allFiles}{allFilestop}g;
791 $fileStr = eval("qq{$Lang->{The_directory_is_empty}}");
794 print (eval("qq{$Lang->{Backup_browse_for__host}}"));
800 my($str, $reply, $i);
801 my $Privileged = CheckPermission($In{host});
802 if ( !$Privileged ) {
803 ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_restore_backup_files}}"));
805 my $host = $In{host};
807 my(@fileList, $fileListStr, $hiddenStr, $share, $pathHdr, $badFileCnt);
808 my @Backups = $bpc->BackupInfoRead($host);
809 for ( $i = 0 ; $i < @Backups ; $i++ ) {
810 last if ( $Backups[$i]{num} == $num );
812 my $mangle = $Backups[$i]{mangle};
815 if ( !defined($Hosts->{$host}) ) {
816 ErrorExit(eval("qq{$Lang->{Bad_host_name}}"));
818 for ( my $i = 0 ; $i < $In{fcbMax} ; $i++ ) {
819 next if ( !defined($In{"fcb$i"}) );
820 (my $name = $In{"fcb$i"}) =~ s/%([0-9A-F]{2})/chr(hex($1))/eg;
821 $badFileCnt++ if ( $name =~ m{(^|/)\.\.(/|$)} );
822 if ( $name =~ m{^/+(.*?)(/.*)} ) {
824 $name = $mangle ? $bpc->fileNameUnmangle($2) : $2;
825 if ( @fileList == 0 ) {
828 while ( substr($name, 0, length($pathHdr)) ne $pathHdr ) {
829 $pathHdr = substr($pathHdr, 0, rindex($pathHdr, "/"));
833 push(@fileList, $name);
834 $share = $mangle ? $bpc->fileNameUnmangle($share) : $share;
836 <input type="hidden" name="fcb$i" value="$In{'fcb' . $i}">
838 $fileListStr .= <<EOF;
839 <li> ${EscapeHTML($name)}
842 $hiddenStr .= "<input type=\"hidden\" name=\"fcbMax\" value=\"$In{fcbMax}\">\n";
843 $badFileCnt++ if ( $In{pathHdr} =~ m{(^|/)\.\.(/|$)} );
844 $badFileCnt++ if ( $In{num} =~ m{(^|/)\.\.(/|$)} );
845 if ( @fileList == 0 ) {
846 ErrorExit($Lang->{You_haven_t_selected_any_files__please_go_Back_to});
849 ErrorExit($Lang->{Nice_try__but_you_can_t_put});
851 if ( @fileList == 1 ) {
852 $pathHdr =~ s/(.*)\/.*/$1/;
854 $pathHdr = "/" if ( $pathHdr eq "" );
855 if ( $In{type} != 0 && @fileList == $In{fcbMax} ) {
857 # All the files in the list were selected, so just restore the
858 # entire parent directory
860 @fileList = ( $pathHdr );
862 if ( $In{type} == 0 ) {
864 # Tell the user what options they have
866 Header(eval("qq{$Lang->{Restore_Options_for__host}}"));
867 print(eval("qq{$Lang->{Restore_Options_for__host2}}"));
870 # Verify that Archive::Zip is available before showing the
873 if ( eval { require Archive::Zip } ) {
874 print (eval("qq{$Lang->{Option_2__Download_Zip_archive}}"));
876 print (eval("qq{$Lang->{Option_2__Download_Zip_archive2}}"));
878 print (eval("qq{$Lang->{Option_3__Download_Zip_archive}}"));
880 } elsif ( $In{type} == 1 ) {
882 # Provide the selected files via a tar archive.
884 $SIG{CHLD} = 'IGNORE';
886 if ( !defined($pid) ) {
887 $bpc->ServerMesg(eval("qq{$Lang->{log_Can_t_fork_for_tar_restore_request_by__User}}"));
888 ErrorExit($Lang->{Can_t_fork_for_tar_restore});
892 # This is the parent.
894 my @fileListTrim = @fileList;
895 if ( @fileListTrim > 10 ) {
896 @fileListTrim = (@fileListTrim[0..9], '...');
898 $bpc->ServerMesg(eval("qq{$Lang->{log_User__User_downloaded_tar_archive_for__host}}"));
902 # This is the child. Print the headers and run BackupPC_tarCreate.
905 if ( $In{relative} ) {
906 @pathOpts = ("-r", $pathHdr, "-p", "");
908 $bpc->ServerDisconnect();
909 print "Content-Type: application/x-gtar\n";
910 print "Content-Transfer-Encoding: binary\n";
911 print "Content-Disposition: attachment; filename=\"restore.tar\"\n\n";
912 exec("$BinDir/BackupPC_tarCreate",
919 } elsif ( $In{type} == 2 ) {
921 # Provide the selected files via a zip archive.
923 $SIG{CHLD} = 'IGNORE';
925 if ( !defined($pid) ) {
926 $bpc->ServerMesg(eval("qq{$Lang->{log_Can_t_fork_for_zip_restore_request_by__User}}"));
927 ErrorExit($Lang->{Can_t_fork_for_zip_restore});
931 # This is the parent.
933 my @fileListTrim = @fileList;
934 if ( @fileListTrim > 10 ) {
935 @fileListTrim = (@fileListTrim[0..9], '...');
937 $bpc->ServerMesg(eval("qq{$Lang->{log_User__User_downloaded_zip_archive_for__host}}"));
941 # This is the child. Print the headers and run BackupPC_tarCreate.
944 if ( $In{relative} ) {
945 @pathOpts = ("-r", $pathHdr, "-p", "");
947 $bpc->ServerDisconnect();
948 print "Content-Type: application/zip\n";
949 print "Content-Transfer-Encoding: binary\n";
950 print "Content-Disposition: attachment; filename=\"restore.zip\"\n\n";
951 $In{compressLevel} = 5 if ( $In{compressLevel} !~ /^\d+$/ );
952 exec("$BinDir/BackupPC_zipCreate",
955 "-c", $In{compressLevel},
960 } elsif ( $In{type} == 3 ) {
962 # Do restore directly onto host
964 if ( !defined($Hosts->{$In{hostDest}}) ) {
965 ErrorExit(eval("qq{$Lang->{Host__doesn_t_exist}}"));
967 if ( !CheckPermission($In{hostDest}) ) {
968 ErrorExit(eval("qq{$Lang->{You_don_t_have_permission_to_restore_onto_host}}"));
971 foreach my $f ( @fileList ) {
973 (my $strippedShare = $share) =~ s/^\///;
974 (my $strippedShareDest = $In{shareDest}) =~ s/^\///;
975 substr($targetFile, 0, length($pathHdr)) = $In{pathHdr};
976 $fileListStr .= <<EOF;
977 <tr><td>$host:/$strippedShare$f</td><td>$In{hostDest}:/$strippedShareDest$targetFile</td></tr>
980 Header(eval("qq{$Lang->{Restore_Confirm_on__host}}"));
981 print(eval("qq{$Lang->{Are_you_sure}}"));
983 } elsif ( $In{type} == 4 ) {
984 if ( !defined($Hosts->{$In{hostDest}}) ) {
985 ErrorExit(eval("qq{$Lang->{Host_doesn_t_exist}}"));
987 if ( !CheckPermission($In{hostDest}) ) {
988 ErrorExit(eval("qq{$Lang->{You_don_t_have_permission_to_restore_onto_host}}"));
990 my $hostDest = $1 if ( $In{hostDest} =~ /(.+)/ );
991 my $ipAddr = ConfirmIPAddress($hostDest);
993 # Prepare and send the restore request. We write the request
994 # information using Data::Dumper to a unique file,
995 # $TopDir/pc/$hostDest/restoreReq.$$.n. We use a file
996 # in case the list of files to restore is very long.
999 for ( my $i = 0 ; ; $i++ ) {
1000 $reqFileName = "restoreReq.$$.$i";
1001 last if ( !-f "$TopDir/pc/$hostDest/$reqFileName" );
1004 # source of restore is hostSrc, #num, path shareSrc/pathHdrSrc
1008 pathHdrSrc => $pathHdr,
1010 # destination of restore is hostDest:shareDest/pathHdrDest
1011 hostDest => $hostDest,
1012 shareDest => $In{shareDest},
1013 pathHdrDest => $In{pathHdr},
1015 # list of files to restore
1016 fileList => \@fileList,
1022 my($dump) = Data::Dumper->new(
1026 if ( open(REQ, ">$TopDir/pc/$hostDest/$reqFileName") ) {
1027 print(REQ $dump->Dump);
1030 ErrorExit(eval("qq{$Lang->{Can_t_open_create}}"));
1032 $reply = $bpc->ServerMesg("restore $ipAddr"
1033 . " $hostDest $User $reqFileName");
1034 $str = eval("qq{$Lang->{Restore_requested_to_host__hostDest__backup___num}}");
1035 Header(eval("qq{$Lang->{Restore_Requested_on__hostDest}}"));
1036 print (eval("qq{$Lang->{Reply_from_server_was___reply}}"));
1041 sub Action_RestoreFile
1043 restoreFile($In{host}, $In{num}, $In{dir});
1048 my($host, $num, $dir, $skipHardLink, $origName) = @_;
1049 my($Privileged) = CheckPermission($host);
1050 my($i, $numF, $mangleF, $compressF, $mangle, $compress, $dirUM);
1052 # Some common content (media) types from www.iana.org (via MIME::Types).
1054 my $Ext2ContentType = {
1055 'asc' => 'text/plain',
1056 'avi' => 'video/x-msvideo',
1057 'bmp' => 'image/bmp',
1058 'book' => 'application/x-maker',
1059 'cc' => 'text/plain',
1060 'cpp' => 'text/plain',
1061 'csh' => 'application/x-csh',
1062 'csv' => 'text/comma-separated-values',
1063 'c' => 'text/plain',
1064 'deb' => 'application/x-debian-package',
1065 'doc' => 'application/msword',
1066 'dot' => 'application/msword',
1067 'dtd' => 'text/xml',
1068 'dvi' => 'application/x-dvi',
1069 'eps' => 'application/postscript',
1070 'fb' => 'application/x-maker',
1071 'fbdoc'=> 'application/x-maker',
1072 'fm' => 'application/x-maker',
1073 'frame'=> 'application/x-maker',
1074 'frm' => 'application/x-maker',
1075 'gif' => 'image/gif',
1076 'gtar' => 'application/x-gtar',
1077 'gz' => 'application/x-gzip',
1078 'hh' => 'text/plain',
1079 'hpp' => 'text/plain',
1080 'h' => 'text/plain',
1081 'html' => 'text/html',
1082 'htmlx'=> 'text/html',
1083 'htm' => 'text/html',
1084 'iges' => 'model/iges',
1085 'igs' => 'model/iges',
1086 'jpeg' => 'image/jpeg',
1087 'jpe' => 'image/jpeg',
1088 'jpg' => 'image/jpeg',
1089 'js' => 'application/x-javascript',
1090 'latex'=> 'application/x-latex',
1091 'maker'=> 'application/x-maker',
1092 'mid' => 'audio/midi',
1093 'midi' => 'audio/midi',
1094 'movie'=> 'video/x-sgi-movie',
1095 'mov' => 'video/quicktime',
1096 'mp2' => 'audio/mpeg',
1097 'mp3' => 'audio/mpeg',
1098 'mpeg' => 'video/mpeg',
1099 'mpg' => 'video/mpeg',
1100 'mpp' => 'application/vnd.ms-project',
1101 'pdf' => 'application/pdf',
1102 'pgp' => 'application/pgp-signature',
1103 'php' => 'application/x-httpd-php',
1104 'pht' => 'application/x-httpd-php',
1105 'phtml'=> 'application/x-httpd-php',
1106 'png' => 'image/png',
1107 'ppm' => 'image/x-portable-pixmap',
1108 'ppt' => 'application/powerpoint',
1109 'ppt' => 'application/vnd.ms-powerpoint',
1110 'ps' => 'application/postscript',
1111 'qt' => 'video/quicktime',
1112 'rgb' => 'image/x-rgb',
1113 'rtf' => 'application/rtf',
1114 'rtf' => 'text/rtf',
1115 'shar' => 'application/x-shar',
1116 'shtml'=> 'text/html',
1117 'swf' => 'application/x-shockwave-flash',
1118 'tex' => 'application/x-tex',
1119 'texi' => 'application/x-texinfo',
1120 'texinfo'=> 'application/x-texinfo',
1121 'tgz' => 'application/x-gtar',
1122 'tiff' => 'image/tiff',
1123 'tif' => 'image/tiff',
1124 'txt' => 'text/plain',
1125 'vcf' => 'text/x-vCard',
1126 'vrml' => 'model/vrml',
1127 'wav' => 'audio/x-wav',
1128 'wmls' => 'text/vnd.wap.wmlscript',
1129 'wml' => 'text/vnd.wap.wml',
1130 'wrl' => 'model/vrml',
1131 'xls' => 'application/vnd.ms-excel',
1132 'xml' => 'text/xml',
1133 'xwd' => 'image/x-xwindowdump',
1134 'z' => 'application/x-compress',
1135 'zip' => 'application/zip',
1138 if ( !$Privileged ) {
1139 ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_restore_backup_files2}}"));
1142 my @Backups = $bpc->BackupInfoRead($host);
1143 if ( $host eq "" ) {
1144 ErrorExit($Lang->{Empty_host_name});
1146 $dir = "/" if ( $dir eq "" );
1147 for ( $i = 0 ; $i < @Backups ; $i++ ) {
1148 if ( !$Backups[$i]{noFill} ) {
1149 $numF = $Backups[$i]{num};
1150 $mangleF = $Backups[$i]{mangle};
1151 $compressF = $Backups[$i]{compress};
1153 last if ( $Backups[$i]{num} == $num );
1155 $mangle = $Backups[$i]{mangle};
1156 $compress = $Backups[$i]{compress};
1157 if ( !$Backups[$i]{noFill} ) {
1158 # no need to back-fill a filled backup
1159 $numF = $mangleF = $compressF = undef;
1161 my $fullPath = "$TopDir/pc/$host/$num/$dir";
1162 $fullPath =~ s{/+}{/}g;
1163 if ( !-f $fullPath && defined($numF) ) {
1166 if ( $mangle && !$mangleF ) {
1167 $fullPathF = "$TopDir/pc/$host/$numF/"
1168 . $bpc->fileNameUnmangle($dir);
1170 $fullPathF = "$TopDir/pc/$host/$numF/$dir";
1172 if ( -f $fullPathF ) {
1173 $fullPath = $fullPathF;
1174 $compress = $compressF;
1177 if ( $fullPath =~ m{(^|/)\.\.(/|$)} || !-f $fullPath ) {
1178 ErrorExit(eval("qq{$Lang->{Can_t_restore_bad_file}}"));
1180 my $dirUM = $mangle ? $bpc->fileNameUnmangle($dir) : $dir;
1181 my $attr = BackupPC::Attrib->new({compress => $compress});
1182 my $fullDir = $fullPath;
1183 $fullDir =~ s{(.*)/.*}{$1};
1184 my $fileName = $1 if ( $dirUM =~ /.*\/(.*)/ );
1185 $attr->read($fullDir) if ( -f $attr->fileName($fullDir) );
1186 my $a = $attr->get($fileName);
1188 my $f = BackupPC::FileZIO->open($fullPath, 0, $compress);
1190 if ( !$skipHardLink && $a->{type} == BPC_FTYPE_HARDLINK ) {
1192 # hardlinks should look like the file they point to
1195 while ( $f->read(\$data, 65536) > 0 ) {
1199 $linkName =~ s/^\.\///;
1200 my $share = $1 if ( $dir =~ /^\/?(.*?)\// );
1201 restoreFile($host, $num,
1202 "$share/" . ($mangle ? $bpc->fileNameMangle($linkName)
1203 : $linkName), 1, $dir);
1206 $dirUM =~ s{//}{/}g;
1207 $fullPath =~ s{//}{/}g;
1208 $bpc->ServerMesg("log User $User recovered file $dirUM ($fullPath)");
1209 $dir = $origName if ( defined($origName) );
1210 $dirUM = $mangle ? $bpc->fileNameUnmangle($dir) : $dir;
1211 my $ext = $1 if ( $dirUM =~ /\.([^\/\.]+)$/ );
1212 my $contentType = $Ext2ContentType->{lc($ext)}
1213 || "application/octet-stream";
1214 $fileName = $1 if ( $dirUM =~ /.*\/(.*)/ );
1215 $fileName =~ s/"/\\"/g;
1216 print "Content-Type: $contentType\n";
1217 print "Content-Transfer-Encoding: binary\n";
1218 print "Content-Disposition: attachment; filename=\"$fileName\"\n\n";
1219 while ( $f->read(\$data, 1024 * 1024) > 0 ) {
1227 my $host = $1 if ( $In{host} =~ /(.*)/ );
1228 my($statusStr, $startIncrStr);
1232 return Action_GeneralInfo() if ( $host eq "" );
1234 if ( !-d "$TopDir/pc/$host" && -d "$TopDir/pc/" . lc($host) );
1235 if ( $host =~ /\.\./ || !-d "$TopDir/pc/$host" ) {
1237 # try to lookup by user name
1239 if ( !defined($Hosts->{$host}) ) {
1240 foreach my $h ( keys(%$Hosts) ) {
1241 if ( $Hosts->{$h}{user} eq $host
1242 || lc($Hosts->{$h}{user}) eq lc($host) ) {
1248 ErrorExit(eval("qq{$Lang->{Unknown_host_or_user}}"))
1249 if ( !defined($Hosts->{$host}) );
1253 GetStatusInfo("host($host)");
1254 $bpc->ConfigRead($host);
1255 %Conf = $bpc->Conf();
1256 my $Privileged = CheckPermission($host);
1257 if ( !$Privileged ) {
1258 ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_view_information_about}}"));
1260 ReadUserEmailInfo();
1262 my @Backups = $bpc->BackupInfoRead($host);
1263 my($str, $sizeStr, $compStr, $errStr, $warnStr);
1264 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
1265 my $startTime = timeStamp2($Backups[$i]{startTime});
1266 my $dur = $Backups[$i]{endTime} - $Backups[$i]{startTime};
1267 $dur = 1 if ( $dur <= 0 );
1268 my $duration = sprintf("%.1f", $dur / 60);
1269 my $MB = sprintf("%.1f", $Backups[$i]{size} / (1024*1024));
1270 my $MBperSec = sprintf("%.2f", $Backups[$i]{size} / (1024*1024*$dur));
1271 my $MBExist = sprintf("%.1f", $Backups[$i]{sizeExist} / (1024*1024));
1272 my $MBNew = sprintf("%.1f", $Backups[$i]{sizeNew} / (1024*1024));
1273 my($MBExistComp, $ExistComp, $MBNewComp, $NewComp);
1274 if ( $Backups[$i]{sizeExist} && $Backups[$i]{sizeExistComp} ) {
1275 $MBExistComp = sprintf("%.1f", $Backups[$i]{sizeExistComp}
1277 $ExistComp = sprintf("%.1f%%", 100 *
1278 (1 - $Backups[$i]{sizeExistComp} / $Backups[$i]{sizeExist}));
1280 if ( $Backups[$i]{sizeNew} && $Backups[$i]{sizeNewComp} ) {
1281 $MBNewComp = sprintf("%.1f", $Backups[$i]{sizeNewComp}
1283 $NewComp = sprintf("%.1f%%", 100 *
1284 (1 - $Backups[$i]{sizeNewComp} / $Backups[$i]{sizeNew}));
1286 my $age = sprintf("%.1f", (time - $Backups[$i]{startTime}) / (24*3600));
1287 my $browseURL = "$MyURL?action=browse&host=$host&num=$Backups[$i]{num}";
1288 my $filled = $Backups[$i]{noFill} ? $Lang->{No} : $Lang->{Yes};
1289 $filled .= " ($Backups[$i]{fillFromNum}) "
1290 if ( $Backups[$i]{fillFromNum} ne "" );
1292 if ($Backups[$i]{type} eq "full") { $ltype = $Lang->{full}; }
1293 else { $ltype = $Lang->{incremental}; }
1295 <tr><td align="center"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
1296 <td align="center"> $ltype </td>
1297 <td align="center"> $filled </td>
1298 <td align="right"> $startTime </td>
1299 <td align="right"> $duration </td>
1300 <td align="right"> $age </td>
1301 <td align="left"> <tt>$TopDir/pc/$host/$Backups[$i]{num}</tt> </td></tr>
1304 <tr><td align="center"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
1305 <td align="center"> $ltype </td>
1306 <td align="right"> $Backups[$i]{nFiles} </td>
1307 <td align="right"> $MB </td>
1308 <td align="right"> $MBperSec </td>
1309 <td align="right"> $Backups[$i]{nFilesExist} </td>
1310 <td align="right"> $MBExist </td>
1311 <td align="right"> $Backups[$i]{nFilesNew} </td>
1312 <td align="right"> $MBNew </td>
1315 $Backups[$i]{compress} ||= "off";
1316 my $is_compress = $Lang->{off};
1317 if ($Backups[$i]{compress} ne "off") {$is_compress = $Lang->{on}; }
1318 if (! $ExistComp) { $ExistComp = " "; }
1319 if (! $MBExistComp) { $MBExistComp = " "; }
1321 <tr><td align="center"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
1322 <td align="center"> $ltype </td>
1323 <td align="center"> $is_compress </td>
1324 <td align="right"> $MBExist </td>
1325 <td align="right"> $MBExistComp </td>
1326 <td align="right"> $ExistComp </td>
1327 <td align="right"> $MBNew </td>
1328 <td align="right"> $MBNewComp </td>
1329 <td align="right"> $NewComp </td>
1333 <tr><td align="center"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
1334 <td align="center"> $ltype </td>
1335 <td align="center"> <a href="$MyURL?action=view&type=XferLOG&num=$Backups[$i]{num}&host=$host">XferLOG</a>,
1336 <a href="$MyURL?action=view&type=XferErr&num=$Backups[$i]{num}&host=$host">Errors</a> </td>
1337 <td align="right"> $Backups[$i]{xferErrs} </td>
1338 <td align="right"> $Backups[$i]{xferBadFile} </td>
1339 <td align="right"> $Backups[$i]{xferBadShare} </td>
1340 <td align="right"> $Backups[$i]{tarErrs} </td></tr>
1344 my @Restores = $bpc->RestoreInfoRead($host);
1347 for ( my $i = 0 ; $i < @Restores ; $i++ ) {
1348 my $startTime = timeStamp2($Restores[$i]{startTime});
1349 my $dur = $Restores[$i]{endTime} - $Restores[$i]{startTime};
1350 $dur = 1 if ( $dur <= 0 );
1351 my $duration = sprintf("%.1f", $dur / 60);
1352 my $MB = sprintf("%.1f", $Restores[$i]{size} / (1024*1024));
1353 my $MBperSec = sprintf("%.2f", $Restores[$i]{size} / (1024*1024*$dur));
1354 my $Restores_Result = $Lang->{failed};
1355 if ($Restores[$i]{result} ne "failed") { $Restores_Result = $Lang->{success}; }
1356 $restoreStr .= <<EOF;
1357 <tr><td align="center"><a href="$MyURL?action=restoreInfo&num=$Restores[$i]{num}&host=$host">$Restores[$i]{num}</a> </td>
1358 <td align="center"> $Restores_Result </td>
1359 <td align="right"> $startTime </td>
1360 <td align="right"> $duration </td>
1361 <td align="right"> $Restores[$i]{nFiles} </td>
1362 <td align="right"> $MB </td>
1363 <td align="right"> $Restores[$i]{tarCreateErrs} </td>
1364 <td align="right"> $Restores[$i]{xferErrs} </td>
1368 if ( $restoreStr ne "" ) {
1369 $restoreStr = eval("qq{$Lang->{Restore_Summary}}");
1371 if ( @Backups == 0 ) {
1372 $warnStr = $Lang->{This_PC_has_never_been_backed_up};
1374 if ( defined($Hosts->{$host}) ) {
1375 my $user = $Hosts->{$host}{user};
1376 my @moreUsers = sort(keys(%{$Hosts->{$host}{moreUsers}}));
1378 foreach my $u ( sort(keys(%{$Hosts->{$host}{moreUsers}})) ) {
1379 $moreUserStr .= ", " if ( $moreUserStr ne "" );
1380 $moreUserStr .= "${UserLink($u)}";
1382 if ( $moreUserStr ne "" ) {
1383 $moreUserStr = " ($Lang->{and} $moreUserStr).\n";
1385 $moreUserStr = ".\n";
1387 if ( $user ne "" ) {
1388 $statusStr .= eval("qq{$Lang->{This_PC_is_used_by}$moreUserStr}");
1390 if ( defined($UserEmailInfo{$user})
1391 && $UserEmailInfo{$user}{lastHost} eq $host ) {
1392 my $mailTime = timeStamp2($UserEmailInfo{$user}{lastTime});
1393 my $subj = $UserEmailInfo{$user}{lastSubj};
1394 $statusStr .= eval("qq{$Lang->{Last_email_sent_to__was_at___subject}}");
1397 if ( defined($Jobs{$host}) ) {
1398 my $startTime = timeStamp2($Jobs{$host}{startTime});
1399 (my $cmd = $Jobs{$host}{cmd}) =~ s/$BinDir\///g;
1400 $statusStr .= eval("qq{$Lang->{The_command_cmd_is_currently_running_for_started}}");
1402 if ( $StatusHost{BgQueueOn} ) {
1403 $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_background_queue_will_be_backed_up_soon}}");
1405 if ( $StatusHost{UserQueueOn} ) {
1406 $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_user_queue__will_be_backed_up_soon}}");
1408 if ( $StatusHost{CmdQueueOn} ) {
1409 $statusStr .= eval("qq{$Lang->{A_command_for_host_is_on_the_command_queue_will_run_soon}}");
1411 my $startTime = timeStamp2($StatusHost{endTime} == 0 ?
1412 $StatusHost{startTime} : $StatusHost{endTime});
1414 if ( $StatusHost{reason} ne "" ) {
1415 $reason = " ($StatusHost{reason})";
1417 $statusStr .= eval("qq{$Lang->{Last_status_is_state_StatusHost_state_reason_as_of_startTime}}");
1419 if ( $StatusHost{error} ne "" ) {
1420 $statusStr .= eval("qq{$Lang->{Last_error_is____EscapeHTML_StatusHost_error}}");
1422 my $priorStr = "Pings";
1423 if ( $StatusHost{deadCnt} > 0 ) {
1424 $statusStr .= eval("qq{$Lang->{Pings_to_host_have_failed_StatusHost_deadCnt__consecutive_times}}");
1425 $priorStr = $Lang->{Prior_to_that__pings};
1427 if ( $StatusHost{aliveCnt} > 0 ) {
1428 $statusStr .= eval("qq{$Lang->{priorStr_to_host_have_succeeded_StatusHostaliveCnt_consecutive_times}}");
1430 if ( $StatusHost{aliveCnt} >= $Conf{BlackoutGoodCnt}
1431 && $Conf{BlackoutGoodCnt} >= 0 && $Conf{BlackoutHourBegin} >= 0
1432 && $Conf{BlackoutHourEnd} >= 0 ) {
1433 my(@days) = qw(Sun Mon Tue Wed Thu Fri Sat);
1434 my($days) = join(", ", @days[@{$Conf{BlackoutWeekDays}}]);
1435 my($t0) = sprintf("%d:%02d", $Conf{BlackoutHourBegin},
1436 60 * ($Conf{BlackoutHourBegin}
1437 - int($Conf{BlackoutHourBegin})));
1438 my($t1) = sprintf("%d:%02d", $Conf{BlackoutHourEnd},
1439 60 * ($Conf{BlackoutHourEnd}
1440 - int($Conf{BlackoutHourEnd})));
1441 $statusStr .= eval("qq{$Lang->{Because__host_has_been_on_the_network_at_least__Conf_BlackoutGoodCnt_consecutive_times___}}");
1444 if ( $StatusHost{backoffTime} > time ) {
1445 my $hours = sprintf("%.1f", ($StatusHost{backoffTime} - time) / 3600);
1446 $statusStr .= eval("qq{$Lang->{Backups_are_deferred_for_hours_hours_change_this_number}}");
1450 # only allow incremental if there are already some backups
1451 $startIncrStr = <<EOF;
1452 <input type="submit" value="\$Lang->{Start_Incr_Backup}" name="action">
1456 $startIncrStr = eval ("qq{$startIncrStr}");
1458 Header(eval("qq{$Lang->{Host__host_Backup_Summary}}"));
1459 print(eval("qq{$Lang->{Host__host_Backup_Summary2}}"));
1463 sub Action_GeneralInfo
1465 GetStatusInfo("info jobs hosts queueLen");
1466 my $Privileged = CheckPermission();
1468 my($jobStr, $statusStr, $tarPidHdr);
1469 foreach my $host ( sort(keys(%Jobs)) ) {
1470 my $startTime = timeStamp2($Jobs{$host}{startTime});
1471 next if ( $host eq $bpc->trashJob
1472 && $Jobs{$host}{processState} ne "running" );
1473 $Jobs{$host}{type} = $Status{$host}{type}
1474 if ( $Jobs{$host}{type} eq "" && defined($Status{$host}));
1475 (my $cmd = $Jobs{$host}{cmd}) =~ s/$BinDir\///g;
1477 <tr><td> ${HostLink($host)} </td>
1478 <td align="center"> $Jobs{$host}{type} </td>
1479 <td align="center"> ${UserLink($Hosts->{$host}{user})} </td>
1480 <td> $startTime </td>
1482 <td align="center"> $Jobs{$host}{pid} </td>
1483 <td align="center"> $Jobs{$host}{xferPid} </td>
1485 if ( $Jobs{$host}{tarPid} > 0 ) {
1486 $jobStr .= " <td align=\"center\"> $Jobs{$host}{tarPid} </td>\n";
1487 $tarPidHdr ||= "<td align=\"center\"> tar PID </td>\n";
1489 $jobStr .= "</tr>\n";
1491 foreach my $host ( sort(keys(%Status)) ) {
1492 next if ( $Status{$host}{reason} ne "backup failed" );
1493 my $startTime = timeStamp2($Status{$host}{startTime});
1494 my($errorTime, $XferViewStr);
1495 if ( $Status{$host}{errorTime} > 0 ) {
1496 $errorTime = timeStamp2($Status{$host}{errorTime});
1498 if ( -f "$TopDir/pc/$host/SmbLOG.bad"
1499 || -f "$TopDir/pc/$host/SmbLOG.bad.z"
1500 || -f "$TopDir/pc/$host/XferLOG.bad"
1501 || -f "$TopDir/pc/$host/XferLOG.bad.z"
1503 $XferViewStr = <<EOF;
1504 <a href="$MyURL?action=view&type=XferLOGbad&host=$host">XferLOG</a>,
1505 <a href="$MyURL?action=view&type=XferErrbad&host=$host">XferErr</a>
1510 (my $shortErr = $Status{$host}{error}) =~ s/(.{48}).*/$1.../;
1511 $statusStr .= <<EOF;
1512 <tr><td> ${HostLink($host)} </td>
1513 <td align="center"> $Status{$host}{type} </td>
1514 <td align="center"> ${UserLink($Hosts->{$host}{user})} </td>
1515 <td align="right"> $startTime </td>
1516 <td> $XferViewStr </td>
1517 <td align="right"> $errorTime </td>
1518 <td> ${EscapeHTML($shortErr)} </td></tr>
1521 my $now = timeStamp2(time);
1522 my $nextWakeupTime = timeStamp2($Info{nextWakeup});
1523 my $DUlastTime = timeStamp2($Info{DUlastValueTime});
1524 my $DUmaxTime = timeStamp2($Info{DUDailyMaxTime});
1525 my $numBgQueue = $QueueLen{BgQueue};
1526 my $numUserQueue = $QueueLen{UserQueue};
1527 my $numCmdQueue = $QueueLen{CmdQueue};
1528 my $serverStartTime = timeStamp2($Info{startTime});
1529 my $poolInfo = genPoolInfo("pool", \%Info);
1530 my $cpoolInfo = genPoolInfo("cpool", \%Info);
1531 if ( $Info{poolFileCnt} > 0 && $Info{cpoolFileCnt} > 0 ) {
1533 <li>Uncompressed pool:
1537 <li>Compressed pool:
1542 } elsif ( $Info{cpoolFileCnt} > 0 ) {
1543 $poolInfo = $cpoolInfo;
1546 Header($Lang->{H_BackupPC_Server_Status});
1547 #Header("H_BackupPC_Server_Status");
1548 print (eval ("qq{$Lang->{BackupPC_Server_Status}}"));
1550 #Header($Lang->{BackupPC_Server_Status});
1552 #my $trans_text = $Lang->{BackupPC_Server_Status};
1553 #print eval ("qq{$trans_text}");
1557 sub Action_RestoreInfo
1559 my $Privileged = CheckPermission($In{host});
1560 my $host = $1 if ( $In{host} =~ /(.*)/ );
1564 if ( !$Privileged ) {
1565 ErrorExit($Lang->{Only_privileged_users_can_view_restore_information});
1568 # Find the requested restore
1570 my @Restores = $bpc->RestoreInfoRead($host);
1571 for ( $i = 0 ; $i < @Restores ; $i++ ) {
1572 last if ( $Restores[$i]{num} == $num );
1574 if ( $i >= @Restores ) {
1575 ErrorExit(eval("qq{$Lang->{Restore_number__num_for_host__does_not_exist}}"));
1579 do "$TopDir/pc/$host/RestoreInfo.$Restores[$i]{num}"
1580 if ( -f "$TopDir/pc/$host/RestoreInfo.$Restores[$i]{num}" );
1582 my $startTime = timeStamp2($Restores[$i]{startTime});
1583 my $reqTime = timeStamp2($RestoreReq{reqTime});
1584 my $dur = $Restores[$i]{endTime} - $Restores[$i]{startTime};
1585 $dur = 1 if ( $dur <= 0 );
1586 my $duration = sprintf("%.1f", $dur / 60);
1587 my $MB = sprintf("%.1f", $Restores[$i]{size} / (1024*1024));
1588 my $MBperSec = sprintf("%.2f", $Restores[$i]{size} / (1024*1024*$dur));
1590 my $fileListStr = "";
1591 foreach my $f ( @{$RestoreReq{fileList}} ) {
1592 my $targetFile = $f;
1593 (my $strippedShareSrc = $RestoreReq{shareSrc}) =~ s/^\///;
1594 (my $strippedShareDest = $RestoreReq{shareDest}) =~ s/^\///;
1595 substr($targetFile, 0, length($RestoreReq{pathHdrSrc}))
1596 = $RestoreReq{pathHdrDest};
1597 $fileListStr .= <<EOF;
1598 <tr><td>$RestoreReq{hostSrc}:/$strippedShareSrc$f</td><td>$RestoreReq{hostDest}:/$strippedShareDest$targetFile</td></tr>
1602 Header(eval("qq{$Lang->{Restore___num_details_for__host}}"));
1603 print(eval("qq{$Lang->{Restore___num_details_for__host2 }}"));
1607 ###########################################################################
1608 # Miscellaneous subroutines
1609 ###########################################################################
1613 my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
1614 = localtime($_[0] == 0 ? time : $_[0] );
1617 if ( $Conf{CgiDateFormatMMDD} ) {
1618 return sprintf("$mon/$mday %02d:%02d", $hour, $min);
1620 return sprintf("$mday/$mon %02d:%02d", $hour, $min);
1628 if ( defined($Hosts->{$host}) || defined($Status{$host}) ) {
1629 $s = "<a href=\"$MyURL?host=$host\">$host</a>";
1641 return \$user if ( $user eq ""
1642 || $Conf{CgiUserUrlCreate} eq "" );
1643 if ( $Conf{CgiUserHomePageCheck} eq ""
1644 || -f sprintf($Conf{CgiUserHomePageCheck}, $user, $user, $user) ) {
1646 . sprintf($Conf{CgiUserUrlCreate}, $user, $user, $user)
1658 $s =~ s/\"/"/g;
1661 $s =~ s{([^[:print:]])}{sprintf("&\#x%02X", ord($1));}eg;
1668 ## $s =~ s{(['"&%[:^print:]])}{sprintf("%%%02X", ord($1));}eg;
1675 my($head) = shift(@mesg);
1676 my($mesg) = join("</p>\n<p>", @mesg);
1677 $Conf{CgiHeaderFontType} ||= "arial";
1678 $Conf{CgiHeaderFontSize} ||= "3";
1679 $Conf{CgiNavBarBgColor} ||= "#ddeeee";
1680 $Conf{CgiHeaderBgColor} ||= "#99cc33";
1682 $bpc->ServerMesg("log User $User (host=$In{host}) got CGI error: $head")
1683 if ( defined($bpc) );
1684 if ( !defined($Lang->{Error}) ) {
1685 Header("BackupPC: Error");
1687 ${h1("Error: Language strings not defined!!")}
1692 Header(eval("qq{$Lang->{Error}}"));
1693 print (eval("qq{$Lang->{Error____head}}"));
1702 # Verify that the server connection is ok
1704 return if ( $bpc->ServerOK() );
1705 $bpc->ServerDisconnect();
1706 if ( my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}) ) {
1707 ErrorExit(eval("qq{$Lang->{Unable_to_connect_to_BackupPC_server}}"));
1715 my $reply = $bpc->ServerMesg("status $status");
1716 $reply = $1 if ( $reply =~ /(.*)/s );
1718 # ignore status related to admin and trashClean jobs
1719 if ( $status =~ /\bhosts\b/ ) {
1720 delete($Status{$bpc->adminJob});
1721 delete($Status{$bpc->trashJob});
1725 sub ReadUserEmailInfo
1727 if ( (stat("$TopDir/log/UserEmailInfo.pl"))[9] != $UserEmailInfoMTime ) {
1728 do "$TopDir/log/UserEmailInfo.pl";
1729 $UserEmailInfoMTime = (stat("$TopDir/log/UserEmailInfo.pl"))[9];
1734 # Check if the user is privileged. A privileged user can access
1735 # any information (backup files, logs, status pages etc).
1737 # A user is privileged if they belong to the group
1738 # $Conf{CgiAdminUserGroup}, or they are in $Conf{CgiAdminUsers}
1739 # or they are the user assigned to a host in the host file.
1746 return 0 if ( $User eq "" || ($host ne "" && !defined($Hosts->{$host})) );
1747 if ( $Conf{CgiAdminUserGroup} ne "" ) {
1748 my($n,$p,$gid,$mem) = getgrnam($Conf{CgiAdminUserGroup});
1749 $Privileged ||= ($mem =~ /\b$User\b/);
1751 if ( $Conf{CgiAdminUsers} ne "" ) {
1752 $Privileged ||= ($Conf{CgiAdminUsers} =~ /\b$User\b/);
1753 $Privileged ||= $Conf{CgiAdminUsers} eq "*";
1755 $PrivAdmin = $Privileged;
1756 $Privileged ||= $User eq $Hosts->{$host}{user};
1757 $Privileged ||= defined($Hosts->{$host}{operators}{$User});
1763 # Returns the list of hosts that should appear in the navigation bar
1764 # for this user. If $Conf{CgiNavBarAdminAllHosts} is set, the admin
1765 # gets all the hosts. Otherwise, regular users get hosts for which
1766 # they are the user or are listed in the moreUsers column in the
1771 if ( $Conf{CgiNavBarAdminAllHosts} && CheckPermission() ) {
1772 return sort keys %$Hosts;
1775 return sort grep { $Hosts->{$_}{user} eq $User ||
1776 defined($Hosts->{$_}{moreUsers}{$User}) } keys(%$Hosts);
1780 # Given a host name tries to find the IP address. For non-dhcp hosts
1781 # we just return the host name. For dhcp hosts we check the address
1782 # the user is using ($ENV{REMOTE_ADDR}) and also the last-known IP
1783 # address for $host. (Later we should replace this with a broadcast
1786 sub ConfirmIPAddress
1791 if ( $Hosts->{$host}{dhcp}
1792 && $ENV{REMOTE_ADDR} =~ /^(\d+[\.\d]*)$/ ) {
1794 my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($ipAddr);
1795 if ( $netBiosHost ne $host ) {
1797 GetStatusInfo("host($host)");
1798 if ( defined($StatusHost{dhcpHostIP})
1799 && $StatusHost{dhcpHostIP} ne $ipAddr ) {
1800 $tryIP = eval("qq{$Lang->{tryIP}}");
1801 ($netBiosHost, $netBiosUser)
1802 = $bpc->NetBiosInfoGet($StatusHost{dhcpHostIP});
1804 if ( $netBiosHost ne $host ) {
1805 ErrorExit(eval("qq{$Lang->{Can_t_find_IP_address_for}}"),
1806 eval("qq{$Lang->{host_is_a_DHCP_host}}"));
1808 $ipAddr = $StatusHost{dhcpHostIP};
1816 my($name, $info) = @_;
1817 my $poolSize = sprintf("%.2f", $info->{"${name}Kb"} / (1000 * 1024));
1818 my $poolRmSize = sprintf("%.2f", $info->{"${name}KbRm"} / (1000 * 1024));
1819 my $poolTime = timeStamp2($info->{"${name}Time"});
1820 $info->{"${name}FileCntRm"} = $info->{"${name}FileCntRm"} + 0;
1821 return eval("qq{$Lang->{Pool_Stat}}");
1825 ###########################################################################
1826 # HTML layout subroutines
1827 ###########################################################################
1833 { link => "", name => $Lang->{Status},
1835 { link => "?action=summary", name => $Lang->{PC_Summary} },
1836 { link => "?action=view&type=LOG", name => $Lang->{LOG_file} },
1837 { link => "?action=LOGlist", name => $Lang->{Old_LOGs} },
1838 { link => "?action=emailSummary", name => $Lang->{Email_summary} },
1839 { link => "?action=view&type=config", name => $Lang->{Config_file} },
1840 { link => "?action=view&type=hosts", name => $Lang->{Hosts_file} },
1841 { link => "?action=queue", name => $Lang->{Current_queues} },
1842 { link => "?action=view&type=docs", name => $Lang->{Documentation},
1844 { link => "http://backuppc.sourceforge.net", name => "SourceForge",
1847 print $Cgi->header();
1849 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
1851 <title>$title</title>
1854 <table cellpadding="0" cellspacing="0" border="0">
1855 <tr valign="top"><td valign="top" bgcolor="$Conf{CgiNavBarBgColor}" width="10%">
1857 NavSectionTitle("BackupPC");
1859 if ( defined($In{host}) && defined($Hosts->{$In{host}}) ) {
1860 my $host = $In{host};
1861 NavSectionTitle( eval("qq{$Lang->{Host_Inhost}}") );
1863 NavLink("?host=$host", $Lang->{Home});
1864 NavLink("?action=view&type=LOG&host=$host", $Lang->{LOG_file});
1865 NavLink("?action=LOGlist&host=$host", $Lang->{Old_LOGs});
1866 if ( -f "$TopDir/pc/$host/SmbLOG.bad"
1867 || -f "$TopDir/pc/$host/SmbLOG.bad.z"
1868 || -f "$TopDir/pc/$host/XferLOG.bad"
1869 || -f "$TopDir/pc/$host/XferLOG.bad.z" ) {
1870 NavLink("?action=view&type=XferLOGbad&host=$host",
1871 $Lang->{Last_bad_XferLOG});
1872 NavLink("?action=view&type=XferErrbad&host=$host",
1873 $Lang->{Last_bad_XferLOG_errors_only});
1875 if ( -f "$TopDir/pc/$host/config.pl" ) {
1876 NavLink("?action=view&type=config&host=$host", $Lang->{Config_file});
1880 NavSectionTitle($Lang->{Hosts});
1881 if ( defined($Hosts) && %$Hosts > 0 ) {
1883 foreach my $host ( GetUserHosts() ) {
1884 NavLink("?host=$host", $host);
1889 <table cellpadding="2" cellspacing="0" border="0" width="100%">
1890 <tr><td>$Lang->{Host_or_User_name}</td>
1891 <tr><td><form action="$MyURL" method="get"><small>
1892 <input type="text" name="host" size="10" maxlength="64">
1893 <input type="hidden" name="action" value="$Lang->{hostInfo}"><input type="submit" value="$Lang->{Go}" name="ignore">
1894 </small></form></td></tr>
1897 NavSectionTitle($Lang->{NavSectionTitle_});
1899 foreach my $l ( @adminLinks ) {
1900 if ( $PrivAdmin || $l->{priv} ) {
1901 NavLink($l->{link}, $l->{name});
1903 NavLink(undef, $l->{name});
1908 </td><td valign="top" width="5"> </td>
1909 <td valign="top" width="90%">
1926 <table cellpadding="2" cellspacing="0" border="0" width="100%">
1927 <tr><td bgcolor="$Conf{CgiHeaderBgColor}"><font face="$Conf{CgiHeaderFontType}"
1928 size="$Conf{CgiHeaderFontSize}"><b>$head</b>
1938 $padding = 2 if ( !defined($padding) );
1940 <table cellpadding="$padding" cellspacing="0" border="0" width="100%">
1951 my($link, $text) = @_;
1952 print "<tr><td width=\"2%\" valign=\"top\"><b>·</b></td>";
1953 if ( defined($link) ) {
1954 $link = "$MyURL$link" if ( $link eq "" || $link =~ /^\?/ );
1956 <td width="98%"><a href="$link"><small>$text</small></a></td></tr>
1960 <td width="98%"><small>$text</small></td></tr>
1969 <table cellpadding="2" cellspacing="0" border="0" width="100%">
1971 <td bgcolor="$Conf{CgiHeaderBgColor}"> <font face="$Conf{CgiHeaderFontType}"
1972 size="$Conf{CgiHeaderFontSize}"><b>$str</b></font>
1982 <table cellpadding="2" cellspacing="0" border="0" width="100%">
1984 <td bgcolor="$Conf{CgiHeaderBgColor}"> <font face="$Conf{CgiHeaderFontType}"
1985 size="$Conf{CgiHeaderFontSize}"><b>$str</b></font>