* On the phase 2 retry pass with rsync, verify the cached checksums
[BackupPC.git] / lib / BackupPC / CGI / Summary.pm
1 #============================================================= -*-perl-*-
2 #
3 # BackupPC::CGI::Summary package
4 #
5 # DESCRIPTION
6 #
7 #   This module implements the Summary action for the CGI interface.
8 #
9 # AUTHOR
10 #   Craig Barratt  <cbarratt@users.sourceforge.net>
11 #
12 # COPYRIGHT
13 #   Copyright (C) 2003  Craig Barratt
14 #
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.
19 #
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.
24 #
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
28 #
29 #========================================================================
30 #
31 # Version 2.1.0beta1, released 9 Apr 2004.
32 #
33 # See http://backuppc.sourceforge.net.
34 #
35 #========================================================================
36
37 package BackupPC::CGI::Summary;
38
39 use strict;
40 use BackupPC::CGI::Lib qw(:all);
41
42 sub action
43 {
44     my($fullTot, $fullSizeTot, $incrTot, $incrSizeTot, $str,
45        $strNone, $strGood, $hostCntGood, $hostCntNone);
46
47     $hostCntGood = $hostCntNone = 0;
48     GetStatusInfo("hosts");
49     my $Privileged = CheckPermission();
50
51     foreach my $host ( GetUserHosts(1) ) {
52         my($fullDur, $incrCnt, $incrAge, $fullSize, $fullRate, $reasonHilite);
53         my($shortErr);
54         my @Backups = $bpc->BackupInfoRead($host);
55         my $fullCnt = $incrCnt = 0;
56         my $fullAge = $incrAge = -1;
57
58         $bpc->ConfigRead($host);
59         %Conf = $bpc->Conf();
60
61         next if ( $Conf{XferMethod} eq "archive" );
62         next if ( !$Privileged && !CheckPermission($host) );
63
64         for ( my $i = 0 ; $i < @Backups ; $i++ ) {
65             if ( $Backups[$i]{type} eq "full" ) {
66                 $fullCnt++;
67                 if ( $fullAge < 0 || $Backups[$i]{startTime} > $fullAge ) {
68                     $fullAge  = $Backups[$i]{startTime};
69                     $fullSize = $Backups[$i]{size} / (1024 * 1024);
70                     $fullDur  = $Backups[$i]{endTime} - $Backups[$i]{startTime};
71                 }
72                 $fullSizeTot += $Backups[$i]{size} / (1024 * 1024);
73             } else {
74                 $incrCnt++;
75                 if ( $incrAge < 0 || $Backups[$i]{startTime} > $incrAge ) {
76                     $incrAge = $Backups[$i]{startTime};
77                 }
78                 $incrSizeTot += $Backups[$i]{size} / (1024 * 1024);
79             }
80         }
81         if ( $fullAge < 0 ) {
82             $fullAge = "";
83             $fullRate = "";
84         } else {
85             $fullAge = sprintf("%.1f", (time - $fullAge) / (24 * 3600));
86             $fullRate = sprintf("%.2f",
87                                 $fullSize / ($fullDur <= 0 ? 1 : $fullDur));
88         }
89         if ( $incrAge < 0 ) {
90             $incrAge = "";
91         } else {
92             $incrAge = sprintf("%.1f", (time - $incrAge) / (24 * 3600));
93         }
94         $fullTot += $fullCnt;
95         $incrTot += $incrCnt;
96         $fullSize = sprintf("%.2f", $fullSize / 1000);
97         $incrAge = "&nbsp;" if ( $incrAge eq "" );
98         $reasonHilite = $Conf{CgiStatusHilightColor}{$Status{$host}{reason}}
99                       || $Conf{CgiStatusHilightColor}{$Status{$host}{state}};
100         $reasonHilite = " bgcolor=\"$reasonHilite\"" if ( $reasonHilite ne "" );
101         if ( $Status{$host}{state} ne "Status_backup_in_progress"
102                 && $Status{$host}{state} ne "Status_restore_in_progress"
103                 && $Status{$host}{error} ne "" ) {
104             ($shortErr = $Status{$host}{error}) =~ s/(.{48}).*/$1.../;
105             $shortErr = " ($shortErr)";
106         }
107
108         $str = <<EOF;
109 <tr$reasonHilite><td class="border"> ${HostLink($host)} </td>
110     <td align="center" class="border"> ${UserLink(defined($Hosts->{$host})
111                                     ? $Hosts->{$host}{user} : "")} </td>
112     <td align="center" class="border"> $fullCnt </td>
113     <td align="center" class="border"> $fullAge </td>
114     <td align="center" class="border"> $fullSize </td>
115     <td align="center" class="border"> $fullRate </td>
116     <td align="center" class="border"> $incrCnt </td>
117     <td align="center" class="border"> $incrAge </td>
118     <td align="center" class="border"> $Lang->{$Status{$host}{state}} </td>
119     <td class="border"> $Lang->{$Status{$host}{reason}}$shortErr </td></tr>
120 EOF
121         if ( @Backups == 0 ) {
122             $hostCntNone++;
123             $strNone .= $str;
124         } else {
125             $hostCntGood++;
126             $strGood .= $str;
127         }
128     }
129     $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
130     $incrSizeTot = sprintf("%.2f", $incrSizeTot / 1000);
131     my $now      = timeStamp2(time);
132
133     my $content = eval ("qq{$Lang->{BackupPC_Summary}}");
134     Header($Lang->{BackupPC__Server_Summary}, $content);
135     Trailer();
136 }
137
138 1;