Ignore:
Timestamp:
2017-08-11T17:07:44+12:00 (7 years ago)
Author:
ak19
Message:

Getting Windows wget to use proxy settings in environment. They didn't need to be in CAPS, as Windows has the side effect of setting env vars in both the original case of the letters of the env variable name as well as in all caps, and unsetting either version unsets both. On Windows however, I noticed that Perl was not on the PATH after open3() in WgetDownload.pm::useWget() failed with an unclear error message. So now the PATH is also propagated from Java to the perl code for downloading using wget.

Location:
main/trunk/greenstone2/perllib/downloaders
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/downloaders/WebDownload.pm

    r31864 r31877  
    193193    my $strBaseCMD = $strOptions." --tries=2 -q -O - \"$self->{'url'}\"";
    194194
     195    #&util::print_env(STDERR, "https_proxy", "http_proxy", "HTTPS_PROXY", "HTTP_PROXY", "ftp_proxy", "FTP_PROXY");
     196    #&util::print_env(STDERR); 
     197   
    195198    my $strIdentifyText = $self->useWget($strBaseCMD);
    196199   
  • main/trunk/greenstone2/perllib/downloaders/WgetDownload.pm

    r31874 r31877  
    165165}
    166166
    167 sub getWgetOptions
    168 {
    169     my ($self) = @_;
    170     my $strOptions = "";
    171 
    172     # If http_proxy ENV VARS are not set, but proxy Perl vars are set, then we're on Windows
    173     # and need to use the proxy vars as flags to wget
    174     # If http_proxy Env Vars are set, then we're on Linux, wget will use the http(s) proxy
    175     # env vars and we shouldn't be passing any proxy perl vars as flags
    176    
    177     # Truth in Perl: https://home.ubalt.edu/abento/452/perl/perltruth.html
    178     # http://www.perlmonks.org/?node=what%20is%20true%20and%20false%20in%20Perl%3F
    179    
    180     if (!$ENV{'http_proxy'} && !$ENV{'https_proxy'}) {
     167# Not using this. On Windows, we used to pass proxying settings as flags to wget. But, as that can be
     168# seen with Task Manager, we now have the proxy settings set in the environment and are no longer passing it
     169sub addProxySettingsAsWgetFlags
     170{
     171    my ($self) = @_;
     172    my $strOptions = "";
     173   
    181174    if ($self->{'proxy_on'} && $self->{'proxy_host'} && $self->{'proxy_port'})
    182175    {
     
    193186        $strOptions .= " --proxy ";
    194187    }
    195     }
    196 
    197     if($self->{'no_check_certificate'}) { #&& $self->{'url'} =~ m/^https\:/) { # URL may be http that gets redirected to https, so if no_check_certificate is on, turn it on even if URL is http
     188   
     189    return $strOptions;
     190}
     191
     192sub getWgetOptions
     193{
     194    my ($self) = @_;
     195    my $strOptions = "";
     196   
     197    # If proxy settings are set up in the environment, wget is ready to use them. More secure.
     198    # But if proxy settings are not set up in the environment, pass them as flags to wget
     199    # This is less secure, as pwd etc visible in task manager, but it was the original way in
     200    # which wget was run on windows.
     201    # Truth in Perl: https://home.ubalt.edu/abento/452/perl/perltruth.html
     202    # http://www.perlmonks.org/?node=what%20is%20true%20and%20false%20in%20Perl%3F
     203
     204    if (!$ENV{'http_proxy'} && !$ENV{'https_proxy'}) {
     205        $strOptions .= $self->addProxySettingsAsWgetFlags();
     206    } # else wget will use proxy settings in environment, assume enough settings have been provided
     207   
     208    if($self->{'no_check_certificate'}) { # URL may be http that gets redirected to https, so if no_check_certificate is on, turn it on even if URL is http
    198209
    199210    $strOptions .= " --no-check-certificate ";
Note: See TracChangeset for help on using the changeset viewer.