From 548f6c0d5fd1e95f62a27dd2f1bef77b2620e121 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Sat, 15 Aug 2015 14:00:58 +0200 Subject: [PATCH] Bug 14321: Switch to Upload in opac-retrieve Content-Type: text/plain; charset=utf-8 A last step to obsolete UploadedFiles.pm. Note that we now also check for the public flag. If that flag is not set, the uploaded file cannot be reached via the opac. Test plan: [1] Check downloading a file marked public in OPAC without logging in. [2] Check another file (not marked as public). Should not be possible. --- .../bootstrap/en/modules/opac-retrieve-file.tt | 6 ++++ opac/opac-retrieve-file.pl | 37 ++++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-retrieve-file.tt diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-retrieve-file.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-retrieve-file.tt new file mode 100644 index 0000000..581d9ea --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-retrieve-file.tt @@ -0,0 +1,6 @@ +[%# This template is called only for a very simple error message %] + + +Your search [% IF hash %]for [% hash %][% END %] was not successful. + + diff --git a/opac/opac-retrieve-file.pl b/opac/opac-retrieve-file.pl index 419f2bd..2e0cda6 100755 --- a/opac/opac-retrieve-file.pl +++ b/opac/opac-retrieve-file.pl @@ -19,19 +19,34 @@ use Modern::Perl; use CGI; +use Encode; +use C4::Auth; use C4::Context; -use C4::UploadedFiles; +use C4::Output; +use Koha::Upload; -my $input = new CGI; +my $input = CGI::->new; +my $hash = $input->param('id'); # historically called id (used in URLs?) -my $id = $input->param('id'); -my $file = C4::UploadedFiles::GetUploadedFile($id); -exit 1 if !$file || !-f $file->{filepath}; - -open my $fh, '<', $file->{filepath} or die "Can't open file: $!"; -print $input->header( C4::UploadedFiles::httpheaders( $file->{filename} )); -while(<$fh>) { - print $_; +my $upl = Koha::Upload->new({ public => 1 }); +my $rec = $upl->get({ hashvalue => $hash, filehandle => 1 }); +my $fh = $rec->{fh}; +if( !$rec || !$fh ) { + my ( $template, $user, $cookie ) = get_template_and_user({ + query => $input, + template_name => 'opac-retrieve-file.tt', + type => 'opac', + authnotrequired => 1, + }); + $template->param( hash => $hash ); + output_html_with_http_headers $input, $cookie, $template->output; +} else { + #FIXME encoding? + my @hdr = $upl->httpheaders( $rec->{name} ); + print Encode::encode_utf8( $input->header( @hdr ) ); + while( <$fh> ) { + print $_; + } + $fh->close; } -close $fh; -- 1.7.10.4