|
Lines 20-25
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 Mojo::UserAgent; |
| 23 |
use File::Copy; |
24 |
use File::Copy; |
| 24 |
use File::Temp; |
25 |
use File::Temp; |
| 25 |
|
26 |
|
|
Lines 46-51
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Link Here
|
| 46 |
|
47 |
|
| 47 |
my $uploadfilename = $input->param('uploadfile'); |
48 |
my $uploadfilename = $input->param('uploadfile'); |
| 48 |
my $uploadfile = $input->upload('uploadfile'); |
49 |
my $uploadfile = $input->upload('uploadfile'); |
|
|
50 |
my $uploadlocation = $input->param('uploadlocation'); |
| 49 |
my $op = $input->param('op') || q{}; |
51 |
my $op = $input->param('op') || q{}; |
| 50 |
|
52 |
|
| 51 |
my ( $total, $handled, @counts, $tempfile, $tfh ); |
53 |
my ( $total, $handled, @counts, $tempfile, $tfh ); |
|
Lines 53-59
my ( $total, $handled, @counts, $tempfile, $tfh );
Link Here
|
| 53 |
my %errors; |
55 |
my %errors; |
| 54 |
|
56 |
|
| 55 |
if ($plugins_enabled) { |
57 |
if ($plugins_enabled) { |
| 56 |
if ( ( $op eq 'Upload' ) && $uploadfile ) { |
58 |
if ( ( $op eq 'Upload' ) && ( $uploadfile || $uploadlocation ) ) { |
| 57 |
my $plugins_dir = C4::Context->config("pluginsdir"); |
59 |
my $plugins_dir = C4::Context->config("pluginsdir"); |
| 58 |
$plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir; |
60 |
$plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir; |
| 59 |
|
61 |
|
|
Lines 69-83
if ($plugins_enabled) {
Link Here
|
| 69 |
$errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i ); |
71 |
$errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i ); |
| 70 |
$errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); |
72 |
$errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); |
| 71 |
$errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir ); |
73 |
$errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir ); |
| 72 |
$errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 ); |
74 |
|
|
|
75 |
if ( $uploadlocation ) { |
| 76 |
my $ua = Mojo::UserAgent->new(max_redirects => 5); |
| 77 |
my $tx = $ua->get($uploadlocation); |
| 78 |
$tx->result->save_to($tempfile); |
| 79 |
} else { |
| 80 |
$errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 ); |
| 81 |
} |
| 73 |
|
82 |
|
| 74 |
if (%errors) { |
83 |
if (%errors) { |
| 75 |
$template->param( ERRORS => [ \%errors ] ); |
84 |
$template->param( ERRORS => [ \%errors ] ); |
| 76 |
} else { |
85 |
} else { |
| 77 |
while (<$uploadfile>) { |
86 |
if ( $uploadfile ) { |
| 78 |
print $tfh $_; |
87 |
while (<$uploadfile>) { |
|
|
88 |
print $tfh $_; |
| 89 |
} |
| 90 |
close $tfh; |
| 79 |
} |
91 |
} |
| 80 |
close $tfh; |
|
|
| 81 |
|
92 |
|
| 82 |
my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' ); |
93 |
my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' ); |
| 83 |
unless ( $ae->extract( to => $plugins_dir ) ) { |
94 |
unless ( $ae->extract( to => $plugins_dir ) ) { |
|
Lines 90-100
if ($plugins_enabled) {
Link Here
|
| 90 |
|
101 |
|
| 91 |
Koha::Plugins->new()->InstallPlugins(); |
102 |
Koha::Plugins->new()->InstallPlugins(); |
| 92 |
} |
103 |
} |
| 93 |
} elsif ( ( $op eq 'Upload' ) && !$uploadfile ) { |
104 |
} elsif ( ( $op eq 'Upload' ) && !$uploadfile && !$uploadlocation ) { |
| 94 |
warn "Problem uploading file or no file uploaded."; |
105 |
warn "Problem uploading file or no file uploaded."; |
| 95 |
} |
106 |
} |
| 96 |
|
107 |
|
| 97 |
if ( $uploadfile && !%errors && !$template->param('ERRORS') ) { |
108 |
if ( ($uploadfile || $uploadlocation) && !%errors && !$template->param('ERRORS') ) { |
| 98 |
print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl"); |
109 |
print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl"); |
| 99 |
} else { |
110 |
} else { |
| 100 |
output_html_with_http_headers $input, $cookie, $template->output; |
111 |
output_html_with_http_headers $input, $cookie, $template->output; |
| 101 |
- |
|
|