source: greenstone3/trunk/web/WEB-INF/cgi/gliserver.pl@ 16248

Last change on this file since 16248 was 16248, checked in by ak19, 16 years ago

Placeholder comment for schedule.pl script

  • Property svn:executable set to *
File size: 42.0 KB
Line 
1#!/usr/bin/perl -w
2# Need to specify the full path of Perl above
3
4# This file merges Michael Dewsnip's gliserver.pl for GS2 and Quan Qiu's gliserver4gs3.pl (GS3)
5
6use strict;
7no strict 'subs';
8no strict 'refs'; # allow filehandles to be variables and viceversa
9
10
11# Set this to 1 to work around IIS 6 craziness
12my $iis6_mode = 0;
13
14##
15# IIS 6: for some reason, IIS runs this script with the working directory set to the Greenstone
16# directory rather than the cgi-bin directory, causing lots of stuff to fail
17if ($iis6_mode)
18{
19 # Change into cgi-bin directory - need to ensure it exists, since gliserver deals with both GS2 and GS3
20 if(-e "cgi-bin" && -d "cgi-bin") { # GS2
21 chdir("cgi-bin");
22 } else { # iis6_mode is not applicable for Greenstone 3
23 $iis6_mode = 0;
24 }
25}
26
27
28# We use require and an eval here (instead of "use package") to catch any errors loading the module (for IIS)
29eval("require \"gsdlCGI.pm\"");
30if ($@)
31{
32 print STDOUT "Content-type:text/plain\n\n";
33 print STDOUT "ERROR: $@\n";
34 exit 0;
35}
36
37
38#my $authentication_enabled = 0;
39my $debugging_enabled = 0; # if 1, debugging is enabled and unlinking intermediate files (deleting files) will not happen
40
41my $mail_enabled = 0;
42my $mail_to_address = "user\@server"; # Set this appropriately
43my $mail_from_address = "user\@server"; # Set this appropriately
44my $mail_smtp_server = "smtp.server"; # Set this appropriately
45
46sub main
47{
48 my $gsdl_cgi = new gsdlCGI();
49
50 # Load the Greenstone modules that we need to use
51 $gsdl_cgi->setup_gsdl();
52 my $gsdlhome = $ENV{'GSDLHOME'};
53
54 $gsdl_cgi->checked_chdir($gsdlhome);
55
56 # Encrypt the password
57 $gsdl_cgi->encrypt_password();
58
59 $gsdl_cgi->parse_cgi_args();
60
61 # We don't want the gsdlCGI module to return errors and warnings in XML
62 $gsdl_cgi->{'xml'} = 0;
63
64 # Retrieve the (required) command CGI argument
65 my $cmd = $gsdl_cgi->clean_param("cmd");
66 if (!defined $cmd) {
67 $gsdl_cgi->generate_error("No command specified.");
68 }
69 $gsdl_cgi->delete("cmd");
70
71 # The check-installation, greenstone-server-version and get-library-url commands have no arguments
72 if ($cmd eq "check-installation") {
73 &check_installation($gsdl_cgi);
74 return;
75 }
76 elsif ($cmd eq "greenstone-server-version") {
77 &greenstone_server_version($gsdl_cgi);
78 return;
79 }
80 elsif ($cmd eq "get-library-url-suffix") {
81 &get_library_url_suffix($gsdl_cgi);
82 return;
83 }
84
85 # All other commands require a username, for locking and authentication
86 my $username = $gsdl_cgi->clean_param("un");
87 if ((!defined $username) || ($username =~ m/^\s*$/)) {
88 $gsdl_cgi->generate_error("No username specified.");
89 }
90 $gsdl_cgi->delete("un");
91
92 # Get then remove the ts (timestamp) argument (since this can mess up other scripts)
93 my $timestamp = $gsdl_cgi->clean_param("ts");
94 if ((!defined $timestamp) || ($timestamp =~ m/^\s*$/)) {
95 $timestamp = time(); # Fall back to using the Perl time() function to generate a timestamp
96 }
97 $gsdl_cgi->delete("ts");
98
99 my $site; # undefined on declaration, see http://perldoc.perl.org/perlsyn.html
100 if($gsdl_cgi->greenstone_version() != 2) { # all GS versions after 2 may define site
101 $site = $gsdl_cgi->clean_param("site");
102 if (!defined $site) {
103 $gsdl_cgi->generate_error("No site specified.");
104 }
105 $gsdl_cgi->delete("site");
106 }
107
108
109 if ($cmd eq "delete-collection") {
110 &delete_collection($gsdl_cgi, $username, $timestamp, $site);
111 }
112 elsif ($cmd eq "download-collection") {
113 &download_collection($gsdl_cgi, $username, $timestamp, $site);
114 }
115 elsif ($cmd eq "download-collection-archives") {
116 &download_collection_archives($gsdl_cgi, $username, $timestamp, $site);
117 }
118 elsif ($cmd eq "download-collection-configurations") {
119 &download_collection_configurations($gsdl_cgi, $username, $timestamp, $site);
120 }
121 elsif ($cmd eq "download-collection-file") {
122 &download_collection_file($gsdl_cgi, $username, $timestamp, $site);
123 }
124 elsif ($cmd eq "delete-collection-file") {
125 &delete_collection_file($gsdl_cgi, $username, $timestamp, $site);
126 }
127 elsif ($cmd eq "get-script-options") {
128 &get_script_options($gsdl_cgi, $username, $timestamp, $site);
129 }
130 elsif ($cmd eq "move-collection-file") {
131 &move_collection_file($gsdl_cgi, $username, $timestamp, $site);
132 }
133 elsif ($cmd eq "new-collection-directory") {
134 &new_collection_directory($gsdl_cgi, $username, $timestamp, $site);
135 }
136 elsif ($cmd eq "run-script") {
137 &run_script($gsdl_cgi, $username, $timestamp, $site);
138 }
139 elsif ($cmd eq "timeout-test") {
140 while (1) { }
141 }
142 elsif ($cmd eq "upload-collection-file") {
143 #print STDERR "CMD upload_collection_file\nusername: $username, site: $site, ts: $timestamp\n";
144 &upload_collection_file($gsdl_cgi, $username, $timestamp, $site);
145 }
146 elsif ($cmd eq "file-exists") {
147 &file_exists($gsdl_cgi, $site);
148 }
149 # cmds not in Greenstone 2:
150 elsif ($gsdl_cgi->greenstone_version() != 2) {
151 if ($cmd eq "download-web-xml-file") {
152 &download_web_xml_file($gsdl_cgi, $username, $timestamp, $site);
153 }
154 elsif ($cmd eq "user-validation") {
155 &user_validation($gsdl_cgi, $username, $timestamp, $site);
156 }
157 elsif ($cmd eq "get-site-names") {
158 &get_site_names($gsdl_cgi, $username, $timestamp, $site);
159 }
160 }
161 else {
162 $gsdl_cgi->generate_error("Unrecognised command: '$cmd'");
163 }
164
165}
166
167
168sub authenticate_user
169{
170 my $gsdl_cgi = shift(@_);
171 my $username = shift(@_);
172 my $collection = shift(@_);
173 my $site = shift(@_);
174
175 # Even if we're not authenticating remove the un and pw arguments, since these can mess up other scripts
176 my $user_password = $gsdl_cgi->clean_param("pw");
177 $gsdl_cgi->delete("pw");
178
179 # Only authenticate if it is enabled
180 # return "all-collections-editor" if (!$authentication_enabled);
181
182 if ((!defined $user_password) || ($user_password =~ m/^\s*$/)) {
183 $gsdl_cgi->generate_error("Authentication failed: no password specified.");
184 }
185
186 my $users_db_content;
187 if($gsdl_cgi->greenstone_version() == 2) {
188 my $etc_directory = &util::filename_cat($ENV{'GSDLHOME'}, "etc");
189 my $users_db_file_path = &util::filename_cat($etc_directory, "users.db");
190
191 # Use db2txt instead of GDBM_File to get the user accounts information
192 $users_db_content = "";
193 open(USERS_DB, "db2txt \"$users_db_file_path\" |");
194 while (<USERS_DB>) {
195 $users_db_content .= $_;
196 }
197 }
198 elsif($gsdl_cgi->greenstone_version() == 3) {
199 my $gsdl3srchome = $ENV{'GSDL3SRCHOME'};
200
201 my $java = $gsdl_cgi->get_java_path();
202 my $java_gsdl3_classpath = &util::filename_cat($gsdl3srchome, "web", "WEB-INF", "lib", "gsdl3.jar");
203 my $java_derby_classpath = &util::filename_cat($gsdl3srchome, "web", "WEB-INF", "lib", "derby.jar");
204 my $java_classpath;
205 my $gsdlos = $ENV{'GSDLOS'};
206 if ($gsdlos !~ /windows/){
207 $java_classpath = $java_gsdl3_classpath . ":" . $java_derby_classpath;
208 }else{
209 $java_classpath = $java_gsdl3_classpath . ";" . $java_derby_classpath;
210 }
211 my $java_args = &util::filename_cat($gsdl3srchome, "web", "sites", $site, "etc", "usersDB");
212 $gsdl_cgi->checked_chdir($java_args);
213 my $java_command="$java -classpath \"$java_classpath\" org.greenstone.gsdl3.util.usersDB2txt \"$java_args\" 2>&1";
214 $users_db_content = `$java_command`;
215 }
216
217 # Get the user account information from the usersDB database
218 my %users_db_data = ();
219 foreach my $users_db_entry (split(/-{70}/, $users_db_content)) {
220 if ($users_db_entry =~ /\n?\[(.+)\]\n/) {
221 $users_db_data{$1} = $users_db_entry;
222 }
223 }
224
225 # Check username
226 my $user_data = $users_db_data{$username};
227 if (!defined $user_data) {
228 $gsdl_cgi->generate_error("Authentication failed: no account for user '$username'.");
229 }
230
231 # Check password
232 my ($valid_user_password) = ($user_data =~ /\<password\>(.*)/);
233 if ($user_password ne $valid_user_password) {
234 $gsdl_cgi->generate_error("Authentication failed: incorrect password.");
235 }
236
237 # Check group
238 my ($user_groups) = ($user_data =~ /\<groups\>(.*)/);
239
240 if ($collection eq "") {
241 # If we're not editing a collection then the user doesn't need to be in a particular group
242 return $user_groups; # Authentication successful
243 }
244
245 foreach my $user_group (split(/\,/, $user_groups)) {
246 # Does this user have access to all collections?
247 if ($user_group eq "all-collections-editor") {
248 return $user_groups; # Authentication successful
249 }
250 # Does this user have access to personal collections, and is this one?
251 if ($user_group eq "personal-collections-editor" && $collection =~ /^$username\-/) {
252 return $user_groups; # Authentication successful
253 }
254 # Does this user have access to this collection
255 if ($user_group eq "$collection-collection-editor") {
256 return $user_groups; # Authentication successful
257 }
258 }
259 $gsdl_cgi->generate_error("Authentication failed: user is not in the required group.");
260}
261
262
263sub lock_collection
264{
265 my $gsdl_cgi = shift(@_);
266 my $username = shift(@_);
267 my $collection = shift(@_);
268 my $site = shift(@_);
269
270 my $steal_lock = $gsdl_cgi->clean_param("steal_lock");
271 $gsdl_cgi->delete("steal_lock");
272
273 my $collection_directory = $gsdl_cgi->get_collection_dir($site, $collection);
274 $gsdl_cgi->checked_chdir($collection_directory);
275
276 # Check if a lock file already exists for this collection
277 my $lock_file_name = "gli.lck";
278 if (-e $lock_file_name) {
279 # A lock file already exists... check if it's ours
280 my $lock_file_content = "";
281 open(LOCK_FILE, "<$lock_file_name");
282 while (<LOCK_FILE>) {
283 $lock_file_content .= $_;
284 }
285 close(LOCK_FILE);
286
287 # Pick out the owner of the lock file
288 $lock_file_content =~ /\<User\>(.*?)\<\/User\>/;
289 my $lock_file_owner = $1;
290
291 # The lock file is ours, so there is no problem
292 if ($lock_file_owner eq $username) {
293 return;
294 }
295
296 # The lock file is not ours, so throw an error unless "steal_lock" is set
297 unless (defined $steal_lock) {
298 $gsdl_cgi->generate_error("Collection is locked by: $lock_file_owner");
299 }
300 }
301
302 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
303 my $current_time = sprintf("%02d/%02d/%d %02d:%02d:%02d", $mday, $mon + 1, $year + 1900, $hour, $min, $sec);
304
305 # Create a lock file for us (in the same format as the GLI) and we're done
306 open(LOCK_FILE, ">$lock_file_name");
307 print LOCK_FILE "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
308 print LOCK_FILE "<LockFile>\n";
309 print LOCK_FILE " <User>" . $username . "</User>\n";
310 print LOCK_FILE " <Machine>(Remote)</Machine>\n";
311 print LOCK_FILE " <Date>" . $current_time . "</Date>\n";
312 print LOCK_FILE "</LockFile>\n";
313 close(LOCK_FILE);
314}
315
316
317# ----------------------------------------------------------------------------------------------------
318# ACTIONS
319# ----------------------------------------------------------------------------------------------------
320# This routine won't get called by GS2, so uses the variable site
321sub user_validation{
322 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
323
324 # Users can be in any group to perform this action
325 my $user_err = &authenticate_user($gsdl_cgi, $username, "", $site);
326 if (defined $user_err && $user_err!~ /ERROR/){
327 if ($user_err!~ /ERROR/){
328 #$gsdl_cgi->generate_error("Authentication failed: $username is not valid");
329 $gsdl_cgi->generate_ok($user_err);
330 #print $user_err;
331 }else{
332 $gsdl_cgi->generate_error($user_err);
333 #print "not valid" . $user_err;
334 }
335 }else{
336 $gsdl_cgi->generate_error("Authentication failed: $username is not valid");
337 }
338}
339
340sub check_installation
341{
342 my ($gsdl_cgi) = @_;
343
344 my $installation_ok = 1;
345 my $installation_status = "";
346
347 # Check that Java is installed and accessible
348 my $java = $gsdl_cgi->get_java_path();
349 my $java_command = "$java -version 2>&1";
350
351 # IIS 6: redirecting output from STDERR to STDOUT just doesn't work, so we have to let it go
352 # directly out to the page
353 if($iis6_mode && $gsdl_cgi->greenstone_version() == 2) { ##
354 print STDOUT "Content-type:text/plain\n\n";
355 $java_command = "java -version";
356 }
357
358 my $java_output = `$java_command`;
359 my $java_status = $?;
360 if ($java_status < 0) {
361 # The Java command failed
362 $installation_status = "Java failed -- do you have the Java run-time installed?\n" . $gsdl_cgi->check_java_home() . "\n";
363 $installation_ok = 0;
364 }
365 else {
366 $installation_status = "Java found: $java_output";
367 }
368
369 # Show the values of some important environment variables
370 $installation_status .= "\n";
371 $installation_status .= "GSDL3SRCHOME: " . $ENV{'GSDL3SRCHOME'} . "\n" unless ($gsdl_cgi->greenstone_version() == 2);
372 $installation_status .= "GSDLHOME: " . $ENV{'GSDLHOME'} . "\n";
373 $installation_status .= "GSDLOS: " . $ENV{'GSDLOS'} . "\n";
374 $installation_status .= "PATH: " . $ENV{'PATH'} . "\n";
375
376
377 if ($installation_ok) { ## M. Dewsnip's svn log comment stated that for iis6_mode output needs to go to STDOUT
378 if($iis6_mode && $gsdl_cgi->greenstone_version() == 2) {
379 print STDOUT $installation_status . "\nInstallation OK!";
380 } else {
381 $gsdl_cgi->generate_ok_message($installation_status . "\nInstallation OK!");
382 }
383 }
384 else {
385 if($iis6_mode && $gsdl_cgi->greenstone_version() == 2) {
386 print STDOUT $installation_status;
387 } else {
388 $gsdl_cgi->generate_error($installation_status);
389 }
390 }
391}
392
393
394sub delete_collection
395{
396 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
397
398 my $collection = $gsdl_cgi->clean_param("c");
399 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
400 $gsdl_cgi->generate_error("No collection specified.");
401 }
402
403 # Ensure the user is allowed to edit this collection
404 &authenticate_user($gsdl_cgi, $username, $collection, $site);
405
406
407 my $collect_directory = $gsdl_cgi->get_collection_dir($site);
408 $gsdl_cgi->checked_chdir($collect_directory);
409
410 # Check that the collection exists
411 if (!-d $collection) {
412 $gsdl_cgi->generate_error("Collection $collection does not exist.");
413 }
414
415 # Make sure the collection isn't locked by someone else
416 &lock_collection($gsdl_cgi, $username, $collection, $site);
417
418 $gsdl_cgi->checked_chdir($collect_directory);
419 $gsdl_cgi->local_rm_r("$collection");
420
421 # Check that the collection was deleted
422 if (-e $collection) {
423 $gsdl_cgi->generate_error("Could not delete collection $collection.");
424 }
425
426 $gsdl_cgi->generate_ok_message("Collection $collection deleted successfully.");
427}
428
429
430sub delete_collection_file
431{
432 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
433
434 my $collection = $gsdl_cgi->clean_param("c");
435 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
436 $gsdl_cgi->generate_error("No collection specified.");
437 }
438 my $file = $gsdl_cgi->clean_param("file");
439 if ((!defined $file) || ($file =~ m/^\s*$/)) {
440 $gsdl_cgi->generate_error("No file specified.");
441 }
442 $file =~ s/\|/&util::get_dirsep()/eg; # Convert the '|' characters into whatever is right for this OS
443
444 # Make sure we don't try to delete anything outside the collection
445 if ($file =~ /\.\./) {
446 $gsdl_cgi->generate_error("Illegal file specified.");
447 }
448
449 # Ensure the user is allowed to edit this collection
450 &authenticate_user($gsdl_cgi, $username, $collection, $site);
451
452 my $collection_directory = $gsdl_cgi->get_collection_dir($site, $collection);
453 if (!-d $collection_directory){ ## wasn't there in gs2, ok_msg or error_msg?
454 $gsdl_cgi->generate_ok_message("Directory $collection_directory does not exist.");
455 die;
456 }
457
458 $gsdl_cgi->checked_chdir($collection_directory);
459
460 # Make sure the collection isn't locked by someone else
461 &lock_collection($gsdl_cgi, $username, $collection, $site);
462
463 # Check that the collection file exists
464 if (!-e $file) { ## original didn't have 'die', but it was an ok message
465 $gsdl_cgi->generate_ok_message("Collection file $file does not exist.");
466 die;
467 }
468 $gsdl_cgi->local_rm_r("$file");
469
470 # Check that the collection file was deleted
471 if (-e $file) {
472 $gsdl_cgi->generate_error("Could not delete collection file $file.");
473 }
474
475 $gsdl_cgi->generate_ok_message("Collection file $file deleted successfully.");
476}
477
478
479sub download_collection
480{
481 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
482
483 my $collection = $gsdl_cgi->clean_param("c");
484 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
485 $gsdl_cgi->generate_error("No collection specified.");
486 }
487
488 # Ensure the user is allowed to edit this collection
489 &authenticate_user($gsdl_cgi, $username, $collection, $site);
490
491 my $collect_directory = $gsdl_cgi->get_collection_dir($site);
492 $gsdl_cgi->checked_chdir($collect_directory);
493
494 # Check that the collection exists
495 if (!-d $collection) {
496 $gsdl_cgi->generate_ok_message("Collection $collection does not exist."); ## original had an error msg (from where it would die)
497 die;
498 }
499
500 # Make sure the collection isn't locked by someone else
501 &lock_collection($gsdl_cgi, $username, $collection, $site);
502
503 # Zip up the collection
504 my $java = $gsdl_cgi->get_java_path();
505 my $java_classpath = &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java", "GLIServer.jar");
506 my $zip_file_path = &util::filename_cat($collect_directory, $collection . "-" . $timestamp . ".zip");
507 my $java_args = "\"$zip_file_path\" \"$collect_directory\" \"$collection\"";
508 if($gsdl_cgi->greenstone_version() != 2) {
509 $java_args .= " gsdl3"; ## must this be done elsewhere as well?
510 }
511 my $java_command = "$java -classpath \"$java_classpath\" org.greenstone.gatherer.remote.ZipCollectionShell $java_args";
512
513 my $java_output = `$java_command`;
514 my $java_status = $?;
515 if ($java_status > 0) {
516 $gsdl_cgi->generate_error("Java failed: $java_command\n--\n$java_output\nExit status: " . ($java_status / 256) . "\n" . $gsdl_cgi->check_java_home());
517 }
518
519 # Check that the zip file was created successfully
520 if (!-e $zip_file_path || -z $zip_file_path) {
521 $gsdl_cgi->generate_error("Collection zip file $zip_file_path could not be created.");
522 }
523
524 &put_file($gsdl_cgi, $zip_file_path, "application/zip"); # file is transferred to client
525 unlink("$zip_file_path") unless $debugging_enabled; # deletes the local intermediate zip file
526}
527
528
529sub download_collection_archives
530{
531 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
532
533 my $collection = $gsdl_cgi->clean_param("c");
534 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
535 $gsdl_cgi->generate_error("No collection specified.");
536 }
537
538 # Ensure the user is allowed to edit this collection
539 &authenticate_user($gsdl_cgi, $username, $collection, $site);
540
541 my $collect_directory = $gsdl_cgi->get_collection_dir($site);
542 $gsdl_cgi->checked_chdir($collect_directory);
543
544 # Check that the collection archives exist
545 if (!-d &util::filename_cat($collection, "archives")) {
546 $gsdl_cgi->generate_error("Collection archives do not exist.");
547 }
548
549 # Make sure the collection isn't locked by someone else
550 &lock_collection($gsdl_cgi, $username, $collection, $site);
551
552 # Zip up the collection archives
553 my $java = $gsdl_cgi->get_java_path();
554 my $java_classpath = &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java", "GLIServer.jar");
555 my $zip_file_path = &util::filename_cat($collect_directory, $collection . "-archives-" . $timestamp . ".zip");
556 my $java_args = "\"$zip_file_path\" \"$collect_directory\" \"$collection\"";
557 my $java_command = "$java -classpath \"$java_classpath\" org.greenstone.gatherer.remote.ZipCollectionArchives $java_args";
558
559 my $java_output = `$java_command`;
560 my $java_status = $?;
561 if ($java_status > 0) {
562 $gsdl_cgi->generate_error("Java failed: $java_command\n--\n$java_output\nExit status: " . ($java_status / 256) . "\n" . $gsdl_cgi->check_java_home());
563 }
564
565 # Check that the zip file was created successfully
566 if (!-e $zip_file_path || -z $zip_file_path) {
567 $gsdl_cgi->generate_error("Collection archives zip file $zip_file_path could not be created.");
568 }
569
570 &put_file($gsdl_cgi, $zip_file_path, "application/zip");
571 unlink("$zip_file_path") unless $debugging_enabled;
572}
573
574
575# Collection locking unnecessary because this action isn't related to a particular collection
576sub download_collection_configurations
577{
578 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
579
580 # Users can be in any group to perform this action
581 my $user_groups = &authenticate_user($gsdl_cgi, $username, "", $site);
582
583 my $collect_directory = $gsdl_cgi->get_collection_dir($site);
584 $gsdl_cgi->checked_chdir($collect_directory);
585
586 # Zip up the collection configurations
587 my $java = $gsdl_cgi->get_java_path();
588 my $java_classpath = &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java", "GLIServer.jar");
589 my $zip_file_path = &util::filename_cat($collect_directory, "collection-configurations-" . $timestamp . ".zip");
590 my $java_args = "\"$zip_file_path\" \"$collect_directory\" \"$username\" \"$user_groups\"";
591 my $java_command = "$java -classpath \"$java_classpath\" org.greenstone.gatherer.remote.ZipCollectionConfigurations $java_args";
592 my $java_output = `$java_command`;
593 my $java_status = $?;
594 if ($java_status > 0) {
595 $gsdl_cgi->generate_error("Java failed: $java_command\n--\n$java_output\nExit status: " . ($java_status / 256) . "\n" . $gsdl_cgi->check_java_home());
596 }
597
598 # Check that the zip file was created successfully
599 if (!-e $zip_file_path || -z $zip_file_path) {
600 $gsdl_cgi->generate_error("Collection configurations zip file $zip_file_path could not be created.");
601 }
602
603 &put_file($gsdl_cgi, $zip_file_path, "application/zip");
604 unlink("$zip_file_path") unless $debugging_enabled;
605}
606
607# Method that will check if the given file exists
608# No error message: all messages generated are OK messages
609# This method will simply state whether the file exists or does not exist.
610sub file_exists
611{
612 my ($gsdl_cgi, $site) = @_;
613
614 my $collection = $gsdl_cgi->clean_param("c");
615 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
616 $gsdl_cgi->generate_error("No collection specified.");
617 }
618 my $file = $gsdl_cgi->clean_param("file");
619 if ((!defined $file) || ($file =~ m/^\s*$/)) {
620 $gsdl_cgi->generate_error("No file specified.");
621 }
622 $file =~ s/\|/&util::get_dirsep()/eg; # Convert the '|' characters into whatever is right for this OS
623
624 # Not necessary: checking whether the user is authenticated to query existence of the file
625 #&authenticate_user($gsdl_cgi, $username, $collection);
626
627 my $collection_directory = $gsdl_cgi->get_collection_dir($site, $collection);
628 $gsdl_cgi->checked_chdir($collection_directory); # cd into the directory of that collection
629
630 # Check that the collection file exists
631 if (-e $file) {
632 $gsdl_cgi->generate_ok_message("File $file exists.");
633 } else {
634 $gsdl_cgi->generate_ok_message("File $file does not exist.");
635 }
636}
637
638sub download_collection_file
639{
640 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
641
642 my $collection = $gsdl_cgi->clean_param("c");
643 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
644 $gsdl_cgi->generate_error("No collection specified.");
645 }
646 my $file = $gsdl_cgi->clean_param("file");
647 if ((!defined $file) || ($file =~ m/^\s*$/)) {
648 $gsdl_cgi->generate_error("No file specified.");
649 }
650 $file =~ s/\|/&util::get_dirsep()/eg; # Convert the '|' characters into whatever is right for this OS
651
652 # Make sure we don't try to download anything outside the collection
653 if ($file =~ /\.\./) {
654 $gsdl_cgi->generate_error("Illegal file specified.");
655 }
656
657 # Ensure the user is allowed to edit this collection
658 &authenticate_user($gsdl_cgi, $username, $collection, $site);
659
660 my $collection_directory = $gsdl_cgi->get_collection_dir($site, $collection);
661 $gsdl_cgi->checked_chdir($collection_directory);
662
663 # Check that the collection file exists
664 if (!-e $file) {
665 $gsdl_cgi->generate_ok_message("Collection file $file does not exist.");
666 die;
667 }
668
669 # Make sure the collection isn't locked by someone else
670 &lock_collection($gsdl_cgi, $username, $collection, $site);
671
672 # Zip up the collection file
673 my $java = $gsdl_cgi->get_java_path();
674 my $java_classpath = &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java", "GLIServer.jar");
675 my $zip_file_path = &util::filename_cat($collection_directory, $collection . "-file-" . $timestamp . ".zip");
676 my $java_args = "\"$zip_file_path\" \"$collection_directory\" \"$file\"";
677 my $java_command = "$java -classpath \"$java_classpath\" org.greenstone.gatherer.remote.ZipFiles $java_args";
678
679 my $java_output = `$java_command`;
680 my $java_status = $?;
681 if ($java_status > 0) {
682 $gsdl_cgi->generate_error("Java failed: $java_command\n--\n$java_output\nExit status: " . ($java_status / 256) . "\n" . $gsdl_cgi->check_java_home());
683 }
684
685 # Check that the zip file was created successfully
686 if (!-e $zip_file_path || -z $zip_file_path) {
687 $gsdl_cgi->generate_error("Collection archives zip file $zip_file_path could not be created.");
688 }
689
690 &put_file($gsdl_cgi, $zip_file_path, "application/zip");
691 unlink("$zip_file_path") unless $debugging_enabled;
692}
693
694# download web.xml from the server
695sub download_web_xml_file
696{
697 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
698
699 # Users can be in any group to perform this action
700 my $user_groups = &authenticate_user($gsdl_cgi, $username, "", $site);
701
702 my $file = $gsdl_cgi->clean_param("file");
703 if ((!defined $file) || ($file =~ m/^\s*$/)) {
704 $gsdl_cgi->generate_error("No file specified.");
705 }
706 $file =~ s/\|/&util::get_dirsep()/eg; # Convert the '|' characters into whatever is right for this OS
707
708 # Make sure we don't try to download anything else
709 if ($file =~ /\.\./) {
710 $gsdl_cgi->generate_error("Illegal file specified.");
711 }
712
713 my $web_inf_directory = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "web", "WEB-INF");
714 $gsdl_cgi->checked_chdir($web_inf_directory);
715
716 # Check that the collection file exists
717 if (!-e $file) {
718 $gsdl_cgi->generate_error("file $file does not exist.");
719 }
720
721 # Zip up the collection file
722 my $java = $gsdl_cgi->get_java_path();
723 my $java_classpath = &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java", "GLIServer.jar");
724 my $zip_file_path = &util::filename_cat($web_inf_directory, "webxml" . $timestamp . ".zip");
725 my $java_args = "\"$zip_file_path\" \"$web_inf_directory\" \"$file\"";
726 my $java_command = "$java -classpath \"$java_classpath\" org.greenstone.gatherer.remote.ZipFiles $java_args";
727 my $java_output = `$java_command`;
728
729 my $java_status = $?;
730 if ($java_status > 0) {
731 $gsdl_cgi->generate_error("Java failed: $java_command\n--\n$java_output\nExit status: " . ($java_status / 256) . "\n" . $gsdl_cgi->check_java_home());
732 }
733
734 # Check that the zip file was created successfully
735 if (!-e $zip_file_path || -z $zip_file_path) {
736 $gsdl_cgi->generate_error("web.xml zip file $zip_file_path could not be created.");
737 }
738
739 &put_file($gsdl_cgi, $zip_file_path, "application/zip");
740
741 unlink("$zip_file_path") unless $debugging_enabled;
742}
743
744# Collection locking unnecessary because this action isn't related to a particular collection
745sub get_script_options
746{
747 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
748
749 my $script = $gsdl_cgi->clean_param("script");
750 if ((!defined $script) || ($script =~ m/^\s*$/)) {
751 $gsdl_cgi->generate_error("No script specified.");
752 }
753 $gsdl_cgi->delete("script");
754
755 # Users can be in any group to perform this action
756 &authenticate_user($gsdl_cgi, $username, "", $site);
757 $gsdl_cgi->delete("ts"); ## two lines from GS3 version, doesn't seem to harm GS2
758 $gsdl_cgi->delete("pw");
759
760
761 my $perl_args = "";
762 if ($script eq "classinfo.pl") {
763 $perl_args = $gsdl_cgi->clean_param("classifier") || "";
764 $gsdl_cgi->delete("classifier");
765 }
766 if ($script eq "pluginfo.pl") {
767 $perl_args = $gsdl_cgi->clean_param("plugin") || "";
768 $gsdl_cgi->delete("plugin");
769 }
770
771 foreach my $cgi_arg_name ($gsdl_cgi->param) {
772 my $cgi_arg_value = $gsdl_cgi->clean_param($cgi_arg_name) || "";
773 $cgi_arg_value = $gsdl_cgi->safe_val($cgi_arg_value);
774 if ($cgi_arg_value eq "") {
775 $perl_args = "-$cgi_arg_name " . $perl_args;
776 }
777 else {
778 $perl_args = "-$cgi_arg_name \"$cgi_arg_value\" " . $perl_args;
779 }
780 }
781
782
783 # IIS 6: redirecting output from STDERR to STDOUT just doesn't work, so we have to let it go
784 # directly out to the page
785 print STDOUT "Content-type:text/plain\n\n";
786 my $perl_command;
787 if($iis6_mode && $gsdl_cgi->greenstone_version() == 2)
788 {
789 $perl_command = "perl -S $script $perl_args";
790 } else {
791 $perl_command = "perl -S $script $perl_args 2>&1";
792 }
793
794 my $perl_output = `$perl_command`;
795 my $perl_status = $?;
796 if ($perl_status > 0) {
797 $gsdl_cgi->generate_error("Perl failed: $perl_command\n--\n$perl_output\nExit status: " . ($perl_status / 256));
798 }
799
800 if (defined($perl_output))
801 {
802 print STDOUT $perl_output;
803 }
804}
805
806# get the names of all sites available on the server
807sub get_site_names
808{
809 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
810 my $sites_directory = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "web", "sites");
811
812 my @sites_dir;
813 my @site_dir;
814
815 $gsdl_cgi->checked_chdir($sites_directory);
816 opendir(DIR, $sites_directory);
817 @sites_dir= readdir(DIR);
818 my $sites_dir;
819 my $sub_dir_file;
820
821 print STDOUT "Content-type:text/plain\n\n";
822 foreach $sites_dir(@sites_dir)
823 {
824 if (!(($sites_dir eq ".") || ($sites_dir eq "..") || ($sites_dir eq "CVS")))
825 {
826 my $site_dir_path= &util::filename_cat($sites_directory,$sites_dir);
827 $gsdl_cgi->checked_chdir($site_dir_path);
828 opendir(DIR,$site_dir_path);
829 @site_dir=readdir(DIR);
830 closedir(DIR);
831
832 foreach $sub_dir_file(@site_dir)
833 {
834 if ($sub_dir_file eq "siteConfig.xml"){
835 print STDOUT "$sites_dir" . "-----";
836 }
837 }
838 }
839 }
840
841}
842
843sub move_collection_file
844{
845 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
846
847 my $collection = $gsdl_cgi->clean_param("c");
848 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
849 $gsdl_cgi->generate_error("No collection specified.");
850 }
851 my $source_file = $gsdl_cgi->clean_param("source");
852 if ((!defined $source_file) || ($source_file =~ m/^\s*$/)) {
853 $gsdl_cgi->generate_error("No source file specified.");
854 }
855 $source_file =~ s/\|/&util::get_dirsep()/eg; # Convert the '|' characters into whatever is right for this OS
856 my $target_file = $gsdl_cgi->clean_param("target");
857 if ((!defined $target_file) || ($target_file =~ m/^\s*$/)) {
858 $gsdl_cgi->generate_error("No target file specified.");
859 }
860 $target_file =~ s/\|/&util::get_dirsep()/eg; # Convert the '|' characters into whatever is right for this OS
861
862 # Make sure we don't try to move anything outside the collection
863 if ($source_file =~ /\.\./ || $target_file =~ /\.\./) {
864 $gsdl_cgi->generate_error("Illegal file specified.");
865 }
866
867 # Ensure the user is allowed to edit this collection
868 &authenticate_user($gsdl_cgi, $username, $collection, $site);
869
870 my $collection_directory = $gsdl_cgi->get_collection_dir($site, $collection);
871 $gsdl_cgi->checked_chdir($collection_directory);
872
873 # Check that the collection source file exists
874 if (!-e $source_file) {
875 $gsdl_cgi->generate_error("Collection file $source_file does not exist.");
876 }
877
878 # Make sure the collection isn't locked by someone else
879 &lock_collection($gsdl_cgi, $username, $collection, $site);
880
881 &util::mv($source_file, $target_file);
882
883 # Check that the collection source file was moved
884 if (-e $source_file || !-e $target_file) {
885 $gsdl_cgi->generate_error("Could not move collection file $source_file to $target_file."); # dies
886 }
887
888 $gsdl_cgi->generate_ok_message("Collection file $source_file moved to $target_file successfully.");
889}
890
891
892sub new_collection_directory
893{
894 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
895
896 my $collection = $gsdl_cgi->clean_param("c");
897 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
898 $gsdl_cgi->generate_error("No collection specified.");
899 }
900 my $directory = $gsdl_cgi->clean_param("directory");
901 if ((!defined $directory) || ($directory =~ m/^\s*$/)) {
902 $gsdl_cgi->generate_error("No directory specified.");
903 }
904 $directory =~ s/\|/&util::get_dirsep()/eg; # Convert the '|' characters into whatever is right for this OS
905
906 # Make sure we don't try to create anything outside the collection
907 if ($directory =~ /\.\./) {
908 $gsdl_cgi->generate_error("Illegal directory specified.");
909 }
910
911 # Ensure the user is allowed to edit this collection
912 &authenticate_user($gsdl_cgi, $username, $collection, $site);
913
914 my $collection_directory = $gsdl_cgi->get_collection_dir($site, $collection);
915 $gsdl_cgi->checked_chdir($collection_directory);
916
917 # Check that the collection directory doesn't already exist
918 # ZipTools doesn't zip up empty directories, so this causes an error when downloading a new collection as we explicity
919 # try to create the import directory
920## log -r13497 for GS2's gliserver.pl, Katherine Don explains:
921# "commented out checking for existence of a directory in new_collection_directory
922# as it throws an error which we don't want"
923 if($gsdl_cgi->greenstone_version() != 2 && -d $directory) {
924 $gsdl_cgi->generate_error("Collection directory $directory already exists.");
925 }
926
927 # Make sure the collection isn't locked by someone else
928 &lock_collection($gsdl_cgi, $username, $collection, $site);
929
930 &util::mk_dir($directory);
931
932 # Check that the collection directory was created
933 if (!-d $directory) {
934 $gsdl_cgi->generate_error("Could not create collection directory $directory.");
935 }
936
937 $gsdl_cgi->generate_ok_message("Collection directory $directory created successfully.");
938}
939
940
941sub run_script
942{
943 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
944
945 my $script = $gsdl_cgi->clean_param("script");
946 if ((!defined $script) || ($script =~ m/^\s*$/)) {
947 $gsdl_cgi->generate_error("No script specified.");
948 }
949 $gsdl_cgi->delete("script");
950 my $collection = $gsdl_cgi->clean_param("c");
951 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
952 $gsdl_cgi->generate_error("No collection specified.");
953 }
954 $gsdl_cgi->delete("c");
955
956 # confuse other, so delete timestamp
957 $gsdl_cgi->delete("ts");
958
959 # Ensure the user is allowed to edit this collection
960 &authenticate_user($gsdl_cgi, $username, $collection, $site);
961
962 # Make sure the collection isn't locked by someone else (unless we're running mkcol.pl, of course)
963 &lock_collection($gsdl_cgi, $username, $collection, $site) unless ($script eq "mkcol.pl");
964
965 # Last argument is the collection name, except for explode_metadata_database.pl and
966 # replace_srcdoc_with_html (where there's a "file" option followed by the filename. These two preceed the collection name)
967 my $perl_args = $collection;
968 if ($script eq "explode_metadata_database.pl" || $script eq "replace_srcdoc_with_html.pl") {
969 # Last argument is the file to be exploded or it is the file to be replaced with its html version
970 my $file = $gsdl_cgi->clean_param("file");
971 if ((!defined $file) || ($file =~ m/^\s*$/)) {
972 $gsdl_cgi->generate_error("No file specified.");
973 }
974 $gsdl_cgi->delete("file");
975 $file =~ s/ /\\ /g; # escape all spaces in filename with a backslash, i.e. "\ ".
976 $perl_args = $file;
977 }
978
979 foreach my $cgi_arg_name ($gsdl_cgi->param) {
980 my $cgi_arg_value = $gsdl_cgi->safe_val($gsdl_cgi->clean_param($cgi_arg_name));
981 if ($cgi_arg_value eq "") {
982 $perl_args = "-$cgi_arg_name " . $perl_args;
983 }
984 else {
985 $perl_args = "-$cgi_arg_name \"$cgi_arg_value\" " . $perl_args;
986 }
987 }
988
989 if (($script eq "import.pl") || ($script eq "buildcol.pl") || ($script eq "mkcol.pl")) { # || ($script eq "schedule.pl")
990 my $collect_directory = $gsdl_cgi->get_collection_dir($site);
991 ## previously only done for GS3, now it will do this for GS2 too. Is this how it should be?
992 $perl_args = $perl_args . " -collectdir " . $collect_directory;
993 }
994
995 my $perl_command = "perl -S $script $perl_args 2>&1";
996 # IIS 6: redirecting output from STDERR to STDOUT just doesn't work, so we have to let it go
997 # directly out to the page
998 if($gsdl_cgi->greenstone_version() == 2 && $iis6_mode)
999 {
1000 $perl_command = "perl -S $script $perl_args";
1001 }
1002 if (!open(PIN, "$perl_command |")) {
1003 $gsdl_cgi->generate_error("Unable to execute command: $perl_command");
1004 }
1005
1006 print STDOUT "Content-type:text/plain\n\n";
1007 print "$perl_command \n";
1008
1009 while (defined (my $perl_output_line = <PIN>)) {
1010 print STDOUT $perl_output_line;
1011 }
1012 close(PIN);
1013
1014 my $perl_status = $?;
1015 if ($perl_status > 0) {
1016 $gsdl_cgi->generate_error("Perl failed: $perl_command\n--\nExit status: " . ($perl_status / 256));
1017 }
1018 elsif ($mail_enabled) {
1019 if ($script eq "buildcol.pl") {
1020 &send_mail($gsdl_cgi, "Remote Greenstone building event", "Build of collection '$collection' complete.");
1021 }
1022 }
1023}
1024
1025sub upload_collection_file
1026{
1027 my ($gsdl_cgi, $username, $timestamp, $site) = @_;
1028
1029 my $collection = $gsdl_cgi->clean_param("c");
1030 if ((!defined $collection) || ($collection =~ m/^\s*$/)) {
1031 $gsdl_cgi->generate_error("No collection specified.");
1032 }
1033 my $file = $gsdl_cgi->clean_param("file");
1034 if ((!defined $file) || ($file =~ m/^\s*$/)) {
1035 $gsdl_cgi->generate_error("No file specified.");
1036 }
1037 my $directory = $gsdl_cgi->clean_param("directory") || "";
1038 $directory =~ s/\|/&util::get_dirsep()/eg; # Convert the '|' characters into whatever is right for this OS
1039 my $zip = $gsdl_cgi->clean_param("zip");
1040
1041 # Make sure we don't try to upload anything outside the collection
1042 if ($file =~ /\.\./) {
1043 $gsdl_cgi->generate_error("Illegal file specified.");
1044 }
1045 if ($directory =~ /\.\./) {
1046 $gsdl_cgi->generate_error("Illegal directory specified.");
1047 }
1048
1049 # Ensure the user is allowed to edit this collection
1050 if($gsdl_cgi->greenstone_version() == 2) { ## Quan commented this out for GS3 in r14325
1051 &authenticate_user($gsdl_cgi, $username, $collection, $site); # site will be undefined for GS2, of course
1052 }
1053
1054 my $collection_directory = $gsdl_cgi->get_collection_dir($site, $collection);
1055 $gsdl_cgi->checked_chdir($collection_directory);
1056
1057 # Make sure the collection isn't locked by someone else
1058 &lock_collection($gsdl_cgi, $username, $collection, $site);
1059
1060 my $directory_path = &util::filename_cat($collection_directory, $directory);
1061 if (!-d $directory_path) {
1062 &util::mk_dir($directory_path);
1063 if (!-d $directory_path) {
1064 $gsdl_cgi->generate_error("Could not create directory $directory_path.");
1065 }
1066 }
1067
1068 #my $file_path = &util::filename_cat($directory_path, $file . "-" . $timestamp);
1069 my $file_path = "";
1070 if($gsdl_cgi->greenstone_version() == 2) {
1071 $file_path = &util::filename_cat($directory_path, $file . "-" . $timestamp);
1072 } else {
1073 $file_path = &util::filename_cat($directory_path, $file);
1074 }
1075
1076 if (!open(FOUT, ">$file_path")) {
1077 print STDERR "Unable to write file $file_path\n";
1078 $gsdl_cgi->generate_error("Unable to write file $file_path");
1079 }
1080
1081 # Read the uploaded data and write it out to file
1082 my $buf;
1083 my $num_bytes = 0;
1084 binmode(FOUT);
1085 if($gsdl_cgi->greenstone_version() == 2) { ##
1086 # We have to pass the size of the uploaded data in the "fs" argument because IIS 6 seems to be
1087 # completely incapable of working this out otherwise (causing the old code to crash)
1088 my $num_bytes_remaining = $gsdl_cgi->clean_param("fs");
1089 my $bytes_to_read = $num_bytes_remaining;
1090 if ($bytes_to_read > 1024) { $bytes_to_read = 1024; }
1091
1092 while (read(STDIN, $buf, $bytes_to_read) > 0) {
1093 print FOUT $buf;
1094 $num_bytes += length($buf);
1095 $num_bytes_remaining -= length($buf);
1096 $bytes_to_read = $num_bytes_remaining;
1097 if ($bytes_to_read > 1024) { $bytes_to_read = 1024; }
1098 }
1099 } else { # GS3 and later
1100 my $bread;
1101 my $fh = $gsdl_cgi->clean_param("uploaded_file");
1102
1103 if (!defined $fh) {
1104 print STDERR "ERROR. Filehandle undefined. No file uploaded onto GS3 server.\n";
1105 $gsdl_cgi->generate_error("ERROR. Filehandle undefined. No file uploaded (GS3 server).");
1106 } else {
1107 while ($bread=read($fh, $buf, 1024)) {
1108 print FOUT $buf;
1109 }
1110 }
1111 }
1112 close(FOUT);
1113
1114 # If we have downloaded a zip file, unzip it
1115 if (defined $zip) {
1116 my $java = $gsdl_cgi->get_java_path();
1117 my $java_classpath = &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java", "GLIServer.jar");
1118 my $java_args = "\"$file_path\" \"$directory_path\"";
1119 my $java_command = "$java -classpath \"$java_classpath\" org.greenstone.gatherer.remote.Unzip $java_args";
1120
1121 my $java_output = `$java_command`;
1122 my $java_status = $?;
1123
1124 # Remove the zip file once we have unzipped it, since it is an intermediate file only
1125 unlink("$file_path") unless $debugging_enabled;
1126
1127 if ($java_status > 0) {
1128 $gsdl_cgi->generate_error("Java failed: $java_command\n--\n$java_output\nExit status: " . ($java_status / 256) . "\n" . $gsdl_cgi->check_java_home()); # dies
1129 }
1130 }
1131
1132 $gsdl_cgi->generate_ok_message("Collection file $file uploaded successfully.");
1133}
1134
1135sub put_file
1136{
1137 my $gsdl_cgi = shift(@_);
1138 my $file_path = shift(@_);
1139 my $content_type = shift(@_);
1140
1141 if(!defined $content_type) { ##
1142 $content_type = "application/zip";
1143 }
1144
1145 if (open(PIN, "<$file_path")) {
1146 print STDOUT "Content-type:$content_type\n\n"; ## For GS3: "Content-type:application/zip\n\n";
1147 my $buf;
1148 my $num_bytes = 0;
1149 binmode(PIN);
1150 while (read(PIN, $buf, 1024) > 0) {
1151 print STDOUT $buf;
1152 $num_bytes += length($buf);
1153 }
1154
1155 close(PIN);
1156 }
1157 else {
1158 $gsdl_cgi->generate_error("Unable to read file $file_path\n $!");
1159 }
1160}
1161
1162
1163sub send_mail
1164{
1165 my $gsdl_cgi = shift(@_);
1166 my $mail_subject = shift(@_);
1167 my $mail_content = shift(@_);
1168
1169 my $sendmail_command = "perl -S sendmail.pl";
1170 $sendmail_command .= " -to \"" . $mail_to_address . "\"";
1171 $sendmail_command .= " -from \"" . $mail_from_address . "\"";
1172 $sendmail_command .= " -smtp \"" . $mail_smtp_server . "\"";
1173 $sendmail_command .= " -subject \"" . $mail_subject . "\"";
1174
1175 if (!open(POUT, "| $sendmail_command")) {
1176 $gsdl_cgi->generate_error("Unable to execute command: $sendmail_command");
1177 }
1178 print POUT $mail_content . "\n";
1179 close(POUT);
1180}
1181
1182sub greenstone_server_version
1183{
1184 my $gsdl_cgi = shift(@_);
1185 my $version = $gsdl_cgi->greenstone_version();
1186 $gsdl_cgi->generate_ok_message("Greenstone server version is: $version\n");
1187}
1188
1189sub get_library_url_suffix
1190{
1191 my $gsdl_cgi = shift(@_);
1192 my $library_url = $gsdl_cgi->library_url_suffix();
1193 $gsdl_cgi->generate_ok_message("Greenstone library URL suffix is: $library_url\n");
1194}
1195
1196&main();
Note: See TracBrowser for help on using the repository browser.