From a8c266402e528fae1b0516fb033d71c2557f1feb Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 16 Jun 2008 12:31:14 +0000 Subject: [PATCH] * configclients.jsp: New. For both clients and webapps. Saves are not yet implemented. --- .../i2p/router/web/ConfigClientsHandler.java | 59 +++++++++++++ .../i2p/router/web/ConfigClientsHelper.java | 83 +++++++++++++++++++ apps/routerconsole/jsp/configclients.jsp | 63 ++++++++++++++ apps/routerconsole/jsp/confignav.jsp | 2 + history.txt | 15 ++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 6 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java create mode 100644 apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java create mode 100644 apps/routerconsole/jsp/configclients.jsp diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java new file mode 100644 index 0000000000..5a9d991c93 --- /dev/null +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java @@ -0,0 +1,59 @@ +package net.i2p.router.web; + +import java.util.HashMap; +import java.util.Map; +import net.i2p.data.DataFormatException; +import net.i2p.util.Log; + +/** + * + */ +public class ConfigClientsHandler extends FormHandler { + private Log _log; + private Map _settings; + private boolean _shouldSave; + + public ConfigClientsHandler() { + _shouldSave = false; + } + + protected void processForm() { + if (_shouldSave) { + saveChanges(); + } else { + // noop + 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); } + + /** + * 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"); + } + } +} diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java new file mode 100644 index 0000000000..715899c208 --- /dev/null +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java @@ -0,0 +1,83 @@ +package net.i2p.router.web; + +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; +import net.i2p.router.RouterContext; +import net.i2p.router.startup.ClientAppConfig; + +public class ConfigClientsHelper { + private RouterContext _context; + /** + * Configure this bean to query a particular router context + * + * @param contextId begging few characters of the routerHash, or null to pick + * the first one we come across. + */ + public void setContextId(String contextId) { + try { + _context = ContextHelper.getContext(contextId); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public ConfigClientsHelper() {} + + + public String getForm1() { + StringBuffer buf = new StringBuffer(1024); + buf.append("\n"); + buf.append("\n"); + + 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); + } + + buf.append("
ClientEnabled?Class and arguments
\n"); + return buf.toString(); + } + + public String getForm2() { + StringBuffer buf = new StringBuffer(1024); + buf.append("\n"); + buf.append("\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 val = props.getProperty(name); + renderForm(buf, cur, app, !"addressbook".equals(app), "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war"); + cur++; + } + } + buf.append("
WebAppEnabled?Description
\n"); + return buf.toString(); + } + + private void renderForm(StringBuffer buf, int index, String name, boolean urlify, boolean enabled, boolean ro, String desc) { + buf.append(""); + if (urlify && enabled) { + String link = "/"; + if (! RouterConsoleRunner.ROUTERCONSOLE.equals(name)) + link += name + "/"; + buf.append("").append(name).append(""); + } else { + buf.append(name); + } + buf.append("").append(desc).append("\n"); + } +} diff --git a/apps/routerconsole/jsp/configclients.jsp b/apps/routerconsole/jsp/configclients.jsp new file mode 100644 index 0000000000..8f4f6c8e27 --- /dev/null +++ b/apps/routerconsole/jsp/configclients.jsp @@ -0,0 +1,63 @@ +<%@page contentType="text/html"%> +<%@page pageEncoding="UTF-8"%> + + + +I2P Router Console - config clients + + + +<%@include file="nav.jsp" %> +<%@include file="summary.jsp" %> + + +" /> + +
+ <%@include file="confignav.jsp" %> + + + " /> + " /> + " /> + " /> + + + + +
+ <% String prev = System.getProperty("net.i2p.router.web.ConfigClientsHandler.nonce"); + 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. +

+ +

+ +

+ All changes require restart to take effect. For other changes edit the clients.config file. +

+
+

WebApp Configuration

+

+ The Java web applications listed below are started by the webConsole client and run in the same JVM as the router. + They are usually web applications accessible through the router console. + They may be complete applications (e.g. i2psnark), + 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). +

+ +

+ +

+ All changes require restart to take effect. For other changes edit the webapps.config file. +

+
+
+ + + diff --git a/apps/routerconsole/jsp/confignav.jsp b/apps/routerconsole/jsp/confignav.jsp index 5bf9338c97..8625ca6877 100644 --- a/apps/routerconsole/jsp/confignav.jsp +++ b/apps/routerconsole/jsp/confignav.jsp @@ -4,6 +4,8 @@ %>Service | <% } else { %>Service | <% } if (request.getRequestURI().indexOf("configupdate.jsp") != -1) { %>Update | <% } else { %>Update | <% } + if (request.getRequestURI().indexOf("configclients.jsp") != -1) { + %>Clients | <% } else { %>Clients | <% } if (request.getRequestURI().indexOf("configtunnels.jsp") != -1) { %>Tunnels | <% } else { %>Tunnels | <% } if (request.getRequestURI().indexOf("configlogging.jsp") != -1) { diff --git a/history.txt b/history.txt index 379ed92fa6..e202dd2064 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,18 @@ +2008-06-16 zzz + * UDP: Prevent 100% CPU when UDP bind fails; + change bind fail message from ERROR to CRIT + * Refactor LoadClientAppsJob.java, move some functions to new + ClientAppConfig.java, to make them easily available to + new configclients.jsp + * RouterConsoleRunner: Use a new config file, webapps.config, + to control which .wars in webapps/ get run. Apps are enabled + by default; disable by (e.g.) webapps.syndie.startOnLoad=false + Config file is written if it does not exist. + Implement methods for use by new configclients.jsp. + * 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 b3568c1fd8..da77a17e2f 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 = 2; + public final static long BUILD = 3; public static void main(String args[]) { System.out.println("I2P Router version: " + VERSION + "-" + BUILD); System.out.println("Router ID: " + RouterVersion.ID);