* configclients.jsp: Implement saves for clients and webapps.

This commit is contained in:
zzz
2008-06-17 13:48:41 +00:00
parent 91950a37f5
commit f3d73a6c15
6 changed files with 85 additions and 55 deletions

View File

@ -1,59 +1,63 @@
package net.i2p.router.web; package net.i2p.router.web;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set;
import net.i2p.data.DataFormatException; import net.i2p.data.DataFormatException;
import net.i2p.router.startup.ClientAppConfig;
import net.i2p.util.Log; import net.i2p.util.Log;
/** /**
* * Saves changes to clients.config or webapps.config
*/ */
public class ConfigClientsHandler extends FormHandler { public class ConfigClientsHandler extends FormHandler {
private Log _log; private Log _log;
private Map _settings; private Map _settings;
private boolean _shouldSave;
public ConfigClientsHandler() { public ConfigClientsHandler() {}
_shouldSave = false;
}
protected void processForm() { protected void processForm() {
if (_shouldSave) { if (_action.startsWith("Save Client")) {
saveChanges(); saveClientChanges();
} else if (_action.startsWith("Save WebApp")) {
saveWebAppChanges();
} else { } else {
// noop addFormError("Unsupported " + _action);
addFormError("Unimplemented");
} }
} }
public void setShouldsave(String moo) {
if ( (moo != null) && (moo.equals("Save changes")) )
_shouldSave = true;
}
public void setSettings(Map settings) { _settings = new HashMap(settings); } public void setSettings(Map settings) { _settings = new HashMap(settings); }
/** private void saveClientChanges() {
* The user made changes to the network config and wants to save them, so List clients = ClientAppConfig.getClientApps(_context);
* lets go ahead and do so. for (int cur = 0; cur < clients.size(); cur++) {
* ClientAppConfig ca = (ClientAppConfig) clients.get(cur);
*/ Object val = _settings.get(cur + ".enabled");
private void saveChanges() { if (! "webConsole".equals(ca.clientName))
_log = _context.logManager().getLog(ConfigClientsHandler.class); ca.disabled = val == null;
boolean saveRequired = false; }
ClientAppConfig.writeClientAppConfig(_context, clients);
addFormNotice("Client configuration saved successfully - restart required to take effect");
}
int updated = 0; private void saveWebAppChanges() {
int index = 0; Properties props = RouterConsoleRunner.webAppProperties();
Set keys = props.keySet();
if (updated > 0) int cur = 0;
addFormNotice("Updated settings"); for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
String name = (String)iter.next();
if (saveRequired) { if (! (name.startsWith(RouterConsoleRunner.PREFIX) && name.endsWith(RouterConsoleRunner.ENABLED)))
boolean saved = _context.router().saveConfig(); continue;
if (saved) String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED));
addFormNotice("Exploratory tunnel configuration saved successfully"); Object val = _settings.get(app + ".enabled");
else if (! RouterConsoleRunner.ROUTERCONSOLE.equals(app))
addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs"); props.setProperty(name, "" + (val != null));
} }
RouterConsoleRunner.storeWebAppProperties(props);
addFormNotice("WebApp configuration saved successfully - restart required to take effect");
} }
} }

View File

@ -26,7 +26,6 @@ public class ConfigClientsHelper {
public ConfigClientsHelper() {} public ConfigClientsHelper() {}
public String getForm1() { public String getForm1() {
StringBuffer buf = new StringBuffer(1024); StringBuffer buf = new StringBuffer(1024);
buf.append("<table border=\"1\">\n"); buf.append("<table border=\"1\">\n");
@ -35,7 +34,7 @@ public class ConfigClientsHelper {
List clients = ClientAppConfig.getClientApps(_context); List clients = ClientAppConfig.getClientApps(_context);
for (int cur = 0; cur < clients.size(); cur++) { for (int cur = 0; cur < clients.size(); cur++) {
ClientAppConfig ca = (ClientAppConfig) clients.get(cur); ClientAppConfig ca = (ClientAppConfig) clients.get(cur);
renderForm(buf, cur, ca.clientName, false, !ca.disabled, "webConsole".equals(ca.clientName), ca.className + " " + ca.args); renderForm(buf, ""+cur, ca.clientName, false, !ca.disabled, "webConsole".equals(ca.clientName), ca.className + " " + ca.args);
} }
buf.append("</table>\n"); buf.append("</table>\n");
@ -48,21 +47,19 @@ public class ConfigClientsHelper {
buf.append("<tr><td>WebApp</td><td>Enabled?</td><td>Description</td></tr>\n"); buf.append("<tr><td>WebApp</td><td>Enabled?</td><td>Description</td></tr>\n");
Properties props = RouterConsoleRunner.webAppProperties(); Properties props = RouterConsoleRunner.webAppProperties();
Set keys = new TreeSet(props.keySet()); Set keys = new TreeSet(props.keySet());
int cur = 0;
for (Iterator iter = keys.iterator(); iter.hasNext(); ) { for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
String name = (String)iter.next(); String name = (String)iter.next();
if (name.startsWith(RouterConsoleRunner.PREFIX) && name.endsWith(RouterConsoleRunner.ENABLED)) { if (name.startsWith(RouterConsoleRunner.PREFIX) && name.endsWith(RouterConsoleRunner.ENABLED)) {
String app = name.substring(8, name.lastIndexOf(RouterConsoleRunner.ENABLED)); String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED));
String val = props.getProperty(name); String val = props.getProperty(name);
renderForm(buf, cur, app, !"addressbook".equals(app), "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war"); renderForm(buf, app, app, !"addressbook".equals(app), "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war");
cur++;
} }
} }
buf.append("</table>\n"); buf.append("</table>\n");
return buf.toString(); return buf.toString();
} }
private void renderForm(StringBuffer buf, int index, String name, boolean urlify, boolean enabled, boolean ro, String desc) { private void renderForm(StringBuffer buf, String index, String name, boolean urlify, boolean enabled, boolean ro, String desc) {
buf.append("<tr><td>"); buf.append("<tr><td>");
if (urlify && enabled) { if (urlify && enabled) {
String link = "/"; String link = "/";
@ -72,7 +69,7 @@ public class ConfigClientsHelper {
} else { } else {
buf.append(name); buf.append(name);
} }
buf.append("</td><td align=\"center\"><input type=\"checkbox\" name=\"enable\" value=\"").append(index).append(".enabled\" "); buf.append("</td><td align=\"center\"><input type=\"checkbox\" name=\"").append(index).append(".enabled\" value=\"true\" ");
if (enabled) { if (enabled) {
buf.append("checked=\"true\" "); buf.append("checked=\"true\" ");
if (ro) if (ro)

View File

@ -18,7 +18,6 @@
<jsp:useBean class="net.i2p.router.web.ConfigClientsHandler" id="formhandler" scope="request" /> <jsp:useBean class="net.i2p.router.web.ConfigClientsHandler" id="formhandler" scope="request" />
<jsp:setProperty name="formhandler" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" /> <jsp:setProperty name="formhandler" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
<jsp:setProperty name="formhandler" property="shouldsave" value="<%=request.getParameter("shouldsave")%>" />
<jsp:setProperty name="formhandler" property="action" value="<%=request.getParameter("action")%>" /> <jsp:setProperty name="formhandler" property="action" value="<%=request.getParameter("action")%>" />
<jsp:setProperty name="formhandler" property="nonce" value="<%=request.getParameter("nonce")%>" /> <jsp:setProperty name="formhandler" property="nonce" value="<%=request.getParameter("nonce")%>" />
<jsp:setProperty name="formhandler" property="settings" value="<%=request.getParameterMap()%>" /> <jsp:setProperty name="formhandler" property="settings" value="<%=request.getParameterMap()%>" />
@ -30,7 +29,6 @@
if (prev != null) System.setProperty("net.i2p.router.web.ConfigClientsHandler.noncePrev", prev); if (prev != null) System.setProperty("net.i2p.router.web.ConfigClientsHandler.noncePrev", prev);
System.setProperty("net.i2p.router.web.ConfigClientsHandler.nonce", new java.util.Random().nextLong()+""); %> System.setProperty("net.i2p.router.web.ConfigClientsHandler.nonce", new java.util.Random().nextLong()+""); %>
<input type="hidden" name="nonce" value="<%=System.getProperty("net.i2p.router.web.ConfigClientsHandler.nonce")%>" /> <input type="hidden" name="nonce" value="<%=System.getProperty("net.i2p.router.web.ConfigClientsHandler.nonce")%>" />
<input type="hidden" name="action" value="blah" />
<h3>Client Configuration</h3> <h3>Client Configuration</h3>
<p> <p>
The Java clients listed below are started by the router and run in the same JVM. The Java clients listed below are started by the router and run in the same JVM.
@ -39,7 +37,7 @@
</p><p> </p><p>
<input type="submit" name="action" value="Save Client Configuration" /> <input type="submit" name="action" value="Save Client Configuration" />
</p><p> </p><p>
<i>All changes require restart to take effect. For other changes edit the clients.config file.</i> <i>All changes require restart to take effect. To change other client options, edit the clients.config file.</i>
</p> </p>
<hr /> <hr />
<h3>WebApp Configuration</h3> <h3>WebApp Configuration</h3>
@ -50,11 +48,15 @@
front-ends to another client or application which must be separately enabled (e.g. susidns, i2ptunnel), front-ends to another client or application which must be separately enabled (e.g. susidns, i2ptunnel),
or have no web interface at all (e.g. addressbook). or have no web interface at all (e.g. addressbook).
</p><p> </p><p>
A web app may also be disabled by removing the .war file from the webapps directory;
however the .war file and web app will reappear when you update your router to a newer version,
so disabling the web app here is the preferred method.
</p><p>
<jsp:getProperty name="clientshelper" property="form2" /> <jsp:getProperty name="clientshelper" property="form2" />
</p><p> </p><p>
<input type="submit" name="action" value="Save WebApp Configuration" /> <input type="submit" name="action" value="Save WebApp Configuration" />
</p><p> </p><p>
<i>All changes require restart to take effect. For other changes edit the webapps.config file.</i> <i>All changes require restart to take effect. To change other webapp options, edit the webapps.config file.</i>
</p> </p>
</form> </form>
</div> </div>

View File

@ -1,3 +1,9 @@
2008-06-17 zzz
* Comm System: Add new STATUS_HOSED for use when UDP bind fails
* Summary bar: Display helpful errror message when UDP bind fails
* UDP: Don't bid when UDP bind fails
* configclients.jsp: Implement saves for clients and webapps.
2008-06-16 zzz 2008-06-16 zzz
* UDP: Prevent 100% CPU when UDP bind fails; * UDP: Prevent 100% CPU when UDP bind fails;
change bind fail message from ERROR to CRIT change bind fail message from ERROR to CRIT
@ -12,7 +18,6 @@
* configclients.jsp: New. For both clients and webapps. * configclients.jsp: New. For both clients and webapps.
Saves are not yet implemented. Saves are not yet implemented.
2008-06-10 zzz 2008-06-10 zzz
* Floodfill: Add new FloodfillMonitorJob, which tracks active * Floodfill: Add new FloodfillMonitorJob, which tracks active
floodfills, and automatically enables/disables floodfill on floodfills, and automatically enables/disables floodfill on

View File

@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
public class RouterVersion { public class RouterVersion {
public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $"; public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $";
public final static String VERSION = "0.6.2"; public final static String VERSION = "0.6.2";
public final static long BUILD = 3; public final static long BUILD = 4;
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD); System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID); System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -2,6 +2,7 @@ package net.i2p.router.startup;
import java.io.IOException; import java.io.IOException;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -22,6 +23,7 @@ public class ClientAppConfig {
private static final String PROP_CLIENT_CONFIG_FILENAME = "router.clientConfigFile"; private static final String PROP_CLIENT_CONFIG_FILENAME = "router.clientConfigFile";
private static final String DEFAULT_CLIENT_CONFIG_FILENAME = "clients.config"; private static final String DEFAULT_CLIENT_CONFIG_FILENAME = "clients.config";
private static final String PREFIX = "clientApp.";
// let's keep this really simple // let's keep this really simple
public String className; public String className;
@ -63,14 +65,14 @@ public class ClientAppConfig {
List rv = new ArrayList(5); List rv = new ArrayList(5);
int i = 0; int i = 0;
while (true) { while (true) {
String className = clientApps.getProperty("clientApp."+i+".main"); String className = clientApps.getProperty(PREFIX + i + ".main");
if (className == null) if (className == null)
break; break;
String clientName = clientApps.getProperty("clientApp."+i+".name"); String clientName = clientApps.getProperty(PREFIX + i + ".name");
String args = clientApps.getProperty("clientApp."+i+".args"); String args = clientApps.getProperty(PREFIX + i + ".args");
String delayStr = clientApps.getProperty("clientApp." + i + ".delay"); String delayStr = clientApps.getProperty(PREFIX + i + ".delay");
String onBoot = clientApps.getProperty("clientApp." + i + ".onBoot"); String onBoot = clientApps.getProperty(PREFIX + i + ".onBoot");
String disabled = clientApps.getProperty("clientApp." + i + ".startOnLoad"); String disabled = clientApps.getProperty(PREFIX + i + ".startOnLoad");
i++; i++;
boolean dis = disabled != null && "false".equals(disabled); boolean dis = disabled != null && "false".equals(disabled);
@ -87,5 +89,25 @@ public class ClientAppConfig {
return rv; return rv;
} }
public static void writeClientAppConfig(RouterContext ctx, List apps) {
String clientConfigFile = ctx.getProperty(PROP_CLIENT_CONFIG_FILENAME, DEFAULT_CLIENT_CONFIG_FILENAME);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(clientConfigFile);
StringBuffer buf = new StringBuffer(2048);
for(int i = 0; i < apps.size(); i++) {
ClientAppConfig app = (ClientAppConfig) apps.get(i);
buf.append(PREFIX).append(i).append(".main=").append(app.className).append("\n");
buf.append(PREFIX).append(i).append(".name=").append(app.clientName).append("\n");
buf.append(PREFIX).append(i).append(".args=").append(app.args).append("\n");
buf.append(PREFIX).append(i).append(".delay=").append(app.delay / 1000).append("\n");
buf.append(PREFIX).append(i).append(".startOnLoad=").append(!app.disabled).append("\n");
}
fos.write(buf.toString().getBytes());
} catch (IOException ioe) {
} finally {
if (fos != null) try { fos.close(); } catch (IOException ioe) {}
}
}
} }