From 41ff47747c5a719eb552d0a606816bd81c0bb0f0 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 8 Jul 2020 11:53:54 +0000 Subject: [PATCH] Bug 25672: use enable_plugin_browser_upload flag to control plugin upload This patch adds a enable_plugin_browser_upload flag to koha-conf.xml, which controls whether or not Koha intranet users can upload Koha plugins via their browser. Like "enable_plugins", it defaults to 0 for new installs. This is useful when you want to provide Koha intranet users with plugins that are pre-installed by administrators (by CLI) or restricting them to plugins from a Github repo. See the following for more information: Bug 23975 - Add ability to search and install plugins from GitHub Bug 23191 - Administrators should be able to install plugins from the command line To test: 1) Apply the patch 2) Set 1 in koha-conf.xml 3) Add 0 in koha-conf.xml 4) restart_all (in koha-testing-docker) 5) Go to /cgi-bin/koha/plugins/plugins-home.pl and note that you don't see an option to upload plugins 6) Go to /cgi-bin/koha/plugins/plugins-upload.pl and note that it says "Plugin browser upload disabled!" and gives instructions on how to enable browser upload 7) Install a plugin from the CLI using koha-shell kohadev -c "/usr/share/koha/bin/devel/install_plugins.pl" 8) Note that the Uninstall option for the plugin does not appear 9) Enable Koha plugin git repos and search for "coverflow" 10) Note that you can find the plugin but you cannot install it 11) Change enable_plugin_browser_upload back to 1 and "restart_all" 12) Note that you can not upload plugins, uninstall plugins, and install plugins from Git repos Signed-off-by: Nicolas Legrand Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- debian/templates/koha-conf-site.xml.in | 1 + etc/koha-conf.xml | 1 + .../prog/en/modules/plugins/plugins-disabled.tt | 6 +++++- .../prog/en/modules/plugins/plugins-home.tt | 2 ++ plugins/plugins-home.pl | 1 + plugins/plugins-upload.pl | 9 +++++++-- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in index c4f9c5139de..5511c3d84b7 100644 --- a/debian/templates/koha-conf-site.xml.in +++ b/debian/templates/koha-conf-site.xml.in @@ -266,6 +266,7 @@ __END_SRU_PUBLICSERVER__ 1 __PLUGINS_DIR__ 0 + 0 __UPLOAD_PATH__ __TMP_PATH__ /usr/share/koha/intranet/cgi-bin diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml index b9a5c061611..3679f5dbd0f 100644 --- a/etc/koha-conf.xml +++ b/etc/koha-conf.xml @@ -79,6 +79,7 @@ 1 __PLUGINS_DIR__ 0 + 0 __INTRANET_CGI_DIR__ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt index 9b799ccae28..4b25a95829c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt @@ -24,9 +24,13 @@
+ [% IF ( browser_upload_enabled.defined ) && ( browser_upload_enabled == 0 ) %] +

Plugin browser upload disabled!

+

To enable Koha plugin browser upload, the flag enable_plugin_browser_upload must be set in the Koha configuration file

+ [% ELSE %]

Plugins disabled!

-

To enable Koha plugins, the flag enable_plugins must be set in the Koha configuration file

+ [% 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 index 3dad8c1ea93..5e2534864f8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt @@ -45,7 +45,9 @@ [% IF ( CAN_user_plugins_manage ) %]
+ [% IF ( enable_browser_upload ) %] Upload plugin + [% END %]
diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl index 870fcadfefc..4b762995355 100755 --- a/plugins/plugins-home.pl +++ b/plugins/plugins-home.pl @@ -59,6 +59,7 @@ if ($plugins_enabled) { ); $template->param( plugins => \@plugins, ); + $template->param( enable_browser_upload => C4::Context->config('enable_plugin_browser_upload') ); $template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 ); my @results; diff --git a/plugins/plugins-upload.pl b/plugins/plugins-upload.pl index 3e44f00b7e1..1fe6b3b0411 100755 --- a/plugins/plugins-upload.pl +++ b/plugins/plugins-upload.pl @@ -31,17 +31,22 @@ use Koha::Logger; use Koha::Plugins; my $plugins_enabled = C4::Context->config("enable_plugins"); +my $browser_upload_enabled = C4::Context->config('enable_plugin_browser_upload'); my $input = CGI->new; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { template_name => ($plugins_enabled) ? "plugins/plugins-upload.tt" : "plugins/plugins-disabled.tt", + { template_name => ($plugins_enabled && $browser_upload_enabled) ? "plugins/plugins-upload.tt" : "plugins/plugins-disabled.tt", query => $input, type => "intranet", flagsrequired => { plugins => 'manage' }, } ); +if ($plugins_enabled){ + $template->param( browser_upload_enabled => $browser_upload_enabled ); +} + my $uploadfilename = $input->param('uploadfile'); my $uploadfile = $input->upload('uploadfile'); my $uploadlocation = $input->param('uploadlocation'); @@ -51,7 +56,7 @@ my ( $tempfile, $tfh ); my %errors; -if ($plugins_enabled) { +if ($plugins_enabled && $browser_upload_enabled) { if ( ( $op eq 'Upload' ) && ( $uploadfile || $uploadlocation ) ) { my $plugins_dir = C4::Context->config("pluginsdir"); $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir; -- 2.30.2