* A failed full dump is now saved as a partial (incomplete) dump,
[BackupPC.git] / lib / BackupPC / CGI / GeneralInfo.pm
1 #============================================================= -*-perl-*-
2 #
3 # BackupPC::CGI::GeneralInfo package
4 #
5 # DESCRIPTION
6 #
7 #   This module implements the GeneralInfo 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.0_CVS, released 3 Jul 2003.
32 #
33 # See http://backuppc.sourceforge.net.
34 #
35 #========================================================================
36
37 package BackupPC::CGI::GeneralInfo;
38
39 use strict;
40 use BackupPC::CGI::Lib qw(:all);
41
42 sub action
43 {
44     GetStatusInfo("info jobs hosts queueLen");
45     my $Privileged = CheckPermission();
46
47     my($jobStr, $statusStr);
48     foreach my $host ( sort(keys(%Jobs)) ) {
49         my $startTime = timeStamp2($Jobs{$host}{startTime});
50         next if ( $host eq $bpc->trashJob
51                     && $Jobs{$host}{processState} ne "running" );
52         $Jobs{$host}{type} = $Status{$host}{type}
53                     if ( $Jobs{$host}{type} eq "" && defined($Status{$host}));
54         (my $cmd = $Jobs{$host}{cmd}) =~ s/$BinDir\///g;
55         (my $xferPid = $Jobs{$host}{xferPid}) =~ s/,/, /g;
56         $jobStr .= <<EOF;
57 <tr><td> ${HostLink($host)} </td>
58     <td align="center"> $Jobs{$host}{type} </td>
59     <td align="center"> ${UserLink(defined($Hosts->{$host})
60                                         ? $Hosts->{$host}{user} : "")} </td>
61     <td> $startTime </td>
62     <td> $cmd </td>
63     <td align="center"> $Jobs{$host}{pid} </td>
64     <td align="center"> $xferPid </td>
65 EOF
66         $jobStr .= "</tr>\n";
67     }
68     foreach my $host ( sort(keys(%Status)) ) {
69         next if ( $Status{$host}{reason} ne "Reason_backup_failed"
70                     && $Status{$host}{reason} ne "Reason_restore_failed"
71                     && (!$Status{$host}{userReq}
72                         || $Status{$host}{reason} ne "Reason_no_ping") );
73         my $startTime = timeStamp2($Status{$host}{startTime});
74         my($errorTime, $XferViewStr);
75         if ( $Status{$host}{errorTime} > 0 ) {
76             $errorTime = timeStamp2($Status{$host}{errorTime});
77         }
78         if ( -f "$TopDir/pc/$host/SmbLOG.bad"
79                 || -f "$TopDir/pc/$host/SmbLOG.bad.z"
80                 || -f "$TopDir/pc/$host/XferLOG.bad"
81                 || -f "$TopDir/pc/$host/XferLOG.bad.z"
82                 ) {
83             $XferViewStr = <<EOF;
84 <a href="$MyURL?action=view&type=XferLOGbad&host=${EscURI($host)}">$Lang->{XferLOG}</a>,
85 <a href="$MyURL?action=view&type=XferErrbad&host=${EscURI($host)}">$Lang->{Errors}</a>
86 EOF
87         } else {
88             $XferViewStr = "";
89         }
90         (my $shortErr = $Status{$host}{error}) =~ s/(.{48}).*/$1.../;   
91         $statusStr .= <<EOF;
92 <tr><td> ${HostLink($host)} </td>
93     <td align="center"> $Status{$host}{type} </td>
94     <td align="center"> ${UserLink(defined($Hosts->{$host})
95                                         ? $Hosts->{$host}{user} : "")} </td>
96     <td align="right"> $startTime </td>
97     <td> $XferViewStr </td>
98     <td align="right"> $errorTime </td>
99     <td> ${EscHTML($shortErr)} </td></tr>
100 EOF
101     }
102     my $now          = timeStamp2(time);
103     my $nextWakeupTime = timeStamp2($Info{nextWakeup});
104     my $DUlastTime   = timeStamp2($Info{DUlastValueTime});
105     my $DUmaxTime    = timeStamp2($Info{DUDailyMaxTime});
106     my $numBgQueue   = $QueueLen{BgQueue};
107     my $numUserQueue = $QueueLen{UserQueue};
108     my $numCmdQueue  = $QueueLen{CmdQueue};
109     my $serverStartTime = timeStamp2($Info{startTime});
110     my $poolInfo     = genPoolInfo("pool", \%Info);
111     my $cpoolInfo    = genPoolInfo("cpool", \%Info);
112     if ( $Info{poolFileCnt} > 0 && $Info{cpoolFileCnt} > 0 ) {
113         $poolInfo = <<EOF;
114 <li>Uncompressed pool:
115 <ul>
116 $poolInfo
117 </ul>
118 <li>Compressed pool:
119 <ul>
120 $cpoolInfo
121 </ul>
122 EOF
123     } elsif ( $Info{cpoolFileCnt} > 0 ) {
124         $poolInfo = $cpoolInfo;
125     }
126
127     Header($Lang->{H_BackupPC_Server_Status});
128     print (eval ("qq{$Lang->{BackupPC_Server_Status}}"));
129     Trailer();
130 }
131
132 sub genPoolInfo
133 {
134     my($name, $info) = @_;
135     my $poolSize   = sprintf("%.2f", $info->{"${name}Kb"} / (1000 * 1024));
136     my $poolRmSize = sprintf("%.2f", $info->{"${name}KbRm"} / (1000 * 1024));
137     my $poolTime   = timeStamp2($info->{"${name}Time"});
138     $info->{"${name}FileCntRm"} = $info->{"${name}FileCntRm"} + 0;
139     return eval("qq{$Lang->{Pool_Stat}}");
140 }
141
142 1;