Changeset 31878
- Timestamp:
- 2017-08-11T18:22:36+12:00 (6 years ago)
- Location:
- main/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/download/DownloadJob.java
r31877 r31878 310 310 Process prcs = null; 311 311 312 313 if (Utility.isWindows()) { 314 prcs = rt.exec(cmd); 312 if (proxy_url != null && !proxy_url.equals("")) { 313 // Specify proxies as environment variables 314 // Need to manually specify GSDLHOME and GSDLOS also 315 316 proxy_url = proxy_url.replaceAll("http://",""); 317 318 env = new String[7]; 319 320 env[0] = "http_proxy=http://"+proxy_url; 321 env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too 322 // see also https://wiki.archlinux.org/index.php/proxy_settings 323 env[2] = "ftp_proxy=ftp://"+proxy_url; 324 env[3] = "GSDLHOME=" + Configuration.gsdl_path; 325 env[4] = "GSDLOS=" + Gatherer.client_operating_system; 326 // teach it where the wgetrc file lives, in gs2build/bin/<os>: 327 env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; 328 // Issue discovered on Windows: If PATH is not made available to perl, so that wget or something else needed by 329 // WgetDownload.pm's open3() call is not on the PATH, then the perl open() call to run wget fails. 330 // So make PATH available to get open3() working: 331 env[6] = "PATH="+System.getenv("PATH"); 332 333 prcs = rt.exec(cmd, env); 334 } 335 else if(Gatherer.isGsdlRemote && Gatherer.isDownloadEnabled && !Utility.isWindows()) { 336 // Not Windows, but running client with download panel 337 // Need to manually specify GSDLHOME and GSDLOS 338 env = new String[3]; 339 env[0] = "GSDLHOME=" + Configuration.gsdl_path; 340 env[1] = "GSDLOS=" + Gatherer.client_operating_system; 341 env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; // teach it where the wgetrc file lives, in gs2build/bin/<os> 342 prcs = rt.exec(cmd, env); 315 343 } 316 344 else { 317 if (proxy_url != null && !proxy_url.equals("")) { 318 // Specify proxies as environment variables 319 // Need to manually specify GSDLHOME and GSDLOS also 320 env = new String[6]; 321 proxy_url = proxy_url.replaceAll("http://",""); 322 env[0] = "http_proxy=http://"+proxy_url; 323 env[1] = "https_proxy=http://"+proxy_url; // HTTP protocol for https:// too 324 // see also https://wiki.archlinux.org/index.php/proxy_settings 325 env[2] = "ftp_proxy=ftp://"+proxy_url; 326 env[3] = "GSDLHOME=" + Configuration.gsdl_path; 327 env[4] = "GSDLOS=" + Gatherer.client_operating_system; 328 env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; // teach it where the wgetrc file lives, in gs2build/bin/<os> 329 prcs = rt.exec(cmd, env); 330 } 331 else if(Gatherer.isGsdlRemote && Gatherer.isDownloadEnabled) { 332 // Not Windows, but running client with download panel 333 // Need to manually specify GSDLHOME and GSDLOS 334 env = new String[3]; 335 env[0] = "GSDLHOME=" + Configuration.gsdl_path; 336 env[1] = "GSDLOS=" + Gatherer.client_operating_system; 337 env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; // teach it where the wgetrc file lives, in gs2build/bin/<os> 338 prcs = rt.exec(cmd, env); 339 } 340 else { 341 // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set 342 prcs = rt.exec(cmd); 343 } 345 // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set 346 prcs = rt.exec(cmd); 344 347 } 345 348 //System.out.println(newcmd); … … 620 623 String [] env = null; 621 624 622 if (proxy_url != null && !proxy_url.equals("")) { 623 // Specify proxies as environment variables 624 // Need to manually specify GSDLHOME and GSDLOS also 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; 634 env[3] = "GSDLHOME=" + Configuration.gsdl_path; 635 env[4] = "GSDLOS=" + Gatherer.client_operating_system; 636 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 641 prcs = new SafeProcess(cmd, env, null); 642 } 643 else if(Gatherer.isGsdlRemote && Gatherer.isDownloadEnabled && !Utility.isWindows()) { 644 // Not Windows, but running client with download panel 645 // Need to manually specify GSDLHOME and GSDLOS 646 env = new String[3]; 647 env[0] = "GSDLHOME=" + Configuration.gsdl_path; 648 env[1] = "GSDLOS=" + Gatherer.client_operating_system; 649 env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; // teach it where the wgetrc file lives, in gs2build/bin/<os> 650 prcs = new SafeProcess(cmd, env, null); 651 } 652 else { 653 // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set 654 prcs = new SafeProcess(cmd); 655 } 656 625 if (proxy_url != null && !proxy_url.equals("")) { 626 // Specify proxies as environment variables 627 // Need to manually specify GSDLHOME and GSDLOS also 628 629 proxy_url = proxy_url.replaceAll("http://",""); 630 631 env = new String[7]; 632 633 env[0] = "http_proxy=http://"+proxy_url; 634 env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too 635 // see also https://wiki.archlinux.org/index.php/proxy_settings 636 env[2] = "ftp_proxy=ftp://"+proxy_url; 637 env[3] = "GSDLHOME=" + Configuration.gsdl_path; 638 env[4] = "GSDLOS=" + Gatherer.client_operating_system; 639 // teach it where the wgetrc file lives, in gs2build/bin/<os>: 640 env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; 641 // Issue discovered on Windows: If PATH is not made available to perl, so that wget or something else needed by 642 // WgetDownload.pm's open3() call is not on the PATH, then the perl open() call to run wget fails. 643 // So make PATH available to get open3() working: 644 env[6] = "PATH="+System.getenv("PATH"); 645 646 prcs = new SafeProcess(cmd, env, null); 647 } 648 else if(Gatherer.isGsdlRemote && Gatherer.isDownloadEnabled && !Utility.isWindows()) { 649 // Not Windows, but running client with download panel 650 // Need to manually specify GSDLHOME and GSDLOS 651 env = new String[3]; 652 env[0] = "GSDLHOME=" + Configuration.gsdl_path; 653 env[1] = "GSDLOS=" + Gatherer.client_operating_system; 654 env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; // teach it where the wgetrc file lives, in gs2build/bin/<os> 655 prcs = new SafeProcess(cmd, env, null); 656 } 657 else { 658 // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set 659 prcs = new SafeProcess(cmd); 660 } 661 657 662 //System.out.println(newcmd); 658 663 prcs.setMainHandler(this); // attach handler to clean up before and after process.destroy() -
main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java
r31877 r31878 111 111 // Need to manually specify GSDLHOME and GSDLOS also 112 112 113 proxy_url = proxy_url.replaceAll("http://",""); 114 115 String [] env = new String[7]; 113 proxy_url = proxy_url.replaceAll("http://",""); 116 114 117 env[0] = "http_proxy=http://"+proxy_url; 118 env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too 119 // see also https://wiki.archlinux.org/index.php/proxy_settings 120 env[2] = "ftp_proxy=ftp://"+proxy_url; 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 119 // see also https://wiki.archlinux.org/index.php/proxy_settings 120 env[2] = "ftp_proxy=ftp://"+proxy_url; 121 121 env[3] = "GSDLHOME=" + Configuration.gsdl_path; 122 122 env[4] = "GSDLOS=" + Gatherer.client_operating_system; 123 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 123 // teach it where the wgetrc file lives, in gs2build/bin/<os>: 124 env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc"; 125 // Issue discovered on Windows: If PATH is not made available to perl, so that wget or something else needed by 126 // WgetDownload.pm's open3() call is not on the PATH, then the perl open() call to run wget fails. 127 // So make PATH available to get open3() working: 128 env[6] = "PATH="+System.getenv("PATH"); 129 128 130 prcs = new SafeProcess(command, env, null); 129 131 } -
main/trunk/greenstone2/perllib/downloaders/WebDownload.pm
r31877 r31878 193 193 my $strBaseCMD = $strOptions." --tries=2 -q -O - \"$self->{'url'}\""; 194 194 195 196 197 195 #&util::print_env(STDERR, "https_proxy", "http_proxy", "HTTPS_PROXY", "HTTP_PROXY", "ftp_proxy", "FTP_PROXY"); 196 #&util::print_env(STDERR); 197 198 198 my $strIdentifyText = $self->useWget($strBaseCMD); 199 199 -
main/trunk/greenstone2/perllib/downloaders/WgetDownload.pm
r31877 r31878 169 169 sub addProxySettingsAsWgetFlags 170 170 { 171 my ($self) = @_;172 my $strOptions = "";173 174 if ($self->{'proxy_on'} && $self->{'proxy_host'} && $self->{'proxy_port'})175 {176 $strOptions .= " -e https_proxy=$self->{'proxy_host'}:$self->{'proxy_port'} ";177 $strOptions .= " -e http_proxy=$self->{'proxy_host'}:$self->{'proxy_port'} ";178 179 if ($self->{'user_name'} && $self->{'user_password'})180 {181 $strOptions .= "--proxy-user=$self->{'user_name'}"." --proxy-passwd=$self->{'user_password'}";182 }183 }184 185 if ($self->{'proxy_on'}) {186 $strOptions .= " --proxy ";187 }188 189 return $strOptions;190 }191 192 sub getWgetOptions193 {194 171 my ($self) = @_; 195 172 my $strOptions = ""; 196 173 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 174 if ($self->{'proxy_on'} && $self->{'proxy_host'} && $self->{'proxy_port'}) 175 { 176 $strOptions .= " -e https_proxy=$self->{'proxy_host'}:$self->{'proxy_port'} "; 177 $strOptions .= " -e http_proxy=$self->{'proxy_host'}:$self->{'proxy_port'} "; 178 179 if ($self->{'user_name'} && $self->{'user_password'}) 180 { 181 $strOptions .= "--proxy-user=$self->{'user_name'}"." --proxy-passwd=$self->{'user_password'}"; 182 } 183 } 184 185 if ($self->{'proxy_on'}) { 186 $strOptions .= " --proxy "; 187 } 188 189 return $strOptions; 190 } 191 192 sub 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 202 # http://www.perlmonks.org/?node=what%20is%20true%20and%20false%20in%20Perl%3F 203 203 204 204 if (!$ENV{'http_proxy'} && !$ENV{'https_proxy'}) { 205 205 $strOptions .= $self->addProxySettingsAsWgetFlags(); 206 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 207 209 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 http209 210 210 $strOptions .= " --no-check-certificate "; 211 211 } 212 212 213 213 return $strOptions; 214 214 } … … 288 288 # closing an extra unused handle, a single handle is used instead for both the child's 289 289 # stderr and stdout. 290 291 290 # See http://blog.0x1fff.com/2009/09/howto-execute-system-commands-in-perl.html 291 # for why this is the right thing to do. 292 292 293 293 # Both open2 and open3 don't return on failure, but raise an exception. The handling
Note:
See TracChangeset
for help on using the changeset viewer.