1 #============================================================= -*-perl-*-
3 # BackupPC::CGI::HostInfo package
7 # This module implements the HostInfo action for the CGI interface.
10 # Craig Barratt <cbarratt@users.sourceforge.net>
13 # Copyright (C) 2003 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 2.1.0_CVS, released 3 Jul 2003.
33 # See http://backuppc.sourceforge.net.
35 #========================================================================
37 package BackupPC::CGI::HostInfo;
40 use BackupPC::CGI::Lib qw(:all);
44 my $host = $1 if ( $In{host} =~ /(.*)/ );
45 my($statusStr, $startIncrStr);
49 return Action_GeneralInfo() if ( $host eq "" );
51 if ( !-d "$TopDir/pc/$host" && -d "$TopDir/pc/" . lc($host) );
52 if ( $host =~ /\.\./ || !-d "$TopDir/pc/$host" ) {
54 # try to lookup by user name
56 if ( !defined($Hosts->{$host}) ) {
57 foreach my $h ( keys(%$Hosts) ) {
58 if ( $Hosts->{$h}{user} eq $host
59 || lc($Hosts->{$h}{user}) eq lc($host) ) {
65 ErrorExit(eval("qq{$Lang->{Unknown_host_or_user}}"))
66 if ( !defined($Hosts->{$host}) );
70 GetStatusInfo("host(${EscURI($host)})");
71 $bpc->ConfigRead($host);
73 my $Privileged = CheckPermission($host);
75 ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_view_information_about}}"));
79 if ($Conf{XferMethod} eq "archive" ) {
80 my @Archives = $bpc->ArchiveInfoRead($host);
81 my ($ArchiveStr,$warnStr);
83 for ( my $i = 0 ; $i < @Archives ; $i++ ) {
84 my $startTime = timeStamp2($Archives[$i]{startTime});
85 my $dur = $Archives[$i]{endTime} - $Archives[$i]{startTime};
86 $dur = 1 if ( $dur <= 0 );
87 my $duration = sprintf("%.1f", $dur / 60);
88 my $Archives_Result = $Lang->{failed};
89 if ($Archives[$i]{result} ne "failed") { $Archives_Result = $Lang->{success}; }
91 <tr><td align="center"><a href="$MyURL?action=archiveInfo&num=$Archives[$i]{num}&host=${EscURI($host)}">$Archives[$i]{num}</a> </td>
92 <td align="center"> $Archives_Result </td>
93 <td align="right"> $startTime </td>
94 <td align="right"> $duration </td>
98 if ( $ArchiveStr ne "" ) {
99 $ArchiveStr = eval("qq{$Lang->{Archive_Summary}}");
101 if ( @Archives == 0 ) {
102 $warnStr = $Lang->{There_have_been_no_archives};
104 if ( $StatusHost{BgQueueOn} ) {
105 $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_background_queue_will_be_backed_up_soon}}");
107 if ( $StatusHost{UserQueueOn} ) {
108 $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_user_queue__will_be_backed_up_soon}}");
110 if ( $StatusHost{CmdQueueOn} ) {
111 $statusStr .= eval("qq{$Lang->{A_command_for_host_is_on_the_command_queue_will_run_soon}}");
114 my $content = eval("qq{$Lang->{Host__host_Archive_Summary2}}");
115 Header(eval("qq{$Lang->{Host__host_Archive_Summary}}"), $content);
121 # Normal, non-archive case
123 my @Backups = $bpc->BackupInfoRead($host);
124 my($str, $sizeStr, $compStr, $errStr, $warnStr);
125 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
126 my $startTime = timeStamp2($Backups[$i]{startTime});
127 my $dur = $Backups[$i]{endTime} - $Backups[$i]{startTime};
128 $dur = 1 if ( $dur <= 0 );
129 my $duration = sprintf("%.1f", $dur / 60);
130 my $MB = sprintf("%.1f", $Backups[$i]{size} / (1024*1024));
131 my $MBperSec = sprintf("%.2f", $Backups[$i]{size} / (1024*1024*$dur));
132 my $MBExist = sprintf("%.1f", $Backups[$i]{sizeExist} / (1024*1024));
133 my $MBNew = sprintf("%.1f", $Backups[$i]{sizeNew} / (1024*1024));
134 my($MBExistComp, $ExistComp, $MBNewComp, $NewComp);
135 if ( $Backups[$i]{sizeExist} && $Backups[$i]{sizeExistComp} ) {
136 $MBExistComp = sprintf("%.1f", $Backups[$i]{sizeExistComp}
138 $ExistComp = sprintf("%.1f%%", 100 *
139 (1 - $Backups[$i]{sizeExistComp} / $Backups[$i]{sizeExist}));
141 if ( $Backups[$i]{sizeNew} && $Backups[$i]{sizeNewComp} ) {
142 $MBNewComp = sprintf("%.1f", $Backups[$i]{sizeNewComp}
144 $NewComp = sprintf("%.1f%%", 100 *
145 (1 - $Backups[$i]{sizeNewComp} / $Backups[$i]{sizeNew}));
147 my $age = sprintf("%.1f", (time - $Backups[$i]{startTime}) / (24*3600));
148 my $browseURL = "$MyURL?action=browse&host=${EscURI($host)}&num=$Backups[$i]{num}";
149 my $filled = $Backups[$i]{noFill} ? $Lang->{No} : $Lang->{Yes};
150 $filled .= " ($Backups[$i]{fillFromNum}) "
151 if ( $Backups[$i]{fillFromNum} ne "" );
152 my $ltype = $Lang->{"backupType_$Backups[$i]{type}"};
154 <tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
155 <td align="center" class="border"> $ltype </td>
156 <td align="center" class="border"> $filled </td>
157 <td align="right" class="border"> $startTime </td>
158 <td align="right" class="border"> $duration </td>
159 <td align="right" class="border"> $age </td>
160 <td align="left" class="border"> <tt>$TopDir/pc/$host/$Backups[$i]{num}</tt> </td></tr>
163 <tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
164 <td align="center" class="border"> $ltype </td>
165 <td align="right" class="border"> $Backups[$i]{nFiles} </td>
166 <td align="right" class="border"> $MB </td>
167 <td align="right" class="border"> $MBperSec </td>
168 <td align="right" class="border"> $Backups[$i]{nFilesExist} </td>
169 <td align="right" class="border"> $MBExist </td>
170 <td align="right" class="border"> $Backups[$i]{nFilesNew} </td>
171 <td align="right" class="border"> $MBNew </td>
174 my $is_compress = $Backups[$i]{compress} || $Lang->{off};
175 if (! $ExistComp) { $ExistComp = " "; }
176 if (! $MBExistComp) { $MBExistComp = " "; }
178 <tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
179 <td align="center" class="border"> $ltype </td>
180 <td align="center" class="border"> $is_compress </td>
181 <td align="right" class="border"> $MBExist </td>
182 <td align="right" class="border"> $MBExistComp </td>
183 <td align="right" class="border"> $ExistComp </td>
184 <td align="right" class="border"> $MBNew </td>
185 <td align="right" class="border"> $MBNewComp </td>
186 <td align="right" class="border"> $NewComp </td>
190 <tr><td align="center" class="border"> <a href="$browseURL">$Backups[$i]{num}</a> </td>
191 <td align="center" class="border"> $ltype </td>
192 <td align="center" class="border"> <a href="$MyURL?action=view&type=XferLOG&num=$Backups[$i]{num}&host=${EscURI($host)}">$Lang->{XferLOG}</a>,
193 <a href="$MyURL?action=view&type=XferErr&num=$Backups[$i]{num}&host=${EscURI($host)}">$Lang->{Errors}</a> </td>
194 <td align="right" class="border"> $Backups[$i]{xferErrs} </td>
195 <td align="right" class="border"> $Backups[$i]{xferBadFile} </td>
196 <td align="right" class="border"> $Backups[$i]{xferBadShare} </td>
197 <td align="right" class="border"> $Backups[$i]{tarErrs} </td></tr>
201 my @Restores = $bpc->RestoreInfoRead($host);
204 for ( my $i = 0 ; $i < @Restores ; $i++ ) {
205 my $startTime = timeStamp2($Restores[$i]{startTime});
206 my $dur = $Restores[$i]{endTime} - $Restores[$i]{startTime};
207 $dur = 1 if ( $dur <= 0 );
208 my $duration = sprintf("%.1f", $dur / 60);
209 my $MB = sprintf("%.1f", $Restores[$i]{size} / (1024*1024));
210 my $MBperSec = sprintf("%.2f", $Restores[$i]{size} / (1024*1024*$dur));
211 my $Restores_Result = $Lang->{failed};
212 if ($Restores[$i]{result} ne "failed") { $Restores_Result = $Lang->{success}; }
213 $restoreStr .= <<EOF;
214 <tr><td align="center" class="border"><a href="$MyURL?action=restoreInfo&num=$Restores[$i]{num}&host=${EscURI($host)}">$Restores[$i]{num}</a> </td>
215 <td align="center" class="border"> $Restores_Result </td>
216 <td align="right" class="border"> $startTime </td>
217 <td align="right" class="border"> $duration </td>
218 <td align="right" class="border"> $Restores[$i]{nFiles} </td>
219 <td align="right" class="border"> $MB </td>
220 <td align="right" class="border"> $Restores[$i]{tarCreateErrs} </td>
221 <td align="right" class="border"> $Restores[$i]{xferErrs} </td>
225 if ( $restoreStr ne "" ) {
226 $restoreStr = eval("qq{$Lang->{Restore_Summary}}");
228 if ( @Backups == 0 ) {
229 $warnStr = $Lang->{This_PC_has_never_been_backed_up};
231 if ( defined($Hosts->{$host}) ) {
232 my $user = $Hosts->{$host}{user};
233 my @moreUsers = sort(keys(%{$Hosts->{$host}{moreUsers}}));
235 foreach my $u ( sort(keys(%{$Hosts->{$host}{moreUsers}})) ) {
236 $moreUserStr .= ", " if ( $moreUserStr ne "" );
237 $moreUserStr .= "${UserLink($u)}";
239 if ( $moreUserStr ne "" ) {
240 $moreUserStr = " ($Lang->{and} $moreUserStr).\n";
242 $moreUserStr = ".\n";
245 $statusStr .= eval("qq{$Lang->{This_PC_is_used_by}$moreUserStr}");
247 if ( defined($UserEmailInfo{$user})
248 && $UserEmailInfo{$user}{lastHost} eq $host ) {
249 my $mailTime = timeStamp2($UserEmailInfo{$user}{lastTime});
250 my $subj = $UserEmailInfo{$user}{lastSubj};
251 $statusStr .= eval("qq{$Lang->{Last_email_sent_to__was_at___subject}}");
254 if ( defined($Jobs{$host}) ) {
255 my $startTime = timeStamp2($Jobs{$host}{startTime});
256 (my $cmd = $Jobs{$host}{cmd}) =~ s/$BinDir\///g;
257 $statusStr .= eval("qq{$Lang->{The_command_cmd_is_currently_running_for_started}}");
259 if ( $StatusHost{BgQueueOn} ) {
260 $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_background_queue_will_be_backed_up_soon}}");
262 if ( $StatusHost{UserQueueOn} ) {
263 $statusStr .= eval("qq{$Lang->{Host_host_is_queued_on_the_user_queue__will_be_backed_up_soon}}");
265 if ( $StatusHost{CmdQueueOn} ) {
266 $statusStr .= eval("qq{$Lang->{A_command_for_host_is_on_the_command_queue_will_run_soon}}");
268 my $startTime = timeStamp2($StatusHost{endTime} == 0 ?
269 $StatusHost{startTime} : $StatusHost{endTime});
271 if ( $StatusHost{reason} ne "" ) {
272 $reason = " ($Lang->{$StatusHost{reason}})";
274 $statusStr .= eval("qq{$Lang->{Last_status_is_state_StatusHost_state_reason_as_of_startTime}}");
276 if ( $StatusHost{state} ne "Status_backup_in_progress"
277 && $StatusHost{state} ne "Status_restore_in_progress"
278 && $StatusHost{error} ne "" ) {
279 $statusStr .= eval("qq{$Lang->{Last_error_is____EscHTML_StatusHost_error}}");
281 my $priorStr = "Pings";
282 if ( $StatusHost{deadCnt} > 0 ) {
283 $statusStr .= eval("qq{$Lang->{Pings_to_host_have_failed_StatusHost_deadCnt__consecutive_times}}");
284 $priorStr = $Lang->{Prior_to_that__pings};
286 if ( $StatusHost{aliveCnt} > 0 ) {
287 $statusStr .= eval("qq{$Lang->{priorStr_to_host_have_succeeded_StatusHostaliveCnt_consecutive_times}}");
289 if ( $StatusHost{aliveCnt} >= $Conf{BlackoutGoodCnt}
290 && $Conf{BlackoutGoodCnt} >= 0 && $Conf{BlackoutHourBegin} >= 0
291 && $Conf{BlackoutHourEnd} >= 0 ) {
292 my(@days) = qw(Sun Mon Tue Wed Thu Fri Sat);
293 my($days) = join(", ", @days[@{$Conf{BlackoutWeekDays}}]);
294 my($t0) = sprintf("%d:%02d", $Conf{BlackoutHourBegin},
295 60 * ($Conf{BlackoutHourBegin}
296 - int($Conf{BlackoutHourBegin})));
297 my($t1) = sprintf("%d:%02d", $Conf{BlackoutHourEnd},
298 60 * ($Conf{BlackoutHourEnd}
299 - int($Conf{BlackoutHourEnd})));
300 $statusStr .= eval("qq{$Lang->{Because__host_has_been_on_the_network_at_least__Conf_BlackoutGoodCnt_consecutive_times___}}");
303 if ( $StatusHost{backoffTime} > time ) {
304 my $hours = sprintf("%.1f", ($StatusHost{backoffTime} - time) / 3600);
305 $statusStr .= eval("qq{$Lang->{Backups_are_deferred_for_hours_hours_change_this_number}}");
309 # only allow incremental if there are already some backups
310 $startIncrStr = <<EOF;
311 <input type="submit" value="\$Lang->{Start_Incr_Backup}" name="action">
315 $startIncrStr = eval ("qq{$startIncrStr}");
316 my $content = eval("qq{$Lang->{Host__host_Backup_Summary2}}");
317 Header(eval("qq{$Lang->{Host__host_Backup_Summary}}"), $content);