JAL-3633 getdown reads jalview_properties for proxy settings
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 25 Mar 2021 02:11:38 +0000 (02:11 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 25 Mar 2021 02:11:38 +0000 (02:11 +0000)
build.gradle
getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/ProxyPanel.java
getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java

index 6dac841..c5e9787 100644 (file)
@@ -1673,6 +1673,7 @@ task getdownWebsite() {
       from launchJvl
       from getdownLauncher
       from "${getdownWebsiteDir}/${getdown_build_properties}"
+      from "${getdownWebsiteDir}/${channel_props}"
       if (file(getdownLauncher).getName() != getdown_launcher) {
         rename(file(getdownLauncher).getName(), getdown_launcher)
       }
index 2178273..5d697df 100644 (file)
@@ -40,6 +40,12 @@ public final class ProxyPanel extends JPanel implements ActionListener
         _getdown = getdown;
         _msgs = msgs;
 
+        String[] hostPortAuthUser = ProxyUtil.jalviewProxyProperties(getdown._app);
+        String host = hostPortAuthUser[0];
+        String port = hostPortAuthUser[1];
+        boolean proxyAuth = Boolean.parseBoolean(hostPortAuthUser[2]);
+        String username = hostPortAuthUser[3];
+
         setLayout(new VGroupLayout());
         setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
         add(new SaneLabelField(get("m.configure_proxy")));
@@ -48,11 +54,13 @@ public final class ProxyPanel extends JPanel implements ActionListener
         JPanel row = new JPanel(new GridLayout());
         row.add(new SaneLabelField(get("m.proxy_host")), BorderLayout.WEST);
         row.add(_host = new SaneTextField());
+        _host.setText(host);
         add(row);
 
         row = new JPanel(new GridLayout());
         row.add(new SaneLabelField(get("m.proxy_port")), BorderLayout.WEST);
         row.add(_port = new SaneTextField());
+        _port.setText(port);
         add(row);
 
         add(new Spacer(5, 5));
@@ -60,20 +68,22 @@ public final class ProxyPanel extends JPanel implements ActionListener
         row = new JPanel(new GridLayout());
         row.add(new SaneLabelField(get("m.proxy_auth_required")), BorderLayout.WEST);
         _useAuth = new JCheckBox();
+        _useAuth.setSelected(proxyAuth);
         row.add(_useAuth);
         add(row);
 
         row = new JPanel(new GridLayout());
         row.add(new SaneLabelField(get("m.proxy_username")), BorderLayout.WEST);
         _username = new SaneTextField();
-        _username.setEnabled(false);
+        _username.setText(username);
+        _username.setEnabled(_useAuth.isSelected());
         row.add(_username);
         add(row);
 
         row = new JPanel(new GridLayout());
         row.add(new SaneLabelField(get("m.proxy_password")), BorderLayout.WEST);
         _password = new SanePasswordField();
-        _password.setEnabled(false);
+        _password.setEnabled(_useAuth.isSelected());
         row.add(_password);
         add(row);
 
index a36b5fa..6295df4 100644 (file)
@@ -6,8 +6,10 @@
 package com.threerings.getdown.launcher;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintStream;
 import java.net.Authenticator;
 import java.net.HttpURLConnection;
@@ -19,6 +21,9 @@ import java.net.URLConnection;
 import java.util.Iterator;
 import java.util.ServiceLoader;
 
+import jalview.bin.LaunchUtils;
+import jalview.util.ChannelProperties;
+
 import ca.beq.util.win32.registry.RegistryKey;
 import ca.beq.util.win32.registry.RegistryValue;
 import ca.beq.util.win32.registry.RootKey;
@@ -88,15 +93,51 @@ public class ProxyUtil {
             port = hostPort[1];
         }
 
+        // look in jalview_properties
+        String[] hostPortAuthUser = jalviewProxyProperties(app);
+        host = hostPortAuthUser[0];
+        port = hostPortAuthUser[1];
+        boolean proxyAuth = Boolean.parseBoolean(hostPortAuthUser[2]);
+        String username = hostPortAuthUser[3];
+
         if (StringUtil.isBlank(host)) {
             return false;
         }
 
         // yay, we found a proxy configuration, configure it in the app
-        initProxy(app, host, port, null, null);
+        initProxy(app, host, port, username, null);
         return true;
     }
 
+    public static String[] jalviewProxyProperties(Application app) {
+      String host = null;
+      String port = null;
+      boolean proxyAuth = false;
+      String username = null;
+      File channelProps = app.getLocalPath(ChannelProperties.CHANNEL_PROPERTIES_FILENAME);
+      if (channelProps.exists()) {
+        try {
+          InputStream is = new FileInputStream(channelProps);
+          ChannelProperties.loadProps(is);
+        } catch (IOException e) {
+          log.error(e.getMessage());
+        }
+        if (Boolean.parseBoolean(LaunchUtils.getUserPreference("USE_PROXY"))) {
+          host = LaunchUtils.getUserPreference("PROXY_SERVER_HTTPS");
+          port = LaunchUtils.getUserPreference("PROXY_PORT_HTTPS");
+          if (StringUtil.isBlank(host)) {
+            host = LaunchUtils.getUserPreference("PROXY_SERVER");
+            port = LaunchUtils.getUserPreference("PROXY_PORT");
+          }
+          proxyAuth = Boolean.parseBoolean(LaunchUtils.getUserPreference("PROXY_AUTH"));
+          if (proxyAuth) {
+            username = LaunchUtils.getUserPreference("PROXY_AUTH_USERNAME");
+          }
+        }
+      }
+      return new String[]{ host, port, String.valueOf(proxyAuth), username };
+    }
+
     public static boolean canLoadWithoutProxy (URL rurl)
     {
         log.info("Testing whether proxy is needed, via: " + rurl);
@@ -179,6 +220,7 @@ public class ProxyUtil {
     public static void initProxy (Application app, String host, String port,
                                   String username, String password)
     {
+System.out.println("**** initProxy(app, '"+host+"', "+port+", '"+username+"', "+(password==null?"null":"*x"+password.length())+")");
         // check whether we have saved proxy credentials
         String appDir = app.getAppDir().getAbsolutePath();
         ServiceLoader<ProxyAuth> loader = ServiceLoader.load(ProxyAuth.class);