diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java index 5a9d991c93..ae9643753a 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java @@ -1,59 +1,63 @@ package net.i2p.router.web; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Properties; +import java.util.Set; + import net.i2p.data.DataFormatException; +import net.i2p.router.startup.ClientAppConfig; import net.i2p.util.Log; /** - * + * Saves changes to clients.config or webapps.config */ public class ConfigClientsHandler extends FormHandler { private Log _log; private Map _settings; - private boolean _shouldSave; - public ConfigClientsHandler() { - _shouldSave = false; - } + public ConfigClientsHandler() {} protected void processForm() { - if (_shouldSave) { - saveChanges(); + if (_action.startsWith("Save Client")) { + saveClientChanges(); + } else if (_action.startsWith("Save WebApp")) { + saveWebAppChanges(); } else { - // noop - addFormError("Unimplemented"); + addFormError("Unsupported " + _action); } } - public void setShouldsave(String moo) { - if ( (moo != null) && (moo.equals("Save changes")) ) - _shouldSave = true; - } - public void setSettings(Map settings) { _settings = new HashMap(settings); } - /** - * The user made changes to the network config and wants to save them, so - * lets go ahead and do so. - * - */ - private void saveChanges() { - _log = _context.logManager().getLog(ConfigClientsHandler.class); - boolean saveRequired = false; - - int updated = 0; - int index = 0; - - if (updated > 0) - addFormNotice("Updated settings"); - - if (saveRequired) { - boolean saved = _context.router().saveConfig(); - if (saved) - addFormNotice("Exploratory tunnel configuration saved successfully"); - else - addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs"); + private void saveClientChanges() { + List clients = ClientAppConfig.getClientApps(_context); + for (int cur = 0; cur < clients.size(); cur++) { + ClientAppConfig ca = (ClientAppConfig) clients.get(cur); + Object val = _settings.get(cur + ".enabled"); + if (! "webConsole".equals(ca.clientName)) + ca.disabled = val == null; } + ClientAppConfig.writeClientAppConfig(_context, clients); + addFormNotice("Client configuration saved successfully - restart required to take effect"); + } + + private void saveWebAppChanges() { + Properties props = RouterConsoleRunner.webAppProperties(); + Set keys = props.keySet(); + int cur = 0; + for (Iterator iter = keys.iterator(); iter.hasNext(); ) { + String name = (String)iter.next(); + if (! (name.startsWith(RouterConsoleRunner.PREFIX) && name.endsWith(RouterConsoleRunner.ENABLED))) + continue; + String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED)); + Object val = _settings.get(app + ".enabled"); + if (! RouterConsoleRunner.ROUTERCONSOLE.equals(app)) + props.setProperty(name, "" + (val != null)); + } + RouterConsoleRunner.storeWebAppProperties(props); + addFormNotice("WebApp configuration saved successfully - restart required to take effect"); } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java index 715899c208..76462246e8 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java @@ -26,7 +26,6 @@ public class ConfigClientsHelper { public ConfigClientsHelper() {} - public String getForm1() { StringBuffer buf = new StringBuffer(1024); buf.append("\n"); @@ -35,7 +34,7 @@ public class ConfigClientsHelper { List clients = ClientAppConfig.getClientApps(_context); for (int cur = 0; cur < clients.size(); 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("
\n"); @@ -48,21 +47,19 @@ public class ConfigClientsHelper { buf.append("WebAppEnabled?Description\n"); Properties props = RouterConsoleRunner.webAppProperties(); Set keys = new TreeSet(props.keySet()); - int cur = 0; for (Iterator iter = keys.iterator(); iter.hasNext(); ) { String name = (String)iter.next(); 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); - renderForm(buf, cur, app, !"addressbook".equals(app), "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war"); - cur++; + renderForm(buf, app, app, !"addressbook".equals(app), "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war"); } } buf.append("\n"); 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(""); if (urlify && enabled) { String link = "/"; @@ -72,7 +69,7 @@ public class ConfigClientsHelper { } else { buf.append(name); } - buf.append(" " /> - " /> " /> " /> @@ -30,7 +29,6 @@ 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()+""); %> " /> -

Client Configuration

The Java clients listed below are started by the router and run in the same JVM. @@ -39,7 +37,7 @@

- All changes require restart to take effect. For other changes edit the clients.config file. + All changes require restart to take effect. To change other client options, edit the clients.config file.


WebApp Configuration

@@ -50,11 +48,15 @@ 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).

+ 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. +

- All changes require restart to take effect. For other changes edit the webapps.config file. + All changes require restart to take effect. To change other webapp options, edit the webapps.config file.

diff --git a/history.txt b/history.txt index e202dd2064..548470b420 100644 --- a/history.txt +++ b/history.txt @@ -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 * UDP: Prevent 100% CPU when UDP bind fails; change bind fail message from ERROR to CRIT @@ -12,7 +18,6 @@ * configclients.jsp: New. For both clients and webapps. Saves are not yet implemented. - 2008-06-10 zzz * Floodfill: Add new FloodfillMonitorJob, which tracks active floodfills, and automatically enables/disables floodfill on diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index da77a17e2f..01f475f2ab 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -17,7 +17,7 @@ import net.i2p.CoreVersion; public class RouterVersion { 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 long BUILD = 3; + public final static long BUILD = 4; public static void main(String args[]) { System.out.println("I2P Router version: " + VERSION + "-" + BUILD); System.out.println("Router ID: " + RouterVersion.ID); diff --git a/router/java/src/net/i2p/router/startup/ClientAppConfig.java b/router/java/src/net/i2p/router/startup/ClientAppConfig.java index 8c54ea1fa9..0a994069f9 100644 --- a/router/java/src/net/i2p/router/startup/ClientAppConfig.java +++ b/router/java/src/net/i2p/router/startup/ClientAppConfig.java @@ -2,6 +2,7 @@ package net.i2p.router.startup; import java.io.IOException; import java.io.File; +import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; 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 DEFAULT_CLIENT_CONFIG_FILENAME = "clients.config"; + private static final String PREFIX = "clientApp."; // let's keep this really simple public String className; @@ -63,14 +65,14 @@ public class ClientAppConfig { List rv = new ArrayList(5); int i = 0; while (true) { - String className = clientApps.getProperty("clientApp."+i+".main"); + String className = clientApps.getProperty(PREFIX + i + ".main"); if (className == null) break; - String clientName = clientApps.getProperty("clientApp."+i+".name"); - String args = clientApps.getProperty("clientApp."+i+".args"); - String delayStr = clientApps.getProperty("clientApp." + i + ".delay"); - String onBoot = clientApps.getProperty("clientApp." + i + ".onBoot"); - String disabled = clientApps.getProperty("clientApp." + i + ".startOnLoad"); + String clientName = clientApps.getProperty(PREFIX + i + ".name"); + String args = clientApps.getProperty(PREFIX + i + ".args"); + String delayStr = clientApps.getProperty(PREFIX + i + ".delay"); + String onBoot = clientApps.getProperty(PREFIX + i + ".onBoot"); + String disabled = clientApps.getProperty(PREFIX + i + ".startOnLoad"); i++; boolean dis = disabled != null && "false".equals(disabled); @@ -87,5 +89,25 @@ public class ClientAppConfig { 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) {} + } + } }