1 #============================================================= -*-perl-*-
3 # BackupPC::CGI::DirHistory package
7 # This module implements the DirHistory 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.0beta1, released 9 Apr 2004.
33 # See http://backuppc.sourceforge.net.
35 #========================================================================
37 package BackupPC::CGI::DirHistory;
40 use BackupPC::CGI::Lib qw(:all);
42 use BackupPC::Attrib qw(:all);
46 my $Privileged = CheckPermission($In{host});
47 my($i, $dirStr, $fileStr, $attr);
51 ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_browse_backup_files}}"));
54 my $share = $In{share};
57 my $shareURI = $share;
58 $dirURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
59 $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
61 ErrorExit($Lang->{Empty_host_name}) if ( $host eq "" );
63 my @Backups = $bpc->BackupInfoRead($host);
64 my $view = BackupPC::View->new($bpc, $host, \@Backups);
65 my $hist = $view->dirHistory($share, $dir);
66 my($backupNumStr, $backupTimeStr, $fileStr);
68 $dir = "/$dir" if ( $dir !~ /^\// );
70 if ( "/$host/$share/$dir/" =~ m{/\.\./} ) {
71 ErrorExit($Lang->{Nice_try__but_you_can_t_put});
74 my @backupList = $view->backupList($share, $dir);
75 foreach $i ( @backupList ) {
76 my $backupTime = timeStamp2($Backups[$i]{startTime});
77 my $num = $Backups[$i]{num};
78 $backupNumStr .= "<td align=center><a href=\"$MyURL?action=browse"
79 . "&host=${EscURI($host)}&num=$num&share=$shareURI"
80 . "&dir=$dirURI\">$num</a></td>";
81 $backupTimeStr .= "<td align=center>$backupTime</td>";
84 foreach my $f ( sort {uc($a) cmp uc($b)} keys(%$hist) ) {
87 (my $fDisp = "${EscHTML($f)}") =~ s/ / /g;
88 $fileStr .= "<tr><td align=\"left\" class=\"histView\">$fDisp</td>";
89 my($colSpan, $url, $inode, $type);
90 my $tdClass = ' class="histView"';
91 foreach $i ( @backupList ) {
95 # The file is the same if it also size==0 (inode == -1)
96 # or if it is a directory and the previous one is (inode == -2)
97 # or if the inodes agree and the types are the same.
99 if ( defined($hist->{$f}[$i])
100 && $hist->{$f}[$i]{type} == $type
101 && (($hist->{$f}[$i]{size} == 0 && $inode == -1)
102 || ($hist->{$f}[$i]{type} == BPC_FTYPE_DIR && $inode == -2)
103 || $hist->{$f}[$i]{inode} == $inode) ) {
108 # Also handle the case of a sequence of missing files
110 if ( !defined($hist->{$f}[$i]) && $inode == -3 ) {
114 $fileStr .= "<td align=center colspan=$colSpan$tdClass>"
117 $tdClass = ' class="histView"';
119 if ( !defined($hist->{$f}[$i]) ) {
122 $inode = -3; # special value for missing
123 $tdClass = ' class="histViewMis"';
129 ($path = "$dir/$f") =~ s{//+}{/}g;
132 $path =~ s/([^\w.\/-])/uc sprintf("%%%02X", ord($1))/eg;
133 my $num = $hist->{$f}[$i]{backupNum};
134 if ( $hist->{$f}[$i]{type} == BPC_FTYPE_DIR ) {
135 $inode = -2; # special value for dir
136 $type = $hist->{$f}[$i]{type};
138 <a href="$MyURL?action=dirHistory&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$Lang->{DirHistory_dirLink}</a>
141 $inode = $hist->{$f}[$i]{inode};
142 $type = $hist->{$f}[$i]{type};
144 # special value for empty file
146 $inode = -1 if ( $hist->{$f}[$i]{size} == 0 );
147 if ( !defined($inode2name{$inode}) ) {
149 = "$Lang->{DirHistory_fileLink}$nameCnt";
153 <a href="$MyURL?action=RestoreFile&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$inode2name{$inode}</a>
158 if ( $colSpan > 0 ) {
159 $fileStr .= "<td align=center colspan=$colSpan$tdClass>$url</td>";
162 $fileStr .= "</tr>\n";
165 my $dirDisplay = "$share/$dir";
166 $dirDisplay =~ s{//+}{/}g;
167 $dirDisplay =~ s{/+$}{}g;
168 $dirDisplay = "/" if ( $dirDisplay eq "" );
169 my $content = eval("qq{$Lang->{DirHistory_for__host}}");
170 Header(eval("qq{$Lang->{DirHistory_backup_for__host}}"), $content);