- 2.0.0 release. Minor tweaks to disable utf8.
[BackupPC.git] / cgi-bin / BackupPC_Admin
index b077bcc..5dd2ba9 100755 (executable)
 #
 #========================================================================
 #
-# Version 2.0.0beta2, released 13 Apr 2003.
+# Version 2.0.0, released 14 Jun 2003.
 #
 # See http://backuppc.sourceforge.net.
 #
 #========================================================================
 
 use strict;
+no  utf8;
 use CGI;
 use lib "/usr/local/BackupPC/lib";
 use BackupPC::Lib;
@@ -76,7 +77,7 @@ $User   = $ENV{REMOTE_USER};
 
 if ( !defined($bpc) ) {
     ErrorExit($Lang->{BackupPC__Lib__new_failed__check_apache_error_log})
-       if ( !($bpc = BackupPC::Lib->new) );
+       if ( !($bpc = BackupPC::Lib->new(undef, undef, 1)) );
     $TopDir = $bpc->TopDir();
     $BinDir = $bpc->BinDir();
     %Conf   = $bpc->Conf();
@@ -100,7 +101,16 @@ $ENV{PATH} = $Conf{MyPath};
 #
 if ( $Conf{BackupPCUserVerify}
         && $> != (my $uid = (getpwnam($Conf{BackupPCUser}))[2]) ) {
-    ErrorExit(eval("qq{$Lang->{Wrong_user__my_userid_is___}}"));
+    ErrorExit(eval("qq{$Lang->{Wrong_user__my_userid_is___}}"), <<EOF);
+This script needs to run as the user specified in \$Conf{BackupPCUser},
+which is set to $Conf{BackupPCUser}.
+<p>
+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 ) {
@@ -195,7 +205,8 @@ sub Action_Summary
         $incrTot += $incrCnt;
         $fullSize = sprintf("%.2f", $fullSize / 1000);
        $incrAge = "&nbsp;" if ( $incrAge eq "" );
-       $reasonHilite = $Conf{CgiStatusHilightColor}{$Status{$host}{reason}};
+       $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"
@@ -378,6 +389,7 @@ sub Action_View
     } elsif ( $type eq "docs" ) {
         $file = "$BinDir/../doc/BackupPC.html";
         if ( open(LOG, $file) ) {
+           binmode(LOG);
             Header($Lang->{BackupPC__Documentation});
             print while ( <LOG> );
             close(LOG);
@@ -462,6 +474,7 @@ sub Action_View
                 # 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($_)};
             }
@@ -874,7 +887,9 @@ EOF
        if ( @fileListTrim > 10 ) {
            @fileListTrim = (@fileListTrim[0..9], '...');
        }
-       $bpc->ServerMesg(eval("qq{$Lang->{log_User__User_downloaded_tar_archive_for__host}}"));
+       $bpc->ServerMesg("log User $User downloaded tar archive for $host,"
+                      . " backup $num; files were: "
+                      . join(", ", @fileListTrim));
 
         my @pathOpts;
         if ( $In{relative} ) {
@@ -908,7 +923,9 @@ EOF
        if ( @fileListTrim > 10 ) {
            @fileListTrim = (@fileListTrim[0..9], '...');
        }
-       $bpc->ServerMesg(eval("qq{$Lang->{log_User__User_downloaded_zip_archive_for__host}}"));
+       $bpc->ServerMesg("log User $User downloaded zip archive for $host,"
+                      . " backup $num; files were: "
+                      . join(", ", @fileListTrim));
 
         my @pathOpts;
         if ( $In{relative} ) {
@@ -1003,6 +1020,7 @@ EOF
                          [qw(*RestoreReq)]);
         $dump->Indent(1);
         if ( open(REQ, ">$TopDir/pc/$hostDest/$reqFileName") ) {
+           binmode(REQ);
             print(REQ $dump->Dump);
             close(REQ);
         } else {
@@ -1425,6 +1443,7 @@ EOF
     }
     foreach my $host ( sort(keys(%Status)) ) {
         next if ( $Status{$host}{reason} ne "Reason_backup_failed"
+                   && $Status{$host}{reason} ne "Reason_restore_failed"
                    && (!$Status{$host}{userReq}
                        || $Status{$host}{reason} ne "Reason_no_ping") );
         my $startTime = timeStamp2($Status{$host}{startTime});
@@ -1611,6 +1630,16 @@ sub ErrorExit
     $Conf{CgiNavBarBgColor}  ||= "#ddeeee";
     $Conf{CgiHeaderBgColor}  ||= "#99cc33";
 
+    if ( !defined($ENV{REMOTE_USER}) ) {
+       $mesg .= <<EOF;
+<p>
+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}) ) {
@@ -1679,7 +1708,8 @@ sub CheckPermission
     my($host) = @_;
     my $Privileged = 0;
 
-    return 0 if ( $User eq "" || ($host ne "" && !defined($Hosts->{$host})) );
+    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/);
@@ -1816,7 +1846,7 @@ EOF
     }
     NavSectionTitle($Lang->{Hosts});
     if ( defined($Hosts) && %$Hosts > 0 ) {
-        NavSectionStart(0);
+        NavSectionStart(1);
         foreach my $host ( GetUserHosts() ) {
             NavLink("?host=${EscURI($host)}", $host);
         }
@@ -1872,7 +1902,7 @@ sub NavSectionStart
 {
     my($padding) = @_;
 
-    $padding = 2 if ( !defined($padding) );
+    $padding = 1 if ( !defined($padding) );
     print <<EOF;
 <table cellpadding="$padding" cellspacing="0" border="0" width="100%">
 EOF