- Timestamp:
- 2020-05-20T15:53:56+12:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/common-src/cgi-bin/gliserver.pl
r33011 r34117 1 #! /usr/bin/perl-w1 #!C:\Perl64\bin\perl.exe -w 2 2 # Need to specify the full path of Perl above 3 3 … … 99 99 $gsdl_cgi->delete("cmd"); 100 100 101 # The check-installation, greenstone-server-version and get-library-url commands have no arguments101 # The check-installation, greenstone-server-version and get-library-url-suffix, get-site-names commands have no arguments 102 102 if ($cmd eq "check-installation") { 103 103 &check_installation($gsdl_cgi); 104 104 return; 105 105 } 106 elsif ($cmd eq "greenstone-server-version") {106 if ($cmd eq "greenstone-server-version") { 107 107 &greenstone_server_version($gsdl_cgi); 108 108 return; 109 109 } 110 elsif ($cmd eq "get-library-url-suffix") {110 if ($cmd eq "get-library-url-suffix") { 111 111 &get_library_url_suffix($gsdl_cgi); 112 112 return; 113 113 } 114 114 115 if ($cmd eq "get-site-names" && $gsdl_cgi->greenstone_version() == 3) { 116 &get_site_names($gsdl_cgi); 117 return; 118 } 119 # I assume this is so we can check handling of a time out 120 if ($cmd eq "timeout-test") { 121 while (1) { } 122 } 123 115 124 # All other commands require a username, for locking and authentication 116 125 my $username = $gsdl_cgi->clean_param("un"); … … 128 137 129 138 my $site; # undefined on declaration, see http://perldoc.perl.org/perlsyn.html 139 130 140 if($gsdl_cgi->greenstone_version() != 2) { # all GS versions after 2 may define site 131 141 $site = $gsdl_cgi->clean_param("site"); … … 134 144 } 135 145 $gsdl_cgi->delete("site"); 146 136 147 } 137 148 … … 139 150 if ($cmd eq "delete-collection") { 140 151 &delete_collection($gsdl_cgi, $username, $timestamp, $site); 141 } 142 elsif ($cmd eq "download-collection") { 152 return; 153 } 154 155 if ($cmd eq "download-collection") { 143 156 &download_collection($gsdl_cgi, $username, $timestamp, $site); 144 } 145 elsif ($cmd eq "download-collection-archives") { 157 return; 158 } 159 if ($cmd eq "download-collection-archives") { 146 160 &download_collection_archives($gsdl_cgi, $username, $timestamp, $site); 147 } 148 elsif ($cmd eq "download-collection-configurations") { 161 return; 162 } 163 if ($cmd eq "download-collection-configurations") { 149 164 &download_collection_configurations($gsdl_cgi, $username, $timestamp, $site); 150 } 151 elsif ($cmd eq "download-collection-file") { 165 return; 166 } 167 if ($cmd eq "download-collection-file") { 152 168 &download_collection_file($gsdl_cgi, $username, $timestamp, $site); 153 } 154 elsif ($cmd eq "delete-collection-file") { 169 return; 170 } 171 if ($cmd eq "delete-collection-file") { 155 172 &delete_collection_file($gsdl_cgi, $username, $timestamp, $site); 156 } 157 elsif ($cmd eq "get-script-options") { 173 return; 174 } 175 if ($cmd eq "get-script-options") { 158 176 &get_script_options($gsdl_cgi, $username, $timestamp, $site); 159 } 160 elsif ($cmd eq "move-collection-file") { 177 return; 178 } 179 if ($cmd eq "move-collection-file") { 161 180 &move_collection_file($gsdl_cgi, $username, $timestamp, $site); 162 } 163 elsif ($cmd eq "new-collection-directory") { 181 return; 182 } 183 if ($cmd eq "new-collection-directory") { 164 184 &new_collection_directory($gsdl_cgi, $username, $timestamp, $site); 165 } 166 elsif ($cmd eq "run-script") { 185 return; 186 } 187 if ($cmd eq "run-script") { 167 188 &run_script($gsdl_cgi, $username, $timestamp, $site); 168 } 169 elsif ($cmd eq "timeout-test") { 170 while (1) { } 171 } 172 elsif ($cmd eq "upload-collection-file") { 189 return; 190 } 191 if ($cmd eq "upload-collection-file") { 173 192 &upload_collection_file($gsdl_cgi, $username, $timestamp, $site); 174 } 175 elsif ($cmd eq "file-exists") { 193 return; 194 } 195 if ($cmd eq "file-exists") { 176 196 &file_exists($gsdl_cgi, $site); 197 return; 177 198 } 178 199 # cmds not in Greenstone 2: 179 elsif ($gsdl_cgi->greenstone_version() != 2) {200 if ($gsdl_cgi->greenstone_version() != 2) { 180 201 if ($cmd eq "download-web-xml-file") { 181 202 &download_web_xml_file($gsdl_cgi, $username, $timestamp, $site); 203 return; 182 204 } 183 elsif ($cmd eq "user-validation") {205 if ($cmd eq "user-validation") { 184 206 &user_validation($gsdl_cgi, $username, $timestamp, $site); 185 } 186 elsif ($cmd eq "get-site-names") { 187 &get_site_names($gsdl_cgi, $username, $timestamp, $site); 188 } 189 } 190 else { 191 $gsdl_cgi->generate_error("Unrecognised command: '$cmd'"); 192 } 207 return; 208 } 209 } 210 211 # if we get here we have an invalid command 212 $gsdl_cgi->generate_error("Unrecognised command: '$cmd'"); 213 193 214 194 215 } … … 200 221 my $username = shift(@_); 201 222 my $collection = shift(@_); 202 my $site = shift(@_); 203 204 # Even if we're not authenticating remove the un and pw arguments, since these can mess up other scripts 223 224 # Check and remove the pw argument, since this can mess up other scripts 205 225 my $user_password = $gsdl_cgi->clean_param("pw"); 206 226 $gsdl_cgi->delete("pw"); 207 227 208 # Only authenticate if it is enabled209 # return "all-collections-editor" if (!$authentication_enabled);210 211 228 if ((!defined $user_password) || ($user_password =~ m/^\s*$/)) { 212 229 $gsdl_cgi->generate_error("Authentication failed: no password specified."); 213 230 } 214 231 232 215 233 if($gsdl_cgi->greenstone_version() == 2) { 216 my $users_db_content; 217 my $etc_directory = &util::filename_cat($ENV{'GSDLHOME'}, "etc"); 218 my $users_db_file_path = &util::filename_cat($etc_directory, "users.gdb"); 219 220 # Use db2txt instead of GDBM_File to get the user accounts information 221 $users_db_content = ""; 222 open(USERS_DB, "db2txt \"$users_db_file_path\" |"); 223 while (<USERS_DB>) { 224 $users_db_content .= $_; 225 } 226 close(USERS_DB); 234 return &authenticate_user_gs2($gsdl_cgi, $username, $user_password, $collection); 235 } 236 # else gs3 237 return &authenticate_user_gs3($gsdl_cgi, $username, $user_password, $collection); 238 } 239 240 sub authenticate_user_gs2 { 241 242 my $gsdl_cgi = shift(@_); 243 my $username = shift(@_); 244 my $user_password = shift(@_); 245 my $collection = shift(@_); 246 247 my $users_db_content; 248 my $etc_directory = &util::filename_cat($ENV{'GSDLHOME'}, "etc"); 249 my $users_db_file_path = &util::filename_cat($etc_directory, "users.gdb"); 250 251 # Use db2txt instead of GDBM_File to get the user accounts information 252 $users_db_content = ""; 253 open(USERS_DB, "db2txt \"$users_db_file_path\" |"); 254 while (<USERS_DB>) { 255 $users_db_content .= $_; 256 } 257 close(USERS_DB); 227 258 228 259 # Get the user account information from the usersDB database 229 260 my %users_db_data = (); 230 261 231 262 # a line dividing one user entry from another is made up of 70 hyphens for GS2 (37 hyphens for GS3) 232 263 my $horizontal_divider = q/-{70}/; … … 236 267 } 237 268 } 238 269 239 270 # Check username 240 271 my $user_data = $users_db_data{$username}; … … 273 304 } 274 305 } 306 # we have not found any group that allows access to the specified collection 275 307 $gsdl_cgi->generate_error("Authentication failed: user is not in the required group."); 276 } 277 278 # "GS3\web\WEB-INF\lib\gsdl3.jar;GS3\web\WEB-INF\lib\derby.jar" 279 # org.greenstone.gsdl3.util.usersDBRealm2txt "GSDL3SRCHOME" username pwd <col> 2>&1 280 elsif($gsdl_cgi->greenstone_version() == 3) { 281 my $gsdl3srchome = $ENV{'GSDL3SRCHOME'}; 282 283 my $java = $gsdl_cgi->get_java_path(); 284 my $java_gsdl3_classpath = &util::filename_cat($gsdl3srchome, "web", "WEB-INF", "lib", "gsdl3.jar"); 285 my $java_derby_classpath = &util::filename_cat($gsdl3srchome, "web", "WEB-INF", "lib", "derby.jar"); 286 my $java_gs3util_classpath = &util::filename_cat($gsdl3srchome, "web", "WEB-INF", "lib", "gutil.jar"); # for ProtocolPortProperties used by server side java code 287 my $java_classpath; 288 my $gsdlos = $ENV{'GSDLOS'}; 289 if ($gsdlos !~ m/windows/){ 290 $java_classpath = $java_gsdl3_classpath . ":" . $java_derby_classpath . ":" . $java_gs3util_classpath; 291 }else{ 292 $java_classpath = $java_gsdl3_classpath . ";" . $java_derby_classpath . ";" . $java_gs3util_classpath; 293 } 294 my $java_args = "\"$gsdl3srchome\" \"$username\" \"$user_password\""; 295 if ($collection ne "") { 296 $java_args += " \"$collection\""; 297 } 298 299 $gsdl_cgi->checked_chdir($gsdl3srchome); 300 my $java_command="\"$java\" -classpath \"$java_classpath\" org.greenstone.gsdl3.util.ServletRealmCheck $java_args 2>&1"; # call it ServletRealmCheck 301 my $java_output = `$java_command`; 302 if ($java_output =~ m/^Authentication failed:/) { # $java_output contains the error message 303 $gsdl_cgi->generate_error($java_output); # "\nJAVA_COMMAND: $java_command\n" 304 } 305 else { # success, $java_output is the user_groups list 306 return $java_output; 307 } 308 } 309 } 308 } 309 310 311 sub authenticate_user_gs3 { 312 313 my $gsdl_cgi = shift(@_); 314 my $username = shift(@_); 315 my $user_password = shift(@_); 316 my $collection = shift(@_); 317 318 my $gsdl3home = $ENV{'GSDL3HOME'}; 319 my $java = $gsdl_cgi->get_java_path(); 320 my $java_gsdl3_classpath = &util::filename_cat($gsdl3home, "WEB-INF", "lib", "gsdl3.jar"); 321 my $java_derby_classpath = ""; #&util::filename_cat($gsdl3home, "WEB-INF", "lib", "derby.jar"); 322 my $java_gs3util_classpath = &util::filename_cat($gsdl3home, "WEB-INF", "lib", "gutil.jar"); # for ProtocolPortProperties used by server side java code 323 my $java_classpath; 324 my $gsdlos = $ENV{'GSDLOS'}; 325 if ($gsdlos !~ m/windows/){ 326 $java_classpath = $java_gsdl3_classpath . ":" . $java_derby_classpath . ":" . $java_gs3util_classpath; 327 }else{ 328 $java_classpath = $java_gsdl3_classpath . ";" . $java_derby_classpath . ";" . $java_gs3util_classpath; 329 } 330 #my $java_args = "\"$gsdl3home\" \"$username\" \"$user_password\" \"$servlet\""; 331 my $java_args = "\"$gsdl3home\" \"$username\" \"$user_password\""; 332 if ($collection ne "") { 333 $java_args .= " \"$collection\""; 334 } 335 336 $gsdl_cgi->checked_chdir($gsdl3home); 337 my $java_command="\"$java\" -classpath \"$java_classpath\" org.greenstone.gsdl3.util.ServletRealmCheck $java_args 2>&1"; 338 my $java_output = `$java_command`; 339 if ($java_output =~ m/^Authentication failed:/) { # $java_output contains the error message 340 $gsdl_cgi->generate_error($java_output); # "\nJAVA_COMMAND: $java_command\n" 341 } 342 # TODO check for errors with running the java command 343 else { # success, $java_output is the user_groups list 344 my @groups = split(/,/, $java_output); 345 my $real_groups = ""; 346 # with the addition of using JAVA_TOOL_OPTIONS, we are now getting 347 #Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 in the output. Lets filter it out by only including valid collection editing groups. 348 foreach my $group (@groups) { 349 if ($group =~ /(all-collections-editor|personal-collections-editor|.*-collection-editor)/) { 350 $real_groups .= $group.","; 351 } 352 } 353 return "$real_groups"; 354 } 355 # Note we don't need to check like for gs2 if we are in the right group if a collection is specified - if a collection arg is passed to ServletRealmCheck, it will only return groups if the user is in a group that can access the collection 356 } 357 358 310 359 311 360 … … 376 425 if ($user_err!~ m/ERROR/){ 377 426 #$gsdl_cgi->generate_error("Authentication failed: $username is not valid"); 378 $gsdl_cgi->generate_ok ($user_err);427 $gsdl_cgi->generate_ok_message($user_err); 379 428 #print $user_err; 380 429 }else{ … … 420 469 $installation_status .= "\n"; 421 470 if($gsdl_cgi->greenstone_version() != 2) { 422 $installation_status .= "GSDL3SRCHOME: " . $ENV{'GSDL3SRCHOME'} . "\n";423 471 $installation_status .= "GSDL3HOME: " . $ENV{'GSDL3HOME'} . "\n"; 424 472 } … … 915 963 { 916 964 my ($gsdl_cgi, $username, $timestamp, $site) = @_; 917 my $sites_directory = &util::filename_cat($ENV{'GSDL3 SRCHOME'}, "web", "sites");965 my $sites_directory = &util::filename_cat($ENV{'GSDL3HOME'}, "sites"); 918 966 919 967 my @sites_dir;
Note:
See TracChangeset
for help on using the changeset viewer.