X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FCGI%2FRestoreFile.pm;h=9af2df12b3f5c9d7d320fe1497f2badfa17e1a9c;hp=4b3a372deb91555594f97865b11c1e0718edec4a;hb=f6fbcc3682d2bc9e7dfdc26e95bd5fcdb359496d;hpb=b81d2da5e16975674f011e4833337ac0fa24e0ea diff --git a/lib/BackupPC/CGI/RestoreFile.pm b/lib/BackupPC/CGI/RestoreFile.pm index 4b3a372..9af2df1 100644 --- a/lib/BackupPC/CGI/RestoreFile.pm +++ b/lib/BackupPC/CGI/RestoreFile.pm @@ -10,7 +10,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2003 Craig Barratt +# Copyright (C) 2003-2007 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 @@ -28,7 +28,7 @@ # #======================================================================== # -# Version 3.0.0beta2, released 11 Nov 2006. +# Version 3.2.0beta0, released 5 April 2009. # # See http://backuppc.sourceforge.net. # @@ -37,12 +37,11 @@ package BackupPC::CGI::RestoreFile; use strict; -use Encode; use BackupPC::CGI::Lib qw(:all); use BackupPC::FileZIO; use BackupPC::Attrib qw(:all); use BackupPC::View; - +use Encode qw/from_to decode_utf8/; sub action { @@ -144,6 +143,8 @@ sub restoreFile 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 "" ); @@ -156,6 +157,10 @@ sub restoreFile 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 ) { # @@ -177,9 +182,21 @@ sub restoreFile || "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; }