From 2fafa3337fd33704bec6e1693a40c4e57b69f074 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sun, 3 May 2015 18:49:34 +0000
Subject: [PATCH] Console: Add floodfill configuration form to /configadvanced

---
 .../i2p/router/web/ConfigAdvancedHandler.java | 20 +++++++++++++++++--
 .../i2p/router/web/ConfigAdvancedHelper.java  | 15 ++++++++++++--
 apps/routerconsole/jsp/configadvanced.jsp     | 16 ++++++++++++++-
 3 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHandler.java
index aa853f0ccb..345f17b0d6 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHandler.java
@@ -17,14 +17,18 @@ public class ConfigAdvancedHandler extends FormHandler {
     //private boolean _forceRestart;
     private boolean _shouldSave;
     private String _config;
+    private String _ff;
     
     @Override
     protected void processForm() {
         if (_shouldSave) {
-            if (isAdvanced())
+            if ("ff".equals(_action) && _ff != null) {
+                saveFF();
+            } else if (isAdvanced()) {
                 saveChanges();
-            else
+            } else {
                 addFormError("Save disabled, edit the router.config file to make changes") ;
+            }
         } else {
             // noop
         }
@@ -33,6 +37,9 @@ public class ConfigAdvancedHandler extends FormHandler {
     public void setShouldsave(String moo) { _shouldSave = true; }
     //public void setRestart(String moo) { _forceRestart = true; }
     
+    /** @since 0.9.20 */
+    public void setFf(String ff) { _ff = ff; }
+
     public void setNofilter_config(String val) {
         _config = val;
     }
@@ -72,4 +79,13 @@ public class ConfigAdvancedHandler extends FormHandler {
             //}
         }
     }
+
+    /** @since 0.9.20 */
+    private void saveFF() {
+        boolean saved = _context.router().saveConfig(ConfigAdvancedHelper.PROP_FLOODFILL_PARTICIPANT, _ff);
+        if (saved) 
+            addFormNotice(_("Configuration saved successfully"));
+        else
+            addFormError(_("Error saving the configuration (applied but not saved) - please see the error logs"));
+    }
 }
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHelper.java
index cbdad00372..c64cb2e5a9 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHelper.java
@@ -6,8 +6,9 @@ import java.util.TreeMap;
 import net.i2p.data.DataHelper;
 
 public class ConfigAdvancedHelper extends HelperBase {
-    public ConfigAdvancedHelper() {}
-    
+    private final static String CHECKED = " checked=\"checked\" ";
+    static final String PROP_FLOODFILL_PARTICIPANT = "router.floodfillParticipant";
+
     public String getSettings() {
         StringBuilder buf = new StringBuilder(4*1024);
         TreeMap<String, String> sorted = new TreeMap<String, String>();
@@ -24,4 +25,14 @@ public class ConfigAdvancedHelper extends HelperBase {
     public String getConfigFileName() {
         return _context.router().getConfigFilename();
     }
+
+    /** @since 0.9.20 */
+    public String getFFChecked(int mode) {
+        String ff = _context.getProperty(PROP_FLOODFILL_PARTICIPANT, "auto");
+        if ((mode == 0 && ff.equals("false")) ||
+            (mode == 1 && ff.equals("true")) ||
+            (mode == 2 && ff.equals("auto")))
+            return CHECKED;
+        return "";
+    }
 }
diff --git a/apps/routerconsole/jsp/configadvanced.jsp b/apps/routerconsole/jsp/configadvanced.jsp
index c6f0e78fbb..637020405e 100644
--- a/apps/routerconsole/jsp/configadvanced.jsp
+++ b/apps/routerconsole/jsp/configadvanced.jsp
@@ -24,12 +24,26 @@
 <%@include file="formhandler.jsi" %>
  <div class="configure">
  <div class="wideload">
+<h3><%=intl._("Floodfill Configuration")%></h3>
+<p><%=intl._("Floodill participation helps the network, but may use more of your computer's resources.")%></p>
+<form action="" method="POST">
+<input type="hidden" name="nonce" value="<%=pageNonce%>" >
+<input type="hidden" name="action" value="ff" >
+<input type="radio" class="optbox" name="ff" value="auto" <%=advancedhelper.getFFChecked(2) %> >
+<%=intl._("Automatic")%><br>
+<input type="radio" class="optbox" name="ff" value="true" <%=advancedhelper.getFFChecked(1) %> >
+<%=intl._("Force On")%><br>
+<input type="radio" class="optbox" name="ff" value="false" <%=advancedhelper.getFFChecked(0) %> >
+<%=intl._("Disable")%><br>
+<div class="formaction">
+<input type="submit" name="shouldsave" class="accept" value="<%=intl._("Save changes")%>" >
+</div></form>
+<h3><%=intl._("Advanced I2P Configuration")%></h3>
 <% if (advancedhelper.isAdvanced()) { %>
  <form action="" method="POST">
  <input type="hidden" name="nonce" value="<%=pageNonce%>" >
  <input type="hidden" name="action" value="blah" >
 <% }  // isAdvanced %>
- <h3><%=intl._("Advanced I2P Configuration")%></h3>
  <textarea rows="32" cols="60" name="nofilter_config" wrap="off" spellcheck="false" <% if (!advancedhelper.isAdvanced()) { %>readonly="readonly"<% } %>><jsp:getProperty name="advancedhelper" property="settings" /></textarea><br><hr>
 <% if (advancedhelper.isAdvanced()) { %>
       <div class="formaction">
-- 
GitLab