Updates in preparation for 3.0.0beta2:
[BackupPC.git] / lib / BackupPC / CGI / Summary.pm
index 50e730b..725e850 100644 (file)
@@ -28,7 +28,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0_CVS, released 3 Jul 2003.
+# Version 3.0.0beta2, released 11 Nov 2006.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -48,23 +48,19 @@ sub action
     GetStatusInfo("hosts");
     my $Privileged = CheckPermission();
 
-    foreach my $host ( GetUserHosts() ) { ## give access to users hosts only
-    ## foreach my $host ( sort(keys(%Status)) ) {
-        my($fullDur, $incrCnt, $incrAge, $fullSize, $fullRate, $reasonHilite);
+    foreach my $host ( GetUserHosts(1) ) {
+        my($fullDur, $incrCnt, $incrAge, $fullSize, $fullRate, $reasonHilite,
+           $lastAge, $tempState, $tempReason);
        my($shortErr);
         my @Backups = $bpc->BackupInfoRead($host);
         my $fullCnt = $incrCnt = 0;
-        my $fullAge = $incrAge = -1;
+        my $fullAge = $incrAge = $lastAge = -1;
 
-        if ( defined(my $error = $bpc->ConfigRead($host)) ) {
-            print("dump failed: Can't read PC's config file: $error\n");
-            exit(1);
-        }
+        $bpc->ConfigRead($host);
         %Conf = $bpc->Conf();
 
-        if ($Conf{XferMethod} eq "archive" ) {
-            next;
-        }
+        next if ( $Conf{XferMethod} eq "archive" );
+        next if ( !$Privileged && !CheckPermission($host) );
 
         for ( my $i = 0 ; $i < @Backups ; $i++ ) {
             if ( $Backups[$i]{type} eq "full" ) {
@@ -83,6 +79,16 @@ sub action
                 $incrSizeTot += $Backups[$i]{size} / (1024 * 1024);
             }
         }
+        if ( $fullAge > $incrAge && $fullAge >= 0 )  {
+            $lastAge = $fullAge;
+        } else {
+            $lastAge = $incrAge;
+        }
+        if ( $lastAge < 0 ) {
+            $lastAge = "";
+        } else {
+            $lastAge = sprintf("%.1f", (time - $lastAge) / (24 * 3600));
+        }
         if ( $fullAge < 0 ) {
             $fullAge = "";
             $fullRate = "";
@@ -102,9 +108,22 @@ sub action
        $incrAge = "&nbsp;" if ( $incrAge eq "" );
        $reasonHilite = $Conf{CgiStatusHilightColor}{$Status{$host}{reason}}
                      || $Conf{CgiStatusHilightColor}{$Status{$host}{state}};
+       if ( $Conf{BackupsDisable} == 1 ) {
+           $reasonHilite = $Conf{CgiStatusHilightColor}{Disabled_OnlyManualBackups};
+           $tempState = "Disabled_OnlyManualBackups";
+           $tempReason = "";
+       } elsif ($Conf{BackupsDisable} == 2 ) {
+           $reasonHilite = $Conf{CgiStatusHilightColor}{Disabled_AllBackupsDisabled};
+           $tempState = "Disabled_AllBackupsDisabled";
+           $tempReason = "";
+       } else {
+           $tempState = $Status{$host}{state};
+           $tempReason = $Status{$host}{reason};
+       }
        $reasonHilite = " bgcolor=\"$reasonHilite\"" if ( $reasonHilite ne "" );
-        if ( $Status{$host}{state} ne "Status_backup_in_progress"
-               && $Status{$host}{state} ne "Status_restore_in_progress"
+        if ( $tempState ne "Status_backup_in_progress"
+               && $tempState ne "Status_restore_in_progress"
+               && $Conf{BackupsDisable} == 0
                && $Status{$host}{error} ne "" ) {
            ($shortErr = $Status{$host}{error}) =~ s/(.{48}).*/$1.../;
            $shortErr = " ($shortErr)";
@@ -120,8 +139,9 @@ sub action
     <td align="center" class="border"> $fullRate </td>
     <td align="center" class="border"> $incrCnt </td>
     <td align="center" class="border"> $incrAge </td>
-    <td align="center" class="border"> $Lang->{$Status{$host}{state}} </td>
-    <td class="border"> $Lang->{$Status{$host}{reason}}$shortErr </td></tr>
+    <td align="center" class="border"> $lastAge </td> 
+    <td align="center" class="border"> $Lang->{$tempState} </td>
+    <td class="border"> $Lang->{$tempReason}$shortErr </td></tr>
 EOF
         if ( @Backups == 0 ) {
             $hostCntNone++;