diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..e2861908aa6016593643c3b57a967e009bb0ee0c --- /dev/null +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigAdvancedHandler.java @@ -0,0 +1,74 @@ +package net.i2p.router.web; + +import java.io.ByteArrayInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * Handler to deal with form submissions from the advanced config form and act + * upon the values. + * + */ +public class ConfigAdvancedHandler extends FormHandler { + private boolean _forceRestart; + private boolean _shouldSave; + private String _config; + + public void ConfigNetHandler() { + _shouldSave = false; + _forceRestart = false; + } + + protected void processForm() { + if (_shouldSave) { + saveChanges(); + } else { + // noop + } + } + + public void setShouldsave(String moo) { _shouldSave = true; } + public void setRestart(String moo) { _forceRestart = true; } + + public void setConfig(String val) { + _config = val; + } + + /** + * The user made changes to the config and wants to save them, so + * lets go ahead and do so. + * + */ + private void saveChanges() { + if (_config != null) { + BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(_config.getBytes()))); + String line = null; + try { + while ( (line = reader.readLine()) != null) { + int eq = line.indexOf('='); + if (eq == -1) continue; + if (eq >= line.length() - 1) continue; + String key = line.substring(0, eq).trim(); + String val = line.substring(eq + 1).trim(); + _context.router().setConfigSetting(key, val); + } + } catch (IOException ioe) { + addFormError("Error updating the configuration (IOERROR) - please see the error logs"); + return; + } + + boolean saved = _context.router().saveConfig(); + if (saved) + addFormNotice("Configuration saved successfully"); + else + addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs"); + + if (_forceRestart) { + addFormNotice("Performing a soft restart"); + _context.router().restart(); + addFormNotice("Soft restart complete"); + } + } + } +} diff --git a/apps/routerconsole/jsp/configadvanced.jsp b/apps/routerconsole/jsp/configadvanced.jsp index 43743c32cf98558d14c69d66359a41b4ebabd5b1..f1c0504d26adf3d40c878a2af76757fd5c765810 100644 --- a/apps/routerconsole/jsp/configadvanced.jsp +++ b/apps/routerconsole/jsp/configadvanced.jsp @@ -15,9 +15,19 @@ <div class="main" id="main"> <%@include file="confignav.jsp" %> + + <jsp:useBean class="net.i2p.router.web.ConfigAdvancedHandler" id="formhandler" scope="request" /> + <jsp:setProperty name="formhandler" property="*" /> + <jsp:setProperty name="formhandler" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" /> + <font color="red"><jsp:getProperty name="formhandler" property="errors" /></font> + <i><jsp:getProperty name="formhandler" property="notices" /></i> + <form action="configadvanced.jsp" method="POST"> <textarea rows="20" cols="80" name="config"><jsp:getProperty name="advancedhelper" property="settings" /></textarea><br /> - <input type="submit" value="Apply" /> <input type="reset" value="Cancel" /> + <input type="submit" name="shouldsave" value="Apply" /> <input type="reset" value="Cancel" /> <br /> + <b>Force restart:</b> <input type="checkbox" name="restart" value="force" /> <i>(specify this + if the changes made above require the router to reset itself - e.g. you are updating TCP ports + or hostnames, etc)</i> </form> </div>