1 #============================================================= -*-perl-*-
3 # BackupPC::CGI::Summary package
7 # This module implements the Summary action for the CGI interface.
10 # Craig Barratt <cbarratt@users.sourceforge.net>
13 # Copyright (C) 2003-2009 Craig Barratt
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #========================================================================
31 # Version 3.2.0, released 31 Jul 2010.
33 # See http://backuppc.sourceforge.net.
35 #========================================================================
37 package BackupPC::CGI::Summary;
40 use BackupPC::CGI::Lib qw(:all);
44 my($fullTot, $fullSizeTot, $incrTot, $incrSizeTot, $str,
45 $strNone, $strGood, $hostCntGood, $hostCntNone);
47 $hostCntGood = $hostCntNone = 0;
48 GetStatusInfo("hosts info");
49 my $Privileged = CheckPermission();
51 foreach my $host ( GetUserHosts(1) ) {
52 my($fullDur, $incrCnt, $incrAge, $fullSize, $fullRate, $reasonHilite,
53 $lastAge, $tempState, $tempReason, $lastXferErrors);
55 my @Backups = $bpc->BackupInfoRead($host);
56 my $fullCnt = $incrCnt = 0;
57 my $fullAge = $incrAge = $lastAge = -1;
59 $bpc->ConfigRead($host);
62 next if ( $Conf{XferMethod} eq "archive" );
63 next if ( !$Privileged && !CheckPermission($host) );
65 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
66 if ( $Backups[$i]{type} eq "full" ) {
68 if ( $fullAge < 0 || $Backups[$i]{startTime} > $fullAge ) {
69 $fullAge = $Backups[$i]{startTime};
70 $fullSize = $Backups[$i]{size} / (1024 * 1024);
71 $fullDur = $Backups[$i]{endTime} - $Backups[$i]{startTime};
73 $fullSizeTot += $Backups[$i]{size} / (1024 * 1024);
76 if ( $incrAge < 0 || $Backups[$i]{startTime} > $incrAge ) {
77 $incrAge = $Backups[$i]{startTime};
79 $incrSizeTot += $Backups[$i]{size} / (1024 * 1024);
82 if ( $fullAge > $incrAge && $fullAge >= 0 ) {
90 $lastAge = sprintf("%.1f", (time - $lastAge) / (24 * 3600));
96 $fullAge = sprintf("%.1f", (time - $fullAge) / (24 * 3600));
97 $fullRate = sprintf("%.2f",
98 $fullSize / ($fullDur <= 0 ? 1 : $fullDur));
100 if ( $incrAge < 0 ) {
103 $incrAge = sprintf("%.1f", (time - $incrAge) / (24 * 3600));
105 $fullTot += $fullCnt;
106 $incrTot += $incrCnt;
107 $fullSize = sprintf("%.2f", $fullSize / 1000);
108 $incrAge = " " if ( $incrAge eq "" );
109 $lastXferErrors = $Backups[@Backups-1]{xferErrs} if ( @Backups );
110 $reasonHilite = $Conf{CgiStatusHilightColor}{$Status{$host}{reason}}
111 || $Conf{CgiStatusHilightColor}{$Status{$host}{state}};
112 if ( $Conf{BackupsDisable} == 1 ) {
113 if ( $Status{$host}{state} ne "Status_backup_in_progress"
114 && $Status{$host}{state} ne "Status_restore_in_progress" ) {
115 $reasonHilite = $Conf{CgiStatusHilightColor}{Disabled_OnlyManualBackups};
116 $tempState = "Disabled_OnlyManualBackups";
119 $tempState = $Status{$host}{state};
120 $tempReason = $Status{$host}{reason};
122 } elsif ($Conf{BackupsDisable} == 2 ) {
123 $reasonHilite = $Conf{CgiStatusHilightColor}{Disabled_AllBackupsDisabled};
124 $tempState = "Disabled_AllBackupsDisabled";
127 $tempState = $Status{$host}{state};
128 $tempReason = $Status{$host}{reason};
130 $reasonHilite = " bgcolor=\"$reasonHilite\"" if ( $reasonHilite ne "" );
131 if ( $tempState ne "Status_backup_in_progress"
132 && $tempState ne "Status_restore_in_progress"
133 && $Conf{BackupsDisable} == 0
134 && $Status{$host}{error} ne "" ) {
135 ($shortErr = $Status{$host}{error}) =~ s/(.{48}).*/$1.../;
136 $shortErr = " ($shortErr)";
140 <tr$reasonHilite><td class="border">${HostLink($host)}</td>
141 <td align="center" class="border"> ${UserLink(defined($Hosts->{$host})
142 ? $Hosts->{$host}{user} : "")} </td>
143 <td align="center" class="border">$fullCnt</td>
144 <td align="center" class="border">$fullAge</td>
145 <td align="center" class="border">$fullSize</td>
146 <td align="center" class="border">$fullRate</td>
147 <td align="center" class="border">$incrCnt</td>
148 <td align="center" class="border">$incrAge</td>
149 <td align="center" class="border">$lastAge</td>
150 <td align="center" class="border">$Lang->{$tempState}</td>
151 <td align="center" class="border">$lastXferErrors</td>
152 <td class="border">$Lang->{$tempReason}$shortErr</td></tr>
154 if ( @Backups == 0 ) {
162 $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
163 $incrSizeTot = sprintf("%.2f", $incrSizeTot / 1000);
164 my $now = timeStamp2(time);
165 my $DUlastTime = timeStamp2($Info{DUlastValueTime});
166 my $DUmaxTime = timeStamp2($Info{DUDailyMaxTime});
168 my $content = eval ("qq{$Lang->{BackupPC_Summary}}");
169 Header($Lang->{BackupPC__Server_Summary}, $content);