* Commit for 2.1.0.
[BackupPC.git] / lib / BackupPC / CGI / HostInfo.pm
index 81d75a3..dbb53d7 100644 (file)
@@ -28,7 +28,7 @@
 #
 #========================================================================
 #
 #
 #========================================================================
 #
-# Version 2.1.0_CVS, released 3 Jul 2003.
+# Version 2.1.0, released 20 Jun 2004.
 #
 # See http://backuppc.sourceforge.net.
 #
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -46,14 +46,16 @@ sub action
 
     $host =~ s/^\s+//;
     $host =~ s/\s+$//;
 
     $host =~ s/^\s+//;
     $host =~ s/\s+$//;
-    return Action_GeneralInfo() if ( $host eq "" );
+    if ( $host eq "" ) {
+       ErrorExit(eval("qq{$Lang->{Unknown_host_or_user}}"));
+    }
     $host = lc($host)
     $host = lc($host)
-                if ( !-d "$TopDir/pc/$host" && -d "$TopDir/pc/" . lc($host) );
+               if ( !-d "$TopDir/pc/$host" && -d "$TopDir/pc/" . lc($host) );
     if ( $host =~ /\.\./ || !-d "$TopDir/pc/$host" ) {
         #
         # try to lookup by user name
         #
     if ( $host =~ /\.\./ || !-d "$TopDir/pc/$host" ) {
         #
         # try to lookup by user name
         #
-        if ( !defined($Hosts->{$host}) ) {
+        if ( $host eq "" || !defined($Hosts->{$host}) ) {
             foreach my $h ( keys(%$Hosts) ) {
                 if ( $Hosts->{$h}{user} eq $host
                         || lc($Hosts->{$h}{user}) eq lc($host) ) {
             foreach my $h ( keys(%$Hosts) ) {
                 if ( $Hosts->{$h}{user} eq $host
                         || lc($Hosts->{$h}{user}) eq lc($host) ) {
@@ -63,7 +65,7 @@ sub action
             }
             CheckPermission();
             ErrorExit(eval("qq{$Lang->{Unknown_host_or_user}}"))
             }
             CheckPermission();
             ErrorExit(eval("qq{$Lang->{Unknown_host_or_user}}"))
-                                if ( !defined($Hosts->{$host}) );
+                               if ( !defined($Hosts->{$host}) );
         }
         $In{host} = $host;
     }
         }
         $In{host} = $host;
     }
@@ -76,6 +78,50 @@ sub action
     }
     ReadUserEmailInfo();
 
     }
     ReadUserEmailInfo();
 
+    if ( $Conf{XferMethod} eq "archive" ) {
+        my @Archives = $bpc->ArchiveInfoRead($host);
+        my ($ArchiveStr,$warnStr);
+
+        for ( my $i = 0 ; $i < @Archives ; $i++ ) {
+            my $startTime = timeStamp2($Archives[$i]{startTime});
+            my $dur       = $Archives[$i]{endTime} - $Archives[$i]{startTime};
+            $dur          = 1 if ( $dur <= 0 );
+            my $duration  = sprintf("%.1f", $dur / 60);
+            my $Archives_Result = $Lang->{failed};
+            if ($Archives[$i]{result} ne "failed") { $Archives_Result = $Lang->{success}; }
+            $ArchiveStr  .= <<EOF;
+<tr><td align="center"><a href="$MyURL?action=archiveInfo&num=$Archives[$i]{num}&host=${EscURI($host)}">$Archives[$i]{num}</a> </td>
+    <td align="center"> $Archives_Result </td>
+    <td align="right"> $startTime </td>
+    <td align="right"> $duration </td>
+</tr>
+EOF
+        }
+        if ( $ArchiveStr ne "" ) {
+            $ArchiveStr = eval("qq{$Lang->{Archive_Summary}}");
+        }
+        if ( @Archives == 0 ) {
+            $warnStr = $Lang->{There_have_been_no_archives};
+        }
+        if ( $StatusHost{BgQueueOn} ) {
+            $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_background_queue_will_be_backed_up_soon}}");
+        }
+        if ( $StatusHost{UserQueueOn} ) {
+            $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_user_queue__will_be_backed_up_soon}}");
+        }
+        if ( $StatusHost{CmdQueueOn} ) {
+            $statusStr .= eval("qq{$Lang->{A_command_for_host_is_on_the_command_queue_will_run_soon}}");
+        }
+
+        my $content = eval("qq{$Lang->{Host__host_Archive_Summary2}}");
+        Header(eval("qq{$Lang->{Host__host_Archive_Summary}}"), $content, 1);
+        Trailer();
+        return;
+    }
+
+    #
+    # Normal, non-archive case
+    #
     my @Backups = $bpc->BackupInfoRead($host);
     my($str, $sizeStr, $compStr, $errStr, $warnStr);
     for ( my $i = 0 ; $i < @Backups ; $i++ ) {
     my @Backups = $bpc->BackupInfoRead($host);
     my($str, $sizeStr, $compStr, $errStr, $warnStr);
     for ( my $i = 0 ; $i < @Backups ; $i++ ) {
@@ -105,52 +151,52 @@ sub action
         my $filled = $Backups[$i]{noFill} ? $Lang->{No} : $Lang->{Yes};
         $filled .= " ($Backups[$i]{fillFromNum}) "
                             if ( $Backups[$i]{fillFromNum} ne "" );
         my $filled = $Backups[$i]{noFill} ? $Lang->{No} : $Lang->{Yes};
         $filled .= " ($Backups[$i]{fillFromNum}) "
                             if ( $Backups[$i]{fillFromNum} ne "" );
-       my $ltype = $Lang->{"backupType_$Backups[$i]{type}"};
+        my $ltype = $Lang->{"backupType_$Backups[$i]{type}"};
         $str .= <<EOF;
         $str .= <<EOF;
-<tr><td align="center"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
-    <td align="center"> $ltype </td>
-    <td align="center"> $filled </td>
-    <td align="right">  $startTime </td>
-    <td align="right">  $duration </td>
-    <td align="right">  $age </td>
-    <td align="left">   <tt>$TopDir/pc/$host/$Backups[$i]{num}</tt> </td></tr>
+<tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
+    <td align="center" class="border"> $ltype </td>
+    <td align="center" class="border"> $filled </td>
+    <td align="right" class="border">  $startTime </td>
+    <td align="right" class="border">  $duration </td>
+    <td align="right" class="border">  $age </td>
+    <td align="left" class="border">   <tt>$TopDir/pc/$host/$Backups[$i]{num}</tt> </td></tr>
 EOF
         $sizeStr .= <<EOF;
 EOF
         $sizeStr .= <<EOF;
-<tr><td align="center"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
-    <td align="center"> $ltype </td>
-    <td align="right">  $Backups[$i]{nFiles} </td>
-    <td align="right">  $MB </td>
-    <td align="right">  $MBperSec </td>
-    <td align="right">  $Backups[$i]{nFilesExist} </td>
-    <td align="right">  $MBExist </td>
-    <td align="right">  $Backups[$i]{nFilesNew} </td>
-    <td align="right">  $MBNew </td>
+<tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
+    <td align="center" class="border"> $ltype </td>
+    <td align="right" class="border">  $Backups[$i]{nFiles} </td>
+    <td align="right" class="border">  $MB </td>
+    <td align="right" class="border">  $MBperSec </td>
+    <td align="right" class="border">  $Backups[$i]{nFilesExist} </td>
+    <td align="right" class="border">  $MBExist </td>
+    <td align="right" class="border">  $Backups[$i]{nFilesNew} </td>
+    <td align="right" class="border">  $MBNew </td>
 </tr>
 EOF
 </tr>
 EOF
-       my $is_compress = $Backups[$i]{compress} || $Lang->{off};
-       if (! $ExistComp) { $ExistComp = "&nbsp;"; }
-       if (! $MBExistComp) { $MBExistComp = "&nbsp;"; }
+        my $is_compress = $Backups[$i]{compress} || $Lang->{off};
+        if (! $ExistComp) { $ExistComp = "&nbsp;"; }
+        if (! $MBExistComp) { $MBExistComp = "&nbsp;"; }
         $compStr .= <<EOF;
         $compStr .= <<EOF;
-<tr><td align="center"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
-    <td align="center"> $ltype </td>
-    <td align="center"> $is_compress </td> 
-    <td align="right">  $MBExist </td>
-    <td align="right">  $MBExistComp </td> 
-    <td align="right">  $ExistComp </td>   
-    <td align="right">  $MBNew </td>
-    <td align="right">  $MBNewComp </td>
-    <td align="right">  $NewComp </td>
+<tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
+    <td align="center" class="border"> $ltype </td>
+    <td align="center" class="border"> $is_compress </td>
+    <td align="right" class="border">  $MBExist </td>
+    <td align="right" class="border">  $MBExistComp </td>
+    <td align="right" class="border">  $ExistComp </td>
+    <td align="right" class="border">  $MBNew </td>
+    <td align="right" class="border">  $MBNewComp </td>
+    <td align="right" class="border">  $NewComp </td>
 </tr>
 EOF
         $errStr .= <<EOF;
 </tr>
 EOF
         $errStr .= <<EOF;
-<tr><td align="center"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
-    <td align="center"> $ltype </td>
-    <td align="center"> <a href="$MyURL?action=view&type=XferLOG&num=$Backups[$i]{num}&host=${EscURI($host)}">$Lang->{XferLOG}</a>,
+<tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
+    <td align="center" class="border"> $ltype </td>
+    <td align="center" class="border"> <a href="$MyURL?action=view&type=XferLOG&num=$Backups[$i]{num}&host=${EscURI($host)}">$Lang->{XferLOG}</a>,
                       <a href="$MyURL?action=view&type=XferErr&num=$Backups[$i]{num}&host=${EscURI($host)}">$Lang->{Errors}</a> </td>
                       <a href="$MyURL?action=view&type=XferErr&num=$Backups[$i]{num}&host=${EscURI($host)}">$Lang->{Errors}</a> </td>
-    <td align="right">  $Backups[$i]{xferErrs} </td>
-    <td align="right">  $Backups[$i]{xferBadFile} </td>
-    <td align="right">  $Backups[$i]{xferBadShare} </td>
-    <td align="right">  $Backups[$i]{tarErrs} </td></tr>
+    <td align="right" class="border">  $Backups[$i]{xferErrs} </td>
+    <td align="right" class="border">  $Backups[$i]{xferBadFile} </td>
+    <td align="right" class="border">  $Backups[$i]{xferBadShare} </td>
+    <td align="right" class="border">  $Backups[$i]{tarErrs} </td></tr>
 EOF
     }
 
 EOF
     }
 
@@ -164,39 +210,39 @@ EOF
         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 $duration  = sprintf("%.1f", $dur / 60);
         my $MB        = sprintf("%.1f", $Restores[$i]{size} / (1024*1024));
         my $MBperSec  = sprintf("%.2f", $Restores[$i]{size} / (1024*1024*$dur));
-       my $Restores_Result = $Lang->{failed};
-       if ($Restores[$i]{result} ne "failed") { $Restores_Result = $Lang->{success}; }
-       $restoreStr  .= <<EOF;
-<tr><td align="center"><a href="$MyURL?action=restoreInfo&num=$Restores[$i]{num}&host=${EscURI($host)}">$Restores[$i]{num}</a> </td>
-    <td align="center"> $Restores_Result </td>
-    <td align="right"> $startTime </td>
-    <td align="right"> $duration </td>
-    <td align="right"> $Restores[$i]{nFiles} </td>
-    <td align="right"> $MB </td>
-    <td align="right"> $Restores[$i]{tarCreateErrs} </td>
-    <td align="right"> $Restores[$i]{xferErrs} </td>
+        my $Restores_Result = $Lang->{failed};
+        if ($Restores[$i]{result} ne "failed") { $Restores_Result = $Lang->{success}; }
+        $restoreStr  .= <<EOF;
+<tr><td align="center" class="border"><a href="$MyURL?action=restoreInfo&num=$Restores[$i]{num}&host=${EscURI($host)}">$Restores[$i]{num}</a> </td>
+    <td align="center" class="border"> $Restores_Result </td>
+    <td align="right" class="border"> $startTime </td>
+    <td align="right" class="border"> $duration </td>
+    <td align="right" class="border"> $Restores[$i]{nFiles} </td>
+    <td align="right" class="border"> $MB </td>
+    <td align="right" class="border"> $Restores[$i]{tarCreateErrs} </td>
+    <td align="right" class="border"> $Restores[$i]{xferErrs} </td>
 </tr>
 EOF
     }
     if ( $restoreStr ne "" ) {
 </tr>
 EOF
     }
     if ( $restoreStr ne "" ) {
-       $restoreStr = eval("qq{$Lang->{Restore_Summary}}");
+        $restoreStr = eval("qq{$Lang->{Restore_Summary}}");
     }
     if ( @Backups == 0 ) {
         $warnStr = $Lang->{This_PC_has_never_been_backed_up};
     }
     if ( defined($Hosts->{$host}) ) {
         my $user = $Hosts->{$host}{user};
     }
     if ( @Backups == 0 ) {
         $warnStr = $Lang->{This_PC_has_never_been_backed_up};
     }
     if ( defined($Hosts->{$host}) ) {
         my $user = $Hosts->{$host}{user};
-       my @moreUsers = sort(keys(%{$Hosts->{$host}{moreUsers}}));
-       my $moreUserStr;
-       foreach my $u ( sort(keys(%{$Hosts->{$host}{moreUsers}})) ) {
-           $moreUserStr .= ", " if ( $moreUserStr ne "" );
-           $moreUserStr .= "${UserLink($u)}";
-       }
-       if ( $moreUserStr ne "" ) {
-           $moreUserStr = " ($Lang->{and} $moreUserStr).\n";
-       } else {
-           $moreUserStr = ".\n";
-       }
+        my @moreUsers = sort(keys(%{$Hosts->{$host}{moreUsers}}));
+        my $moreUserStr;
+        foreach my $u ( sort(keys(%{$Hosts->{$host}{moreUsers}})) ) {
+            $moreUserStr .= ", " if ( $moreUserStr ne "" );
+            $moreUserStr .= "${UserLink($u)}";
+        }
+        if ( $moreUserStr ne "" ) {
+            $moreUserStr = " ($Lang->{and} $moreUserStr).\n";
+        } else {
+            $moreUserStr = ".\n";
+        }
         if ( $user ne "" ) {
             $statusStr .= eval("qq{$Lang->{This_PC_is_used_by}$moreUserStr}");
         }
         if ( $user ne "" ) {
             $statusStr .= eval("qq{$Lang->{This_PC_is_used_by}$moreUserStr}");
         }
@@ -230,8 +276,8 @@ EOF
     $statusStr .= eval("qq{$Lang->{Last_status_is_state_StatusHost_state_reason_as_of_startTime}}");
 
     if ( $StatusHost{state} ne "Status_backup_in_progress"
     $statusStr .= eval("qq{$Lang->{Last_status_is_state_StatusHost_state_reason_as_of_startTime}}");
 
     if ( $StatusHost{state} ne "Status_backup_in_progress"
-           && $StatusHost{state} ne "Status_restore_in_progress"
-           && $StatusHost{error} ne "" ) {
+            && $StatusHost{state} ne "Status_restore_in_progress"
+            && $StatusHost{error} ne "" ) {
         $statusStr .= eval("qq{$Lang->{Last_error_is____EscHTML_StatusHost_error}}");
     }
     my $priorStr = "Pings";
         $statusStr .= eval("qq{$Lang->{Last_error_is____EscHTML_StatusHost_error}}");
     }
     my $priorStr = "Pings";
@@ -242,17 +288,52 @@ EOF
     if ( $StatusHost{aliveCnt} > 0 ) {
         $statusStr .= eval("qq{$Lang->{priorStr_to_host_have_succeeded_StatusHostaliveCnt_consecutive_times}}");
 
     if ( $StatusHost{aliveCnt} > 0 ) {
         $statusStr .= eval("qq{$Lang->{priorStr_to_host_have_succeeded_StatusHostaliveCnt_consecutive_times}}");
 
-        if ( $StatusHost{aliveCnt} >= $Conf{BlackoutGoodCnt}
-               && $Conf{BlackoutGoodCnt} >= 0 && $Conf{BlackoutHourBegin} >= 0
-               && $Conf{BlackoutHourEnd} >= 0 ) {
+        if ( (@{$Conf{BlackoutPeriods}} || defined($Conf{BlackoutHourBegin}))
+               && $StatusHost{aliveCnt} >= $Conf{BlackoutGoodCnt}
+                && $Conf{BlackoutGoodCnt} >= 0 ) {
+            #
+            # Handle backward compatibility with original separate scalar
+            # blackout parameters.
+            #
+            if ( defined($Conf{BlackoutHourBegin}) ) {
+                push(@{$Conf{BlackoutPeriods}},
+                     {
+                         hourBegin => $Conf{BlackoutHourBegin},
+                         hourEnd   => $Conf{BlackoutHourEnd},
+                         weekDays  => $Conf{BlackoutWeekDays},
+                     }
+                );
+            }
+
+            #
+            # TODO: this string needs i18n.  Also, comma-separated
+            # list with "and" for the last element might not translate
+            # correctly.
+            #
             my(@days) = qw(Sun Mon Tue Wed Thu Fri Sat);
             my(@days) = qw(Sun Mon Tue Wed Thu Fri Sat);
-            my($days) = join(", ", @days[@{$Conf{BlackoutWeekDays}}]);
-            my($t0) = sprintf("%d:%02d", $Conf{BlackoutHourBegin},
-                            60 * ($Conf{BlackoutHourBegin}
-                                     - int($Conf{BlackoutHourBegin})));
-            my($t1) = sprintf("%d:%02d", $Conf{BlackoutHourEnd},
-                            60 * ($Conf{BlackoutHourEnd}
-                                     - int($Conf{BlackoutHourEnd})));
+            my $blackoutStr;
+            my $periodCnt = 0;
+            foreach my $p ( @{$Conf{BlackoutPeriods}} ) {
+                next if ( ref($p->{weekDays}) ne "ARRAY"
+                            || !defined($p->{hourBegin})
+                            || !defined($p->{hourEnd})
+                        );
+                my $days = join(", ", @days[@{$p->{weekDays}}]);
+                my $t0   = sprintf("%d:%02d", $p->{hourBegin},
+                              60 * ($p->{hourBegin} - int($p->{hourBegin})));
+                my $t1   = sprintf("%d:%02d", $p->{hourEnd},
+                              60 * ($p->{hourEnd} - int($p->{hourEnd})));
+                if ( $periodCnt ) {
+                    $blackoutStr .= ", ";
+                    if ( $periodCnt == @{$Conf{BlackoutPeriods}} - 1 ) {
+                        $blackoutStr .= eval("qq{$Lang->{and}}");
+                        $blackoutStr .= " ";
+                    }
+                }
+                $blackoutStr
+                        .= eval("qq{$Lang->{__time0_to__time1_on__days}}");
+                $periodCnt++;
+            }
             $statusStr .= eval("qq{$Lang->{Because__host_has_been_on_the_network_at_least__Conf_BlackoutGoodCnt_consecutive_times___}}");
         }
     }
             $statusStr .= eval("qq{$Lang->{Because__host_has_been_on_the_network_at_least__Conf_BlackoutGoodCnt_consecutive_times___}}");
         }
     }
@@ -269,9 +350,8 @@ EOF
     }
 
     $startIncrStr = eval ("qq{$startIncrStr}");
     }
 
     $startIncrStr = eval ("qq{$startIncrStr}");
-
-    Header(eval("qq{$Lang->{Host__host_Backup_Summary}}"));
-    print(eval("qq{$Lang->{Host__host_Backup_Summary2}}"));
+    my $content = eval("qq{$Lang->{Host__host_Backup_Summary2}}");
+    Header(eval("qq{$Lang->{Host__host_Backup_Summary}}"), $content);
     Trailer();
 }
 
     Trailer();
 }