📄 hostinfo.pm
字号:
#============================================================= -*-perl-*-## BackupPC::CGI::HostInfo package## DESCRIPTION## This module implements the HostInfo action for the CGI interface.## AUTHOR# Craig Barratt <cbarratt@users.sourceforge.net>## COPYRIGHT# Copyright (C) 2003-2007 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# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA##========================================================================## Version 3.1.0, released 25 Nov 2007.## See http://backuppc.sourceforge.net.##========================================================================package BackupPC::CGI::HostInfo;use strict;use BackupPC::CGI::Lib qw(:all);sub action{ my $host = $1 if ( $In{host} =~ /(.*)/ ); my($statusStr, $startIncrStr); $host =~ s/^\s+//; $host =~ s/\s+$//; 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 ( $host =~ /\.\./ || !-d "$TopDir/pc/$host" ) { # # try to lookup by user name # if ( $host eq "" || !defined($Hosts->{$host}) ) { foreach my $h ( keys(%$Hosts) ) { if ( $Hosts->{$h}{user} eq $host || lc($Hosts->{$h}{user}) eq lc($host) ) { $host = $h; last; } } CheckPermission(); ErrorExit(eval("qq{$Lang->{Unknown_host_or_user}}")) if ( !defined($Hosts->{$host}) ); } $In{host} = $host; } GetStatusInfo("host(${EscURI($host)})"); $bpc->ConfigRead($host); %Conf = $bpc->Conf(); my $Privileged = CheckPermission($host); if ( !$Privileged ) { ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_view_information_about}}")); } 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 $startTime = timeStamp2($Backups[$i]{startTime}); my $dur = $Backups[$i]{endTime} - $Backups[$i]{startTime}; $dur = 1 if ( $dur <= 0 ); my $duration = sprintf("%.1f", $dur / 60); my $MB = sprintf("%.1f", $Backups[$i]{size} / (1024*1024)); my $MBperSec = sprintf("%.2f", $Backups[$i]{size} / (1024*1024*$dur)); my $MBExist = sprintf("%.1f", $Backups[$i]{sizeExist} / (1024*1024)); my $MBNew = sprintf("%.1f", $Backups[$i]{sizeNew} / (1024*1024)); my($MBExistComp, $ExistComp, $MBNewComp, $NewComp); if ( $Backups[$i]{sizeExist} && $Backups[$i]{sizeExistComp} ) { $MBExistComp = sprintf("%.1f", $Backups[$i]{sizeExistComp} / (1024 * 1024)); $ExistComp = sprintf("%.1f%%", 100 * (1 - $Backups[$i]{sizeExistComp} / $Backups[$i]{sizeExist})); } if ( $Backups[$i]{sizeNew} && $Backups[$i]{sizeNewComp} ) { $MBNewComp = sprintf("%.1f", $Backups[$i]{sizeNewComp} / (1024 * 1024)); $NewComp = sprintf("%.1f%%", 100 * (1 - $Backups[$i]{sizeNewComp} / $Backups[$i]{sizeNew})); } 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 = $Lang->{"backupType_$Backups[$i]{type}"}; $str .= <<EOF;<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="center" class="border"> $level </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;<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 my $is_compress = $Backups[$i]{compress} || $Lang->{off}; if (! $ExistComp) { $ExistComp = " "; } if (! $MBExistComp) { $MBExistComp = " "; } $compStr .= <<EOF;<tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -