Changeset 31877 for main/trunk


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
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/download/DownloadJob.java

    r31865 r31877  
    619619
    620620        String [] env = null;
    621          
    622         if (Utility.isWindows()) {
    623                 prcs = new SafeProcess(cmd);
    624         }
    625         else {
     621
    626622        if (proxy_url != null && !proxy_url.equals("")) {           
    627623            // Specify proxies as environment variables
    628624            // Need to manually specify GSDLHOME and GSDLOS also
    629             env = new String[6];
    630                     proxy_url = proxy_url.replaceAll("http://","");
    631             env[0] = "http_proxy=http://"+proxy_url;
    632             env[1] = "https_proxy=http://"+proxy_url; // HTTP protocol for https:// too
    633                         // see also https://wiki.archlinux.org/index.php/proxy_settings
    634             env[2] = "ftp_proxy=ftp://"+proxy_url;
     625           
     626            proxy_url = proxy_url.replaceAll("http://","");
     627                   
     628            env = new String[7];
     629           
     630            env[0] = "http_proxy=http://"+proxy_url;
     631            env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too
     632                           // see also https://wiki.archlinux.org/index.php/proxy_settings
     633            env[2] = "ftp_proxy=ftp://"+proxy_url;
    635634            env[3] = "GSDLHOME=" + Configuration.gsdl_path;
    636635            env[4] = "GSDLOS=" + Gatherer.client_operating_system;
    637636            env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; // teach it where the wgetrc file lives, in gs2build/bin/<os>
     637            // If PATH is not made available, so that Perl is not on the PATH, then WgetDownload.pm's open3() call
     638            // to run wget fails with cryptic failure message. So make PATH available for open3():
     639            env[6] = "PATH="+System.getenv("PATH");     
     640           
    638641            prcs = new SafeProcess(cmd, env, null);
    639642        }
    640         else if(Gatherer.isGsdlRemote && Gatherer.isDownloadEnabled) {
     643        else if(Gatherer.isGsdlRemote && Gatherer.isDownloadEnabled && !Utility.isWindows()) {
    641644            // Not Windows, but running client with download panel
    642645            // Need to manually specify GSDLHOME and GSDLOS
     
    651654            prcs = new SafeProcess(cmd);
    652655        }
    653         }
     656
    654657        //System.out.println(newcmd);
    655658        prcs.setMainHandler(this); // attach handler to clean up before and after process.destroy()
  • main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java

    r31860 r31877  
    104104    String[] command = (String[]) commands.toArray(new String[0]);
    105105    DebugStream.println("Getting server info: "+commands);
    106     try {
    107         String [] env = null;
     106    try {       
    108107        SafeProcess prcs = null;
    109108       
    110         if (Utility.isWindows()) {
    111         prcs = new SafeProcess(command);
    112         }
    113         else {
    114         if (proxy_url != null && !proxy_url.equals("")) {           
     109        if (proxy_url != null && !proxy_url.equals("")) {
    115110            // Specify proxies as environment variables
    116111            // Need to manually specify GSDLHOME and GSDLOS also
    117             env = new String[6];
    118                     proxy_url = proxy_url.replaceAll("http://","");
    119             env[0] = "http_proxy=http://"+proxy_url;
    120             env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too
     112           
     113            proxy_url = proxy_url.replaceAll("http://","");
     114           
     115            String [] env = new String[7];
     116           
     117            env[0] = "http_proxy=http://"+proxy_url;
     118            env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too
    121119                           // see also https://wiki.archlinux.org/index.php/proxy_settings
    122             env[2] = "ftp_proxy=ftp://"+proxy_url;
     120            env[2] = "ftp_proxy=ftp://"+proxy_url;
    123121            env[3] = "GSDLHOME=" + Configuration.gsdl_path;
    124122            env[4] = "GSDLOS=" + Gatherer.client_operating_system;
    125123            env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; // teach it where the wgetrc file lives, in gs2build/bin/<os>
     124            // If PATH is not made available, so that Perl is not on the PATH, then WgetDownload.pm's open3() call
     125            // to run wget fails with cryptic failure message. So make PATH available for open3():
     126            env[6] = "PATH="+System.getenv("PATH");
     127           
    126128            prcs = new SafeProcess(command, env, null);
    127129        }
     
    130132            prcs = new SafeProcess(command);
    131133        }
    132         }
    133134       
    134135        // special processing of Process' stderr stream:
  • main/trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java

    r31864 r31877  
    780780       
    781781        // Write the use proxy command - we don't do this anymore, instead we set environment variables - hopefully these can't be spied on like the following can (using ps) - actually the environment stuff didn't work for windows, so lets go back to this
    782         if (Utility.isWindows()) {
     782        /*if (Utility.isWindows()) {
    783783       
    784784           arg = current_download.getArgument("user_name");
     
    790790           arg.setAssigned(true);
    791791          }
    792            else{
     792         
     793           else{*/
    793794            String user_name = user_pass.substring(0, user_pass.indexOf("@"));
    794795            String user_pwd = user_pass.substring(user_pass.indexOf("@") + 1);
    795796            proxy_url = user_name+":"+user_pwd+"@"+proxy_host+":"+proxy_port+"/";
    796797           
    797            }
     798           /*}*/
    798799       
    799800           return true;
  • 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.