@@ -, +, @@ Add a way to access files from the intranet - Adds a page to access log files on the server from the intranet - Update ID to allow for permalinking - Rename config to "'accessdir' and fix qa - Allows for multiple directories to be accessible - Update the link under reports - (Follow-up) Fixing merge error and cosmetic changes - (Follow-up) Fix tab chars and move javascript to the footer - (QA Follow-up) Fix datatable - Make filename unicode-proof, renamed accessdir to access_dir and fix update - Apply patch, update database - Add to koha-conf: - Create these directories ( mkdir /tmp/koha-public , etc...) - Create these files: - Login as Superadmin, go to tools > reports files - Click on ❤, make sure it's downloadable and readable - Click on both samename.txt, look inside and make sure the file is different - Login as NON-superadmin. Go under tools, see no Report/Log under the third column - Go to add tools/access_file permission to user - See new entry under tools third column. - validate link is ok. --- debian/templates/koha-conf-site.xml.in | 5 +- etc/koha-conf.xml | 3 + ...z11317-add-permission-for-tools-access-file.sql | 1 + installer/data/mysql/userpermissions.sql | 1 + .../intranet-tmpl/prog/en/includes/permissions.inc | 1 + .../intranet-tmpl/prog/en/includes/tools-menu.inc | 3 + .../prog/en/modules/reports/reports-home.tt | 38 +++---- .../prog/en/modules/tools/access_files.tt | 71 +++++++++++++ .../prog/en/modules/tools/tools-home.tt | 6 ++ tools/access_files.pl | 111 +++++++++++++++++++++ 10 files changed, 221 insertions(+), 19 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bz11317-add-permission-for-tools-access-file.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/access_files.tt create mode 100755 tools/access_files.pl --- a/debian/templates/koha-conf-site.xml.in +++ a/debian/templates/koha-conf-site.xml.in @@ -296,7 +296,10 @@ __END_SRU_PUBLICSERVER__ __API_SECRET__ - + + + + /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif-Bold.ttf --- a/etc/koha-conf.xml +++ a/etc/koha-conf.xml @@ -127,6 +127,9 @@ __PAZPAR2_TOGGLE_XML_POST__ CHANGEME + + + __FONT_DIR__/DejaVuSerif.ttf --- a/installer/data/mysql/atomicupdate/bz11317-add-permission-for-tools-access-file.sql +++ a/installer/data/mysql/atomicupdate/bz11317-add-permission-for-tools-access-file.sql @@ -0,0 +1, @@ +INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (13, 'access_files', 'Access to the files stored on the server'); --- a/installer/data/mysql/userpermissions.sql +++ a/installer/data/mysql/userpermissions.sql @@ -58,6 +58,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES (13, 'records_batchmod', 'Perform batch modification of records (biblios or authorities)'), (13, 'marc_modification_templates', 'Manage marc modification templates'), (13, 'records_batchdel', 'Perform batch deletion of records (bibliographic or authority)'), + (13, 'access_files', 'Access to the files stored on the server'), (13, 'upload_general_files', 'Upload any file'), (13, 'upload_manage', 'Manage uploaded files'), (15, 'check_expiration', 'Check the expiration of a serial'), --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -107,6 +107,7 @@ [%- CASE 'delete_public_lists' -%]Delete public lists [%- CASE 'upload_general_files' -%]Upload any file [%- CASE 'upload_manage' -%]Manage uploaded files (Useless without upload_general_files) + [%- CASE 'access_files' -%]Access to the files stored on the server [%- CASE 'edit_clubs' -%]Create and edit clubs [%- CASE 'edit_templates' -%]Create and edit club templates [%- CASE 'enroll' -%]Enroll patrons in clubs --- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc @@ -108,4 +108,7 @@ [% IF ( CAN_user_tools_upload_general_files ) %]
  • Upload any file
  • [% END %] + [% IF ( CAN_user_tools_access_files ) %] +
  • Report/log files
  • + [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt @@ -63,27 +63,29 @@ +<<<<<<< 3dd4c261c3d9d152edb12ead6b10b71b44418eab +

    Other

    + --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/access_files.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/access_files.tt @@ -0,0 +1,71 @@ +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] +Report/log files +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + + +
    +
    +
    +
    + +

    Report/log files

    + +[% IF ( error_no_dir ) %] +
    Error : Report/log files could not be found because the "access_dir" 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 'tools-menu.inc' %] +
    +
    + +[% MACRO jsinclude BLOCK %] + + [% INCLUDE 'datatables.inc' %] + +[% END %] +[% INCLUDE 'intranet-bottom.inc' %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt @@ -113,6 +113,12 @@
    Upload
    Upload any type of file, manage uploads
    [% END %] + + [% IF CAN_user_tools_access_files %] +
    Report/log files
    +
    Access report or log files
    + [% END %] +
    --- a/tools/access_files.pl +++ a/tools/access_files.pl @@ -0,0 +1,111 @@ +#!/usr/bin/perl + +# Frédérick Capovilla, 2011 - Libéo +# +# Show a list of all the files in the directory specified by the option +# "access_dir" in koha-conf.xml so they can be downloaded by users with the +# "access_files" 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 3 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 Modern::Perl; + +use C4::Auth; +use CGI; +use C4::Context; +use C4::Output; +use C4::Koha; +use File::stat qw(stat); +use Digest::MD5 qw(md5_hex); +use Encode; + +my $input = new CGI; +my $file_id = $input->param("id"); +my $access_dir = C4::Context->config('access_dir'); +my @directories = $access_dir ? (ref $access_dir ? @{$access_dir} : ($access_dir)) : (); + +my ($template, $borrowernumber, $cookie) + = get_template_and_user({template_name => "tools/access_files.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { tools => 'access_files' }, + }); + +unless(@directories) { + $template->param(error_no_dir => 1); +} +else { + #Get the files list + my @files_list; + foreach my $dir(@directories){ + opendir(DIR, $dir); + foreach my $filename (readdir(DIR)) { + my $full_path = "$dir/$filename"; + my $id = md5_hex($full_path); + next if ($filename =~ /^\./ or -d $full_path); + + # Make sure the filename is unicode-friendly + my $decoded_filename = decode('utf8', $filename); + my $st = stat("$dir/$decoded_filename"); + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime); + my $dt=DateTime->new(year => $year + 1900, + month => $mon + 1, + day => $mday, + hour => $hour, + minute => $min, + ); + push(@files_list, {name => $decoded_filename, + access_dir => $dir, + date =>Koha::DateUtils::output_pref($dt), + size => $st->size, + id => $id}); + } + closedir(DIR); + } + + my %files_hash = map { $_->{id} => $_ } @files_list; + # If we received a file_id and it is valid, send the file to the browser + if(defined $file_id and exists $files_hash{$file_id} ){ + my $filename = $files_hash{$file_id}->{name}; + my $dir = $files_hash{$file_id}->{access_dir}; + binmode STDOUT; + # Open the selected file and send it to the browser + print $input->header(-type => 'application/x-download', + -name => "$filename", + -Content_length => -s "$dir/$filename", + -attachment => "$filename"); + + my $fh; + open $fh, "<:encoding(UTF-8)", "$dir/$filename"; + binmode $fh; + + my $buf; + while(read($fh, $buf, 65536)) { + print $buf; + } + close $fh; + + exit(0); + } + else{ + # Send the file list to the template + $template->param(files_loop => \@files_list); + } +} + +output_html_with_http_headers $input, $cookie, $template->output; --