X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FCGI%2FHostInfo.pm;h=d43ccfcd6239b88850b5f9d1c0784fce9d3f4e55;hp=ce075ab1037b12ddc1d9bc132f619ec6c4fbc142;hb=f9796d809e6a7d4ed2c356f0f32f1a3d628d3d1f;hpb=329e870f56fb6572fa697998d33676588034c149 diff --git a/lib/BackupPC/CGI/HostInfo.pm b/lib/BackupPC/CGI/HostInfo.pm index ce075ab..d43ccfc 100644 --- a/lib/BackupPC/CGI/HostInfo.pm +++ b/lib/BackupPC/CGI/HostInfo.pm @@ -10,7 +10,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2003 Craig Barratt +# Copyright (C) 2003-2009 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 @@ -28,7 +28,7 @@ # #======================================================================== # -# Version 2.1.0_CVS, released 3 Jul 2003. +# Version 3.2.0, released 31 Jul 2010. # # 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; } @@ -76,6 +78,50 @@ sub action } 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 .= <$Archives[$i]{num} + $Archives_Result + $startTime + $duration + +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++ ) { @@ -102,57 +148,57 @@ sub action } my $age = sprintf("%.1f", (time - $Backups[$i]{startTime}) / (24*3600)); my $browseURL = "$MyURL?action=browse&host=${EscURI($host)}&num=$Backups[$i]{num}"; + my $level = $Backups[$i]{level}; my $filled = $Backups[$i]{noFill} ? $Lang->{No} : $Lang->{Yes}; $filled .= " ($Backups[$i]{fillFromNum}) " if ( $Backups[$i]{fillFromNum} ne "" ); - my $ltype; - if ($Backups[$i]{type} eq "full") { $ltype = $Lang->{full}; } - else { $ltype = $Lang->{incremental}; } + my $ltype = $Lang->{"backupType_$Backups[$i]{type}"}; $str .= < $Backups[$i]{num} - $ltype - $filled - $startTime - $duration - $age - $TopDir/pc/$host/$Backups[$i]{num} + $Backups[$i]{num} + $ltype + $filled + $level + $startTime + $duration + $age + $TopDir/pc/$host/$Backups[$i]{num} EOF $sizeStr .= < $Backups[$i]{num} - $ltype - $Backups[$i]{nFiles} - $MB - $MBperSec - $Backups[$i]{nFilesExist} - $MBExist - $Backups[$i]{nFilesNew} - $MBNew + $Backups[$i]{num} + $ltype + $Backups[$i]{nFiles} + $MB + $MBperSec + $Backups[$i]{nFilesExist} + $MBExist + $Backups[$i]{nFilesNew} + $MBNew EOF - my $is_compress = $Backups[$i]{compress} || $Lang->{off}; - if (! $ExistComp) { $ExistComp = " "; } - if (! $MBExistComp) { $MBExistComp = " "; } + my $is_compress = $Backups[$i]{compress} || $Lang->{off}; + if (! $ExistComp) { $ExistComp = " "; } + if (! $MBExistComp) { $MBExistComp = " "; } $compStr .= < $Backups[$i]{num} - $ltype - $is_compress - $MBExist - $MBExistComp - $ExistComp - $MBNew - $MBNewComp - $NewComp + $Backups[$i]{num} + $ltype + $is_compress + $MBExist + $MBExistComp + $ExistComp + $MBNew + $MBNewComp + $NewComp EOF $errStr .= < $Backups[$i]{num} - $ltype - $Lang->{XferLOG}, + $Backups[$i]{num} + $ltype + $Lang->{XferLOG}, $Lang->{Errors} - $Backups[$i]{xferErrs} - $Backups[$i]{xferBadFile} - $Backups[$i]{xferBadShare} - $Backups[$i]{tarErrs} + $Backups[$i]{xferErrs} + $Backups[$i]{xferBadFile} + $Backups[$i]{xferBadShare} + $Backups[$i]{tarErrs} EOF } @@ -166,44 +212,51 @@ 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 $Restores_Result = $Lang->{failed}; - if ($Restores[$i]{result} ne "failed") { $Restores_Result = $Lang->{success}; } - $restoreStr .= <$Restores[$i]{num} - $Restores_Result - $startTime - $duration - $Restores[$i]{nFiles} - $MB - $Restores[$i]{tarCreateErrs} - $Restores[$i]{xferErrs} + my $Restores_Result = $Lang->{failed}; + if ($Restores[$i]{result} ne "failed") { $Restores_Result = $Lang->{success}; } + $restoreStr .= <$Restores[$i]{num} + $Restores_Result + $startTime + $duration + $Restores[$i]{nFiles} + $MB + $Restores[$i]{tarCreateErrs} + $Restores[$i]{xferErrs} 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}; - 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 ( defined($UserEmailInfo{$user}) + if ( defined($UserEmailInfo{$user}) && defined($UserEmailInfo{$user}{$host}) ) { + my $mailTime = timeStamp2($UserEmailInfo{$user}{$host}{lastTime}); + my $subj = $UserEmailInfo{$user}{$host}{lastSubj}; + $statusStr .= eval("qq{$Lang->{Last_email_sent_to__was_at___subject}}"); + } elsif ( defined($UserEmailInfo{$user}) && $UserEmailInfo{$user}{lastHost} eq $host ) { + # + # Old format %UserEmailInfo - pre 3.2.0. + # my $mailTime = timeStamp2($UserEmailInfo{$user}{lastTime}); my $subj = $UserEmailInfo{$user}{lastSubj}; $statusStr .= eval("qq{$Lang->{Last_email_sent_to__was_at___subject}}"); @@ -232,8 +285,8 @@ EOF $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"; @@ -244,17 +297,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___}}"); } } @@ -266,14 +354,15 @@ EOF if ( @Backups ) { # only allow incremental if there are already some backups $startIncrStr = < + EOF } - $startIncrStr = eval ("qq{$startIncrStr}"); - - Header(eval("qq{$Lang->{Host__host_Backup_Summary}}")); - print(eval("qq{$Lang->{Host__host_Backup_Summary2}}")); + $startIncrStr = eval("qq{$startIncrStr}"); + my $content = eval("qq{$Lang->{Host__host_Backup_Summary2}}"); + Header(eval("qq{$Lang->{Host__host_Backup_Summary}}"), $content); Trailer(); }