X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FCGI%2FRestoreFile.pm;h=2a726d297c7c91c20ca1d7c6b2c8ce55f0402e16;hp=d8d1b9507ef8c8859ed416079081a9bdd7aaf787;hb=16755c17628b28a58d75663d7541036344826961;hpb=d13d57e035dac9362ca393991b978530402969b7 diff --git a/lib/BackupPC/CGI/RestoreFile.pm b/lib/BackupPC/CGI/RestoreFile.pm index d8d1b95..2a726d2 100644 --- a/lib/BackupPC/CGI/RestoreFile.pm +++ b/lib/BackupPC/CGI/RestoreFile.pm @@ -28,7 +28,7 @@ # #======================================================================== # -# Version 2.1.0, released 20 Jun 2004. +# Version 3.0.0, released 28 Jan 2007. # # See http://backuppc.sourceforge.net. # @@ -41,6 +41,7 @@ use BackupPC::CGI::Lib qw(:all); use BackupPC::FileZIO; use BackupPC::Attrib qw(:all); use BackupPC::View; +use Encode qw/from_to/; sub action { @@ -142,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 "" ); @@ -150,7 +153,8 @@ sub restoreFile 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)} ($num, $share, $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}); my $data; @@ -174,8 +178,19 @@ sub restoreFile || "application/octet-stream"; my $fileName = $1 if ( $dir =~ /.*\/(.*)/ ); $fileName =~ s/"/\\"/g; + print "Content-Type: $contentType\n"; print "Content-Transfer-Encoding: binary\n"; + + if ( $ENV{HTTP_USER_AGENT} =~ /\bmsie\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\"\n\n"; while ( $f->read(\$data, 1024 * 1024) > 0 ) { print STDOUT $data;