From d6362cfb1393293bfa0eb04d8731b47bc3fbbfa5 Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Sun, 21 Jun 2020 22:39:27 +0300 Subject: [PATCH] Download files with defined MIME type https://github.com/webmin/webmin/issues/1250 --- custom/run.cgi | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/custom/run.cgi b/custom/run.cgi index a9689e1a2..ffdd3ba7c 100755 --- a/custom/run.cgi +++ b/custom/run.cgi @@ -36,7 +36,11 @@ else { # Run and display output if ($cmd->{'format'} ne 'redirect' && $cmd->{'format'} ne 'form') { if ($cmd->{'format'}) { - print "Content-type: ",$cmd->{'format'},"\n"; + my ($f, $e) = $cmd->{'cmd'} =~ /([\p{L}\_\-\.0-9]+)\.(tar\..*?|[^.]*)$/; + my $filename = $f || 'download'; + my $extension = $e || 'unknown'; + print "Content-Disposition: attachment; filename=\"$filename.$extension\"\n"; + print "Content-type: application/x-download\n"; print "\n"; } else {