Changeset 31880 for main/trunk/gli


Ignore:
Timestamp:
2017-08-14T22:23:04+12:00 (7 years ago)
Author:
ak19
Message:

All the changes that were required to set up multiple proxy servers, one for HTTP, one for HTTPS, one for FTP. Still need to test on Windows

Location:
main/trunk/gli
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/classes/dictionary.properties

    r31875 r31880  
    10041004Preferences.Connection.No_Check_Certificate: No certificate checking (effective on 'https' URLs)
    10051005Preferences.Connection.No_Check_Certificate_Tooltip:Tick to download even from 'https' URLs that don't have a (valid) security certificate.
    1006 Preferences.Connection.Proxy_Host:Proxy Host:
    1007 Preferences.Connection.Proxy_Host_Tooltip:The address of your proxy server
    1008 Preferences.Connection.Proxy_Port:Proxy Port:
    1009 Preferences.Connection.Proxy_Port_Tooltip:The port number of your proxy server
    1010 Preferences.Connection.Proxy_Host_Missing:Enter a value for the proxy host or turn off Use Proxy Connection in the Connection tab.
     1006Preferences.Connection.HTTP_Proxy_Host:HTTP Proxy Host:
     1007Preferences.Connection.HTTP_Proxy_Host_Tooltip:The address of your HTTP proxy server
     1008Preferences.Connection.HTTP_Proxy_Port_Tooltip:The port number of your HTTP proxy server
     1009Preferences.Connection.HTTPS_Proxy_Host:HTTPS Proxy Host:
     1010Preferences.Connection.HTTPS_Proxy_Host_Tooltip:The address of your HTTPS proxy server
     1011Preferences.Connection.HTTPS_Proxy_Port_Tooltip:The port number of your HTTPS proxy server
     1012Preferences.Connection.FTP_Proxy_Host:FTP Proxy Host:
     1013Preferences.Connection.FTP_Proxy_Host_Tooltip:The address of your FTP proxy server
     1014Preferences.Connection.FTP_Proxy_Port_Tooltip:The port number of your FTP proxy server
     1015Preferences.Connection.Proxy_Host_Missing:Enter a value for at least one proxy host or turn off Use Proxy Connection in the Connection tab.
     1016Preferences.Connection.Proxy_Port:Port:
    10111017Preferences.Connection.Servlet:Servlet:
    10121018Preferences.Connection.Servlet_Tooltip:The servlet to use to view your site
  • main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r31814 r31880  
    14531453        try {// Can throw several exceptions
    14541454            if(Configuration.get("general.use_proxy", true)) {
     1455                // These are Java properties, therefore see
     1456                // https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
     1457                // https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
     1458                // https://stackoverflow.com/questions/14243590/proxy-settings-in-java
     1459
     1460                // Not sure what proxyType is. And proxySet ceased to exist since JDK 6 or before
    14551461                System.setProperty("http.proxyType", "4");
    1456                 System.setProperty("http.proxyHost", Configuration.getString("general.proxy_host", true));
    1457                 System.setProperty("http.proxyPort", Configuration.getString("general.proxy_port", true));
    1458                 System.setProperty("http.proxySet", "true");
     1462                System.setProperty("http.proxyHost", Configuration.getString("general.HTTP_proxy_host", true));
     1463                System.setProperty("http.proxyPort", Configuration.getString("general.HTTP_proxy_port", true));
     1464                //System.setProperty("http.proxySet", "true");
     1465               
     1466                System.setProperty("https.proxyHost", Configuration.getString("general.HTTPS_proxy_host", true));
     1467                System.setProperty("https.proxyPort", Configuration.getString("general.HTTPS_proxy_port", true));
     1468
     1469                System.setProperty("ftp.proxyHost", Configuration.getString("general.FTP_proxy_host", true));
     1470                System.setProperty("ftp.proxyPort", Configuration.getString("general.FTP_proxy_port", true));
     1471               
    14591472            } else {
    14601473                System.setProperty("http.proxyHost", "");
    14611474                System.setProperty("http.proxyPort", "");
    1462                 System.setProperty("http.proxySet", "false");
     1475                //System.setProperty("http.proxySet", "false");
     1476                System.setProperty("https.proxyHost", "");
     1477                System.setProperty("https.proxyPort", "");
     1478                System.setProperty("ftp.proxyHost", "");
     1479                System.setProperty("ftp.proxyPort", "");
    14631480            }
    14641481        } catch (Exception error) {
  • main/trunk/gli/src/org/greenstone/gatherer/download/DownloadJob.java

    r31878 r31880  
    107107    private final String mode;
    108108   
    109     private String proxy_url; // only the main thread (where DownloadJob runs) modifies this, so no synching needed
     109    private Properties proxy_urls; // only the main thread (where DownloadJob runs) modifies this, so no synching needed
    110110   
    111111    /**
    112112     */
    113     public DownloadJob(Download download, String proxy_pass, String proxy_user, DownloadScrollPane mummy, String mode, String proxy_url) {
     113    public DownloadJob(Download download, String proxy_pass, String proxy_user, DownloadScrollPane mummy, String mode, Properties proxy_urls) {
    114114    URL url = null;
    115115    int folder_hash;
    116116
    117         this.proxy_url =  proxy_url;
     117        this.proxy_urls =  proxy_urls;
    118118   
    119119        download_option = downloadToHashMap(download);
     
    310310        Process prcs = null;
    311311
    312         if (proxy_url != null && !proxy_url.equals("")) {           
     312        if (proxy_urls.size() != 0) {
    313313        // Specify proxies as environment variables
    314314        // Need to manually specify GSDLHOME and GSDLOS also
     315        env = new String[4+proxy_urls.size()];
    315316       
    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;
     317        env[0] = "GSDLHOME=" + Configuration.gsdl_path;
     318        env[1] = "GSDLOS=" + Gatherer.client_operating_system;
    326319        // teach it where the wgetrc file lives, in gs2build/bin/<os>:
    327         env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
     320        env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
    328321        // Issue discovered on Windows: If PATH is not made available to perl, so that wget or something else needed by
    329322        // WgetDownload.pm's open3()  call is not on the PATH, then the perl open() call to run wget fails.
    330323        // So make PATH available to get open3() working:
    331         env[6] = "PATH="+System.getenv("PATH");     
     324        env[3] = "PATH="+System.getenv("PATH");
     325
     326        int next_index = 4;
     327        String proxy_url = proxy_urls.getProperty("HTTP");
     328        if(proxy_url != null) {
     329            env[next_index] = "http_proxy="+proxy_url;
     330            next_index++;
     331        }
     332        proxy_url = proxy_urls.getProperty("HTTPS");
     333        if(proxy_url != null) {
     334            env[next_index] = "https_proxy="+proxy_url;
     335            next_index++;
     336        }
     337        proxy_url = proxy_urls.getProperty("FTP");
     338        if(proxy_url != null) {
     339            env[next_index] = "ftp_proxy="+proxy_url;
     340            next_index++;
     341        }               
    332342       
    333343        prcs = rt.exec(cmd, env);
     
    623633        String [] env = null;
    624634
    625         if (proxy_url != null && !proxy_url.equals("")) {           
     635        if (proxy_urls.size() != 0) {
    626636        // Specify proxies as environment variables
    627637        // Need to manually specify GSDLHOME and GSDLOS also
     638        env = new String[4+proxy_urls.size()];
    628639       
    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;
     640        env[0] = "GSDLHOME=" + Configuration.gsdl_path;
     641        env[1] = "GSDLOS=" + Gatherer.client_operating_system;
    639642        // teach it where the wgetrc file lives, in gs2build/bin/<os>:
    640         env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
     643        env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
    641644        // Issue discovered on Windows: If PATH is not made available to perl, so that wget or something else needed by
    642645        // WgetDownload.pm's open3()  call is not on the PATH, then the perl open() call to run wget fails.
    643646        // So make PATH available to get open3() working:
    644         env[6] = "PATH="+System.getenv("PATH");     
     647        env[3] = "PATH="+System.getenv("PATH");
     648
     649        int next_index = 4;
     650        String proxy_url = proxy_urls.getProperty("HTTP");
     651        if(proxy_url != null) {
     652            env[next_index] = "http_proxy="+proxy_url;         
     653            next_index++;
     654        }
     655        proxy_url = proxy_urls.getProperty("HTTPS");
     656        if(proxy_url != null) {
     657            env[next_index] = "https_proxy="+proxy_url;
     658            next_index++;
     659        }
     660        proxy_url = proxy_urls.getProperty("FTP");
     661        if(proxy_url != null) {
     662            env[next_index] = "ftp_proxy="+proxy_url;
     663            next_index++;
     664        }               
    645665       
    646666        prcs = new SafeProcess(cmd, env, null);
    647         } 
     667        }
    648668        else if(Gatherer.isGsdlRemote && Gatherer.isDownloadEnabled && !Utility.isWindows()) {
    649669        // Not Windows, but running client with download panel
  • main/trunk/gli/src/org/greenstone/gatherer/download/DownloadScrollPane.java

    r31822 r31880  
    183183    }
    184184
    185     public void newDownloadJob(Download download, String mode, String proxy_url) {
     185    public void newDownloadJob(Download download, String mode, Properties proxy_urls) {
    186186    // Create the job and fill in the details from gatherer.config.
    187187
    188188    DebugStream.println("About to create a new job");
    189189   
    190         DownloadJob new_job = new DownloadJob(download, Configuration.proxy_pass, Configuration.proxy_user, this, mode, proxy_url);
     190        DownloadJob new_job = new DownloadJob(download, Configuration.proxy_pass, Configuration.proxy_user, this, mode, proxy_urls);
    191191    // Tell it to run as soon as possible
    192192
  • main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java

    r31878 r31880  
    88import java.io.*;
    99import java.util.ArrayList;
     10import java.util.Properties;
    1011import org.greenstone.gatherer.cdm.Argument;
    1112import org.greenstone.gatherer.Configuration;
     
    2728    private JDialog info_dialog;
    2829    private Download download;
    29     private String proxy_url;
     30    private Properties proxy_urls;
    3031   
    31     public ServerInfoDialog(String url, String proxy_url, String mode, Download download) {
     32    public ServerInfoDialog(String url, Properties proxy_urls, String mode, Download download) {
    3233    super();
    3334    this.url = url;
    3435    this.mode = mode;
    3536        this.download = download;
    36         this.proxy_url = proxy_url;
     37        this.proxy_urls = proxy_urls;
    3738    this.info_dialog = this;
    3839   
     
    106107    try {       
    107108        SafeProcess prcs = null;
    108        
    109         if (proxy_url != null && !proxy_url.equals("")) {
    110             // Specify proxies as environment variables
    111             // Need to manually specify GSDLHOME and GSDLOS also
    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
    119             // see also https://wiki.archlinux.org/index.php/proxy_settings
    120             env[2] = "ftp_proxy=ftp://"+proxy_url;
    121             env[3] = "GSDLHOME=" + Configuration.gsdl_path;
    122             env[4] = "GSDLOS=" + Gatherer.client_operating_system;
    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            
    130             prcs = new SafeProcess(command, env, null);
    131         }
    132         else {
    133             // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set
    134             prcs = new SafeProcess(command);
     109
     110        if (proxy_urls.size() != 0) {
     111        // Specify proxies as environment variables
     112        // Need to manually specify GSDLHOME and GSDLOS also
     113        String[] env = new String[4+proxy_urls.size()];
     114
     115        env[0] = "GSDLHOME=" + Configuration.gsdl_path;
     116        env[1] = "GSDLOS=" + Gatherer.client_operating_system;
     117        // teach it where the wgetrc file lives, in gs2build/bin/<os>:
     118        env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
     119        // Issue discovered on Windows: If PATH is not made available to perl, so that wget or something else needed by
     120        // WgetDownload.pm's open3()  call is not on the PATH, then the perl open() call to run wget fails.
     121        // So make PATH available to get open3() working:
     122        env[3] = "PATH="+System.getenv("PATH");     
     123
     124        int next_index = 4;
     125        String proxy_url = proxy_urls.getProperty("HTTP");
     126        if(proxy_url != null) {
     127            env[next_index] = "http_proxy="+proxy_url;
     128            next_index++;
    135129        }
     130        proxy_url = proxy_urls.getProperty("HTTPS");
     131        if(proxy_url != null) {
     132            env[next_index] = "https_proxy="+proxy_url;
     133            next_index++;
     134        }
     135        proxy_url = proxy_urls.getProperty("FTP");
     136        if(proxy_url != null) {
     137            env[next_index] = "ftp_proxy="+proxy_url;
     138            next_index++;
     139        }               
     140       
     141        prcs = new SafeProcess(command, env, null);
     142        } else {
     143        // Will inherit the GLI's environment, with GSDLHOME and GSDLOS set
     144        prcs = new SafeProcess(command);
     145        }
    136146       
    137147        // special processing of Process' stderr stream:
  • main/trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java

    r31877 r31880  
    9191    private String mode = null;
    9292    private TreePath previous_path;
    93     private String proxy_url = "";
     93    private Properties proxy_urls = new Properties(); // proxy_urls for each of HTTP, HTTPS, FTP
    9494    private Proxy proxyObject = null;
    9595       
     
    601601        }
    602602       
    603         getter.newDownloadJob((Download)download_map.get(mode) ,mode,proxy_url);
     603        getter.newDownloadJob((Download)download_map.get(mode) ,mode,proxy_urls);
    604604        }
    605605    }
     
    723723    }
    724724
    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.
     741Uncheck this box if you want to enter separate proxy servers for HTTP, HTTPS, and FTP connections. This isn’t common.
     742If 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(){
    730881     
    731     proxy_url = null;
    732 
     882    String proxy_url = null; // ORIGINALLY A MEMBER VAR
     883   
    733884    Download current_download = (Download)download_map.get(mode);
    734885   
     
    8601011        }
    8611012
    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));
    8631014       
    8641015    }
  • main/trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java

    r31861 r31880  
    5656    extends ModalDialog
    5757{
     58    static final public String HTTP = "HTTP";
     59    static final public String HTTPS = "HTTPS";
     60    static final public String FTP = "FTP";
     61   
    5862    static final public String CONNECTION_PREFS = "connection";
    5963    static final public String GENERAL_PREFS = "general";
     
    8690    private JRadioButton expert_mode_radio_button;
    8791    private JRadioButton librarian_mode_radio_button;
    88     private JSpinner proxy_port_field;
     92    private JSpinner http_proxy_port_field;
     93    private JSpinner https_proxy_port_field;
     94    private JSpinner ftp_proxy_port_field;
    8995    private JTabbedPane tab_pane;
    9096    private JTextArea mode_description_textarea;
     
    9399    private JTextField library_path_field;
    94100    private JTextField program_field;
    95     private JTextField proxy_host_field;
     101    private JTextField http_proxy_host_field;
     102    private JTextField https_proxy_host_field;
     103    private JTextField ftp_proxy_host_field;
    96104    private JTextField collect_dir_field;
    97105
     
    337345    use_proxy_checkbox.setPreferredSize(ROW_SIZE);
    338346   
    339         JPanel proxy_host_pane = new JPanel();
    340         proxy_host_pane.setComponentOrientation(Dictionary.getOrientation());
    341     proxy_host_pane.setPreferredSize(ROW_SIZE);
    342        
    343     JLabel proxy_host_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Host"));
    344         proxy_host_label.setComponentOrientation(Dictionary.getOrientation());
    345     proxy_host_label.setPreferredSize(LABEL_SIZE);
    346    
    347     proxy_host_field = new JTextField(Configuration.getString("general.proxy_host", true));
    348     proxy_host_field.setEnabled(currently_enabled);
    349     proxy_host_field.setToolTipText(Dictionary.get("Preferences.Connection.Proxy_Host_Tooltip"));
    350     proxy_host_field.setComponentOrientation(Dictionary.getOrientation());
    351        
    352     JPanel proxy_port_pane = new JPanel();
    353         proxy_port_pane.setComponentOrientation(Dictionary.getOrientation());
    354     proxy_port_pane.setPreferredSize(ROW_SIZE);
    355        
    356     JLabel proxy_port_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Port"));
    357     proxy_port_label.setPreferredSize(LABEL_SIZE);
    358         proxy_port_label.setComponentOrientation(Dictionary.getOrientation());
    359    
    360     String port_value = Configuration.getString("general.proxy_port", true);
    361     if(port_value.length() > 0) {
    362        proxy_port_field = new JSpinner(new SpinnerNumberModel((new Integer(port_value)).intValue(), 0, 65535, 1));
    363     }
    364     else {
    365        proxy_port_field = new JSpinner(new SpinnerNumberModel(0, 0, 65535, 1));
    366     }
    367     proxy_port_field.setEnabled(currently_enabled);
    368     proxy_port_field.setToolTipText(Dictionary.get("Preferences.Connection.Proxy_Port_Tooltip"));
    369347   
    370348    // Connection
     
    405383    collect_dir_pane.add(chdir_button, BorderLayout.LINE_END);
    406384
    407     proxy_host_pane.setLayout(new BorderLayout());
    408     proxy_host_pane.add(proxy_host_label, BorderLayout.LINE_START);
    409     proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
    410 
    411     proxy_port_pane.setLayout(new BorderLayout());
    412     proxy_port_pane.add(proxy_port_label, BorderLayout.LINE_START);
    413     proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
    414385
    415386    connection_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    416     connection_pane.setLayout(new GridLayout(9,1,0,2));
     387    connection_pane.setLayout(new GridLayout(10,1,0,2));
    417388    connection_pane.add(program_pane);
    418389    connection_pane.add(library_path_pane);
     
    428399    connection_pane.add(no_check_certificate_checkbox);
    429400    connection_pane.add(use_proxy_checkbox);
    430     connection_pane.add(proxy_host_pane);
    431     connection_pane.add(proxy_port_pane);
     401   
     402    // set up the proxy host and port fields for each of http, https and ftp   
     403        setupProxyHostPane(HTTP, connection_pane, currently_enabled, http_proxy_host_field, http_proxy_port_field);
     404    setupProxyHostPane(HTTPS, connection_pane, currently_enabled, https_proxy_host_field, https_proxy_port_field);
     405    setupProxyHostPane(FTP, connection_pane, currently_enabled, ftp_proxy_host_field, ftp_proxy_port_field);
    432406
    433407    return connection_pane;
     
    570544    return general_pane;
    571545    }
     546
     547    private void setupProxyHostPane(String protocol, JPanel connection_pane, boolean isEnabled,
     548                    JTextField proxy_host_field, JSpinner proxy_port_field)
     549    {
     550    final Dimension WIDER_LABEL_SIZE = new Dimension(180, 25);
     551    final Dimension NARROWER_LABEL_SIZE = new Dimension(60, 25);
     552    final Dimension WIDER_ROW_SIZE = new Dimension(480, 25);
     553    final Dimension NARROWER_ROW_SIZE = new Dimension(120, 25);
     554   
     555    JPanel proxy_host_pane = new JPanel();
     556        proxy_host_pane.setComponentOrientation(Dictionary.getOrientation());
     557    proxy_host_pane.setPreferredSize(WIDER_ROW_SIZE);
     558       
     559    JLabel proxy_host_label = new JLabel(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Host"));
     560        proxy_host_label.setComponentOrientation(Dictionary.getOrientation());
     561    proxy_host_label.setPreferredSize(WIDER_LABEL_SIZE);
     562   
     563    proxy_host_field = new JTextField(Configuration.getString("general."+protocol+"_proxy_host", true));
     564    proxy_host_field.setEnabled(isEnabled);
     565    proxy_host_field.setToolTipText(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Host_Tooltip"));
     566    proxy_host_field.setComponentOrientation(Dictionary.getOrientation());
     567       
     568    JPanel proxy_port_pane = new JPanel();
     569        proxy_port_pane.setComponentOrientation(Dictionary.getOrientation());
     570    proxy_port_pane.setPreferredSize(NARROWER_ROW_SIZE);
     571       
     572    JLabel proxy_port_label = new JLabel(Dictionary.get("Preferences.Connection.Proxy_Port"));
     573    proxy_port_label.setPreferredSize(NARROWER_LABEL_SIZE);
     574        proxy_port_label.setComponentOrientation(Dictionary.getOrientation());
     575   
     576    String port_value = Configuration.getString("general."+protocol+"_proxy_port", true);
     577    if(port_value.length() > 0) {
     578       proxy_port_field = new JSpinner(new SpinnerNumberModel((new Integer(port_value)).intValue(), 0, 65535, 1));
     579    }
     580    else {
     581       proxy_port_field = new JSpinner(new SpinnerNumberModel(0, 0, 65535, 1));
     582    }
     583    proxy_port_field.setEnabled(isEnabled);
     584    proxy_port_field.setToolTipText(Dictionary.get("Preferences.Connection."+protocol+"_Proxy_Port_Tooltip"));
     585
     586
     587    // Since the actual object member vars were null when this method is called
     588    // need to ensure they are assigned the correct value now, else those refs will remain null
     589    if(protocol.equals(HTTP)) {
     590        http_proxy_host_field = proxy_host_field;
     591        http_proxy_port_field = proxy_port_field;
     592    } else if (protocol.equals(HTTPS)) {
     593        https_proxy_host_field = proxy_host_field;
     594        https_proxy_port_field = proxy_port_field;
     595    } else if(protocol.equals(FTP)) {
     596        ftp_proxy_host_field = proxy_host_field;
     597        ftp_proxy_port_field = proxy_port_field;
     598    }
     599   
     600    proxy_host_pane.setLayout(new BorderLayout());
     601    proxy_host_pane.add(proxy_host_label, BorderLayout.LINE_START);
     602    proxy_host_pane.add(proxy_host_field, BorderLayout.CENTER);
     603
     604    proxy_port_pane.setLayout(new BorderLayout());
     605    proxy_port_pane.add(proxy_port_label, BorderLayout.LINE_START);
     606    proxy_port_pane.add(proxy_port_field, BorderLayout.CENTER);
     607
     608    //connection_pane.add(proxy_host_pane);
     609    //connection_pane.add(proxy_port_pane);
     610
     611    JPanel proxy_panel = new JPanel();
     612    proxy_panel.setLayout(new BorderLayout()); 
     613    proxy_panel.add(proxy_host_pane, BorderLayout.WEST);
     614    proxy_panel.add(proxy_port_pane, BorderLayout.CENTER);
     615
     616    connection_pane.add(proxy_panel);
     617    }
     618   
    572619
    573620    /** Generate the controls for altering the detail mode.
     
    786833        this.close = close;
    787834    }
     835
     836    private void setProxyHostForProtocol(String protocol,
     837                         JTextField proxy_host_field,
     838                         JSpinner proxy_port_field)
     839    {       
     840        Configuration.setString("general."+protocol+"_proxy_host", true, proxy_host_field.getText());
     841        Configuration.setString("general."+protocol+"_proxy_port", true, proxy_port_field.getValue() + "");
     842    }
     843   
    788844    public void actionPerformed(ActionEvent event)
    789845    {
     
    876932       
    877933        Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
    878         Configuration.setString("general.proxy_host", true, proxy_host_field.getText());
    879         Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
     934        setProxyHostForProtocol(HTTP, http_proxy_host_field, http_proxy_port_field);
     935        setProxyHostForProtocol(HTTPS, https_proxy_host_field, https_proxy_port_field);
     936        setProxyHostForProtocol(FTP, ftp_proxy_host_field, ftp_proxy_port_field);
    880937        Gatherer.setProxy();
    881938
     
    9751032
    9761033        // If proxy is on but proxy details are incomplete, then can't continue
    977         if (use_proxy_checkbox.isSelected() && proxy_host_field.getText().equals("")) {
     1034        if (use_proxy_checkbox.isSelected()
     1035        && http_proxy_host_field.getText().equals("")
     1036        && https_proxy_host_field.getText().equals("")
     1037        && ftp_proxy_host_field.getText().equals("")) {
    9781038        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Preferences.Connection.Proxy_Host_Missing"),
    9791039                          Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     
    11441204        Configuration.set("general.use_proxy", true, enabled);
    11451205        // Fortunately this is already driven by the event thread.
    1146         proxy_host_field.setEnabled(enabled);
    1147         proxy_port_field.setEnabled(enabled);
     1206        http_proxy_host_field.setEnabled(enabled);
     1207        http_proxy_port_field.setEnabled(enabled);
     1208        https_proxy_host_field.setEnabled(enabled);
     1209        https_proxy_port_field.setEnabled(enabled);
     1210        ftp_proxy_host_field.setEnabled(enabled);
     1211        ftp_proxy_port_field.setEnabled(enabled);
    11481212    }
    11491213    }
Note: See TracChangeset for help on using the changeset viewer.