From a5e3bc9b853662baf5588ec0632118f8e9b43f7a Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Fri, 4 Oct 2013 20:21:54 +0000
Subject: [PATCH]  Update:  - New config for proxying news, separate from
 proxying update  - Default logic cleanup

---
 .../src/net/i2p/router/update/NewsFetcher.java   |  2 +-
 .../i2p/router/update/PluginUpdateRunner.java    |  2 +-
 .../src/net/i2p/router/update/UpdateRunner.java  |  2 +-
 .../net/i2p/router/web/ConfigUpdateHandler.java  | 16 +++++++++++++---
 .../net/i2p/router/web/ConfigUpdateHelper.java   | 11 +++++++++--
 apps/routerconsole/jsp/configupdate.jsp          |  2 ++
 6 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java b/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java
index edd3ddbae0..9de3156b12 100644
--- a/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java
+++ b/apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java
@@ -73,7 +73,7 @@ class NewsFetcher extends UpdateRunner {
     }
 
     public void fetchNews() {
-        boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
+        boolean shouldProxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY_NEWS, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY_NEWS);
         String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
         int proxyPort = ConfigUpdateHandler.proxyPort(_context);
 
diff --git a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java
index a7646afc79..78e03e0365 100644
--- a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java
+++ b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java
@@ -98,7 +98,7 @@ class PluginUpdateRunner extends UpdateRunner {
             } else {
                 updateStatus("<b>" + _("Downloading plugin from {0}", _xpi2pURL) + "</b>");
                 // use the same settings as for updater
-                boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
+                boolean shouldProxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY);
                 String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
                 int proxyPort = ConfigUpdateHandler.proxyPort(_context);
                 try {
diff --git a/apps/routerconsole/java/src/net/i2p/router/update/UpdateRunner.java b/apps/routerconsole/java/src/net/i2p/router/update/UpdateRunner.java
index c3b388db2a..98055fa2df 100644
--- a/apps/routerconsole/java/src/net/i2p/router/update/UpdateRunner.java
+++ b/apps/routerconsole/java/src/net/i2p/router/update/UpdateRunner.java
@@ -149,7 +149,7 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
         int proxyPort;
         boolean isSSL = false;
         if (_method == HTTP) {
-            shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
+            shouldProxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY);
             proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
             proxyPort = ConfigUpdateHandler.proxyPort(_context);
         } else if (_method == HTTP_CLEARNET) {
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java
index 72486b68bc..abbddd0833 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java
@@ -23,6 +23,7 @@ public class ConfigUpdateHandler extends FormHandler {
     private String _proxyHost;
     private String _proxyPort;
     private boolean _updateThroughProxy;
+    private boolean _newsThroughProxy;
     private String _trustedKeys;
     private boolean _updateUnsigned;
     private String _zipURL;
@@ -37,7 +38,11 @@ public class ConfigUpdateHandler extends FormHandler {
     public static final String PROP_UPDATE_POLICY = "router.updatePolicy";
     public static final String DEFAULT_UPDATE_POLICY = "download";
     public static final String PROP_SHOULD_PROXY = "router.updateThroughProxy";
-    public static final String DEFAULT_SHOULD_PROXY = Boolean.TRUE.toString();
+    public static final boolean DEFAULT_SHOULD_PROXY = true;
+    /** @since 0.9.9 */
+    public static final String PROP_SHOULD_PROXY_NEWS = "router.fetchNewsThroughProxy";
+    /** @since 0.9.9 */
+    public static final boolean DEFAULT_SHOULD_PROXY_NEWS = true;
     public static final String PROP_PROXY_HOST = "router.updateProxyHost";
     public static final String DEFAULT_PROXY_HOST = "127.0.0.1";
     public static final String PROP_PROXY_PORT = "router.updateProxyPort";
@@ -164,6 +169,8 @@ public class ConfigUpdateHandler extends FormHandler {
         Map<String, String> changes = new HashMap();
 
         if ( (_newsURL != null) && (_newsURL.length() > 0) ) {
+            if (_newsURL.startsWith("https"))
+                _newsThroughProxy = false;
             String oldURL = ConfigUpdateHelper.getNewsURL(_context);
             if ( (oldURL == null) || (!_newsURL.equals(oldURL)) ) {
                 changes.put(PROP_NEWS_URL, _newsURL);
@@ -189,8 +196,9 @@ public class ConfigUpdateHandler extends FormHandler {
             }
         }
         
-        changes.put(PROP_SHOULD_PROXY, "" + _updateThroughProxy);
-        changes.put(PROP_UPDATE_UNSIGNED, "" + _updateUnsigned);
+        changes.put(PROP_SHOULD_PROXY, Boolean.toString(_updateThroughProxy));
+        changes.put(PROP_SHOULD_PROXY_NEWS, Boolean.toString(_newsThroughProxy));
+        changes.put(PROP_UPDATE_UNSIGNED, Boolean.toString(_updateUnsigned));
         
         String oldFreqStr = _context.getProperty(PROP_REFRESH_FREQUENCY, DEFAULT_REFRESH_FREQUENCY);
         long oldFreq = DEFAULT_REFRESH_FREQ;
@@ -252,4 +260,6 @@ public class ConfigUpdateHandler extends FormHandler {
     public void setProxyPort(String port) { _proxyPort = port; }
     public void setUpdateUnsigned(String foo) { _updateUnsigned = true; }
     public void setZipURL(String url) { _zipURL = url; }
+     /** @since 0.9.9 */
+    public void setNewsThroughProxy(String foo) { _newsThroughProxy = true; }
 }
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java
index 7fecfc85f5..037acb8bc9 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java
@@ -73,13 +73,20 @@ public class ConfigUpdateHelper extends HelperBase {
     }
     
     public String getUpdateThroughProxy() {
-        String proxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY);
-        if (Boolean.parseBoolean(proxy)) 
+        if (_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY))
             return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateThroughProxy\" checked=\"checked\" >";
         else
             return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateThroughProxy\" >";
     }
     
+    /** @since 0.9.9 */
+    public String getNewsThroughProxy() {
+        if (_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY_NEWS, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY_NEWS))
+            return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"newsThroughProxy\" checked=\"checked\" >";
+        else
+            return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"newsThroughProxy\" >";
+    }
+    
     public String getUpdateUnsigned() {
         if (_context.getBooleanProperty(ConfigUpdateHandler.PROP_UPDATE_UNSIGNED))
             return "<input type=\"checkbox\" class=\"optbox\" value=\"true\" name=\"updateUnsigned\" checked=\"checked\" >";
diff --git a/apps/routerconsole/jsp/configupdate.jsp b/apps/routerconsole/jsp/configupdate.jsp
index 2fd5e65360..c29a9a95da 100644
--- a/apps/routerconsole/jsp/configupdate.jsp
+++ b/apps/routerconsole/jsp/configupdate.jsp
@@ -48,6 +48,8 @@
         <tr><td class="mediumtags" align="right"><b><%=formhandler._("Update policy")%>:</b></td>
           <td><jsp:getProperty name="updatehelper" property="updatePolicySelectBox" /></td></tr>
     <% }   // if canInstall %>
+        <tr><td class="mediumtags" align="right"><b><%=intl._("Fetch news through the eepProxy?")%></b></td>
+          <td><jsp:getProperty name="updatehelper" property="newsThroughProxy" /></td></tr>
         <tr><td class="mediumtags" align="right"><b><%=intl._("Update through the eepProxy?")%></b></td>
           <td><jsp:getProperty name="updatehelper" property="updateThroughProxy" /></td></tr>
       <% if (updatehelper.isAdvanced()) { %>
-- 
GitLab