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