-
Notifications
You must be signed in to change notification settings - Fork 3
/
publish_upload.cgi
73 lines (60 loc) · 1.91 KB
/
publish_upload.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl
require './jru-lib.pl';
use File::Basename;
use File::Path 'rmtree';
sub inst_error{
print "<b>$main::whatfailed : $_[0]</b> <p>\n";
&ui_print_footer("", $text{'index_return'});
exit;
}
if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) { &ReadParseMime(); }
else { &ReadParse(); $no_upload = 1; }
$| = 1;
$theme_no_table = 1 if ($in{'source'} == 2 || $in{'source'} == 4);
&ui_print_header(undef, $text{'publish_install'}, "");
my $upload_path = get_jasper_home().'/reports';
my $dest_dir = $upload_path.'/'.$in{'destination'};
#check if upload dir has .. in path
if($dest_dir =~ /\.\./){
print "Error: Invalid upload dir $dest_dir</br>";
&ui_print_footer("", $text{'index_return'}, $in{'edit_publish'}, "Publish");
exit;
}
my $file = process_file_source();
if(! $file){
print "Error: Invalid file $file</br>";
&ui_print_footer("", $text{'index_return'}, $in{'edit_publish'}, "Publish");
exit;
}
my $unzip_dir = '';
my @files; #file to be published
#Check if its a .zip or .jar
print "Source: $file<br>";
if($in{'publish_extract'} && $file =~ /\.zip$/){
$unzip_dir = unzip_me($file);
#make a list of extension jars
opendir(DIR, $unzip_dir) or die $!;
@files = grep { $_ = $unzip_dir.'/'.$_ ; -f } readdir(DIR);
closedir(DIR);
}else{
push(@files, $file);
}
if(! -d $dest_dir){
&make_dir($dest_dir, 0750, 1);
&set_ownership_permissions('tomcat','tomcat', 0750, $dest_dir);
print "Created $dest_dir</br>";
}
foreach my $f (@files) {
my $file_name = basename($f);
if($in{'publish_overwrite'} == 0 && -f $dest_dir.'/'.$file_name){
print "Error: $dest_dir.'/'.$file_name exists</br>";
next;
}
&rename_file($f, $dest_dir);
&set_ownership_permissions('tomcat','tomcat', 0644, $dest_dir.'/'.$file_name);
print "Published $file_name successfully in $dest_dir/$file_name</br>";
}
if($unzip_dir ne ''){
&rmtree($unzip_dir); #remove temp dir
}
&ui_print_footer("", $text{'index_return'}, 'edit_publish.cgi', "Publish");