added the handler component to deal with arbitrary changes
This commit is contained in:
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,9 +15,19 @@
|
|||||||
|
|
||||||
<div class="main" id="main">
|
<div class="main" id="main">
|
||||||
<%@include file="confignav.jsp" %>
|
<%@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">
|
<form action="configadvanced.jsp" method="POST">
|
||||||
<textarea rows="20" cols="80" name="config"><jsp:getProperty name="advancedhelper" property="settings" /></textarea><br />
|
<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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user