From e35a7355303302e54bc1e92c605e70d5fa0c3d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick?= Date: Wed, 27 Nov 2013 13:46:24 -0500 Subject: [PATCH] Bug 11317: Adds a page to access log files on the server from the intranet. The directory used is defined by the "publiclogdir" preference in koha-conf.xml. Test case : Preparation : * Add the "publiclogdir" preference to your "koha-conf.xml" file. This * preference should be in the "config" section. For this test cas, we * will use the "/tmp/koha-public" directory : ... /tmp/koha-public ... * Create the log directory on your server. Make sure this directory * is readable by your web server : $ mkdir /tmp/koha-public * Add a test file in the log directory : $ cd /tmp/koha-public $ echo "Hello world!" > test.txt Test : * Go in the "Reports" section in the intranet and select "Report/log * files" * The "test.txt" should appear in the files list. * Click on the "test.txt" file, a download dialog should appear. * Download the file and verify its content. It should contain the * text "Hello world!". Sponsored by : CCSR Signed-off-by: Jonathan Druart Signed-off-by: Bernardo Gonzalez Kriegel Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer Signed-off-by: Josef Moravec --- .../prog/en/modules/reports/report_files.tt | 68 ++++++++++++++++ .../prog/en/modules/reports/reports-home.tt | 32 ++++---- reports/report_files.pl | 94 ++++++++++++++++++++++ 3 files changed, 179 insertions(+), 15 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reports/report_files.tt create mode 100755 reports/report_files.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report_files.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report_files.tt new file mode 100644 index 0000000..3ee409e --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report_files.tt @@ -0,0 +1,68 @@ +[% INCLUDE 'doc-head-open.inc' %] +Report/log files +[% INCLUDE 'doc-head-close.inc' %] + + +[% INCLUDE 'datatables-strings.inc' %] + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + + +
+
+
+
+ +

Report/log files

+ +[% IF ( error_no_publiclogdir ) %] +
Error : Report/log files could not be found because the "publiclogdir" option was not set in "koha-conf.xml". Contact your system administrator to add this option.
+[% ELSE %] + [% IF ( files_loop ) %] + + + + + + + + + + [% FOREACH file IN files_loop %] + + + + + + [% END %] + +
NameSize (bytes)Date last modified
[% file.name %][% file.size %][% file.date %]
+ [% ELSE %] + No file found. + [% END %] +[% END %] + +
+
+
+[% INCLUDE 'reports-menu.inc' %] +
+
+[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt index 6b47b70..4b9fdf6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt @@ -52,23 +52,25 @@ + -

Inactive

- +

Inactive

+ -

Other

-
+

Other

+ diff --git a/reports/report_files.pl b/reports/report_files.pl new file mode 100755 index 0000000..06221ce --- /dev/null +++ b/reports/report_files.pl @@ -0,0 +1,94 @@ +#!/usr/bin/perl + +# Frédérick Capovilla, 2011 - Libéo +# +# Show a list of all the files in the directory specified by the option +# "publiclogdir" in koha-conf.xml so they can be downloaded by users with the +# "reports" permission. +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; +use C4::Auth; +use CGI; +use C4::Context; +use C4::Output; +use C4::Koha; +use File::stat; + +my $input = new CGI; +my $file_id = $input->param("id"); +my $directory = C4::Context->config('publiclogdir'); + +my ($template, $borrowernumber, $cookie) + = get_template_and_user({template_name => "reports/report_files.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {reports => '*'}, + }); + +unless($directory) { + $template->param(error_no_publiclogdir => 1); +} +else { + #Get the files list + my @files_list; + opendir(DIR, $directory); + + my $i=0; + foreach my $filename (readdir(DIR)) { + my $full_path = "$directory/$filename"; + next if ($filename =~ /^\./ or -d $full_path); + + my $st = stat($full_path); + push(@files_list, {name => $filename, + date => scalar localtime($st->mtime), + size => $st->size, + id => $i}); + $i++; + } + closedir(DIR); + + # If we received a file_id and it is valid, send the file to the browser + if(defined $file_id and $file_id >= 0 and $file_id < scalar @files_list){ + my $filename = $files_list[$file_id]->{name}; + binmode STDOUT; + # Open the selected file and send it to the browser + print $input->header(-type => 'application/x-download', + -name => "$filename", + -Content_length => -s "$directory/$filename", + -attachment => "$filename"); + + open FILE, "<:utf8", "$directory/$filename"; + binmode FILE; + + my $buf; + while(read(FILE, $buf, 65536)) { + print $buf; + } + close FILE; + + exit(1); + } + else{ + # Send the file list to the template + $template->param(files_loop => \@files_list); + } +} + +output_html_with_http_headers $input, $cookie, $template->output; -- 2.1.4