* Commit for 2.1.0.
[BackupPC.git] / lib / BackupPC / CGI / HostInfo.pm
index cf58ad7..dbb53d7 100644 (file)
@@ -28,7 +28,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0_CVS, released 8 Feb 2004.
+# Version 2.1.0, released 20 Jun 2004.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -46,14 +46,16 @@ sub action
 
     $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)
-                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 ( !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) ) {
@@ -63,7 +65,7 @@ sub action
             }
             CheckPermission();
             ErrorExit(eval("qq{$Lang->{Unknown_host_or_user}}"))
-                                if ( !defined($Hosts->{$host}) );
+                               if ( !defined($Hosts->{$host}) );
         }
         $In{host} = $host;
     }
@@ -286,17 +288,52 @@ EOF
     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) = 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___}}");
         }
     }