From 329e870f56fb6572fa697998d33676588034c149 Mon Sep 17 00:00:00 2001
From: cbarratt
Date: Fri, 4 Jul 2003 05:51:33 +0000
Subject: [PATCH] * Split BackupPC_Admin into a set of modules, one for each
major action. Each action is now a seperate module in lib/BackupPC/CGI.
* Added directory history display to BackupPC_Admin, allowing the
user to quickly see which files changed between backups.
* Swapped the Server and Hosts sections on the Nav bar. Moved the
host search text box to the top of the hosts section. This was
done to move the variable-length part of the Nav bar (when all
hosts are displayed) to the bottom.
---
bin/BackupPC | 4 +-
bin/BackupPC_compressPool | 4 +-
bin/BackupPC_dump | 4 +-
bin/BackupPC_link | 4 +-
bin/BackupPC_nightly | 4 +-
bin/BackupPC_restore | 4 +-
bin/BackupPC_sendEmail | 4 +-
bin/BackupPC_serverMesg | 4 +-
bin/BackupPC_tarCreate | 4 +-
bin/BackupPC_tarExtract | 4 +-
bin/BackupPC_trashClean | 4 +-
bin/BackupPC_zcat | 4 +-
bin/BackupPC_zipCreate | 4 +-
cgi-bin/BackupPC_Admin | 1921 +--------------------------
configure.pl | 43 +-
lib/BackupPC/Attrib.pm | 4 +-
lib/BackupPC/CGI/Browse.pm | 284 ++++
lib/BackupPC/CGI/DirHistory.pm | 159 +++
lib/BackupPC/CGI/EmailSummary.pm | 70 +
lib/BackupPC/CGI/GeneralInfo.pm | 142 ++
lib/BackupPC/CGI/HostInfo.pm | 280 ++++
lib/BackupPC/CGI/LOGlist.pm | 82 ++
lib/BackupPC/CGI/Lib.pm | 539 ++++++++
lib/BackupPC/CGI/Queue.pm | 89 ++
lib/BackupPC/CGI/Restore.pm | 273 ++++
lib/BackupPC/CGI/RestoreFile.pm | 187 +++
lib/BackupPC/CGI/RestoreInfo.pm | 92 ++
lib/BackupPC/CGI/StartStopBackup.pm | 98 ++
lib/BackupPC/CGI/Summary.pm | 135 ++
lib/BackupPC/CGI/View.pm | 189 +++
lib/BackupPC/FileZIO.pm | 4 +-
lib/BackupPC/Lang/de.pm | 30 +-
lib/BackupPC/Lang/en.pm | 27 +-
lib/BackupPC/Lang/es.pm | 28 +-
lib/BackupPC/Lang/fr.pm | 28 +-
lib/BackupPC/Lib.pm | 6 +-
lib/BackupPC/PoolWrite.pm | 4 +-
lib/BackupPC/View.pm | 140 +-
lib/BackupPC/Xfer/Rsync.pm | 4 +-
lib/BackupPC/Xfer/RsyncFileIO.pm | 4 +-
lib/BackupPC/Xfer/Smb.pm | 4 +-
lib/BackupPC/Xfer/Tar.pm | 4 +-
lib/BackupPC/Zip/FileMember.pm | 4 +-
makeDist | 35 +-
44 files changed, 2997 insertions(+), 1964 deletions(-)
create mode 100644 lib/BackupPC/CGI/Browse.pm
create mode 100644 lib/BackupPC/CGI/DirHistory.pm
create mode 100644 lib/BackupPC/CGI/EmailSummary.pm
create mode 100644 lib/BackupPC/CGI/GeneralInfo.pm
create mode 100644 lib/BackupPC/CGI/HostInfo.pm
create mode 100644 lib/BackupPC/CGI/LOGlist.pm
create mode 100644 lib/BackupPC/CGI/Lib.pm
create mode 100644 lib/BackupPC/CGI/Queue.pm
create mode 100644 lib/BackupPC/CGI/Restore.pm
create mode 100644 lib/BackupPC/CGI/RestoreFile.pm
create mode 100644 lib/BackupPC/CGI/RestoreInfo.pm
create mode 100644 lib/BackupPC/CGI/StartStopBackup.pm
create mode 100644 lib/BackupPC/CGI/Summary.pm
create mode 100644 lib/BackupPC/CGI/View.pm
diff --git a/bin/BackupPC b/bin/BackupPC
index c95b330..027bbf2 100755
--- a/bin/BackupPC
+++ b/bin/BackupPC
@@ -29,7 +29,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -47,7 +47,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_compressPool b/bin/BackupPC_compressPool
index 4f22a27..8e07763 100755
--- a/bin/BackupPC_compressPool
+++ b/bin/BackupPC_compressPool
@@ -31,7 +31,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -49,7 +49,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_dump b/bin/BackupPC_dump
index 176c93a..79393bf 100755
--- a/bin/BackupPC_dump
+++ b/bin/BackupPC_dump
@@ -52,7 +52,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -70,7 +70,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_link b/bin/BackupPC_link
index b70376e..d17752c 100755
--- a/bin/BackupPC_link
+++ b/bin/BackupPC_link
@@ -21,7 +21,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -39,7 +39,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_nightly b/bin/BackupPC_nightly
index 5ab8fd8..a5b724e 100755
--- a/bin/BackupPC_nightly
+++ b/bin/BackupPC_nightly
@@ -17,7 +17,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -35,7 +35,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_restore b/bin/BackupPC_restore
index 6583b00..56d8b79 100755
--- a/bin/BackupPC_restore
+++ b/bin/BackupPC_restore
@@ -11,7 +11,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_sendEmail b/bin/BackupPC_sendEmail
index 6f1f95f..d9e1c7e 100755
--- a/bin/BackupPC_sendEmail
+++ b/bin/BackupPC_sendEmail
@@ -13,7 +13,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_serverMesg b/bin/BackupPC_serverMesg
index cab0896..52eb22a 100755
--- a/bin/BackupPC_serverMesg
+++ b/bin/BackupPC_serverMesg
@@ -25,7 +25,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -43,7 +43,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_tarCreate b/bin/BackupPC_tarCreate
index 6fb9c0b..80ba759 100755
--- a/bin/BackupPC_tarCreate
+++ b/bin/BackupPC_tarCreate
@@ -30,7 +30,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -48,7 +48,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_tarExtract b/bin/BackupPC_tarExtract
index 6f0251a..17e28f5 100755
--- a/bin/BackupPC_tarExtract
+++ b/bin/BackupPC_tarExtract
@@ -9,7 +9,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_trashClean b/bin/BackupPC_trashClean
index 546bbba..513401c 100755
--- a/bin/BackupPC_trashClean
+++ b/bin/BackupPC_trashClean
@@ -11,7 +11,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_zcat b/bin/BackupPC_zcat
index 4957bec..4b7ffb8 100755
--- a/bin/BackupPC_zcat
+++ b/bin/BackupPC_zcat
@@ -14,7 +14,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/bin/BackupPC_zipCreate b/bin/BackupPC_zipCreate
index 960743a..978c449 100755
--- a/bin/BackupPC_zipCreate
+++ b/bin/BackupPC_zipCreate
@@ -33,7 +33,7 @@
# Based on Backup_tarCreate by Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2002 Craig Barratt and Guillaume Filion
+# Copyright (C) 2002-2003 Craig Barratt and Guillaume Filion
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -51,7 +51,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/cgi-bin/BackupPC_Admin b/cgi-bin/BackupPC_Admin
index 5dd2ba9..c99ba4c 100755
--- a/cgi-bin/BackupPC_Admin
+++ b/cgi-bin/BackupPC_Admin
@@ -21,7 +21,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -39,7 +39,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
@@ -48,97 +48,30 @@
use strict;
no utf8;
use CGI;
+use CGI::Carp qw(fatalsToBrowser);
use lib "/usr/local/BackupPC/lib";
-use BackupPC::Lib;
-use BackupPC::FileZIO;
-use BackupPC::Attrib qw(:all);
-use BackupPC::View;
-use Data::Dumper;
-
-use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
-use vars qw(%Status %Info %Jobs @BgQueue @UserQueue @CmdQueue
- %QueueLen %StatusHost);
-use vars qw($Hosts $HostsMTime $ConfigMTime $PrivAdmin);
-use vars qw(%UserEmailInfo $UserEmailInfoMTime %RestoreReq);
-
-use vars qw ($Lang);
-
-$Cgi = new CGI;
-%In = $Cgi->Vars;
-
-#
-# We require that Apache pass in $ENV{SCRIPT_NAME} and $ENV{REMOTE_USER}.
-# The latter requires .ht_access style authentication. Replace this
-# code if you are using some other type of authentication, and have
-# a different way of getting the user name.
-#
-$MyURL = $ENV{SCRIPT_NAME};
-$User = $ENV{REMOTE_USER};
-
-if ( !defined($bpc) ) {
- ErrorExit($Lang->{BackupPC__Lib__new_failed__check_apache_error_log})
- if ( !($bpc = BackupPC::Lib->new(undef, undef, 1)) );
- $TopDir = $bpc->TopDir();
- $BinDir = $bpc->BinDir();
- %Conf = $bpc->Conf();
- $Lang = $bpc->Lang();
- $ConfigMTime = $bpc->ConfigMTime();
-} elsif ( $bpc->ConfigMTime() != $ConfigMTime ) {
- $bpc->ConfigRead();
- %Conf = $bpc->Conf();
- $ConfigMTime = $bpc->ConfigMTime();
- $Lang = $bpc->Lang();
-}
-#
-# Clean up %ENV for taint checking
-#
-delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
-$ENV{PATH} = $Conf{MyPath};
-
-#
-# Verify we are running as the correct user
-#
-if ( $Conf{BackupPCUserVerify}
- && $> != (my $uid = (getpwnam($Conf{BackupPCUser}))[2]) ) {
- ErrorExit(eval("qq{$Lang->{Wrong_user__my_userid_is___}}"), <
-This is an installation problem. If you are using mod_perl then
-it appears that Apache is not running as user $Conf{BackupPCUser}.
-If you are not using mod_perl, then most like setuid is not working
-properly on BackupPC_Admin. Check the permissions on
-$Conf{CgiDir}/BackupPC_Admin and look at the documentation.
-EOF
-}
-
-if ( !defined($Hosts) || $bpc->HostsMTime() != $HostsMTime ) {
- $HostsMTime = $bpc->HostsMTime();
- $Hosts = $bpc->HostInfoRead();
+use BackupPC::Lib;
+use BackupPC::CGI::Lib qw(:all);
- # turn moreUsers list into a hash for quick lookups
- foreach my $host (keys %$Hosts) {
- $Hosts->{$host}{moreUsers} =
- {map {$_, 1} split(",", $Hosts->{$host}{moreUsers}) }
- }
-}
+BackupPC::CGI::Lib::NewRequest;
my %ActionDispatch = (
- "summary" => \&Action_Summary,
- $Lang->{Start_Incr_Backup} => \&Action_StartStopBackup,
- $Lang->{Start_Full_Backup} => \&Action_StartStopBackup,
- $Lang->{Stop_Dequeue_Backup} => \&Action_StartStopBackup,
- "queue" => \&Action_Queue,
- "view" => \&Action_View,
- "LOGlist" => \&Action_LOGlist,
- "emailSummary" => \&Action_EmailSummary,
- "browse" => \&Action_Browse,
- $Lang->{Restore} => \&Action_Restore,
- "RestoreFile" => \&Action_RestoreFile,
- "hostInfo" => \&Action_HostInfo,
- "generalInfo" => \&Action_GeneralInfo,
- "restoreInfo" => \&Action_RestoreInfo,
+ "summary" => "Summary",
+ $Lang->{Start_Incr_Backup} => "StartStopBackup",
+ $Lang->{Start_Full_Backup} => "StartStopBackup",
+ $Lang->{Stop_Dequeue_Backup} => "StartStopBackup",
+ "queue" => "Queue",
+ "view" => "View",
+ "LOGlist" => "LOGlist",
+ "emailSummary" => "EmailSummary",
+ "browse" => "Browse",
+ "dirHistory" => "DirHistory",
+ $Lang->{Restore} => "Restore",
+ "RestoreFile" => "RestoreFile",
+ "hostInfo" => "HostInfo",
+ "generalInfo" => "GeneralInfo",
+ "restoreInfo" => "RestoreInfo",
);
#
@@ -146,1811 +79,7 @@ my %ActionDispatch = (
#
$In{action} ||= "hostInfo" if ( defined($In{host}) );
$In{action} = "generalInfo" if ( !defined($ActionDispatch{$In{action}}) );
-$ActionDispatch{$In{action}}();
-exit(0);
-
-###########################################################################
-# Action handling subroutines
-###########################################################################
-
-sub Action_Summary
-{
- my($fullTot, $fullSizeTot, $incrTot, $incrSizeTot, $str,
- $strNone, $strGood, $hostCntGood, $hostCntNone);
-
- $hostCntGood = $hostCntNone = 0;
- GetStatusInfo("hosts");
- my $Privileged = CheckPermission();
-
- if ( !$Privileged ) {
- ErrorExit($Lang->{Only_privileged_users_can_view_PC_summaries} );
- }
- foreach my $host ( sort(keys(%Status)) ) {
- my($fullDur, $incrCnt, $incrAge, $fullSize, $fullRate, $reasonHilite);
- my($shortErr);
- my @Backups = $bpc->BackupInfoRead($host);
- my $fullCnt = $incrCnt = 0;
- my $fullAge = $incrAge = -1;
- for ( my $i = 0 ; $i < @Backups ; $i++ ) {
- if ( $Backups[$i]{type} eq "full" ) {
- $fullCnt++;
- if ( $fullAge < 0 || $Backups[$i]{startTime} > $fullAge ) {
- $fullAge = $Backups[$i]{startTime};
- $fullSize = $Backups[$i]{size} / (1024 * 1024);
- $fullDur = $Backups[$i]{endTime} - $Backups[$i]{startTime};
- }
- $fullSizeTot += $Backups[$i]{size} / (1024 * 1024);
- } else {
- $incrCnt++;
- if ( $incrAge < 0 || $Backups[$i]{startTime} > $incrAge ) {
- $incrAge = $Backups[$i]{startTime};
- }
- $incrSizeTot += $Backups[$i]{size} / (1024 * 1024);
- }
- }
- if ( $fullAge < 0 ) {
- $fullAge = "";
- $fullRate = "";
- } else {
- $fullAge = sprintf("%.1f", (time - $fullAge) / (24 * 3600));
- $fullRate = sprintf("%.2f",
- $fullSize / ($fullDur <= 0 ? 1 : $fullDur));
- }
- if ( $incrAge < 0 ) {
- $incrAge = "";
- } else {
- $incrAge = sprintf("%.1f", (time - $incrAge) / (24 * 3600));
- }
- $fullTot += $fullCnt;
- $incrTot += $incrCnt;
- $fullSize = sprintf("%.2f", $fullSize / 1000);
- $incrAge = " " if ( $incrAge eq "" );
- $reasonHilite = $Conf{CgiStatusHilightColor}{$Status{$host}{reason}}
- || $Conf{CgiStatusHilightColor}{$Status{$host}{state}};
- $reasonHilite = " bgcolor=\"$reasonHilite\"" if ( $reasonHilite ne "" );
- if ( $Status{$host}{state} ne "Status_backup_in_progress"
- && $Status{$host}{state} ne "Status_restore_in_progress"
- && $Status{$host}{error} ne "" ) {
- ($shortErr = $Status{$host}{error}) =~ s/(.{48}).*/$1.../;
- $shortErr = " ($shortErr)";
- }
-
- $str = <
", @mesg);
- $Conf{CgiHeaderFontType} ||= "arial";
- $Conf{CgiHeaderFontSize} ||= "3";
- $Conf{CgiNavBarBgColor} ||= "#ddeeee";
- $Conf{CgiHeaderBgColor} ||= "#99cc33";
-
- if ( !defined($ENV{REMOTE_USER}) ) {
- $mesg .= <
-Note: \$ENV{REMOTE_USER} is not set, which could mean there is an
-installation problem. BackupPC_Admin expects Apache to authenticate
-the user and pass their user name into this script as the REMOTE_USER
-environment variable. See the documentation.
-EOF
- }
-
- $bpc->ServerMesg("log User $User (host=$In{host}) got CGI error: $head")
- if ( defined($bpc) );
- if ( !defined($Lang->{Error}) ) {
- Header("BackupPC: Error");
- $mesg = <$mesg
-EOF
- Trailer();
- } else {
- Header(eval("qq{$Lang->{Error}}"));
- print (eval("qq{$Lang->{Error____head}}"));
- Trailer();
- }
- exit(1);
-}
-
-sub ServerConnect
-{
- #
- # Verify that the server connection is ok
- #
- return if ( $bpc->ServerOK() );
- $bpc->ServerDisconnect();
- if ( my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}) ) {
- ErrorExit(eval("qq{$Lang->{Unable_to_connect_to_BackupPC_server}}"));
- }
-}
-
-sub GetStatusInfo
-{
- my($status) = @_;
- ServerConnect();
- my $reply = $bpc->ServerMesg("status $status");
- $reply = $1 if ( $reply =~ /(.*)/s );
- eval($reply);
- # ignore status related to admin and trashClean jobs
- if ( $status =~ /\bhosts\b/ ) {
- delete($Status{$bpc->adminJob});
- delete($Status{$bpc->trashJob});
- }
-}
-
-sub ReadUserEmailInfo
-{
- if ( (stat("$TopDir/log/UserEmailInfo.pl"))[9] != $UserEmailInfoMTime ) {
- do "$TopDir/log/UserEmailInfo.pl";
- $UserEmailInfoMTime = (stat("$TopDir/log/UserEmailInfo.pl"))[9];
- }
-}
-
-#
-# Check if the user is privileged. A privileged user can access
-# any information (backup files, logs, status pages etc).
-#
-# A user is privileged if they belong to the group
-# $Conf{CgiAdminUserGroup}, or they are in $Conf{CgiAdminUsers}
-# or they are the user assigned to a host in the host file.
-#
-sub CheckPermission
-{
- my($host) = @_;
- my $Privileged = 0;
-
- return 0 if ( $User eq "" && $Conf{CgiAdminUsers} ne "*"
- || $host ne "" && !defined($Hosts->{$host}) );
- if ( $Conf{CgiAdminUserGroup} ne "" ) {
- my($n,$p,$gid,$mem) = getgrnam($Conf{CgiAdminUserGroup});
- $Privileged ||= ($mem =~ /\b$User\b/);
- }
- if ( $Conf{CgiAdminUsers} ne "" ) {
- $Privileged ||= ($Conf{CgiAdminUsers} =~ /\b$User\b/);
- $Privileged ||= $Conf{CgiAdminUsers} eq "*";
- }
- $PrivAdmin = $Privileged;
- $Privileged ||= $User eq $Hosts->{$host}{user};
- $Privileged ||= defined($Hosts->{$host}{moreUsers}{$User});
-
- return $Privileged;
-}
-
-#
-# Returns the list of hosts that should appear in the navigation bar
-# for this user. If $Conf{CgiNavBarAdminAllHosts} is set, the admin
-# gets all the hosts. Otherwise, regular users get hosts for which
-# they are the user or are listed in the moreUsers column in the
-# hosts file.
-#
-sub GetUserHosts
-{
- if ( $Conf{CgiNavBarAdminAllHosts} && CheckPermission() ) {
- return sort keys %$Hosts;
- }
-
- return sort grep { $Hosts->{$_}{user} eq $User ||
- defined($Hosts->{$_}{moreUsers}{$User}) } keys(%$Hosts);
-}
-
-#
-# Given a host name tries to find the IP address. For non-dhcp hosts
-# we just return the host name. For dhcp hosts we check the address
-# the user is using ($ENV{REMOTE_ADDR}) and also the last-known IP
-# address for $host. (Later we should replace this with a broadcast
-# nmblookup.)
-#
-sub ConfirmIPAddress
-{
- my($host) = @_;
- my $ipAddr = $host;
-
- if ( defined($Hosts->{$host}) && $Hosts->{$host}{dhcp}
- && $ENV{REMOTE_ADDR} =~ /^(\d+[\.\d]*)$/ ) {
- $ipAddr = $1;
- my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($ipAddr);
- if ( $netBiosHost ne $host ) {
- my($tryIP);
- GetStatusInfo("host(${EscURI($host)})");
- if ( defined($StatusHost{dhcpHostIP})
- && $StatusHost{dhcpHostIP} ne $ipAddr ) {
- $tryIP = eval("qq{$Lang->{tryIP}}");
- ($netBiosHost, $netBiosUser)
- = $bpc->NetBiosInfoGet($StatusHost{dhcpHostIP});
- }
- if ( $netBiosHost ne $host ) {
- ErrorExit(eval("qq{$Lang->{Can_t_find_IP_address_for}}"),
- eval("qq{$Lang->{host_is_a_DHCP_host}}"));
- }
- $ipAddr = $StatusHost{dhcpHostIP};
- }
- }
- return $ipAddr;
-}
-
-sub genPoolInfo
-{
- my($name, $info) = @_;
- my $poolSize = sprintf("%.2f", $info->{"${name}Kb"} / (1000 * 1024));
- my $poolRmSize = sprintf("%.2f", $info->{"${name}KbRm"} / (1000 * 1024));
- my $poolTime = timeStamp2($info->{"${name}Time"});
- $info->{"${name}FileCntRm"} = $info->{"${name}FileCntRm"} + 0;
- return eval("qq{$Lang->{Pool_Stat}}");
-}
-
-###########################################################################
-# HTML layout subroutines
-###########################################################################
-
-sub Header
-{
- my($title) = @_;
- my @adminLinks = (
- { link => "", name => $Lang->{Status},
- priv => 1},
- { link => "?action=summary", name => $Lang->{PC_Summary} },
- { link => "?action=view&type=LOG", name => $Lang->{LOG_file} },
- { link => "?action=LOGlist", name => $Lang->{Old_LOGs} },
- { link => "?action=emailSummary", name => $Lang->{Email_summary} },
- { link => "?action=view&type=config", name => $Lang->{Config_file} },
- { link => "?action=view&type=hosts", name => $Lang->{Hosts_file} },
- { link => "?action=queue", name => $Lang->{Current_queues} },
- { link => "?action=view&type=docs", name => $Lang->{Documentation},
- priv => 1},
- { link => "http://backuppc.sourceforge.net/faq", name => "FAQ",
- priv => 1},
- { link => "http://backuppc.sourceforge.net", name => "SourceForge",
- priv => 1},
- );
- print $Cgi->header();
- print <
-
-$title
-$Conf{CgiHeaders}
-
-
+$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 "" || $relDir eq "/" || $relDir !~ /(.*)\/(.*)/ ) {
+ $currDir = $share;
+ $share = "";
+ $relDir = "";
+ } else {
+ $relDir = $1;
+ $currDir = $2;
+ }
+ }
+ $share = $currDir;
+ my $dirDisplay = "$share/$dir";
+ $dirDisplay =~ s{//+}{/}g;
+ $dirDisplay =~ s{/+$}{}g;
+ $dirDisplay = "/" if ( $dirDisplay eq "" );
+ 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 .= "
{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;
+ my $pathURI = $dir;
+ my $shareURI = $share;
+ $pathURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
+ $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
+ foreach my $i ( $view->backupList($share, $dir) ) {
+ push(@otherDirs, "$i");
+ }
+ if ( @otherDirs ) {
+ my $otherDirs = join(",\n", @otherDirs);
+ $filledBackup .= eval("qq{$Lang->{Visit_this_directory_in_backup}}");
+ }
+ print (eval("qq{$Lang->{Backup_browse_for__host}}"));
+ Trailer();
+}
+
+1;
diff --git a/lib/BackupPC/CGI/DirHistory.pm b/lib/BackupPC/CGI/DirHistory.pm
new file mode 100644
index 0000000..45bb01d
--- /dev/null
+++ b/lib/BackupPC/CGI/DirHistory.pm
@@ -0,0 +1,159 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::DirHistory package
+#
+# DESCRIPTION
+#
+# This module implements the DirHistory action for the CGI interface.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::DirHistory;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+use BackupPC::View;
+use BackupPC::Attrib qw(:all);
+
+sub action
+{
+ 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 $share = $In{share};
+ my $dir = $In{dir};
+ my $dirURI = $dir;
+ my $shareURI = $share;
+ $dirURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
+ $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
+
+ ErrorExit($Lang->{Empty_host_name}) if ( $host eq "" );
+
+ my @Backups = $bpc->BackupInfoRead($host);
+ my $view = BackupPC::View->new($bpc, $host, \@Backups);
+ my $hist = $view->dirHistory($share, $dir);
+ my($backupNumStr, $backupTimeStr, $fileStr);
+
+ $dir = "/$dir" if ( $dir !~ /^\// );
+
+ if ( "/$host/$share/$dir/" =~ m{/\.\./} ) {
+ ErrorExit($Lang->{Nice_try__but_you_can_t_put});
+ }
+
+ for ( $i = 0 ; $i < @Backups ; $i++ ) {
+ my $backupTime = timeStamp2($Backups[$i]{startTime});
+ my $num = $Backups[$i]{num};
+ $backupNumStr .= "
";
+ my($colSpan, $url, $inode, $type);
+ for ( $i = 0 ; $i < @Backups ; $i++ ) {
+ my($path);
+ if ( $colSpan > 0 ) {
+ #
+ # The file is the same if it also size==0 (inode == -1)
+ # or if it is a directory and the previous one is (inode == -2)
+ # or if the inodes agree and the types are the same.
+ #
+ if ( defined($hist->{$f}[$i])
+ && $hist->{$f}[$i]{type} == $type
+ && (($hist->{$f}[$i]{size} == 0 && $inode == -1)
+ || ($hist->{$f}[$i]{type} == BPC_FTYPE_DIR && $inode == -2)
+ || $hist->{$f}[$i]{inode} == $inode) ) {
+ $colSpan++;
+ next;
+ }
+ $fileStr .= "
\n";
+ }
+
+ my $dirDisplay = "$share/$dir";
+ $dirDisplay =~ s{//+}{/}g;
+ $dirDisplay =~ s{/+$}{}g;
+ $dirDisplay = "/" if ( $dirDisplay eq "" );
+
+ Header(eval("qq{$Lang->{DirHistory_backup_for__host}}"));
+
+ print (eval("qq{$Lang->{DirHistory_for__host}}"));
+
+ Trailer();
+}
+
+1;
diff --git a/lib/BackupPC/CGI/EmailSummary.pm b/lib/BackupPC/CGI/EmailSummary.pm
new file mode 100644
index 0000000..1b9ec70
--- /dev/null
+++ b/lib/BackupPC/CGI/EmailSummary.pm
@@ -0,0 +1,70 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::EmailSummary package
+#
+# DESCRIPTION
+#
+# This module implements the EmailSummary action for the CGI interface.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::EmailSummary;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+
+sub action
+{
+ 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();
+}
+
+1;
diff --git a/lib/BackupPC/CGI/GeneralInfo.pm b/lib/BackupPC/CGI/GeneralInfo.pm
new file mode 100644
index 0000000..bb71e51
--- /dev/null
+++ b/lib/BackupPC/CGI/GeneralInfo.pm
@@ -0,0 +1,142 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::GeneralInfo package
+#
+# DESCRIPTION
+#
+# This module implements the GeneralInfo action for the CGI interface.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::GeneralInfo;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+
+sub action
+{
+ GetStatusInfo("info jobs hosts queueLen");
+ my $Privileged = CheckPermission();
+
+ my($jobStr, $statusStr);
+ foreach my $host ( sort(keys(%Jobs)) ) {
+ my $startTime = timeStamp2($Jobs{$host}{startTime});
+ next if ( $host eq $bpc->trashJob
+ && $Jobs{$host}{processState} ne "running" );
+ $Jobs{$host}{type} = $Status{$host}{type}
+ if ( $Jobs{$host}{type} eq "" && defined($Status{$host}));
+ (my $cmd = $Jobs{$host}{cmd}) =~ s/$BinDir\///g;
+ (my $xferPid = $Jobs{$host}{xferPid}) =~ s/,/, /g;
+ $jobStr .= <
+EOF
+ }
+ Header($Lang->{BackupPC__Log_File_History});
+ print (eval("qq{$Lang->{Log_File_History__hdr}}"));
+ Trailer();
+}
+
+1;
diff --git a/lib/BackupPC/CGI/Lib.pm b/lib/BackupPC/CGI/Lib.pm
new file mode 100644
index 0000000..baa168f
--- /dev/null
+++ b/lib/BackupPC/CGI/Lib.pm
@@ -0,0 +1,539 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::Lib package
+#
+# DESCRIPTION
+#
+# This library defines a BackupPC::Lib class and a variety of utility
+# functions used by BackupPC.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::Lib;
+
+use strict;
+use BackupPC::Lib;
+
+require Exporter;
+
+use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS );
+
+use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
+use vars qw(%Status %Info %Jobs @BgQueue @UserQueue @CmdQueue
+ %QueueLen %StatusHost);
+use vars qw($Hosts $HostsMTime $ConfigMTime $PrivAdmin);
+use vars qw(%UserEmailInfo $UserEmailInfoMTime %RestoreReq);
+use vars qw($Lang);
+
+@ISA = qw(Exporter);
+
+@EXPORT = qw( );
+
+@EXPORT_OK = qw(
+ timeStamp2
+ HostLink
+ UserLink
+ EscHTML
+ EscURI
+ ErrorExit
+ ServerConnect
+ GetStatusInfo
+ ReadUserEmailInfo
+ CheckPermission
+ GetUserHosts
+ ConfirmIPAddress
+ Header
+ Trailer
+ NavSectionTitle
+ NavSectionStart
+ NavSectionEnd
+ NavLink
+ h1
+ h2
+ $Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc
+ %Status %Info %Jobs @BgQueue @UserQueue @CmdQueue
+ %QueueLen %StatusHost
+ $Hosts $HostsMTime $ConfigMTime $PrivAdmin
+ %UserEmailInfo $UserEmailInfoMTime %RestoreReq
+ $Lang
+ );
+
+%EXPORT_TAGS = (
+ 'all' => [ @EXPORT_OK ],
+);
+
+sub NewRequest
+{
+ $Cgi = new CGI;
+ %In = $Cgi->Vars;
+
+ #
+ # We require that Apache pass in $ENV{SCRIPT_NAME} and $ENV{REMOTE_USER}.
+ # The latter requires .ht_access style authentication. Replace this
+ # code if you are using some other type of authentication, and have
+ # a different way of getting the user name.
+ #
+ $MyURL = $ENV{SCRIPT_NAME};
+ $User = $ENV{REMOTE_USER};
+
+ if ( !defined($bpc) ) {
+ ErrorExit($Lang->{BackupPC__Lib__new_failed__check_apache_error_log})
+ if ( !($bpc = BackupPC::Lib->new(undef, undef, 1)) );
+ $TopDir = $bpc->TopDir();
+ $BinDir = $bpc->BinDir();
+ %Conf = $bpc->Conf();
+ $Lang = $bpc->Lang();
+ $ConfigMTime = $bpc->ConfigMTime();
+ } elsif ( $bpc->ConfigMTime() != $ConfigMTime ) {
+ $bpc->ConfigRead();
+ %Conf = $bpc->Conf();
+ $ConfigMTime = $bpc->ConfigMTime();
+ $Lang = $bpc->Lang();
+ }
+
+ #
+ # Clean up %ENV for taint checking
+ #
+ delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
+ $ENV{PATH} = $Conf{MyPath};
+
+ #
+ # Verify we are running as the correct user
+ #
+ if ( $Conf{BackupPCUserVerify}
+ && $> != (my $uid = (getpwnam($Conf{BackupPCUser}))[2]) ) {
+ ErrorExit(eval("qq{$Lang->{Wrong_user__my_userid_is___}}"), <
+This is an installation problem. If you are using mod_perl then
+it appears that Apache is not running as user $Conf{BackupPCUser}.
+If you are not using mod_perl, then most like setuid is not working
+properly on BackupPC_Admin. Check the permissions on
+$Conf{CgiDir}/BackupPC_Admin and look at the documentation.
+EOF
+ }
+
+ if ( !defined($Hosts) || $bpc->HostsMTime() != $HostsMTime ) {
+ $HostsMTime = $bpc->HostsMTime();
+ $Hosts = $bpc->HostInfoRead();
+
+ # turn moreUsers list into a hash for quick lookups
+ foreach my $host (keys %$Hosts) {
+ $Hosts->{$host}{moreUsers} =
+ {map {$_, 1} split(",", $Hosts->{$host}{moreUsers}) }
+ }
+ }
+}
+
+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 EscHTML
+{
+ 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 EscURI
+{
+ my($s) = @_;
+ $s =~ s{([^\w.\/-])}{sprintf("%%%02X", ord($1));}eg;
+ return \$s;
+}
+
+sub ErrorExit
+{
+ my(@mesg) = @_;
+ my($head) = shift(@mesg);
+ my($mesg) = join("\n
", @mesg);
+ $Conf{CgiHeaderFontType} ||= "arial";
+ $Conf{CgiHeaderFontSize} ||= "3";
+ $Conf{CgiNavBarBgColor} ||= "#ddeeee";
+ $Conf{CgiHeaderBgColor} ||= "#99cc33";
+
+ if ( !defined($ENV{REMOTE_USER}) ) {
+ $mesg .= <
+Note: \$ENV{REMOTE_USER} is not set, which could mean there is an
+installation problem. BackupPC_Admin expects Apache to authenticate
+the user and pass their user name into this script as the REMOTE_USER
+environment variable. See the documentation.
+EOF
+ }
+
+ $bpc->ServerMesg("log User $User (host=$In{host}) got CGI error: $head")
+ if ( defined($bpc) );
+ if ( !defined($Lang->{Error}) ) {
+ Header("BackupPC: Error");
+ $mesg = <$mesg
+EOF
+ Trailer();
+ } else {
+ Header(eval("qq{$Lang->{Error}}"));
+ print (eval("qq{$Lang->{Error____head}}"));
+ Trailer();
+ }
+ exit(1);
+}
+
+sub ServerConnect
+{
+ #
+ # Verify that the server connection is ok
+ #
+ return if ( $bpc->ServerOK() );
+ $bpc->ServerDisconnect();
+ if ( my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}) ) {
+ ErrorExit(eval("qq{$Lang->{Unable_to_connect_to_BackupPC_server}}"));
+ }
+}
+
+sub GetStatusInfo
+{
+ my($status) = @_;
+ ServerConnect();
+ my $reply = $bpc->ServerMesg("status $status");
+ $reply = $1 if ( $reply =~ /(.*)/s );
+ eval($reply);
+ # ignore status related to admin and trashClean jobs
+ if ( $status =~ /\bhosts\b/ ) {
+ delete($Status{$bpc->adminJob});
+ delete($Status{$bpc->trashJob});
+ }
+}
+
+sub ReadUserEmailInfo
+{
+ if ( (stat("$TopDir/log/UserEmailInfo.pl"))[9] != $UserEmailInfoMTime ) {
+ do "$TopDir/log/UserEmailInfo.pl";
+ $UserEmailInfoMTime = (stat("$TopDir/log/UserEmailInfo.pl"))[9];
+ }
+}
+
+#
+# Check if the user is privileged. A privileged user can access
+# any information (backup files, logs, status pages etc).
+#
+# A user is privileged if they belong to the group
+# $Conf{CgiAdminUserGroup}, or they are in $Conf{CgiAdminUsers}
+# or they are the user assigned to a host in the host file.
+#
+sub CheckPermission
+{
+ my($host) = @_;
+ my $Privileged = 0;
+
+ return 0 if ( $User eq "" && $Conf{CgiAdminUsers} ne "*"
+ || $host ne "" && !defined($Hosts->{$host}) );
+ if ( $Conf{CgiAdminUserGroup} ne "" ) {
+ my($n,$p,$gid,$mem) = getgrnam($Conf{CgiAdminUserGroup});
+ $Privileged ||= ($mem =~ /\b$User\b/);
+ }
+ if ( $Conf{CgiAdminUsers} ne "" ) {
+ $Privileged ||= ($Conf{CgiAdminUsers} =~ /\b$User\b/);
+ $Privileged ||= $Conf{CgiAdminUsers} eq "*";
+ }
+ $PrivAdmin = $Privileged;
+ $Privileged ||= $User eq $Hosts->{$host}{user};
+ $Privileged ||= defined($Hosts->{$host}{moreUsers}{$User});
+
+ return $Privileged;
+}
+
+#
+# Returns the list of hosts that should appear in the navigation bar
+# for this user. If $Conf{CgiNavBarAdminAllHosts} is set, the admin
+# gets all the hosts. Otherwise, regular users get hosts for which
+# they are the user or are listed in the moreUsers column in the
+# hosts file.
+#
+sub GetUserHosts
+{
+ if ( $Conf{CgiNavBarAdminAllHosts} && CheckPermission() ) {
+ return sort keys %$Hosts;
+ }
+
+ return sort grep { $Hosts->{$_}{user} eq $User ||
+ defined($Hosts->{$_}{moreUsers}{$User}) } keys(%$Hosts);
+}
+
+#
+# Given a host name tries to find the IP address. For non-dhcp hosts
+# we just return the host name. For dhcp hosts we check the address
+# the user is using ($ENV{REMOTE_ADDR}) and also the last-known IP
+# address for $host. (Later we should replace this with a broadcast
+# nmblookup.)
+#
+sub ConfirmIPAddress
+{
+ my($host) = @_;
+ my $ipAddr = $host;
+
+ if ( defined($Hosts->{$host}) && $Hosts->{$host}{dhcp}
+ && $ENV{REMOTE_ADDR} =~ /^(\d+[\.\d]*)$/ ) {
+ $ipAddr = $1;
+ my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($ipAddr);
+ if ( $netBiosHost ne $host ) {
+ my($tryIP);
+ GetStatusInfo("host(${EscURI($host)})");
+ if ( defined($StatusHost{dhcpHostIP})
+ && $StatusHost{dhcpHostIP} ne $ipAddr ) {
+ $tryIP = eval("qq{$Lang->{tryIP}}");
+ ($netBiosHost, $netBiosUser)
+ = $bpc->NetBiosInfoGet($StatusHost{dhcpHostIP});
+ }
+ if ( $netBiosHost ne $host ) {
+ ErrorExit(eval("qq{$Lang->{Can_t_find_IP_address_for}}"),
+ eval("qq{$Lang->{host_is_a_DHCP_host}}"));
+ }
+ $ipAddr = $StatusHost{dhcpHostIP};
+ }
+ }
+ return $ipAddr;
+}
+
+###########################################################################
+# HTML layout subroutines
+###########################################################################
+
+sub Header
+{
+ my($title) = @_;
+ my @adminLinks = (
+ { link => "", name => $Lang->{Status},
+ priv => 1},
+ { link => "?action=summary", name => $Lang->{PC_Summary} },
+ { link => "?action=view&type=LOG", name => $Lang->{LOG_file} },
+ { link => "?action=LOGlist", name => $Lang->{Old_LOGs} },
+ { link => "?action=emailSummary", name => $Lang->{Email_summary} },
+ { link => "?action=view&type=config", name => $Lang->{Config_file} },
+ { link => "?action=view&type=hosts", name => $Lang->{Hosts_file} },
+ { link => "?action=queue", name => $Lang->{Current_queues} },
+ { link => "?action=view&type=docs", name => $Lang->{Documentation},
+ priv => 1},
+ { link => "http://backuppc.sourceforge.net/faq", name => "FAQ",
+ priv => 1},
+ { link => "http://backuppc.sourceforge.net", name => "SourceForge",
+ priv => 1},
+ );
+ print $Cgi->header();
+ print <
+
+$title
+$Conf{CgiHeaders}
+
+
+
+EOF
+}
diff --git a/lib/BackupPC/CGI/Queue.pm b/lib/BackupPC/CGI/Queue.pm
new file mode 100644
index 0000000..116ea0f
--- /dev/null
+++ b/lib/BackupPC/CGI/Queue.pm
@@ -0,0 +1,89 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::Queue package
+#
+# DESCRIPTION
+#
+# This module implements the Queue action for the CGI interface.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::Queue;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+
+sub action
+{
+ 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}[0]) =~ s/$BinDir\///;
+ $strCmd .= <
${HostLink($req->{host})}
+
$reqTime
+
$req->{user}
+
$cmd $req->{cmd}[0]
+EOF
+ }
+ Header($Lang->{BackupPC__Queue_Summary});
+
+ print ( eval ( "qq{$Lang->{Backup_Queue_Summary}}") );
+
+ Trailer();
+}
+
+1;
diff --git a/lib/BackupPC/CGI/Restore.pm b/lib/BackupPC/CGI/Restore.pm
new file mode 100644
index 0000000..8e2022e
--- /dev/null
+++ b/lib/BackupPC/CGI/Restore.pm
@@ -0,0 +1,273 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::Restore package
+#
+# DESCRIPTION
+#
+# This module implements the Restore action for the CGI interface.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::Restore;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+
+sub action
+{
+ my($str, $reply);
+ my $Privileged = CheckPermission($In{host});
+ if ( !$Privileged ) {
+ ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_restore_backup_files}}"));
+ }
+ my $host = $In{host};
+ my $num = $In{num};
+ my $share = $In{share};
+ my(@fileList, $fileListStr, $hiddenStr, $pathHdr, $badFileCnt);
+ my @Backups = $bpc->BackupInfoRead($host);
+
+ ServerConnect();
+ if ( !defined($Hosts->{$host}) ) {
+ ErrorExit(eval("qq{$Lang->{Bad_host_name}}"));
+ }
+ for ( my $i = 0 ; $i < $In{fcbMax} ; $i++ ) {
+ next if ( !defined($In{"fcb$i"}) );
+ (my $name = $In{"fcb$i"}) =~ s/%([0-9A-F]{2})/chr(hex($1))/eg;
+ $badFileCnt++ if ( $name =~ m{(^|/)\.\.(/|$)} );
+ if ( @fileList == 0 ) {
+ $pathHdr = $name;
+ } else {
+ while ( substr($name, 0, length($pathHdr)) ne $pathHdr ) {
+ $pathHdr = substr($pathHdr, 0, rindex($pathHdr, "/"));
+ }
+ }
+ push(@fileList, $name);
+ $hiddenStr .= <
+EOF
+ $fileListStr .= < ${EscHTML($name)}
+EOF
+ }
+ $hiddenStr .= "\n";
+ $hiddenStr .= "\n";
+ $badFileCnt++ if ( $In{pathHdr} =~ m{(^|/)\.\.(/|$)} );
+ $badFileCnt++ if ( $In{num} =~ m{(^|/)\.\.(/|$)} );
+ if ( @fileList == 0 ) {
+ ErrorExit($Lang->{You_haven_t_selected_any_files__please_go_Back_to});
+ }
+ if ( $badFileCnt ) {
+ ErrorExit($Lang->{Nice_try__but_you_can_t_put});
+ }
+ if ( @fileList == 1 ) {
+ $pathHdr =~ s/(.*)\/.*/$1/;
+ }
+ $pathHdr = "/" if ( $pathHdr eq "" );
+ if ( $In{type} != 0 && @fileList == $In{fcbMax} ) {
+ #
+ # All the files in the list were selected, so just restore the
+ # entire parent directory
+ #
+ @fileList = ( $pathHdr );
+ }
+ if ( $In{type} == 0 ) {
+ #
+ # Tell the user what options they have
+ #
+ Header(eval("qq{$Lang->{Restore_Options_for__host}}"));
+ print(eval("qq{$Lang->{Restore_Options_for__host2}}"));
+
+ #
+ # Verify that Archive::Zip is available before showing the
+ # zip restore option
+ #
+ if ( eval { require Archive::Zip } ) {
+ print (eval("qq{$Lang->{Option_2__Download_Zip_archive}}"));
+ } else {
+ print (eval("qq{$Lang->{Option_2__Download_Zip_archive2}}"));
+ }
+ print (eval("qq{$Lang->{Option_3__Download_Zip_archive}}"));
+ Trailer();
+ } elsif ( $In{type} == 1 ) {
+ #
+ # Provide the selected files via a tar archive.
+ #
+ my @fileListTrim = @fileList;
+ if ( @fileListTrim > 10 ) {
+ @fileListTrim = (@fileListTrim[0..9], '...');
+ }
+ $bpc->ServerMesg("log User $User downloaded tar archive for $host,"
+ . " backup $num; files were: "
+ . join(", ", @fileListTrim));
+
+ my @pathOpts;
+ if ( $In{relative} ) {
+ @pathOpts = ("-r", $pathHdr, "-p", "");
+ }
+ print(STDOUT <cmdSystemOrEval(["$BinDir/BackupPC_tarCreate",
+ "-h", $host,
+ "-n", $num,
+ "-s", $share,
+ @pathOpts,
+ @fileList
+ ],
+ sub { print(@_); }
+ );
+ } elsif ( $In{type} == 2 ) {
+ #
+ # Provide the selected files via a zip archive.
+ #
+ my @fileListTrim = @fileList;
+ if ( @fileListTrim > 10 ) {
+ @fileListTrim = (@fileListTrim[0..9], '...');
+ }
+ $bpc->ServerMesg("log User $User downloaded zip archive for $host,"
+ . " backup $num; files were: "
+ . join(", ", @fileListTrim));
+
+ my @pathOpts;
+ if ( $In{relative} ) {
+ @pathOpts = ("-r", $pathHdr, "-p", "");
+ }
+ print(STDOUT <cmdSystemOrEval(["$BinDir/BackupPC_zipCreate",
+ "-h", $host,
+ "-n", $num,
+ "-c", $In{compressLevel},
+ "-s", $share,
+ @pathOpts,
+ @fileList
+ ],
+ sub { print(@_); }
+ );
+ } elsif ( $In{type} == 3 ) {
+ #
+ # Do restore directly onto host
+ #
+ 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}}"));
+ }
+ $fileListStr = "";
+ foreach my $f ( @fileList ) {
+ my $targetFile = $f;
+ (my $strippedShare = $share) =~ s/^\///;
+ (my $strippedShareDest = $In{shareDest}) =~ s/^\///;
+ substr($targetFile, 0, length($pathHdr)) = $In{pathHdr};
+ $fileListStr .= <
$host:/$strippedShare$f
$In{hostDest}:/$strippedShareDest$targetFile
+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") ) {
+ binmode(REQ);
+ print(REQ $dump->Dump);
+ close(REQ);
+ } else {
+ ErrorExit(eval("qq{$Lang->{Can_t_open_create}}"));
+ }
+ $reply = $bpc->ServerMesg("restore ${EscURI($ipAddr)}"
+ . " ${EscURI($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();
+ }
+}
+
+1;
diff --git a/lib/BackupPC/CGI/RestoreFile.pm b/lib/BackupPC/CGI/RestoreFile.pm
new file mode 100644
index 0000000..fa732b6
--- /dev/null
+++ b/lib/BackupPC/CGI/RestoreFile.pm
@@ -0,0 +1,187 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::RestoreFile package
+#
+# DESCRIPTION
+#
+# This module implements the RestoreFile action for the CGI interface.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::RestoreFile;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+use BackupPC::FileZIO;
+use BackupPC::Attrib qw(:all);
+use BackupPC::View;
+
+sub action
+{
+ 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 ${EscHTML($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;
+}
+
+1;
diff --git a/lib/BackupPC/CGI/RestoreInfo.pm b/lib/BackupPC/CGI/RestoreInfo.pm
new file mode 100644
index 0000000..83583e8
--- /dev/null
+++ b/lib/BackupPC/CGI/RestoreInfo.pm
@@ -0,0 +1,92 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::RestoreInfo package
+#
+# DESCRIPTION
+#
+# This module implements the RestoreInfo action for the CGI interface.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::RestoreInfo;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+
+sub action
+{
+ 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 .= <
+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();
+}
+
+1;
diff --git a/lib/BackupPC/CGI/View.pm b/lib/BackupPC/CGI/View.pm
new file mode 100644
index 0000000..2a4239b
--- /dev/null
+++ b/lib/BackupPC/CGI/View.pm
@@ -0,0 +1,189 @@
+#============================================================= -*-perl-*-
+#
+# BackupPC::CGI::View package
+#
+# DESCRIPTION
+#
+# This module implements the View action for the CGI interface.
+#
+# AUTHOR
+# Craig Barratt
+#
+# COPYRIGHT
+# Copyright (C) 2003 Craig Barratt
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#========================================================================
+#
+# Version 2.1.0_CVS, released 3 Jul 2003.
+#
+# See http://backuppc.sourceforge.net.
+#
+#========================================================================
+
+package BackupPC::CGI::View;
+
+use strict;
+use BackupPC::CGI::Lib qw(:all);
+use BackupPC::FileZIO;
+
+sub action
+{
+ 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 = $Lang->{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 = $Lang->{Extracting_only_Errors};
+ } elsif ( $type eq "RestoreLOG" ) {
+ $file = "$TopDir/pc/$host/RestoreLOG$ext";
+ } elsif ( $type eq "RestoreErr" ) {
+ $file = "$TopDir/pc/$host/RestoreLOG$ext";
+ $comment = $Lang->{Extracting_only_Errors};
+ } elsif ( $host ne "" && $type eq "config" ) {
+ $file = "$TopDir/pc/$host/config.pl";
+ $file = "$TopDir/conf/$host.pl"
+ if ( $host ne "config" && -f "$TopDir/conf/$host.pl"
+ && !-f $file );
+ } elsif ( $type eq "docs" ) {
+ $file = "$BinDir/../doc/BackupPC.html";
+ if ( open(LOG, $file) ) {
+ binmode(LOG);
+ Header($Lang->{BackupPC__Documentation});
+ print while ( );
+ close(LOG);
+ Trailer();
+ } else {
+ ErrorExit(eval("qq{$Lang->{Unable_to_open__file__configuration_problem}}"));
+ }
+ return;
+ } elsif ( $type eq "config" ) {
+ $file = "$TopDir/conf/config.pl";
+ } elsif ( $type eq "hosts" ) {
+ $file = "$TopDir/conf/hosts";
+ } elsif ( $host ne "" ) {
+ $file = "$TopDir/pc/$host/LOG$ext";
+ } else {
+ $file = "$TopDir/log/LOG$ext";
+ $linkHosts = 1;
+ }
+ if ( !$Privileged ) {
+ ErrorExit($Lang->{Only_privileged_users_can_view_log_or_config_files});
+ }
+ if ( !-f $file && -f "$file.z" ) {
+ $file .= ".z";
+ $compress = 1;
+ }
+ Header(eval("qq{$Lang->{Backup_PC__Log_File__file}}") );
+ print( eval ("qq{$Lang->{Log_File__file__comment}}"));
+ if ( defined($fh = BackupPC::FileZIO->open($file, 0, $compress)) ) {
+ my $mtimeStr = $bpc->timeStamp((stat($file))[9], 1);
+
+ print ( eval ("qq{$Lang->{Contents_of_log_file}}"));
+
+ print "
";
+ 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}}"))
+ if ( $skipped );
+ 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 ${EscHTML($_)};
+ }
+ } elsif ( $linkHosts ) {
+ while ( 1 ) {
+ $_ = $fh->readLine();
+ last if ( $_ eq "" );
+ my $s = ${EscHTML($_)};
+ $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/(RsyncdPasswd.*=.*['"]).*(['"])/$1$2/ig;
+ s/(ServerMesgSecret.*=.*['"]).*(['"])/$1$2/ig;
+ print ${EscHTML($_)};
+ }
+ } else {
+ while ( 1 ) {
+ $_ = $fh->readLine();
+ last if ( $_ eq "" );
+ print ${EscHTML($_)};
+ }
+ }
+ $fh->close();
+ } else {
+ printf( eval("qq{$Lang->{_pre___Can_t_open_log_file__file}}"));
+ }
+ print <
+EOF
+ Trailer();
+}
+
+1;
diff --git a/lib/BackupPC/FileZIO.pm b/lib/BackupPC/FileZIO.pm
index 512bbab..4bae50a 100644
--- a/lib/BackupPC/FileZIO.pm
+++ b/lib/BackupPC/FileZIO.pm
@@ -11,7 +11,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/lib/BackupPC/Lang/de.pm b/lib/BackupPC/Lang/de.pm
index 9de994e..23fc3a1 100644
--- a/lib/BackupPC/Lang/de.pm
+++ b/lib/BackupPC/Lang/de.pm
@@ -575,8 +575,9 @@ $Lang{Backup_browse_for__host} = < Sie browsen das Backup #\$num, erstellt am \$backupTime
(vor \$backupAge Tagen),
\$filledBackup
-
Klicken Sie auf ein Verzeichnis um dieses zu durchsuchen.
-
Klicken Sie auf eine Datei um diese per download wiederherzustellen.
+
Klicken Sie auf ein Verzeichnis um dieses zu durchsuchen,
+
Klicken Sie auf eine Datei um diese per download wiederherzustellen,
+
(ENGLISH) You can view the backup history of the current directory.
\${h2("Inhalt von \${EscHTML(\$dirDisplay)}")}
@@ -614,6 +615,31 @@ This is now in the checkAll row
EOF
+# ------------------------------
+$Lang{DirHistory_backup_for__host} = "(ENGLISH) BackupPC: Directory backup history for \$host";
+
+$Lang{DirHistory_for__host} = <
+
Click on a backup number to return to the backup browser,
+
Click on a directory link to navigate into that directory,
+
Click on a file version link to download that file.
+
+
+\${h2("History of \${EscHTML(\$dirDisplay)}")}
+
+
+
+
Backup number
\$backupNumStr
+
Backup time
\$backupTimeStr
+\$fileStr
+
+EOF
+
# ------------------------------
$Lang{Restore___num_details_for__host} = "BackupServer: Restore #\$num Details für Computer \$host";
diff --git a/lib/BackupPC/Lang/en.pm b/lib/BackupPC/Lang/en.pm
index c10cec3..099bfab 100644
--- a/lib/BackupPC/Lang/en.pm
+++ b/lib/BackupPC/Lang/en.pm
@@ -573,7 +573,8 @@ $Lang{Backup_browse_for__host} = < Click on a directory below to navigate into that directory,
-
Click on a file below to restore that file.
+
Click on a file below to restore that file,
+
You can view the backup history of the current directory.
\${h2("Contents of \${EscHTML(\$dirDisplay)}")}
@@ -611,6 +612,30 @@ This is now in the checkAll row
EOF
+# ------------------------------
+$Lang{DirHistory_backup_for__host} = "BackupPC: Directory backup history for \$host";
+
+$Lang{DirHistory_for__host} = <
+
Click on a backup number to return to the backup browser,
+
Click on a directory link to navigate into that directory,
+
Click on a file version link to download that file.
+
+
+\${h2("History of \${EscHTML(\$dirDisplay)}")}
+
+
+
+
Backup number
\$backupNumStr
+
Backup time
\$backupTimeStr
+\$fileStr
+
+EOF
+
# ------------------------------
$Lang{Restore___num_details_for__host} = "BackupPC: Restore #\$num details for \$host";
diff --git a/lib/BackupPC/Lang/es.pm b/lib/BackupPC/Lang/es.pm
index c829e3c..7454817 100644
--- a/lib/BackupPC/Lang/es.pm
+++ b/lib/BackupPC/Lang/es.pm
@@ -575,7 +575,8 @@ $Lang{Backup_browse_for__host} = < Haga click en uno de los directorios de abajo para revisar sus contenidos,
-
Haga click en un archivo para restaurarlo.
+
Haga click en un archivo para restaurarlo,
+
(ENGLISH) You can view the backup history of the current directory.
\${h2("Contenido de \${EscHTML(\$dirDisplay)}")}
@@ -613,6 +614,31 @@ This is now in the checkAll row
EOF
+# ------------------------------
+$Lang{DirHistory_backup_for__host} = "(ENGLISH) BackupPC: Directory backup history for \$host";
+
+$Lang{DirHistory_for__host} = <
+
Click on a backup number to return to the backup browser,
+
Click on a directory link to navigate into that directory,
+
Click on a file version link to download that file.
+
+
+\${h2("History of \${EscHTML(\$dirDisplay)}")}
+
+
+
+
Backup number
\$backupNumStr
+
Backup time
\$backupTimeStr
+\$fileStr
+
+EOF
+
# ------------------------------
$Lang{Restore___num_details_for__host} = "BackupPC: Detalles de la restauración Nº\$num de \$host";
diff --git a/lib/BackupPC/Lang/fr.pm b/lib/BackupPC/Lang/fr.pm
index 13b80cb..d45d9e7 100644
--- a/lib/BackupPC/Lang/fr.pm
+++ b/lib/BackupPC/Lang/fr.pm
@@ -572,7 +572,8 @@ $Lang{Backup_browse_for__host} = < Cliquer dans un répertoire ci-dessous pour y naviguer,
-
Cliquer dans un fichier ci-dessous pour le restaurer.
+
Cliquer dans un fichier ci-dessous pour le restaurer,
+
(ENGLISH) You can view the backup history of the current directory.
\${h2("Contenu de \${EscHTML(\$dirDisplay)}")}
@@ -610,9 +611,32 @@ This is now in the checkAll row
EOF
-
# ------------------------------
+$Lang{DirHistory_backup_for__host} = "(ENGLISH) BackupPC: Directory backup history for \$host";
+
+$Lang{DirHistory_for__host} = <
+
Click on a backup number to return to the backup browser,
+
Click on a directory link to navigate into that directory,
+
Click on a file version link to download that file.
+
+
+\${h2("History of \${EscHTML(\$dirDisplay)}")}
+
+
+
Backup number
\$backupNumStr
+
Backup time
\$backupTimeStr
+\$fileStr
+
+EOF
+
+# ------------------------------
$Lang{Restore___num_details_for__host} = "BackupPC: Détails de la restauration n° \$num pour \$host";
$Lang{Restore___num_details_for__host2 } = <
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
@@ -58,7 +58,7 @@ sub new
TopDir => $topDir || '/data/BackupPC',
BinDir => $installDir || '/usr/local/BackupPC',
LibDir => $installDir || '/usr/local/BackupPC',
- Version => '2.0.0',
+ Version => '2.1.0_CVS',
BackupFields => [qw(
num type startTime endTime
nFiles size nFilesExist sizeExist nFilesNew sizeNew
diff --git a/lib/BackupPC/PoolWrite.pm b/lib/BackupPC/PoolWrite.pm
index 4e94ab8..b9da132 100644
--- a/lib/BackupPC/PoolWrite.pm
+++ b/lib/BackupPC/PoolWrite.pm
@@ -38,7 +38,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -56,7 +56,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/lib/BackupPC/View.pm b/lib/BackupPC/View.pm
index f008968..357c9e3 100644
--- a/lib/BackupPC/View.pm
+++ b/lib/BackupPC/View.pm
@@ -13,7 +13,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2002 Craig Barratt
+# Copyright (C) 2002-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
@@ -301,6 +301,142 @@ sub backupList
return @backupList;
}
+#
+# Return the history of all backups for a particular directory
+#
+sub dirHistory
+{
+ my($m, $share, $dir) = @_;
+ my($i, $level);
+ my $files = {};
+
+ $dir = "/$dir" if ( $dir !~ m{^/} );
+ $dir =~ s{/+$}{};
+
+ #
+ # merge backups, starting at the first one, and working
+ # forward.
+ #
+ for ( $i = 0 ; $i < @{$m->{backups}} ; $i++ ) {
+ $level = $m->{backups}[$i]{level};
+ my $backupNum = $m->{backups}[$i]{num};
+ my $mangle = $m->{backups}[$i]{mangle};
+ my $compress = $m->{backups}[$i]{compress};
+ my $path = "$m->{topDir}/pc/$m->{host}/$backupNum/";
+ my $sharePathM;
+ if ( $mangle ) {
+ $sharePathM = $m->{bpc}->fileNameEltMangle($share)
+ . $m->{bpc}->fileNameMangle($dir);
+ } else {
+ $sharePathM = $share . $dir;
+ }
+ $path .= $sharePathM;
+ #print(STDERR "Opening $path (share=$share)\n");
+ if ( !opendir(DIR, $path) ) {
+ #
+ # Oops, directory doesn't exist.
+ #
+ next;
+ }
+ my @dir = readdir(DIR);
+ closedir(DIR);
+ my $attr;
+ if ( $mangle ) {
+ $attr = BackupPC::Attrib->new({ compress => $compress });
+ if ( -f $attr->fileName($path) && !$attr->read($path) ) {
+ $m->{error} = "Can't read attribute file in $path";
+ $attr = undef;
+ }
+ }
+ foreach my $file ( @dir ) {
+ $file = $1 if ( $file =~ /(.*)/ );
+ my $fileUM = $file;
+ $fileUM = $m->{bpc}->fileNameUnmangle($fileUM) if ( $mangle );
+ #print(STDERR "Doing $fileUM\n");
+ #
+ # skip special files
+ #
+ next if ( $file eq ".."
+ || $file eq "."
+ || $mangle && $file eq "attrib"
+ || defined($files->{$fileUM}[$i]) );
+ my @s = stat("$path/$file");
+ if ( defined($attr) && defined(my $a = $attr->get($fileUM)) ) {
+ $files->{$fileUM}[$i] = $a;
+ $attr->set($fileUM, undef);
+ } else {
+ #
+ # Very expensive in the non-attribute case when compresseion
+ # is on. We have to stat the file and read compressed files
+ # to determine their size.
+ #
+ $files->{$fileUM}[$i] = {
+ type => -d _ ? BPC_FTYPE_DIR : BPC_FTYPE_FILE,
+ mode => $s[2],
+ uid => $s[4],
+ gid => $s[5],
+ size => -f _ ? $s[7] : 0,
+ mtime => $s[9],
+ };
+ if ( $compress && -f _ ) {
+ #
+ # Compute the correct size by reading the whole file
+ #
+ my $f = BackupPC::FileZIO->open("$path/$file",
+ 0, $compress);
+ if ( !defined($f) ) {
+ $m->{error} = "Can't open $path/$file";
+ } else {
+ my($data, $size);
+ while ( $f->read(\$data, 65636 * 8) > 0 ) {
+ $size += length($data);
+ }
+ $f->close;
+ $files->{$fileUM}[$i]{size} = $size;
+ }
+ }
+ }
+ $files->{$fileUM}[$i]{relPath} = "$dir/$fileUM";
+ $files->{$fileUM}[$i]{sharePathM} = "$sharePathM/$file";
+ $files->{$fileUM}[$i]{fullPath} = "$path/$file";
+ $files->{$fileUM}[$i]{backupNum} = $backupNum;
+ $files->{$fileUM}[$i]{compress} = $compress;
+ $files->{$fileUM}[$i]{nlink} = $s[3];
+ $files->{$fileUM}[$i]{inode} = $s[1];
+ }
+
+ #
+ # Merge old backups. Don't merge directories from old
+ # backups because every backup has an accurate directory
+ # tree.
+ #
+ for ( my $k = $i - 1 ; $level > 0 && $k >= 0 ; $k-- ) {
+ next if ( $m->{backups}[$k]{level} >= $level );
+ $level = $m->{backups}[$k]{level};
+ foreach my $fileUM ( keys(%$files) ) {
+ next if ( !defined($files->{$fileUM}[$k])
+ || defined($files->{$fileUM}[$i])
+ || $files->{$fileUM}[$k]{type} == BPC_FTYPE_DIR );
+ $files->{$fileUM}[$i] = $files->{$fileUM}[$k];
+ }
+ }
+
+ #
+ # Finally, remove deleted files
+ #
+ if ( defined($attr) ) {
+ my $a = $attr->get;
+ foreach my $fileUM ( keys(%$a) ) {
+ next if ( $a->{$fileUM}{type} != BPC_FTYPE_DELETED );
+ $files->{$fileUM}[$i] = undef;
+ }
+ }
+ }
+ #print STDERR "Returning:\n", Dumper($files);
+ return $files;
+}
+
+
#
# Do a recursive find starting at the given path (either a file
# or directory). The callback function $callback is called on each
diff --git a/lib/BackupPC/Xfer/Rsync.pm b/lib/BackupPC/Xfer/Rsync.pm
index 1b43096..8f8093b 100644
--- a/lib/BackupPC/Xfer/Rsync.pm
+++ b/lib/BackupPC/Xfer/Rsync.pm
@@ -11,7 +11,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2002 Craig Barratt
+# Copyright (C) 2002-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/lib/BackupPC/Xfer/RsyncFileIO.pm b/lib/BackupPC/Xfer/RsyncFileIO.pm
index 4311e7b..cc29e29 100644
--- a/lib/BackupPC/Xfer/RsyncFileIO.pm
+++ b/lib/BackupPC/Xfer/RsyncFileIO.pm
@@ -8,11 +8,11 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2002 Craig Barratt
+# Copyright (C) 2002-2003 Craig Barratt
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/lib/BackupPC/Xfer/Smb.pm b/lib/BackupPC/Xfer/Smb.pm
index 968df3a..5e1df82 100644
--- a/lib/BackupPC/Xfer/Smb.pm
+++ b/lib/BackupPC/Xfer/Smb.pm
@@ -11,7 +11,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/lib/BackupPC/Xfer/Tar.pm b/lib/BackupPC/Xfer/Tar.pm
index d7b6488..382c26b 100644
--- a/lib/BackupPC/Xfer/Tar.pm
+++ b/lib/BackupPC/Xfer/Tar.pm
@@ -11,7 +11,7 @@
# Craig Barratt
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/lib/BackupPC/Zip/FileMember.pm b/lib/BackupPC/Zip/FileMember.pm
index f4215b5..7ddce4d 100644
--- a/lib/BackupPC/Zip/FileMember.pm
+++ b/lib/BackupPC/Zip/FileMember.pm
@@ -15,7 +15,7 @@
# Based on Archive::Zip::FileMember, Copyright (c) 2000 Ned Konz.
#
# COPYRIGHT
-# Copyright (C) 2002 Craig Barratt
+# Copyright (C) 2002-2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@
#
#========================================================================
#
-# Version 2.0.0, released 14 Jun 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
#
# See http://backuppc.sourceforge.net.
#
diff --git a/makeDist b/makeDist
index 6079896..712ca05 100755
--- a/makeDist
+++ b/makeDist
@@ -41,8 +41,8 @@ use File::Copy;
umask(0022);
-my $Version = "2.0.0";
-my $ReleaseDate = "14 Jun 2003";
+my $Version = "2.1.0_CVS";
+my $ReleaseDate = "3 Jul 2003";
my $DistDir = "dist/BackupPC-$Version";
my @PerlSrc = qw(
@@ -62,12 +62,26 @@ my @PerlSrc = qw(
lib/BackupPC/Attrib.pm
lib/BackupPC/FileZIO.pm
lib/BackupPC/Lib.pm
+ lib/BackupPC/PoolWrite.pm
+ lib/BackupPC/View.pm
+ lib/BackupPC/CGI/Browse.pm
+ lib/BackupPC/CGI/DirHistory.pm
+ lib/BackupPC/CGI/EmailSummary.pm
+ lib/BackupPC/CGI/GeneralInfo.pm
+ lib/BackupPC/CGI/HostInfo.pm
+ lib/BackupPC/CGI/Lib.pm
+ lib/BackupPC/CGI/LOGlist.pm
+ lib/BackupPC/CGI/Queue.pm
+ lib/BackupPC/CGI/RestoreFile.pm
+ lib/BackupPC/CGI/RestoreInfo.pm
+ lib/BackupPC/CGI/Restore.pm
+ lib/BackupPC/CGI/StartStopBackup.pm
+ lib/BackupPC/CGI/Summary.pm
+ lib/BackupPC/CGI/View.pm
lib/BackupPC/Lang/de.pm
lib/BackupPC/Lang/en.pm
lib/BackupPC/Lang/es.pm
lib/BackupPC/Lang/fr.pm
- lib/BackupPC/PoolWrite.pm
- lib/BackupPC/View.pm
lib/BackupPC/Xfer/Smb.pm
lib/BackupPC/Xfer/Tar.pm
lib/BackupPC/Xfer/Rsync.pm
@@ -103,8 +117,12 @@ exit(1) if ( $errCnt );
rmtree($DistDir, 0, 0);
mkpath($DistDir, 0, 0777);
-foreach my $dir ( qw(bin lib/BackupPC/Xfer lib/BackupPC/Zip lib/BackupPC/Lang
- doc conf images init.d/src cgi-bin) ) {
+foreach my $dir ( qw(bin doc conf images init.d/src cgi-bin
+ lib/BackupPC/CGI
+ lib/BackupPC/Lang
+ lib/BackupPC/Xfer
+ lib/BackupPC/Zip
+ ) ) {
mkpath("$DistDir/$dir", 0, 0777);
}
@@ -306,7 +324,10 @@ sub CheckLangUsage
my $errors;
my $vars = {};
- foreach my $file ( qw(cgi-bin/BackupPC_Admin bin/BackupPC_sendEmail) ) {
+ foreach my $file ( (
+ qw(cgi-bin/BackupPC_Admin bin/BackupPC_sendEmail),
+
+ ) ) {
open(F, $file) || die("can't open $file");
binmode(F);
while ( ) {
--
2.20.1