"Fossies" - the Fresh Open Source Software Archive 
Member "BackupPC-4.4.0/lib/BackupPC/CGI/DirHistory.pm" (20 Jun 2020, 8253 Bytes) of package /linux/privat/BackupPC-4.4.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "DirHistory.pm" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
4.3.2_vs_4.4.0.
1 #============================================================= -*-perl-*-
2 #
3 # BackupPC::CGI::DirHistory package
4 #
5 # DESCRIPTION
6 #
7 # This module implements the DirHistory action for the CGI interface.
8 #
9 # AUTHOR
10 # Craig Barratt <cbarratt@users.sourceforge.net>
11 #
12 # COPYRIGHT
13 # Copyright (C) 2003-2020 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 3 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, see <http://www.gnu.org/licenses/>.
27 #
28 #========================================================================
29 #
30 # Version 4.4.0, released 20 Jun 2020.
31 #
32 # See http://backuppc.sourceforge.net.
33 #
34 #========================================================================
35
36 package BackupPC::CGI::DirHistory;
37
38 use strict;
39 use BackupPC::CGI::Lib qw(:all);
40 use BackupPC::View;
41 use BackupPC::XS qw(:all);
42 use Encode;
43
44 sub action
45 {
46 my $Privileged = CheckPermission($In{host});
47 my($i, $dirStr, $fileStr, $attr);
48 my $checkBoxCnt = 0;
49
50 if ( !$Privileged ) {
51 ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_browse_backup_files}}"));
52 }
53
54 my $host = $In{host};
55 my $share = $In{share};
56 my $dir = $In{dir};
57 my $dirURI = $dir;
58 my $shareURI = $share;
59
60 $dirURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
61 $shareURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
62
63 ErrorExit($Lang->{Empty_host_name}) if ( $host eq "" );
64
65 my @Backups = $bpc->BackupInfoRead($host);
66 my $view = BackupPC::View->new($bpc, $host, \@Backups, {inode => 1});
67 my $hist = $view->dirHistory($share, $dir);
68 my($backupNumStr, $backupTimeStr, $fileStr);
69
70 $dir = "/$dir" if ( $dir !~ /^\// );
71
72 if ( "/$host/$share/$dir/" =~ m{/\.\./} ) {
73 ErrorExit($Lang->{Nice_try__but_you_can_t_put});
74 }
75
76 my @backupList = $view->backupList($share, $dir);
77 foreach $i ( @backupList ) {
78 my $backupTime = timeStamp2($Backups[$i]{startTime});
79 my $num = $Backups[$i]{num};
80 $backupNumStr .=
81 "<td align=center><a href=\"$MyURL?action=browse"
82 . "&host=${EscURI($host)}&num=$num&share=$shareURI"
83 . "&dir=$dirURI\">$num</a></td>";
84 $backupTimeStr .= "<td align=center>$backupTime</td>";
85 }
86
87 #
88 # For V3 we rely on inodes to identify identical files.
89 #
90 # For V4 the (fake) inodes might be the same between different versions of
91 # a file, so we rely on matching the digests instead.
92 #
93 # So, if digests are defined, we use those. Otherwise we used inodes.
94 #
95 foreach my $f ( sort { uc($a) cmp uc($b) } keys(%$hist) ) {
96 my %inode2name;
97 my %digest2name;
98 my $nameCnt = 0;
99 (my $fDisp = "${EscHTML($f)}") =~ s/ / /g;
100 $fDisp = decode_utf8($fDisp);
101 $fileStr .= "<tr><td align=\"left\" class=\"histView\">$fDisp</td>";
102 my($colSpan, $url, $inode, $type, $digest);
103 my $tdClass = ' class="histView"';
104
105 foreach $i ( @backupList ) {
106 my($path);
107 if ( $colSpan > 0 ) {
108 #
109 # The file is the same if it also size==0 (inode == -1)
110 # or if it is a directory and the previous one is (inode == -2)
111 # or if the inodes and digests agree and the types are the same.
112 #
113 if (
114 defined($hist->{$f}[$i])
115 && $hist->{$f}[$i]{type} == $type
116 && (
117 ($hist->{$f}[$i]{size} == 0 && $inode == -1)
118 || ($hist->{$f}[$i]{type} == BPC_FTYPE_DIR && $inode == -2)
119 || (
120 length($hist->{$f}[$i]{digest})
121 ? $hist->{$f}[$i]{digest} eq $digest
122 : $hist->{$f}[$i]{inode} == $inode
123 )
124 )
125 ) {
126 $colSpan++;
127 next;
128 }
129 #
130 # Also handle the case of a sequence of missing files
131 #
132 if ( !defined($hist->{$f}[$i]) && $inode == -3 ) {
133 $colSpan++;
134 next;
135 }
136 $fileStr .= "<td align=center colspan=$colSpan$tdClass>$url</td>";
137 $colSpan = 0;
138 $tdClass = ' class="histView"';
139 }
140 if ( !defined($hist->{$f}[$i]) ) {
141 $colSpan = 1;
142 $url = " ";
143 $inode = -3; # special value for missing
144 $digest = "";
145 $tdClass = ' class="histViewMis"';
146 next;
147 }
148 if ( $dir eq "" ) {
149 $path = "/$f";
150 } else {
151 ($path = "$dir/$f") =~ s{//+}{/}g;
152 }
153 $path =~ s{^/+}{/};
154 $path =~ s/([^\w.\/-])/uc sprintf("%%%02X", ord($1))/eg;
155 my $num = $hist->{$f}[$i]{backupNum};
156 if ( $hist->{$f}[$i]{type} == BPC_FTYPE_DIR ) {
157 $inode = -2; # special value for dir
158 $type = $hist->{$f}[$i]{type};
159 $url = <<EOF;
160 <a href="$MyURL?action=dirHistory&host=${EscURI($host)}&share=$shareURI&dir=$path">$Lang->{DirHistory_dirLink}</a>
161 EOF
162 } else {
163 my $thisName;
164 $inode = $hist->{$f}[$i]{inode};
165 $digest = $hist->{$f}[$i]{digest};
166 $type = $hist->{$f}[$i]{type};
167 #
168 # special value for empty file
169 #
170 $inode = -1 if ( $hist->{$f}[$i]{size} == 0 );
171 if ( length($digest) ) {
172 if ( !defined($digest2name{$digest}) ) {
173 $digest2name{$digest} = "$Lang->{DirHistory_fileLink}$nameCnt";
174 $nameCnt++;
175 }
176 $thisName = $digest2name{$digest};
177 } else {
178 if ( !defined($inode2name{$inode}) ) {
179 $inode2name{$inode} = "$Lang->{DirHistory_fileLink}$nameCnt";
180 $nameCnt++;
181 }
182 $thisName = $inode2name{$inode};
183 }
184 $url = <<EOF;
185 <a href="$MyURL?action=RestoreFile&host=${EscURI($host)}&num=$num&share=$shareURI&dir=$path">$thisName</a>
186 EOF
187 }
188 $colSpan = 1;
189 }
190 if ( $colSpan > 0 ) {
191 $fileStr .= "<td align=center colspan=$colSpan$tdClass>$url</td>";
192 $colSpan = 0;
193 }
194 $fileStr .= "</tr>\n";
195 }
196
197 #
198 # allow each level of the directory path to be navigated to
199 #
200 my($thisPath, $dirDisplay);
201 my $dirClean = $dir;
202 $dirClean =~ s{//+}{/}g;
203 $dirClean =~ s{/+$}{};
204 my @dirElts = split(/\//, $dirClean);
205 @dirElts = ("/") if ( !@dirElts );
206 foreach my $d ( @dirElts ) {
207 my($thisDir);
208
209 if ( $thisPath eq "" ) {
210 $thisDir = decode_utf8($share);
211 $thisPath = "/";
212 } else {
213 $thisPath .= "/" if ( $thisPath ne "/" );
214 $thisPath .= "$d";
215 $thisDir = decode_utf8($d);
216 }
217 my $thisPathURI = $thisPath;
218 $thisPathURI =~ s/([^\w.\/-])/uc sprintf("%%%02x", ord($1))/eg;
219 $dirDisplay .= "/" if ( $dirDisplay ne "" );
220 $dirDisplay .=
221 "<a href=\"$MyURL?action=dirHistory&host=${EscURI($host)}&share=$shareURI&dir=$thisPathURI\">${EscHTML($thisDir)}</a>";
222 }
223 my $content = eval("qq{$Lang->{DirHistory_for__host}}");
224 Header(eval("qq{$Lang->{DirHistory_backup_for__host}}"), $content);
225 Trailer();
226 }
227
228 1;