* Added Simplified Chinese CGI translation from Youlin Feng.
[BackupPC.git] / lib / BackupPC / CGI / RestoreFile.pm
index d8d1b95..2a726d2 100644 (file)
@@ -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;