|
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 |
- |
|
|