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

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

Return to bug 25672