- Timestamp:
- 2017-08-14T22:23:04+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java
r31877 r31880 91 91 private String mode = null; 92 92 private TreePath previous_path; 93 private String proxy_url = "";93 private Properties proxy_urls = new Properties(); // proxy_urls for each of HTTP, HTTPS, FTP 94 94 private Proxy proxyObject = null; 95 95 … … 601 601 } 602 602 603 getter.newDownloadJob((Download)download_map.get(mode) ,mode,proxy_url );603 getter.newDownloadJob((Download)download_map.get(mode) ,mode,proxy_urls); 604 604 } 605 605 } … … 723 723 } 724 724 725 // TODO: Still need to read up on and test how to set wget proxy on windows 726 // Need to be on a windows machine that requires proxy, and get wget to work on cmdline 727 // If that works, then need to check https URLS also work. 728 // See https://superuser.com/questions/526710/how-to-set-http-proxy-address-for-wget-under-windows 729 private boolean checkProxy(){ 725 726 // SOME READING: 727 // https://superuser.com/questions/526710/how-to-set-http-proxy-address-for-wget-under-windows 728 // https://arstechnica.com/civis/viewtopic.php?f=10&t=1281165 729 // "http or https to an https proxy?" 730 // About "CONNECT": https://daniel.haxx.se/docs/sshproxy.html 731 // "You need an SSH client that can issue CONNECT requests through the company HTTP proxy." Seems to imply http? Also uses it for ftp. 732 // https://forum.ivorde.com/set-up-ftp-proxy-via-command-line-in-linux-freebsd-t19733.html sets ftp_proxy to a http url. 733 // So it's seems to be just whatever protocol the proxy server has. When the proxy supports all three protocols 734 // (apparently the common case as per page below describing firefox prefs), then wiki.archlinux sets all three ftp_proxy/http_proxy/https_proxy to the same. 735 // See https://forums.freebsd.org/threads/57378/ 736 // "I believe that ftp(1) only uses HTTP-type proxies for fetching URLs. I.e. you can't do traditional open->cd->get interactive style of FTP with it via a HTTP proxy. If you do something like ftp ftp://ftp.example.com/path/file, it should work with your proxy setup. For traditional interactive FTP, you need to be directly talking to the remote server or using the less common FTP proxy/gate functionality." 737 // https://wiki.archlinux.org/index.php/Proxy_settings 738 // This does https_proxy = http_proxy, and explicitly prefixes "https://" to http_proxy. 739 // https://www.howtogeek.com/293213/how-to-configure-a-proxy-server-in-firefox/ 740 /* Youâll usually want to click the âUse the proxy server for all protocolsâ option. Firefox will also use your HTTP proxy server for SSL-encrypted HTTPS connections and File Transfer Protocol (FTP) connections. 741 Uncheck this box if you want to enter separate proxy servers for HTTP, HTTPS, and FTP connections. This isnât common. 742 If youâre configuring a SOCKS proxy, leave the HTTP Proxy, SSL Proxy, and FTP Proxy boxes empty. Enter the address of the SOCKS proxy into the âSOCKS Hostâ and its port into the âPortâ box. 743 */ 744 private boolean checkProxy(){ 745 746 proxy_urls.clear(); 747 748 Download current_download = (Download)download_map.get(mode); 749 750 Argument arg = current_download.getArgument("proxy_on"); 751 752 if (arg == null) return true; 753 754 // Determine if we have to use a proxy. 755 if(Configuration.get("general.use_proxy", true)) { 756 757 boolean http_proxy_set = setProxyURLFor("HTTP"); 758 boolean https_proxy_set = setProxyURLFor("HTTPS"); 759 boolean ftp_proxy_set = setProxyURLFor("FTP"); 760 761 if(proxy_urls.size() == 0 || 762 (!http_proxy_set && !https_proxy_set && !ftp_proxy_set)) { 763 764 // if checkProxy() failed for all protocols 765 // OR if none of the proxies were setup by user, then turn off proxying 766 arg = current_download.getArgument("proxy_on"); 767 arg.setValue("false"); 768 arg.setAssigned(false); 769 proxy_urls.clear(); 770 return false; 771 } else { // proxy details have been successfully set for at least one proxy protocol 772 return true; 773 } 774 775 } else { // if proxy_on was off 776 // unset proxy_on argument too 777 arg = current_download.getArgument("proxy_on"); 778 arg.setValue("false"); 779 arg.setAssigned(false); 780 } 781 782 return true; 783 } 784 785 private boolean setProxyURLFor(String protocol) { 786 String proxy_host = Configuration.getString("general."+protocol+"_proxy_host", true); 787 if(proxy_host.equals("")) { // no proxy details for this protocol 788 ///System.err.println("### general."+protocol+"proxy_host was empty"); 789 return true; 790 } 791 792 String proxy_port = Configuration.getString("general."+protocol+"_proxy_port", true); 793 // Find out whether the user has already authenticated themselves 794 795 // remove the protocol prefix from proxy_host, and store it 796 String proxy_protocol = ""; 797 int proxy_protocol_index = proxy_host.indexOf("://"); 798 if(proxy_protocol_index != -1) { 799 proxy_protocol_index += "://".length(); 800 proxy_protocol = proxy_host.substring(0, proxy_protocol_index); 801 proxy_host = proxy_host.substring(proxy_protocol_index); 802 } else { // no explicit protocol for proxy host specified, 803 // then set explicit protocol to be the same as the protocol param: http|https|ftp 804 proxy_protocol = protocol.toLowerCase()+"://"; 805 } 806 807 String user_pass = ""; 808 String address = proxy_host + ":" + proxy_port; 809 810 int count = 0; 811 // Only for wget, need to avoid a second automatic authentication popup (first asks 812 // the proxy authentication for wget, and the second will ask the same for the realm) 813 // Once the authentication has been reused, it will set the GAuthenticator state back to REGULAR 814 GAuthenticator.setMode(GAuthenticator.DOWNLOAD); 815 while(count < 3 && (user_pass = (String) GAuthenticator.authentications.get(address)) == null) { 816 Authenticator.requestPasswordAuthentication(proxy_host, null, Integer.parseInt(proxy_port), "http://", Dictionary.get("WGet.Prompt"), "HTTP"); 817 count++; 818 } 819 if(count >= 3) { 820 return false; 821 } 822 823 // https://askubuntu.com/questions/664777/systemwide-proxy-settings-in-ubuntu 824 // http://www.rgagnon.com/javadetails/java-0085.html 825 // how-do-i-make-httpurlconnection-use-a-proxy 826 // https://stackoverflow.com/questions/8030908/how-to-check-if-proxy-is-working-in-java 827 828 //proxyObject = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy_host, Integer.parseInt(proxy_port))); // proxyObject only used by getRedirectURL(), which we're no longer calling 829 830 Download current_download = (Download)download_map.get(mode); 831 Argument arg = current_download.getArgument("proxy_on"); 832 833 if(user_pass.indexOf("@") != -1) { 834 835 arg.setValue("true"); // proxy_on argument 836 arg.setAssigned(true); 837 838 arg = current_download.getArgument(protocol.toLowerCase()+"_proxy_host"); 839 arg.setValue(proxy_host); 840 arg.setAssigned(true); 841 842 arg = current_download.getArgument(protocol.toLowerCase()+"_proxy_port"); 843 arg.setValue(proxy_port); 844 arg.setAssigned(true); 845 846 // Write the use proxy command - we don't do this anymore, instead we set environment 847 // variables as these do work for windows after all (Aug 2017). Hopefully these can't 848 // be spied on like the following can (using ps/task manager. If going back to the 849 // following, be aware: can't add protocol+user_name and protocol+user_password as 850 // accepted parameters in WgetDownload.pm for HTTP, HTTPS and FTP protocols. Only 851 // one set of username and password can be set for wget's --proxy-user and 852 // --proxy-password flags. No separate flags for each protocol. 853 /*if (Utility.isWindows()) { 854 855 arg = current_download.getArgument("user_name"); 856 arg.setValue(user_pass.substring(0, user_pass.indexOf("@"))); 857 arg.setAssigned(true); 858 859 arg = current_download.getArgument("user_password"); 860 arg.setValue(user_pass.substring(user_pass.indexOf("@") + 1)); 861 arg.setAssigned(true); 862 } 863 864 else{*/ 865 String user_name = user_pass.substring(0, user_pass.indexOf("@")); 866 String user_pwd = user_pass.substring(user_pass.indexOf("@") + 1); 867 /*}*/ 868 869 // construct proxy_url and prefix the stored proxy protocol to it 870 String proxy_url = proxy_protocol+user_name+":"+user_pwd+"@"+proxy_host+":"+proxy_port+"/"; 871 proxy_urls.setProperty(protocol, proxy_url); 872 return true; 873 } 874 else{ 875 return false; 876 } 877 } 878 879 880 private boolean old_checkProxy(){ 730 881 731 proxy_url = null;732 882 String proxy_url = null; // ORIGINALLY A MEMBER VAR 883 733 884 Download current_download = (Download)download_map.get(mode); 734 885 … … 860 1011 } 861 1012 862 server_info = new ServerInfoDialog(str_url ,proxy_url , mode,(Download)download_map.get(mode));1013 server_info = new ServerInfoDialog(str_url ,proxy_urls, mode,(Download)download_map.get(mode)); 863 1014 864 1015 }
Note:
See TracChangeset
for help on using the changeset viewer.