# Craig Barratt <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
-# Copyright (C) 2003 Craig Barratt
+# Copyright (C) 2003-2009 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
#
#========================================================================
#
-# Version 2.1.0_CVS, released 3 Jul 2003.
+# Version 3.2.0, released 31 Jul 2010.
#
# See http://backuppc.sourceforge.net.
#
use BackupPC::FileZIO;
use BackupPC::Attrib qw(:all);
use BackupPC::View;
+use Encode qw/from_to decode_utf8/;
sub action
{
if ( !$Privileged ) {
ErrorExit(eval("qq{$Lang->{Only_privileged_users_can_restore_backup_files2}}"));
}
+ $bpc->ConfigRead($host);
+ %Conf = $bpc->Conf();
ServerConnect();
ErrorExit($Lang->{Empty_host_name}) if ( $host eq "" );
my $view = BackupPC::View->new($bpc, $host, \@Backups);
my $a = $view->fileAttrib($num, $share, $dir);
if ( $dir =~ m{(^|/)\.\.(/|$)} || !defined($a) ) {
- ErrorExit("Can't restore bad file ${EscHTML($dir)}");
+ $dir = decode_utf8($dir);
+ ErrorExit("Can't restore bad file ${EscHTML($dir)} ($num, $share)");
}
my $f = BackupPC::FileZIO->open($a->{fullPath}, 0, $a->{compress});
+ if ( !defined($f) ) {
+ my $fullPath = decode_utf8($a->{fullPath});
+ ErrorExit("Unable to open file ${EscHTML($fullPath)} ($num, $share)");
+ }
my $data;
if ( !$skipHardLink && $a->{type} == BPC_FTYPE_HARDLINK ) {
#
}
$f->close;
$linkName =~ s/^\.\///;
- my $share = $1 if ( $dir =~ /^\/?(.*?)\// );
restoreFile($host, $num, $share, $linkName, 1, $dir);
return;
}
|| "application/octet-stream";
my $fileName = $1 if ( $dir =~ /.*\/(.*)/ );
$fileName =~ s/"/\\"/g;
- print "Content-Type: $contentType\n";
- print "Content-Transfer-Encoding: binary\n";
- print "Content-Disposition: attachment; filename=\"$fileName\"\n\n";
+
+ print "Content-Type: $contentType\r\n";
+ print "Content-Transfer-Encoding: binary\r\n";
+
+ if ( $ENV{HTTP_USER_AGENT} =~ /\bmsie\b/i
+ && $ENV{HTTP_USER_AGENT} !~ /\bopera\b/i ) {
+ #
+ # Convert to cp1252 for MS IE. TODO: find a way to get IE
+ # to accept UTF8 encoding. Firefox accepts inline encoding
+ # using the "=?UTF-8?B?base64?=" format, but IE doesn't.
+ #
+ from_to($fileName, "utf8", "cp1252")
+ if ( $Conf{ClientCharset} ne "" );
+ }
+ print "Content-Disposition: attachment; filename=\"$fileName\"\r\n\r\n";
while ( $f->read(\$data, 1024 * 1024) > 0 ) {
print STDOUT $data;
}