View | Details | Raw Unified | Return to bug 25672
Collapse All | Expand All

(-)a/debian/templates/koha-conf-site.xml.in (-2 / +2 lines)
Lines 266-272 __END_SRU_PUBLICSERVER__ Link Here
266
 <authorityservershadow>1</authorityservershadow>
266
 <authorityservershadow>1</authorityservershadow>
267
 <pluginsdir>__PLUGINS_DIR__</pluginsdir> <!-- This entry can be repeated to use multiple directories -->
267
 <pluginsdir>__PLUGINS_DIR__</pluginsdir> <!-- This entry can be repeated to use multiple directories -->
268
 <enable_plugins>0</enable_plugins>
268
 <enable_plugins>0</enable_plugins>
269
 <enable_plugin_browser_upload>1</enable_plugin_browser_upload>
270
 <upload_path>__UPLOAD_PATH__</upload_path>
269
 <upload_path>__UPLOAD_PATH__</upload_path>
271
 <tmp_path>__TMP_PATH__</tmp_path>
270
 <tmp_path>__TMP_PATH__</tmp_path>
272
 <intranetdir>/usr/share/koha/intranet/cgi-bin</intranetdir>
271
 <intranetdir>/usr/share/koha/intranet/cgi-bin</intranetdir>
Lines 409-414 __END_SRU_PUBLICSERVER__ Link Here
409
      developers use it to catch bugs related to strict SQL modes -->
408
      developers use it to catch bugs related to strict SQL modes -->
410
 <dev_install>0</dev_install>
409
 <dev_install>0</dev_install>
411
 <strict_sql_modes>0</strict_sql_modes>
410
 <strict_sql_modes>0</strict_sql_modes>
411
 <plugins_restricted>1</plugins_restricted>
412
 <plugin_repos>
412
 <plugin_repos>
413
    <!--
413
    <!--
414
    <repo>
414
    <repo>
Lines 423-429 __END_SRU_PUBLICSERVER__ Link Here
423
    </repo>
423
    </repo>
424
    <repo>
424
    <repo>
425
        <name>PTFS Europe</name>
425
        <name>PTFS Europe</name>
426
        <org_name>ptfs-europe</org_name>
426
        <org_name>PTFS-Europe</org_name>
427
        <service>github</service>
427
        <service>github</service>
428
    </repo>
428
    </repo>
429
    <repo>
429
    <repo>
(-)a/etc/koha-conf.xml (-4 / +2 lines)
Lines 79-85 Link Here
79
 <authorityservershadow>1</authorityservershadow>
79
 <authorityservershadow>1</authorityservershadow>
80
 <pluginsdir>__PLUGINS_DIR__</pluginsdir> <!-- This entry can be repeated to use multiple directories -->
80
 <pluginsdir>__PLUGINS_DIR__</pluginsdir> <!-- This entry can be repeated to use multiple directories -->
81
 <enable_plugins>0</enable_plugins>
81
 <enable_plugins>0</enable_plugins>
82
 <enable_plugin_browser_upload>1</enable_plugin_browser_upload>
83
 <upload_path></upload_path>
82
 <upload_path></upload_path>
84
 <tmp_path></tmp_path>
83
 <tmp_path></tmp_path>
85
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
84
 <intranetdir>__INTRANET_CGI_DIR__</intranetdir>
Lines 226-233 Link Here
226
      developers use it to catch bugs related to strict SQL modes -->
225
      developers use it to catch bugs related to strict SQL modes -->
227
 <dev_install>0</dev_install>
226
 <dev_install>0</dev_install>
228
 <strict_sql_modes>0</strict_sql_modes>
227
 <strict_sql_modes>0</strict_sql_modes>
228
 <plugins_restricted>1</plugins_restricted>
229
 <plugin_repos>
229
 <plugin_repos>
230
    <!--
231
    <repo>
230
    <repo>
232
        <name>ByWater Solutions</name>
231
        <name>ByWater Solutions</name>
233
        <org_name>bywatersolutions</org_name>
232
        <org_name>bywatersolutions</org_name>
Lines 240-249 Link Here
240
    </repo>
239
    </repo>
241
    <repo>
240
    <repo>
242
        <name>PTFS Europe</name>
241
        <name>PTFS Europe</name>
243
        <org_name>ptfs-europe</org_name>
242
        <org_name>PTFS-Europe</org_name>
244
        <service>github</service>
243
        <service>github</service>
245
    </repo>
244
    </repo>
246
    -->
247
 </plugin_repos>
245
 </plugin_repos>
248
246
249
 <koha_xslt_security>
247
 <koha_xslt_security>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt (-3 / +3 lines)
Lines 29-37 Link Here
29
    <div class="container-fluid">
29
    <div class="container-fluid">
30
        <div class="row">
30
        <div class="row">
31
            <div class="col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3">
31
            <div class="col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3">
32
                [% IF ( browser_upload_enabled.defined ) && ( browser_upload_enabled == 0 ) %]
32
                [% IF ( plugins_restricted.defined ) && ( plugins_restricted == 1 ) %]
33
                <h1>Plugin browser upload disabled</h1>
33
                <h1>Plugin upload is restricted to only those plugins listed by your server administrator</h1>
34
                <p>To enable Koha plugin browser upload, the flag enable_plugin_browser_upload must be set in the Koha configuration file</p>
34
                <p>To enable unrestricted plugin uploads, ask your administrator to unset plugins_restricted in the Koha configuration file</p>
35
                [% ELSE %]
35
                [% ELSE %]
36
                <h1>Plugins disabled</h1>
36
                <h1>Plugins disabled</h1>
37
                <p>To enable Koha plugins, the flag enable_plugins must be set in the Koha configuration file</p>
37
                <p>To enable Koha plugins, the flag enable_plugins must be set in the Koha configuration file</p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt (-7 / +1 lines)
Lines 46-52 Link Here
46
46
47
                    [% IF ( CAN_user_plugins_manage ) %]
47
                    [% IF ( CAN_user_plugins_manage ) %]
48
                        <div class="btn-toolbar" id="toolbar">
48
                        <div class="btn-toolbar" id="toolbar">
49
                            [% IF ( enable_browser_upload ) %]
49
                            [% IF ( !plugins_restricted ) %]
50
                            <a href="/cgi-bin/koha/plugins/plugins-upload.pl" id="upload_plugin" class="btn btn-default"><i class="fa fa-upload"></i> Upload plugin</a>
50
                            <a href="/cgi-bin/koha/plugins/plugins-upload.pl" id="upload_plugin" class="btn btn-default"><i class="fa fa-upload"></i> Upload plugin</a>
51
                            [% END %]
51
                            [% END %]
52
52
Lines 90-98 Link Here
90
                                        <th>Description</th>
90
                                        <th>Description</th>
91
                                        <th>Organization</th>
91
                                        <th>Organization</th>
92
                                        <th>Latest version</th>
92
                                        <th>Latest version</th>
93
                                        [% IF ( enable_browser_upload ) %]
94
                                        <th>&nbsp;</th>
93
                                        <th>&nbsp;</th>
95
                                        [% END %]
96
                                    </tr>
94
                                    </tr>
97
                                </thead>
95
                                </thead>
98
96
Lines 102-110 Link Here
102
                                        <td>[% sr.result.description | html %]</td>
100
                                        <td>[% sr.result.description | html %]</td>
103
                                        <td>[% sr.repo.name | html %]</td>
101
                                        <td>[% sr.repo.name | html %]</td>
104
                                        <td>[% sr.result.tag_name | html %]</td>
102
                                        <td>[% sr.result.tag_name | html %]</td>
105
                                        [% IF ( enable_browser_upload ) %]
106
                                        <td><a class="btn btn-default btn-sm btn-install-plugin" href="/cgi-bin/koha/plugins/plugins-upload.pl?op=Upload&uploadfile=[% sr.result.install_name | uri %]&uploadlocation=[% sr.result.install_url | uri %]"><i class="fa fa-download"></i> Install</a></td>
103
                                        <td><a class="btn btn-default btn-sm btn-install-plugin" href="/cgi-bin/koha/plugins/plugins-upload.pl?op=Upload&uploadfile=[% sr.result.install_name | uri %]&uploadlocation=[% sr.result.install_url | uri %]"><i class="fa fa-download"></i> Install</a></td>
107
                                        [% END %]
108
                                    </tr>
104
                                    </tr>
109
                                [% END %]
105
                                [% END %]
110
                            </table>
106
                            </table>
Lines 220-228 Link Here
220
                                                            [% END %]
216
                                                            [% END %]
221
                                                        [% END %]
217
                                                        [% END %]
222
                                                        [% IF ( CAN_user_plugins_manage ) %]
218
                                                        [% IF ( CAN_user_plugins_manage ) %]
223
                                                            [% IF ( enable_browser_upload ) %]
224
                                                                <li><a class="uninstall_plugin" data-plugin-name="[% plugin.metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-uninstall.pl?class=[% plugin.class | html %]"><i class="fa fa-trash-can fa-fw"></i> Uninstall</a></li>
219
                                                                <li><a class="uninstall_plugin" data-plugin-name="[% plugin.metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-uninstall.pl?class=[% plugin.class | html %]"><i class="fa fa-trash-can fa-fw"></i> Uninstall</a></li>
225
                                                            [% END %]
226
                                                            [% IF ( plugin.is_enabled ) %]
220
                                                            [% IF ( plugin.is_enabled ) %]
227
                                                                    <li><a class="enable_plugin" data-plugin-name="[% plugin.metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-enable.pl?class=[% plugin.class | html %]&method=disable"><i class="fa fa-pause fa-fw"></i> Disable</a></li>
221
                                                                    <li><a class="enable_plugin" data-plugin-name="[% plugin.metadata.name | html %]" href="/cgi-bin/koha/plugins/plugins-enable.pl?class=[% plugin.class | html %]&method=disable"><i class="fa fa-pause fa-fw"></i> Disable</a></li>
228
                                                            [% ELSE %]
222
                                                            [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt (+1 lines)
Lines 39-44 Link Here
39
                        [% ELSIF ( ERROR.EMPTYUPLOAD ) %]<li><strong>The upload file appears to be empty.</strong></li>
39
                        [% ELSIF ( ERROR.EMPTYUPLOAD ) %]<li><strong>The upload file appears to be empty.</strong></li>
40
                        [% ELSIF ( ERROR.UZIPFAIL ) %]<li><strong>[% ERROR.UZIPFAIL | html %] failed to unpack.<br />Please verify the integrity of the zip file and retry.</strong></li>
40
                        [% ELSIF ( ERROR.UZIPFAIL ) %]<li><strong>[% ERROR.UZIPFAIL | html %] failed to unpack.<br />Please verify the integrity of the zip file and retry.</strong></li>
41
                        [% ELSIF ( ERROR.NOWRITEPLUGINS ) %]<li><strong>Cannot unpack file to the plugins directory.<br />Please verify that the Apache user can write to the plugins directory.</strong></li>
41
                        [% ELSIF ( ERROR.NOWRITEPLUGINS ) %]<li><strong>Cannot unpack file to the plugins directory.<br />Please verify that the Apache user can write to the plugins directory.</strong></li>
42
                        [% ELSIF ( ERROR.RESTRICTED ) %]<li><strong>Cannot install plugin from unknown source whilst plugins_restricted is enabled.<br /></strong></li>
42
                        [% ELSE %]<li><strong>[% ERROR.CORERR | html %] An unknown error has occurred.<br />Please review the error log for more details.</strong></li>[% END %]
43
                        [% ELSE %]<li><strong>[% ERROR.CORERR | html %] An unknown error has occurred.<br />Please review the error log for more details.</strong></li>[% END %]
43
                    [% END %]
44
                    [% END %]
44
                </div>
45
                </div>
(-)a/plugins/plugins-home.pl (-1 / +1 lines)
Lines 59-65 if ($plugins_enabled) { Link Here
59
    );
59
    );
60
60
61
    $template->param( plugins => \@plugins, );
61
    $template->param( plugins => \@plugins, );
62
    $template->param( enable_browser_upload => C4::Context->config('enable_plugin_browser_upload') );
62
    $template->param( plugins_restricted => C4::Context->config('plugins_restricted') );
63
63
64
    $template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 );
64
    $template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 );
65
    my @results;
65
    my @results;
(-)a/plugins/plugins-uninstall.pl (-2 / +1 lines)
Lines 38-47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
38
    }
38
    }
39
);
39
);
40
40
41
my $browser_upload_enabled = C4::Context->config('enable_plugin_browser_upload');
42
my $class = $input->param('class');
41
my $class = $input->param('class');
43
42
44
if ( $browser_upload_enabled && $class ) {
43
if ( $class ) {
45
    Koha::Plugins::Handler->delete( { class => $class } );
44
    Koha::Plugins::Handler->delete( { class => $class } );
46
}
45
}
47
46
(-)a/plugins/plugins-upload.pl (-17 / +38 lines)
Lines 20-50 use Modern::Perl; Link Here
20
20
21
use Archive::Extract;
21
use Archive::Extract;
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use List::Util qw( any );
23
use Mojo::UserAgent;
24
use Mojo::UserAgent;
24
use File::Temp;
25
use File::Temp;
25
26
26
use C4::Context;
27
use C4::Context;
27
use C4::Auth qw( get_template_and_user );
28
use C4::Auth   qw( get_template_and_user );
28
use C4::Output qw( output_html_with_http_headers );
29
use C4::Output qw( output_html_with_http_headers );
29
use C4::Members;
30
use C4::Members;
30
use Koha::Logger;
31
use Koha::Logger;
31
use Koha::Plugins;
32
use Koha::Plugins;
32
33
33
my $plugins_enabled = C4::Context->config("enable_plugins");
34
my $plugins_enabled    = C4::Context->config("enable_plugins");
34
my $browser_upload_enabled = C4::Context->config('enable_plugin_browser_upload');
35
my $plugins_restricted = C4::Context->config("plugins_restricted");
35
36
36
my $input = CGI->new;
37
my $input = CGI->new;
37
38
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
    {   template_name => ($plugins_enabled && $browser_upload_enabled) ? "plugins/plugins-upload.tt" : "plugins/plugins-disabled.tt",
40
    {
41
        template_name => $plugins_enabled ? "plugins/plugins-upload.tt" : "plugins/plugins-disabled.tt",
40
        query         => $input,
42
        query         => $input,
41
        type          => "intranet",
43
        type          => "intranet",
42
        flagsrequired   => { plugins => 'manage' },
44
        flagsrequired => { plugins => 'manage' },
43
    }
45
    }
44
);
46
);
45
47
46
if ($plugins_enabled){
48
if ($plugins_enabled) {
47
    $template->param( browser_upload_enabled => $browser_upload_enabled );
49
    $template->param( plugins_restricted => $plugins_restricted );
50
} else {
51
    # Exit early if uploads are not enabled
52
    output_html_with_http_headers $input, $cookie, $template->output;
48
}
53
}
49
54
50
my $uploadfilename = $input->param('uploadfile');
55
my $uploadfilename = $input->param('uploadfile');
Lines 56-62 my ( $tempfile, $tfh ); Link Here
56
61
57
my %errors;
62
my %errors;
58
63
59
if ($plugins_enabled && $browser_upload_enabled) {
64
if ($plugins_enabled) {
60
    if ( ( $op eq 'Upload' ) && ( $uploadfile || $uploadlocation ) ) {
65
    if ( ( $op eq 'Upload' ) && ( $uploadfile || $uploadlocation ) ) {
61
        my $plugins_dir = C4::Context->config("pluginsdir");
66
        my $plugins_dir = C4::Context->config("pluginsdir");
62
        $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
67
        $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
Lines 67-88 if ($plugins_enabled && $browser_upload_enabled) { Link Here
67
        $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
72
        $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
68
        ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 );
73
        ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 );
69
74
70
        $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
75
        $errors{'NOTKPZ'}         = 1 if ( $uploadfilename !~ /\.kpz$/i );
71
        $errors{'NOWRITETEMP'}    = 1 unless ( -w $dirname );
76
        $errors{'NOWRITETEMP'}    = 1 unless ( -w $dirname );
72
        $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
77
        $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
73
78
74
        if ( $uploadlocation ) {
79
        if ($uploadlocation) {
75
            my $ua = Mojo::UserAgent->new(max_redirects => 5);
80
            my $do_get = 1;
76
            my $tx = $ua->get($uploadlocation);
81
            if ( $plugins_restricted ) {
77
            $tx->result->content->asset->move_to($tempfile);
82
                my $repos = C4::Context->config('plugin_repos');
83
84
                # Fix data structure if only one repo defined
85
                if ( ref($repos->{repo}) eq 'HASH' ) {
86
                    $repos = { repo => [ $repos->{repo} ] };
87
                }
88
89
                $do_get = any { index($uploadlocation, $_->{org_name}) != -1 } @{ $repos->{repo} };
90
            }
91
92
            if ( $do_get ) {
93
                my $ua = Mojo::UserAgent->new( max_redirects => 5 );
94
                my $tx = $ua->get($uploadlocation);
95
                $tx->result->content->asset->move_to($tempfile);
96
            } else {
97
                $errors{'RESTRICTED'} = 1;
98
            }
78
        } else {
99
        } else {
79
            $errors{'EMPTYUPLOAD'}    = 1 unless ( length($uploadfile) > 0 );
100
            $errors{'RESTRICTED'} = 1 unless ( !$plugins_restricted );
101
            $errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 );
80
        }
102
        }
81
103
82
        if (%errors) {
104
        if (%errors) {
83
            $template->param( ERRORS => [ \%errors ] );
105
            $template->param( ERRORS => [ \%errors ] );
84
        } else {
106
        } else {
85
            if ( $uploadfile ) {
107
            if ($uploadfile && !$plugins_restricted) {
86
                while (<$uploadfile>) {
108
                while (<$uploadfile>) {
87
                    print $tfh $_;
109
                    print $tfh $_;
88
                }
110
                }
Lines 104-110 if ($plugins_enabled && $browser_upload_enabled) { Link Here
104
        warn "Problem uploading file or no file uploaded.";
126
        warn "Problem uploading file or no file uploaded.";
105
    }
127
    }
106
128
107
    if ( ($uploadfile || $uploadlocation) && !%errors && !$template->param('ERRORS') ) {
129
    if ( ( $uploadfile || $uploadlocation ) && !%errors && !$template->param('ERRORS') ) {
108
        print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
130
        print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
109
    } else {
131
    } else {
110
        output_html_with_http_headers $input, $cookie, $template->output;
132
        output_html_with_http_headers $input, $cookie, $template->output;
111
- 

Return to bug 25672