Lines 1-4
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
|
|
2 |
|
2 |
# |
3 |
# |
3 |
# This file is part of Koha. |
4 |
# This file is part of Koha. |
4 |
# |
5 |
# |
Lines 30-44
use C4::Members;
Link Here
|
30 |
use C4::Debug; |
31 |
use C4::Debug; |
31 |
use Koha::Plugins; |
32 |
use Koha::Plugins; |
32 |
|
33 |
|
33 |
die("Koha plugins are disabled!") |
34 |
my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins"); |
34 |
unless C4::Context->preference('UseKohaPlugins'); |
|
|
35 |
|
35 |
|
36 |
my $input = new CGI; |
36 |
my $input = new CGI; |
37 |
|
37 |
|
38 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
38 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
39 |
{ template_name => "plugins/plugins-upload.tmpl", |
39 |
{ template_name => ($plugins_enabled) ? "plugins/plugins-upload.tmpl" : "plugins/plugins-disabled.tt", |
40 |
query => $input, |
40 |
query => $input, |
41 |
type => "intranet", |
41 |
type => "intranet", |
42 |
authnotrequired => 0, |
42 |
authnotrequired => 0, |
43 |
flagsrequired => { plugins => 'manage' }, |
43 |
flagsrequired => { plugins => 'manage' }, |
44 |
debug => 1, |
44 |
debug => 1, |
Lines 53-98
my ( $total, $handled, @counts, $tempfile, $tfh );
Link Here
|
53 |
|
53 |
|
54 |
my %errors; |
54 |
my %errors; |
55 |
|
55 |
|
56 |
if ( ( $op eq 'Upload' ) && $uploadfile ) { |
56 |
if ($plugins_enabled) { |
57 |
my $plugins_dir = C4::Context->config("pluginsdir"); |
57 |
if ( ( $op eq 'Upload' ) && $uploadfile ) { |
58 |
|
58 |
my $plugins_dir = C4::Context->config("pluginsdir"); |
59 |
my $dirname = File::Temp::tempdir( CLEANUP => 1 ); |
|
|
60 |
$debug and warn "dirname = $dirname"; |
61 |
|
59 |
|
62 |
my $filesuffix; |
60 |
my $dirname = File::Temp::tempdir( CLEANUP => 1 ); |
63 |
$filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i; |
61 |
$debug and warn "dirname = $dirname"; |
64 |
( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); |
|
|
65 |
|
62 |
|
66 |
$debug and warn "tempfile = $tempfile"; |
63 |
my $filesuffix; |
|
|
64 |
$filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i; |
65 |
( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); |
67 |
|
66 |
|
68 |
$errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i ); |
67 |
$debug and warn "tempfile = $tempfile"; |
69 |
$errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); |
|
|
70 |
$errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir ); |
71 |
$errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 ); |
72 |
|
68 |
|
73 |
if (%errors) { |
69 |
$errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i ); |
74 |
$template->param( ERRORS => [ \%errors ] ); |
70 |
$errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); |
75 |
} else { |
71 |
$errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir ); |
76 |
while (<$uploadfile>) { |
72 |
$errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 ); |
77 |
print $tfh $_; |
|
|
78 |
} |
79 |
close $tfh; |
80 |
|
73 |
|
81 |
my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' ); |
74 |
if (%errors) { |
82 |
unless ( $ae->extract( to => $plugins_dir ) ) { |
|
|
83 |
warn "ERROR: " . $ae->error; |
84 |
$errors{'UZIPFAIL'} = $uploadfilename; |
85 |
$template->param( ERRORS => [ \%errors ] ); |
75 |
$template->param( ERRORS => [ \%errors ] ); |
86 |
output_html_with_http_headers $input, $cookie, $template->output; |
76 |
} else { |
87 |
exit; |
77 |
while (<$uploadfile>) { |
|
|
78 |
print $tfh $_; |
79 |
} |
80 |
close $tfh; |
81 |
|
82 |
my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' ); |
83 |
unless ( $ae->extract( to => $plugins_dir ) ) { |
84 |
warn "ERROR: " . $ae->error; |
85 |
$errors{'UZIPFAIL'} = $uploadfilename; |
86 |
$template->param( ERRORS => [ \%errors ] ); |
87 |
output_html_with_http_headers $input, $cookie, $template->output; |
88 |
exit; |
89 |
} |
88 |
} |
90 |
} |
|
|
91 |
} elsif ( ( $op eq 'Upload' ) && !$uploadfile ) { |
92 |
warn "Problem uploading file or no file uploaded."; |
93 |
} |
94 |
|
95 |
if ( $uploadfile && !%errors && !$template->param('ERRORS') ) { |
96 |
print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl"); |
97 |
} else { |
98 |
output_html_with_http_headers $input, $cookie, $template->output; |
89 |
} |
99 |
} |
90 |
} elsif ( ( $op eq 'Upload' ) && !$uploadfile ) { |
|
|
91 |
warn "Problem uploading file or no file uploaded."; |
92 |
} |
93 |
|
100 |
|
94 |
if ( $uploadfile && !%errors && !$template->param('ERRORS') ) { |
|
|
95 |
print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl"); |
96 |
} else { |
101 |
} else { |
97 |
output_html_with_http_headers $input, $cookie, $template->output; |
102 |
output_html_with_http_headers $input, $cookie, $template->output; |
98 |
} |
103 |
} |