From 6c01f6b5472648ef7863da2ff2891155c5729576 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 22 Jan 2010 16:34:52 +0000 Subject: [PATCH] Koha Plugins Adds support for custom plugins. At the moment the Plugins feature supports two types of plugins, reports and tools. Plugins are installed by uploading KPZ ( Koha Plugin Zip ) packages. A KPZ file is just a zip file containing a plugin.ini file describing the plugin, as well as the perl file, template files, and any other files neccessary to make the plugin work. http://bugs.koha-community.org/show_bug.cgi?id=7804 Merged in Bug 7804: Follow up fixing FSF address by Chris Cormack --- C4/Auth.pm | 1 + C4/Installer/PerlDependencies.pm | 10 ++ C4/Plugins.pm | 163 ++++++++++++++++++++ Makefile.PL | 10 +- debian/templates/koha-conf-site.xml.in | 1 + etc/koha-conf.xml | 1 + etc/koha-httpd.conf | 1 + install_misc/debian.packages | 1 + install_misc/ubuntu.packages | 1 + install_misc/ubuntu_maverick.packages | 1 + installer/data/mysql/updatedatabase.pl | 9 + .../intranet-tmpl/prog/en/includes/header.inc | 3 + .../prog/en/modules/plugins/plugins-home.tt | 76 +++++++++ .../prog/en/modules/plugins/plugins-upload.tt | 56 +++++++ .../prog/en/modules/reports/report-plugins.tt | 54 +++++++ .../prog/en/modules/reports/reports-home.tt | 5 + .../prog/en/modules/tools/tool-plugins.tt | 54 +++++++ .../prog/en/modules/tools/tools-home.tt | 6 +- plugins/plugins-home.pl | 53 +++++++ plugins/plugins-upload.pl | 89 +++++++++++ reports/report-plugins.pl | 52 ++++++ rewrite-config.PL | 3 +- skel/var/lib/koha/plugins/.htaccess | 2 + skel/var/lib/koha/plugins/README | 1 + tools/tool-plugins.pl | 52 ++++++ 25 files changed, 702 insertions(+), 3 deletions(-) create mode 100644 C4/Plugins.pm create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reports/report-plugins.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/tool-plugins.tt create mode 100755 plugins/plugins-home.pl create mode 100755 plugins/plugins-upload.pl create mode 100755 reports/report-plugins.pl create mode 100644 skel/var/lib/koha/plugins/.htaccess create mode 100644 skel/var/lib/koha/plugins/README create mode 100755 tools/tool-plugins.pl diff --git a/C4/Auth.pm b/C4/Auth.pm index 0b737e7..fab03f0 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -202,6 +202,7 @@ sub get_template_and_user { $template->param( CAN_user_serials => 1 ); $template->param( CAN_user_reports => 1 ); $template->param( CAN_user_staffaccess => 1 ); + $template->param( CAN_user_plugins => 1 ); foreach my $module (keys %$all_perms) { foreach my $subperm (keys %{ $all_perms->{$module} }) { $template->param( "CAN_user_${module}_${subperm}" => 1 ); diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 0a888a8..700c88b 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -484,6 +484,16 @@ our $PERL_DEPS = { 'required' => '1', 'min_ver' => '0.09', }, + 'File::Temp' => { + 'usage' => 'Plugins', + 'required' => '0', + 'min_ver' => '0.22', + }, + 'File::Copy' => { + 'usage' => 'Plugins', + 'required' => '0', + 'min_ver' => '2.08', + }, }; 1; diff --git a/C4/Plugins.pm b/C4/Plugins.pm new file mode 100644 index 0000000..648b7b3 --- /dev/null +++ b/C4/Plugins.pm @@ -0,0 +1,163 @@ +package C4::Plugins; + +# Copyright 2010 Kyle Hall +# +# 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 CGI; + +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); + +use C4::Context; +use C4::Output; +use C4::Dates; +use C4::Debug; + +BEGIN { + # set the version for version checking + $VERSION = 0.01; + require Exporter; + @ISA = qw(Exporter); + @EXPORT = qw( + GetPlugins + GetPluginsDir + ); +} + +=head1 NAME + +C4::Plugins - Module for loading and managing plugins. + +=head1 SYNOPSIS + + use C4::Plugins; + +=over 2 + +=cut + +=item GetPlugins() + +This will return a list of all the available plugins of the passed type. + +Usage: my ( $plugins_hasref, $plugins_count ) = C4::Plugins::GetPlugins( $type ); + +At the moment, the available types are 'report' and 'tool'. +=cut + +sub GetPlugins { + my ( $type ) = @_; + my @plugins_ini = _GetPluginIniFiles(); + my $version = C4::Context->preference("Version"); + + my @plugins; + foreach my $plugin_ini ( @plugins_ini ) { + my $ini_hashref = _ParsePluginIni( $plugin_ini ); + chomp( $ini_hashref->{'minimum_version'} ); + chomp( $ini_hashref->{'maximum_version'} ); + + if ( ( defined $type && $ini_hashref->{'type'} eq $type ) || ! defined $type ) { + $ini_hashref->{'date_updated'} = C4::Dates->new( $ini_hashref->{'date_updated'}, "iso")->output(); + if ( $ini_hashref->{'minimum_version'} > $version ) { + $ini_hashref->{'db_version_too_old'} = 1; + } + if ( $ini_hashref->{'maximum_version'} && $ini_hashref->{'maximum_version'} < $version ) { + $ini_hashref->{'db_version_too_new'} = 1; + } + push( @plugins, $ini_hashref ); + } + } + + @plugins = sort { $a->{name} cmp $b->{name} } @plugins; + + my $count = @plugins; + return ( \@plugins, $count ); +} + +=item GetPluginsDir() + +Returns the path of the plugins directory. + +=cut + +sub GetPluginsDir { + return C4::Context->config("pluginsdir"); +} + +=item _GetPluginIniFiles() + +This will return an array of all the ini files for the custom plugins. + +=cut + +sub _GetPluginIniFiles { + my $plugins_dir = GetPluginsDir(); + opendir(DIRHANDLE, $plugins_dir); + my @plugins_dirs = readdir(DIRHANDLE); + closedir(DIRHANDLE); + + my @plugins; + foreach my $plugin_dir ( @plugins_dirs ) { + + my $plugin_path = $plugins_dir . '/' . $plugin_dir; + if ( -d $plugin_path ) { + my $ini_path = $plugin_path . '/plugin.ini'; + + if ( -f $ini_path ) { + push( @plugins, $ini_path ); + } + + } + + } + + return ( @plugins ); +} + +=item _ParsePluginIni( $ini_path ) + +This will return a hasref of key/value pairs found in the ini file + +=cut + +sub _ParsePluginIni { + my ( $ini_path ) = @_; + + my $ini; + + open( INIFILE, '<', $ini_path ) or die("Could not open file $ini_path"); + foreach my $line ( ) { + my ( $key, $value ); + ( $key, $value ) = split(/=/, $line ); + $ini->{$key} = $value; + } + + return $ini; +} + +1; +__END__ + +=back + +=head1 AUTHOR + +Kyle M Hall + +=cut diff --git a/Makefile.PL b/Makefile.PL index 2e414d5..6c15a6d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -226,6 +226,10 @@ command-line, e.g., READMEs. Directory for Apache and Zebra logs produced by Koha. +=item PLUGINS_DIR + +Directory for external Koha plugins. + =item PAZPAR2_CONF_DIR Directory for PazPar2 configuration files. @@ -303,6 +307,7 @@ my $target_map = { './skel/var/lib/koha/zebradb/biblios/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 }, './skel/var/lib/koha/zebradb/biblios/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 }, './skel/var/lib/koha/zebradb/biblios/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 }, + './skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 }, './sms' => 'INTRANET_CGI_DIR', './suggestion' => 'INTRANET_CGI_DIR', './svc' => 'INTRANET_CGI_DIR', @@ -1204,6 +1209,7 @@ sub get_target_directories { $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc'); $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb'); $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log'); + $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'koha', 'plugins'); $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb'); $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb'); } elsif ($mode eq 'dev') { @@ -1233,6 +1239,7 @@ sub get_target_directories { $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc'); $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb'); $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log'); + $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'plugins'); $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb'); $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb'); } else { @@ -1254,6 +1261,7 @@ sub get_target_directories { $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc'); $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb'); $dirmap{'LOG_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package); + $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'plugins'); $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb'); $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb'); } @@ -1525,7 +1533,7 @@ make_upgrade_backup :: \t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\ /; foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR - PAZPAR2_CONF_DIR ZEBRA_CONF_DIR/) { + PAZPAR2_CONF_DIR ZEBRA_CONF_DIR PLUGINS_DIR/) { $upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n" unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key} or diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in index a440c96..23dbd0f 100644 --- a/debian/templates/koha-conf-site.xml.in +++ b/debian/templates/koha-conf-site.xml.in @@ -257,6 +257,7 @@ 1 authorities 1 + __PLUGINS_DIR__ /usr/share/koha/intranet/cgi-bin /usr/share/koha/opac/cgi-bin/opac /usr/share/koha/opac/htdocs/opac-tmpl diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml index f5e2c0f..0d5eefc 100644 --- a/etc/koha-conf.xml +++ b/etc/koha-conf.xml @@ -266,6 +266,7 @@ __PAZPAR2_TOGGLE_XML_POST__ 1 authorities 1 + __PLUGINS_DIR__ __INTRANET_CGI_DIR__ __OPAC_CGI_DIR__/opac __OPAC_TMPL_DIR__ diff --git a/etc/koha-httpd.conf b/etc/koha-httpd.conf index 2b986ac..4d6c03d 100644 --- a/etc/koha-httpd.conf +++ b/etc/koha-httpd.conf @@ -102,6 +102,7 @@ DocumentRoot __INTRANET_WWW_DIR__ ServerName __WEBSERVER_HOST__:__WEBSERVER_PORT_LIBRARIAN__ # ServerAlias intranet.mydomain.com + ScriptAlias /cgi-bin/koha/plugins/run "__PLUGINS_DIR__/" ScriptAlias /cgi-bin/koha/ "__INTRANET_CGI_DIR__/" ScriptAlias /index.html "__INTRANET_CGI_DIR__/mainpage.pl" ScriptAlias /search "__INTRANET_CGI_DIR__/search.pl" diff --git a/install_misc/debian.packages b/install_misc/debian.packages index 6be4daa..9b2b14b 100644 --- a/install_misc/debian.packages +++ b/install_misc/debian.packages @@ -109,3 +109,4 @@ make install mysql-server install yaz-doc install yaz install +libconfig-simple-perl install \ No newline at end of file diff --git a/install_misc/ubuntu.packages b/install_misc/ubuntu.packages index f211769..1aabd75 100644 --- a/install_misc/ubuntu.packages +++ b/install_misc/ubuntu.packages @@ -120,3 +120,4 @@ libxml-simple-perl install libxml-xslt-perl install libyaml-perl install libyaml-syck-perl install +libconfig-simple-perl install diff --git a/install_misc/ubuntu_maverick.packages b/install_misc/ubuntu_maverick.packages index 9b806bb..1bdabb5 100644 --- a/install_misc/ubuntu_maverick.packages +++ b/install_misc/ubuntu_maverick.packages @@ -127,3 +127,4 @@ libxml-simple-perl install libxml-xslt-perl install libyaml-perl install libyaml-syck-perl install +libconfig-simple-perl install diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 32099d8..ffaa8a0 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4994,6 +4994,15 @@ if ( C4::Context->preference("Version") lt TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.07.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT INTO userflags (bit, flag, flagdesc, defaulton) VALUES ('19', 'plugins', 'Koha Plugins', '0')"); + $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ('19', 'manage', 'Manage Plugins'), ('19', 'tools', 'Use Tool Plugins'), ('19', 'reports', 'Use Report Plugins')"); + print "Upgrade to $DBversion done (Added system preference RoutingListNote for adding a general note to all routing lists.)\n"; + + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc index 5da4991..615ed8a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -34,6 +34,9 @@ [% IF ( CAN_user_tools ) %]
  • Tools
  • [% END %] + [% IF ( CAN_user_plugins ) %] +
  • Plugins
  • + [% END %] [% IF ( CAN_user_parameters ) %]
  • Administration
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt new file mode 100644 index 0000000..631e972 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt @@ -0,0 +1,76 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Tools › Plugins +[% INCLUDE 'doc-head-close.inc' %] +[% INCLUDE 'calendar.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'circ-search.inc' %] + + + +
    +
    +
    +
    +
    +

    Plugins

    + + [% IF ( ERROR_NO_PLUGINS ) %] +

    No Plugins Exist.

    +

    Please upload one or more Koha Plugin files (.krz) before using.

    + [% ELSE %] + + + + + + + + + + + + + [% FOREACH PLUGINS_LOO IN PLUGINS_LOOP %] + + + + + + + + + + [% END %] +
    NameTypeDescriptionAuthorPlugin VersionMinimum Koha VersionMaximum Koha VersionLast Updated
    [% PLUGINS_LOO.name %][% PLUGINS_LOO.type %] + [% PLUGINS_LOO.description %] + + [% IF ( PLUGINS_LOO.db_version_too_old ) %] +
    Warning: This report was written for a newer version of Koha. Run at your own risk.
    + [% END %] + + [% IF ( PLUGINS_LOO.db_version_too_new ) %] +
    Warning: This report was written for an older version of Koha. Run at your own risk.
    + [% END %] +
    [% PLUGINS_LOO.author %][% PLUGINS_LOO.version %][% PLUGINS_LOO.minimum_version %][% PLUGINS_LOO.maximum_version %][% PLUGINS_LOO.date_updated %]
    + [% END %] +
    +
    +
    + +
    + +
    +
    +
    + + +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt new file mode 100644 index 0000000..5d40366 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt @@ -0,0 +1,56 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Tools › Plugins › Upload Plugin + +[% INCLUDE 'doc-head-close.inc' %] +[% INCLUDE 'calendar.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'circ-search.inc' %] + + + +
    +
    +
    +
    +
    +
    +

    Upload Koha Plugin

    + [% IF ( ERRORS ) %] +
    + [% FOREACH ERROR IN ERRORS %] + [% IF ( ERROR.NOTKPZ ) %]
  • The upload file does not appear to be a kpz file. The extention is not '.kpz'.
  • + [% ELSIF ( ERROR.NOWRITETEMP ) %]
  • This script is not able to create/write to the necessary temporary directory.
  • + [% ELSIF ( ERROR.EMPTYUPLOAD ) %]
  • The upload file appears to be empty.
  • + [% ELSIF ( ERROR.UZIPFAIL ) %]
  • [% ERROR.UZIPFAIL %] failed to unpack.
    Please verify the integrity of the zip file and retry.
  • + [% ELSIF ( ERROR.NOWRITEPLUGINS ) %]
  • Cannot unpack file to the plugins directory.
    Please verify that the Apache user can write to the plugins directory.
  • + [% ELSE %]
  • [% ERROR.CORERR %] An unknown error has occurred.
    Please review the error log for more details.
  • [% END %] + [% END %] +
    + [% END %] +
    +
    +
    NOTE: Only KPZ file format is supported.
    +
      +
    1. + +
    2. +
    + +
    +
    + + +
    +
    + +
    +
    +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report-plugins.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report-plugins.tt new file mode 100644 index 0000000..782f15f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report-plugins.tt @@ -0,0 +1,54 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Reports › Report Plugins +[% INCLUDE 'doc-head-close.inc' %] +[% INCLUDE 'calendar.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'circ-search.inc' %] + + + +
    +
    +
    +
    +

    Report Plugins

    + + [% IF ( ERROR_NO_REPORTS ) %] +

    No Report Plugins Exist.

    + [% ELSE %] + + + + + + + + + [% FOREACH REPORTS_LOO IN REPORTS_LOOP %] + + + + + + [% END %] +
    NameDescriptionAuthorLast Update
    [% REPORTS_LOO.name %] + [% REPORTS_LOO.description %] + [% IF ( REPORTS_LOO.db_version_too_old ) %] +
    Warning: This report was written for a newer version of Koha. Run at your own risk.
    + [% END %] +
    [% REPORTS_LOO.author %][% REPORTS_LOO.date_updated %]
    + [% END %] +
    +
    +
    +
    + + + +[% 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 e8bb4d5..1c68b13 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 @@ -27,6 +27,11 @@
  • View Dictionary
  • +

    Report Plugins

    + +

    Statistics wizards

    • Acquisitions
    • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tool-plugins.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tool-plugins.tt new file mode 100644 index 0000000..6d8a856 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tool-plugins.tt @@ -0,0 +1,54 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Tools › Tool Plugins +[% INCLUDE 'doc-head-close.inc' %] +[% INCLUDE 'calendar.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'circ-search.inc' %] + + + +
      +
      +
      +
      +

      Tool Plugins

      + + [% IF ( ERROR_NO_TOOLS ) %] +

      No Tool Plugins Exist.

      + [% ELSE %] + + + + + + + + + [% FOREACH TOOLS_LOO IN TOOLS_LOOP %] + + + + + + [% END %] +
      NameDescriptionAuthorLast Update
      [% TOOLS_LOO.name %] + [% TOOLS_LOO.description %] + [% IF ( TOOLS_LOO.db_version_too_old ) %] +
      Warning: This report was written for a newer version of Koha. Run at your own risk.
      + [% END %] +
      [% TOOLS_LOO.author %][% TOOLS_LOO.date_updated %]
      + [% END %] +
      +
      +
      +
      + + + +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt index 5cc3bbf..8d36174 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt @@ -86,7 +86,11 @@
      Task scheduler
      Schedule tasks to run
      [% END %] - + + [% IF ( CAN_user_plugins_tools ) %] +
      Tool Plugins
      +
      Schedule tasks to run
      + [% END %]
    diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl new file mode 100755 index 0000000..9be61b2 --- /dev/null +++ b/plugins/plugins-home.pl @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +# Copyright 2010 Kyle M Hall +# +# 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 CGI; + +use C4::Plugins; +use C4::Auth; +use C4::Output; +use C4::Dates; +use C4::Debug; +use C4::Context; + +my $input = new CGI; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "plugins/plugins-home.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { plugins => "manage" }, + debug => 1, + } +); + +my ( $plugins_loop, $plugins_count ) = GetPlugins(); + +$template->param( PLUGINS_LOOP => $plugins_loop ); + +unless ( $plugins_count ) { + $template->param( ERROR_NO_PLUGINS => 1 ); +} + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/plugins/plugins-upload.pl b/plugins/plugins-upload.pl new file mode 100755 index 0000000..8532799 --- /dev/null +++ b/plugins/plugins-upload.pl @@ -0,0 +1,89 @@ +#!/usr/bin/perl +# +# 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 File::Temp; +use File::Copy; +use CGI; + +use C4::Context; +use C4::Auth; +use C4::Output; +use C4::Members; +use C4::Debug; +use C4::Plugins; + +my $input = new CGI; + +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "plugins/plugins-upload.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { plugins => 'manage'}, + debug => 1, + }); + +my $uploadfilename = $input->param('uploadfile'); +my $uploadfile = $input->upload('uploadfile'); +my $op = $input->param('op'); + +my ( $total, $handled, @counts, $tempfile, $tfh ); + +my %errors; + +if ( ($op eq 'Upload') && $uploadfile ) { + my $plugins_dir = GetPluginsDir(); + + my $dirname = File::Temp::tempdir( CLEANUP => 1); + $debug and warn "dirname = $dirname"; + + my $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i; + ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); + + $debug and warn "tempfile = $tempfile"; + + $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i ); + $errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); + $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir ); + $errors{'EMPTYUPLOAD'} = 1 unless ( length( $uploadfile ) > 0 ); + + if ( %errors ) { + $template->param( ERRORS => [ \%errors ] ); + } else { + while ( <$uploadfile> ) { + print $tfh $_; + } + close $tfh; + unless (system("unzip -o $tempfile -d $plugins_dir") == 0) { + $errors{'UZIPFAIL'} = $uploadfilename; + $template->param( ERRORS => [ \%errors ] ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; + } + } +} elsif ( ($op eq 'Upload') && !$uploadfile ) { + warn "Problem uploading file or no file uploaded."; +} + +if ( $uploadfile && !%errors && !$template->param('ERRORS') ) { + print $input->redirect ("/cgi-bin/koha/plugins/plugins-home.pl"); +} else { + output_html_with_http_headers $input, $cookie, $template->output; +} diff --git a/reports/report-plugins.pl b/reports/report-plugins.pl new file mode 100755 index 0000000..257342b --- /dev/null +++ b/reports/report-plugins.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +# Copyright 2010 Kyle M Hall +# +# 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 CGI; + +use C4::Plugins; +use C4::Auth; +use C4::Output; +use C4::Dates; +use C4::Debug; + +my $input = new CGI; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "reports/report-plugins.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { plugins => "reports" }, + debug => 1, + } +); + +my ( $reports_loop, $reports_count ) = GetPlugins( 'report' ); + +$template->param( REPORTS_LOOP => $reports_loop ); + +unless ( $reports_count ) { + $template->param( ERROR_NO_REPORTS => 1 ); +} + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/rewrite-config.PL b/rewrite-config.PL index 967a546..cdcb657 100644 --- a/rewrite-config.PL +++ b/rewrite-config.PL @@ -43,7 +43,7 @@ guesses worked out by the script. The following configuration keywords are available: PREFIX, -BASE_DIR, CGI_DIR, LOG_DIR, INSTALL_BASE, +BASE_DIR, CGI_DIR, LOG_DIR, PLUGINS_DIR, INSTALL_BASE, DB_TYPE, DB_HOST, DB_PORT, DB_NAME, DB_PASS, DB_USER, WEBMASTER_EMAIL, WEBSERVER_DOMAIN, WEBSERVER_HOST, WEBSERVER_IP, WEBSERVER_PORT, WEBSERVER_PORT_LIBRARIAN, ZEBRA_PASS, ZEBRA_USER @@ -82,6 +82,7 @@ $prefix = $ENV{'INSTALL_BASE'} || "/usr"; %configuration = ( "__KOHA_INSTALLED_VERSION__" => "no_version_found", "__LOG_DIR__" => "/var/log", + "__PLUGINS_DIR__" => "/var/lib/koha/plugins", "__DB_TYPE__" => "mysql", "__DB_NAME__" => "koha", "__DB_HOST__" => $myhost, diff --git a/skel/var/lib/koha/plugins/.htaccess b/skel/var/lib/koha/plugins/.htaccess new file mode 100644 index 0000000..4d7523a --- /dev/null +++ b/skel/var/lib/koha/plugins/.htaccess @@ -0,0 +1,2 @@ +AddHandler cgi-script .pl +AddHandler send-as-is .css .js .gif .jpg \ No newline at end of file diff --git a/skel/var/lib/koha/plugins/README b/skel/var/lib/koha/plugins/README new file mode 100644 index 0000000..d4290ea --- /dev/null +++ b/skel/var/lib/koha/plugins/README @@ -0,0 +1 @@ +plugins dir \ No newline at end of file diff --git a/tools/tool-plugins.pl b/tools/tool-plugins.pl new file mode 100755 index 0000000..9e9db65 --- /dev/null +++ b/tools/tool-plugins.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +# Copyright 2010 Kyle M Hall +# +# 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 CGI; + +use C4::Plugins; +use C4::Auth; +use C4::Output; +use C4::Dates; +use C4::Debug; + +my $input = new CGI; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "tools/tool-plugins.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { plugins => "tools" }, + debug => 1, + } +); + +my ( $reports_loop, $reports_count ) = GetPlugins( 'tool' ); + +$template->param( TOOLS_LOOP => $reports_loop ); + +unless ( $reports_count ) { + $template->param( ERROR_NO_TOOLS => 1 ); +} + +output_html_with_http_headers $input, $cookie, $template->output; -- 1.7.2.5