1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
#============================================================= -*-perl-*-
#
# BackupPC::CGI::DirHistory package
#
# DESCRIPTION
#
# This module implements the DirHistory action for the CGI interface.
#
# AUTHOR
# Craig Barratt <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
# Copyright (C) 2003 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#========================================================================
#
# Version 2.1.1, released 13 Mar 2005.
#
# See http://backuppc.sourceforge.net.
#
#========================================================================
package BackupPC::CGI::DirHistory;
use strict;
use BackupPC::CGI::Lib qw(:all);
use BackupPC::View;
use BackupPC::Attrib qw(:all);
sub action
{
my $Privileged = CheckPermission($In{host});
my($i, $dirStr, $fileStr, $attr);
my $checkBoxCnt = 0;
if ( !$Privileged ) {
ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_browse_backup_files}}"));
}
my $host = $In{host};
my $share = $In{share};
my $dir = $In{dir};
my $dirURI = $dir;
my $shareURI = $share;
$dirURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
$shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
ErrorExit($Lang->{Empty_host_name}) if ( $host eq "" );
my @Backups = $bpc->BackupInfoRead($host);
my $view = BackupPC::View->new($bpc, $host, \@Backups);
my $hist = $view->dirHistory($share, $dir);
my($backupNumStr, $backupTimeStr, $fileStr);
$dir = "/$dir" if ( $dir !~ /^\// );
if ( "/$host/$share/$dir/" =~ m{/\.\./} ) {
ErrorExit($Lang->{Nice_try__but_you_can_t_put});
}
my @backupList = $view->backupList($share, $dir);
foreach $i ( @backupList ) {
my $backupTime = timeStamp2($Backups[$i]{startTime});
my $num = $Backups[$i]{num};
$backupNumStr .= "<td align=center><a href=\"$MyURL?action=browse"
. "&host=${EscURI($host)}&num=$num&share=$shareURI"
. "&dir=$dirURI\">$num</a></td>";
$backupTimeStr .= "<td align=center>$backupTime</td>";
}
foreach my $f ( sort {uc($a) cmp uc($b)} keys(%$hist) ) {
my %inode2name;
my $nameCnt = 0;
(my $fDisp = "${EscHTML($f)}") =~ s/ / /g;
$fileStr .= "<tr><td align=\"left\" class=\"histView\">$fDisp</td>";
my($colSpan, $url, $inode, $type);
my $tdClass = ' class="histView"';
foreach $i ( @backupList ) {
my($path);
if ( $colSpan > 0 ) {
#
# The file is the same if it also size==0 (inode == -1)
# or if it is a directory and the previous one is (inode == -2)
# or if the inodes agree and the types are the same.
#
if ( defined($hist->{$f}[$i])
&& $hist->{$f}[$i]{type} == $type
&& (($hist->{$f}[$i]{size} == 0 && $inode == -1)
|| ($hist->{$f}[$i]{type} == BPC_FTYPE_DIR && $inode == -2)
|| $hist->{$f}[$i]{inode} == $inode) ) {
$colSpan++;
next;
}
#
# Also handle the case of a sequence of missing files
#
if ( !defined($hist->{$f}[$i]) && $inode == -3 ) {
$colSpan++;
next;
}
$fileStr .= "<td align=center colspan=$colSpan$tdClass>"
. "$url</td>";
$colSpan = 0;
$tdClass = ' class="histView"';
}
if ( !defined($hist->{$f}[$i]) ) {
$colSpan = 1;
$url = " ";
$inode = -3; # special value for missing
$tdClass = ' class="histViewMis"';
next;
}
if ( $dir eq "" ) {
$path = "/$f";
} else {
($path = "$dir/$f") =~ s{//+}{/}g;
}
$path =~ s{^/+}{/};
$path =~ s/([^\w.\/-])/uc sprintf("%%%02X", ord($1))/eg;
my $num = $hist->{$f}[$i]{backupNum};
if ( $hist->{$f}[$i]{type} == BPC_FTYPE_DIR ) {
$inode = -2; # special value for dir
$type = $hist->{$f}[$i]{type};
$url = <<EOF;
<a href="$MyURL?action=dirHistory&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$Lang->{DirHistory_dirLink}</a>
EOF
} else {
$inode = $hist->{$f}[$i]{inode};
$type = $hist->{$f}[$i]{type};
#
# special value for empty file
#
$inode = -1 if ( $hist->{$f}[$i]{size} == 0 );
if ( !defined($inode2name{$inode}) ) {
$inode2name{$inode}
= "$Lang->{DirHistory_fileLink}$nameCnt";
$nameCnt++;
}
$url = <<EOF;
<a href="$MyURL?action=RestoreFile&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$inode2name{$inode}</a>
EOF
}
$colSpan = 1;
}
if ( $colSpan > 0 ) {
$fileStr .= "<td align=center colspan=$colSpan$tdClass>$url</td>";
$colSpan = 0;
}
$fileStr .= "</tr>\n";
}
my $dirDisplay = "$share/$dir";
$dirDisplay =~ s{//+}{/}g;
$dirDisplay =~ s{/+$}{}g;
$dirDisplay = "/" if ( $dirDisplay eq "" );
my $content = eval("qq{$Lang->{DirHistory_for__host}}");
Header(eval("qq{$Lang->{DirHistory_backup_for__host}}"), $content);
Trailer();
}
1;
|