source: main/trunk/greenstone2/common-src/cgi-bin/talkback-transfer.pl@ 33011

Last change on this file since 33011 was 33011, checked in by ak19, 2 years ago

On Ubuntu 18.04, confirmed Renate's findings that gsdlCGI.pm wasn't found by gliserver.pl in its @INC paths. Have now added the containing cgi-bin folder on GS2 and cgi folder on GS3 to @INC to teach gliserver.pl to find gsdlCGI.pm. This however needed a fix in build.xml where force-start-tomcat was passing the wrong value for GSDL3HOME to tomcat: it was passing in basedir instead of web.home. With this fix, gliserver.pl now works on Ubuntu 18.04. Have added lines identical to the changes in gliserver.pl to the other pl files in the cgi(-bin) folder for those pl files that similarly import gsdlCGI.pm.

  • Property svn:executable set to *
File size: 5.5 KB
Line 
1#!/usr/bin/perl -w
2
3use strict;
4
5use LWP::UserAgent;
6use HTTP::Request::Common;
7
8use CGI::Carp qw(fatalsToBrowser);
9use CGI;
10
11use File::Basename;
12
13BEGIN {
14 # On Ubuntu 18.04, gsdlCGI.pm can't be found as the cgi folder is not among @INC paths.
15 # Ensure gsdlCGI.pm is available in @INC by adding the cgi folder to it.
16 # For GS2:
17 my $gsdl_cgi_path = $ENV{'GSDLHOME'} . "/cgi-bin";
18 # For GS3:
19 $gsdl_cgi_path = $ENV{'GSDL3HOME'} . "/WEB-INF" . "/cgi" if defined $ENV{'GSDL3HOME'};
20
21 my $found_cgi_path = 0;
22 foreach my $inc_path (@INC) {
23 if($inc_path eq $gsdl_cgi_path) {
24 $found_cgi_path = 1;
25 last;
26 }
27 }
28 if(!$found_cgi_path) {
29 unshift (@INC, $gsdl_cgi_path);
30 }
31
32 eval('require "./gsdlCGI.pm"');
33 if ($@)
34 {
35 print STDOUT "Content-type:text/plain\n\n";
36 print STDOUT "ERROR: $@\n";
37 exit 0;
38 }
39
40 # Line to stop annoying child DOS CMD windows from appearing
41 Win32::SetChildShowWindow(0)
42 if defined &Win32::SetChildShowWindow;
43}
44
45
46
47
48sub get_infodb_type
49{
50 my ($opt_site,$collect_home,$collect) = @_;
51
52 my $out = "STDERR";
53
54 $collect = &colcfg::use_collection($opt_site, $collect, $collect_home);
55
56 if ($collect eq "") {
57 print STDERR "Error: failed to find collection $collect in $collect_home\n";
58 print STDOUT "Content-type:text/plain\n\n";
59 print STDOUT "ERROR: Failed to find collection $collect\n";
60 exit 0;
61
62 }
63
64 # Read in the collection configuration file.
65 my ($config_filename, $gs_mode) = &colcfg::get_collect_cfg_name($out);
66 my $collectcfg = &colcfg::read_collection_cfg ($config_filename, $gs_mode);
67
68 return $collectcfg->{'infodbtype'};
69}
70
71
72sub oid_to_docxml_filename
73{
74 my ($opt_site,$collect_home,$collect,$docid) = @_;
75
76 my $infodb_type = get_infodb_type($opt_site,$collect_home,$collect);
77
78 # Derive the archives dir
79 my $archive_dir = &util::filename_cat($collect_home,$collect,"archives");
80
81 # Obtain the doc.xml path for the specified docID
82 my $arcinfo_doc_filename
83 = &dbutil::get_infodb_file_path($infodb_type, "archiveinf-doc",
84 $archive_dir);
85 my $doc_rec
86 = &dbutil::read_infodb_entry($infodb_type, $arcinfo_doc_filename,
87 $docid);
88
89 my $doc_xml_file = $doc_rec->{'doc-file'}->[0];
90 my $assoc_path = dirname($doc_xml_file);
91
92 # The $doc_xml_file is relative to the archives, so now let's get the
93 # full path
94 my $doc_xml_filename = &util::filename_cat($archive_dir,$doc_xml_file);
95
96 return ($doc_xml_filename,$assoc_path);
97}
98
99sub zip_up_archives_doc
100{
101 my ($gsdl_cgi,$collect_home,$collect,$doc_xml_filename,$assoc_path) = @_;
102
103 my $timestamp = time();
104 my $lang_env = $gsdl_cgi->clean_param("lr") || "";
105
106 my $archive_dir = &util::filename_cat($collect_home,$collect,"archives");
107
108 # Zip up the doc_xml file and all the files associated with it
109 my $java = $gsdl_cgi->get_java_path();
110 my $jar_dir= &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java");
111 my $java_classpath = &util::filename_cat($jar_dir,"GLIServer.jar");
112
113 if (!-f $java_classpath) {
114 my $progname = $0;
115 $progname =~ s/^.*[\/\\]//;
116 my $mess = "$progname:\nFailed to find $java_classpath\n";
117 $gsdl_cgi->generate_error($mess);
118 }
119
120 my $zip_file = "$collect-$timestamp.zip";
121 my $zip_file_path = &util::filename_cat($archive_dir,$zip_file);
122
123 my $java_args = "\"$zip_file_path\" \"$archive_dir\" \"$assoc_path\"";
124
125 $ENV{'LANG'} = $lang_env;
126 my $java_command = "\"$java\" -classpath \"$java_classpath\" org.greenstone.gatherer.remote.ZipFiles $java_args";
127
128 my $java_output = `$java_command`;
129 my $java_status = $?;
130 if ($java_status > 0) {
131 $gsdl_cgi->generate_error("Java failed: $java_command\n--\n$java_output\nExit status: " . ($java_status / 256) . "\n" . $gsdl_cgi->check_java_home());
132 }
133
134 # Check that the zip file was created successfully
135 if (!-e $zip_file_path || -z $zip_file_path) {
136 $gsdl_cgi->generate_error("Collection zip file $zip_file_path could not be created.");
137 }
138
139 return $zip_file_path;
140
141}
142
143sub main
144{
145 # Setup greenstone Perl include paths so additional packages can be found
146 my $gsdl_cgi = gsdlCGI->new();
147 $gsdl_cgi->setup_gsdl();
148
149 my $gsdl_home = $gsdl_cgi->get_gsdl_home();
150 my $collect_home = &util::filename_cat($gsdl_home,"collect");
151
152 require dbutil;
153 require talkback;
154 require colcfg;
155
156 my $oid = $gsdl_cgi->param('oid');
157 my $collect = $gsdl_cgi->param('fromCollect');
158 my $toCollect = $gsdl_cgi->param('toCollect');
159 my $site = $gsdl_cgi->param('site');
160
161 # sanity check
162 if (!defined $oid || !defined $collect) {
163 print STDOUT "Content-type:text/plain\n\n";
164 print STDOUT "ERROR: Malformed CGI argments. Need to specify 'oid' and 'collect'\n";
165 exit 0;
166 }
167
168 my $uniq_prefix = "$collect-$oid";
169
170 my ($docxml_filename,$assoc_path)
171 = oid_to_docxml_filename($site,$collect_home,$collect,$oid);
172
173 my $zip_filename
174 = zip_up_archives_doc($gsdl_cgi,$collect_home,$collect,
175 $docxml_filename,$assoc_path);
176
177 my $talktoUploadURL = $gsdl_cgi->param('talktoUpload');
178
179 my $browser = LWP::UserAgent->new(agent => 'Perl File Upload');
180
181 my $response = $browser->post(
182 $talktoUploadURL,
183 [ 'yes_upload' => '1',
184 'process' => '1',
185 'oid' => $oid,
186 'toCollect' => $toCollect,
187 'uploadedfile' => [$zip_filename, "$uniq_prefix-doc.zip"]
188 ],
189 'Content_Type' => 'form-data'
190 );
191
192 if ($response->is_success) {
193 print "Content-type:text/html\n\n";
194 print $response->content;
195 }
196 else {
197 print $response->error_as_HTML;
198 }
199
200}
201
202main();
203
Note: See TracBrowser for help on using the repository browser.