* Changes for 3.0.0 release
[BackupPC.git] / lib / BackupPC / CGI / RestoreInfo.pm
1 #============================================================= -*-perl-*-
2 #
3 # BackupPC::CGI::RestoreInfo package
4 #
5 # DESCRIPTION
6 #
7 #   This module implements the RestoreInfo 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 3.0.0, released 28 Jan 2007.
32 #
33 # See http://backuppc.sourceforge.net.
34 #
35 #========================================================================
36
37 package BackupPC::CGI::RestoreInfo;
38
39 use strict;
40 use BackupPC::CGI::Lib qw(:all);
41 use Encode;
42
43 sub action
44 {
45     my $Privileged = CheckPermission($In{host});
46     my $host = $1 if ( $In{host} =~ /(.*)/ );
47     my $num  = $In{num};
48     my $i;
49
50     if ( !$Privileged ) {
51         ErrorExit($Lang->{Only_privileged_users_can_view_restore_information});
52     }
53     #
54     # Find the requested restore
55     #
56     my @Restores = $bpc->RestoreInfoRead($host);
57     for ( $i = 0 ; $i < @Restores ; $i++ ) {
58         last if ( $Restores[$i]{num} == $num );
59     }
60     if ( $i >= @Restores ) {
61         ErrorExit(eval("qq{$Lang->{Restore_number__num_for_host__does_not_exist}}"));
62     }
63
64     %RestoreReq = ();
65     do "$TopDir/pc/$host/RestoreInfo.$Restores[$i]{num}"
66             if ( -f "$TopDir/pc/$host/RestoreInfo.$Restores[$i]{num}" );
67
68     my $startTime = timeStamp2($Restores[$i]{startTime});
69     my $reqTime   = timeStamp2($RestoreReq{reqTime});
70     my $dur       = $Restores[$i]{endTime} - $Restores[$i]{startTime};
71     $dur          = 1 if ( $dur <= 0 );
72     my $duration  = sprintf("%.1f", $dur / 60);
73     my $MB        = sprintf("%.1f", $Restores[$i]{size} / (1024*1024));
74     my $MBperSec  = sprintf("%.2f", $Restores[$i]{size} / (1024*1024*$dur));
75
76     my $fileListStr = "";
77     foreach my $f ( @{$RestoreReq{fileList}} ) {
78         my $targetFile = $f;
79         (my $strippedShareSrc  = $RestoreReq{shareSrc}) =~ s/^\///;
80         (my $strippedShareDest = $RestoreReq{shareDest}) =~ s/^\///;
81         substr($targetFile, 0, length($RestoreReq{pathHdrSrc}))
82                                         = $RestoreReq{pathHdrDest};
83         $targetFile =~ s{//+}{/}g;
84         $strippedShareDest = decode_utf8($strippedShareDest);
85         $targetFile = decode_utf8($targetFile);
86         $strippedShareSrc = decode_utf8($strippedShareSrc);
87         $f = decode_utf8($f);
88         $fileListStr .= <<EOF;
89 <tr><td>$RestoreReq{hostSrc}:/$strippedShareSrc$f</td><td>$RestoreReq{hostDest}:/$strippedShareDest$targetFile</td></tr>
90 EOF
91     }
92     my $content = eval("qq{$Lang->{Restore___num_details_for__host2}}");
93     Header(eval("qq{$Lang->{Restore___num_details_for__host}}"),$content);
94     Trailer();
95 }
96
97 1;