Changeset 31519
- Timestamp:
- 2017-03-14T20:10:48+13:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/servercontrol.pm
r31518 r31519 397 397 } 398 398 399 sub OLD_get_library_URL {400 my $self = shift(@_);401 402 # For web servers that are external to a Greenstone installation,403 # the user can pass in their web server's library URL.404 if($self->{'library_url'}) {405 return $self->{'library_url'};406 }407 408 # For web servers included with GS (like tomcat for GS3 and server.exe409 # and apache for GS2), we work out the library URL:410 my ($gs_mode, $lib_name); # gs_mode can be gs3 or gs2, lib_name is the custom servlet name411 $gs_mode = $self->{'gs_mode'};412 $lib_name = $self->{'library_name'};413 414 # If we get here, we are dealing with a server included with GS.415 # For GS3, we ask ant for the library URL.416 # For GS2, we derive the URL from the llssite.cfg file.417 418 my $url = undef;419 420 if($gs_mode eq "gs2") {421 my $llssite_cfg = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "llssite.cfg");422 423 if(-f $llssite_cfg) {424 # check llssite.cfg for line with url property425 # for server.exe also need to use portnumber and enterlib properties426 427 # Read in the entire contents of the file in one hit428 if (!open (FIN, $llssite_cfg)) {429 $self->print_msg("activate.pl::get_library_URL failed to open $llssite_cfg ($!)\n");430 return undef;431 }432 433 my $contents;434 sysread(FIN, $contents, -s FIN);435 close(FIN);436 437 my @lines = split(/[\n\r]+/, $contents); # split on carriage-returns and/or linefeeds438 my $enterlib = "";439 my $portnumber = "8282"; # will remain empty (implicit port 80) unless it's specifically been assigned440 441 foreach my $line (@lines) {442 if($line =~ m/^url=(.*)$/) {443 $url = $1;444 } elsif($line =~ m/^enterlib=(.*)$/) {445 $enterlib = $1;446 } elsif($line =~ m/^portnumber=(.*)$/) {447 $portnumber = $1;448 }449 }450 451 if(!$url) {452 return undef;453 }454 elsif($url eq "URL_pending") { # library is not running455 # do not process url=URL_pending in the file, since for server.exe456 # this just means the Enter Library button hasn't been pressed yet457 $url = undef;458 }459 else {460 # In the case of server.exe, need to do extra work to get the proper URL461 # But first, need to know whether we're indeed dealing with server.exe:462 463 # compare the URL's domain to the full URL464 # E.g. for http://localhost:8383/greenstone3/cgi-bin, the domain is localhost:8383465 my $uri = URI->new( $url );466 my $host = $uri->host;467 #print STDERR "@@@@@ host: $host\n";468 if($url =~ m/https?:\/\/$host(\/)?$/) {469 #if($url !~ m/https?:\/\/$host:$portnumber(\/)?/ || $url =~ m/https?:\/\/$host(\/)?$/) {470 # (if the URL does not contain the portnumber, OR if the port is implicitly 80 and)471 # If the domain with http:// prefix is completely the same as the URL, assume server.exe472 # then the actual URL is the result of suffixing the port and enterlib properties in llssite.cfg473 $url = $url.":".$portnumber.$enterlib;474 } # else, apache web server475 476 }477 }478 } elsif($gs_mode eq "gs3") {479 # Either check build.properties for tomcat.server, tomcat.port and app.name (and default servlet name).480 # app.name is stored in app.path by build.xml. Need to move app.name in build.properties from build.xml481 482 # Or, run the new target get-default-servlet-url483 # the output can look like:484 #485 # Buildfile: build.xml486 # [echo] os.name: Windows Vista487 #488 # get-default-servlet-url:489 # [echo] http://localhost:8383/greenstone3/library490 # BUILD SUCCESSFUL491 # Total time: 0 seconds492 493 #my $output = qx/ant get-default-servlet-url/; # backtick operator, to get STDOUT (else 2>&1)494 # - see http://stackoverflow.com/questions/799968/whats-the-difference-between-perls-backticks-system-and-exec495 496 # The get-default-servlet-url ant target can be run from anywhere by specifying the497 # location of GS3's ant build.xml buildfile. Activate.pl can be run from anywhere for GS3498 # GSDL3SRCHOME will be set for GS3 by gs3-setup.sh, a step that would have been necessary499 # to run the activate.pl script in the first place500 501 my $full_build_xml = &FileUtils::javaFilenameConcatenate($ENV{'GSDL3SRCHOME'},"build.xml");502 my $perl_command = "ant -buildfile \"$full_build_xml\" get-default-servlet-url";503 504 if (open(PIN, "$perl_command |")) {505 while (defined (my $perl_output_line = <PIN>)) {506 if($perl_output_line =~ m@(https?):\/\/(\S*)@) { # grab all the non-whitespace chars507 $url="$1://".$2; # preserve the http protocol #$url="http://".$1;508 }509 }510 close(PIN);511 512 if(defined $lib_name) { # url won't be undef513 # replace the servlet_name portion of the url found, with the given library_name514 $url =~ s@/[^/]*$@/$lib_name@;515 }516 } else {517 $self->print_msg("activate.pl::get_library_URL: Failed to run $perl_command to work out library URL for $gs_mode\n");518 }519 }520 521 # either the url is still undef or it is now set522 #print STDERR "\n@@@@@ final URL:|$url|\n" if $url;523 #print STDERR "\n@@@@@ URL still undef\n" if !$url;524 525 $self->{'library_url'} = $url;526 return $url;527 }528 529 530 399 sub do_deactivate { 531 400 my $self = shift(@_);
Note:
See TracChangeset
for help on using the changeset viewer.