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 ae9643753a17e885acfe0beb2c4c061c4d0a4420..d6f46ae8e7293e0daa87fb43b6bccfd6a421927d 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java @@ -1,5 +1,6 @@ package net.i2p.router.web; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -9,8 +10,12 @@ import java.util.Set; import net.i2p.data.DataFormatException; import net.i2p.router.startup.ClientAppConfig; +import net.i2p.router.startup.LoadClientAppsJob; import net.i2p.util.Log; +import org.mortbay.http.HttpListener; +import org.mortbay.jetty.Server; + /** * Saves changes to clients.config or webapps.config */ @@ -18,13 +23,25 @@ public class ConfigClientsHandler extends FormHandler { private Log _log; private Map _settings; - public ConfigClientsHandler() {} - + public ConfigClientsHandler() { + _log = ContextHelper.getContext(null).logManager().getLog(ConfigClientsHandler.class); + } + protected void processForm() { if (_action.startsWith("Save Client")) { saveClientChanges(); } else if (_action.startsWith("Save WebApp")) { saveWebAppChanges(); + } else if (_action.startsWith("Start ")) { + String app = _action.substring(6); + int appnum = -1; + try { + appnum = Integer.parseInt(app); + } catch (NumberFormatException nfe) {} + if (appnum >= 0) + startClient(appnum); + else + startWebApp(app); } else { addFormError("Unsupported " + _action); } @@ -44,6 +61,17 @@ public class ConfigClientsHandler extends FormHandler { addFormNotice("Client configuration saved successfully - restart required to take effect"); } + private void startClient(int i) { + List clients = ClientAppConfig.getClientApps(_context); + if (i >= clients.size()) { + addFormError("Bad client index"); + return; + } + ClientAppConfig ca = (ClientAppConfig) clients.get(i); + LoadClientAppsJob.runClient(ca.className, ca.clientName, LoadClientAppsJob.parseArgs(ca.args), _log); + addFormNotice("Client " + ca.clientName + " started"); + } + private void saveWebAppChanges() { Properties props = RouterConsoleRunner.webAppProperties(); Set keys = props.keySet(); @@ -60,4 +88,28 @@ public class ConfigClientsHandler extends FormHandler { RouterConsoleRunner.storeWebAppProperties(props); addFormNotice("WebApp configuration saved successfully - restart required to take effect"); } + + // Big hack for the moment, not using properties for directory and port + // Go through all the Jetty servers, find the one serving port 7657, + // requested and add the .war to that one + private void startWebApp(String app) { + Collection c = Server.getHttpServers(); + for (int i = 0; i < c.size(); i++) { + Server s = (Server) c.toArray()[i]; + HttpListener[] hl = s.getListeners(); + for (int j = 0; j < hl.length; j++) { + if (hl[j].getPort() == 7657) { + try { + s.addWebApplication("/"+ app, "./webapps/" + app + ".war").start(); + // no passwords... initialize(wac); + addFormNotice("WebApp " + app + " started"); + } catch (Exception ioe) { + addFormError("Failed to start " + app + " " + ioe); + } + return; + } + } + } + addFormError("Failed to find server"); + } } 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 76462246e85abdddc5f4e79520f2e4f1b54b8181..a678b48a5a426030497da103f14ea780f9ec90da 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java @@ -29,7 +29,7 @@ public class ConfigClientsHelper { public String getForm1() { StringBuffer buf = new StringBuffer(1024); buf.append("<table border=\"1\">\n"); - buf.append("<tr><td>Client</td><td>Enabled?</td><td>Class and arguments</td></tr>\n"); + buf.append("<tr><td>Client</td><td>Run at Startup?</td><td>Start Now</td><td>Class and arguments</td></tr>\n"); List clients = ClientAppConfig.getClientApps(_context); for (int cur = 0; cur < clients.size(); cur++) { @@ -44,7 +44,7 @@ public class ConfigClientsHelper { public String getForm2() { StringBuffer buf = new StringBuffer(1024); buf.append("<table border=\"1\">\n"); - buf.append("<tr><td>WebApp</td><td>Enabled?</td><td>Description</td></tr>\n"); + buf.append("<tr><td>WebApp</td><td>Run at Startup?</td><td>Start Now</td><td>Description</td></tr>\n"); Properties props = RouterConsoleRunner.webAppProperties(); Set keys = new TreeSet(props.keySet()); for (Iterator iter = keys.iterator(); iter.hasNext(); ) { @@ -75,6 +75,10 @@ public class ConfigClientsHelper { if (ro) buf.append("disabled=\"true\" "); } - buf.append("/><td>").append(desc).append("</td></tr>\n"); + buf.append("/></td><td> "); + if (!enabled) { + buf.append("<button type=\"submit\" name=\"action\" value=\"Start ").append(index).append("\" />Start</button>"); + } + buf.append(" </td><td>").append(desc).append("</td></tr>\n"); } } diff --git a/apps/routerconsole/jsp/confignav.jsp b/apps/routerconsole/jsp/confignav.jsp index 8625ca6877b87b0910fad00283c0e50f5fcb5359..7ab47f76be1956ccd754f6c1281e9fe5c37eefc7 100644 --- a/apps/routerconsole/jsp/confignav.jsp +++ b/apps/routerconsole/jsp/confignav.jsp @@ -4,10 +4,10 @@ %>Service | <% } else { %><a href="configservice.jsp">Service</a> | <% } if (request.getRequestURI().indexOf("configupdate.jsp") != -1) { %>Update | <% } else { %><a href="configupdate.jsp">Update</a> | <% } - if (request.getRequestURI().indexOf("configclients.jsp") != -1) { - %>Clients | <% } else { %><a href="configclients.jsp">Clients</a> | <% } if (request.getRequestURI().indexOf("configtunnels.jsp") != -1) { %>Tunnels | <% } else { %><a href="configtunnels.jsp">Tunnels</a> | <% } + if (request.getRequestURI().indexOf("configclients.jsp") != -1) { + %>Clients | <% } else { %><a href="configclients.jsp">Clients</a> | <% } if (request.getRequestURI().indexOf("configlogging.jsp") != -1) { %>Logging | <% } else { %><a href="configlogging.jsp">Logging</a> | <% } if (request.getRequestURI().indexOf("configstats.jsp") != -1) { diff --git a/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java b/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java index 62e7132382f6733234849bf2d14b8b4b54eb742f..0770241d6b4f66886ef5efce791a3f6e9e25fafd 100644 --- a/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java +++ b/router/java/src/net/i2p/router/startup/LoadClientAppsJob.java @@ -15,7 +15,7 @@ import net.i2p.util.Log; * it'll get queued up for starting 2 minutes later. * */ -class LoadClientAppsJob extends JobImpl { +public class LoadClientAppsJob extends JobImpl { private Log _log; private static boolean _loaded = false; @@ -36,7 +36,7 @@ class LoadClientAppsJob extends JobImpl { String argVal[] = parseArgs(app.args); if (app.delay == 0) { // run this guy now - runClient(app.className, app.clientName, argVal); + runClient(app.className, app.clientName, argVal, _log); } else { // wait before firing it up getContext().jobQueue().addJob(new DelayedRunClient(getContext(), app.className, app.clientName, argVal, app.delay)); @@ -56,11 +56,11 @@ class LoadClientAppsJob extends JobImpl { } public String getName() { return "Delayed client job"; } public void runJob() { - runClient(_className, _clientName, _args); + runClient(_className, _clientName, _args, _log); } } - static String[] parseArgs(String args) { + public static String[] parseArgs(String args) { List argList = new ArrayList(4); if (args != null) { char data[] = args.toCharArray(); @@ -109,9 +109,9 @@ class LoadClientAppsJob extends JobImpl { return rv; } - private void runClient(String className, String clientName, String args[]) { - _log.info("Loading up the client application " + clientName + ": " + className + " " + args); - I2PThread t = new I2PThread(new RunApp(className, clientName, args)); + public static void runClient(String className, String clientName, String args[], Log log) { + log.info("Loading up the client application " + clientName + ": " + className + " " + args); + I2PThread t = new I2PThread(new RunApp(className, clientName, args, log)); if (clientName == null) clientName = className + " client"; t.setName(clientName); @@ -119,17 +119,19 @@ class LoadClientAppsJob extends JobImpl { t.start(); } - private final class RunApp implements Runnable { + private final static class RunApp implements Runnable { private String _className; private String _appName; private String _args[]; - public RunApp(String className, String appName, String args[]) { + private Log _log; + public RunApp(String className, String appName, String args[], Log log) { _className = className; _appName = appName; if (args == null) _args = new String[0]; else _args = args; + _log = log; } public void run() { try {