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