* configclients.jsp: Add start button for clients and webapps.

This commit is contained in:
zzz
2008-06-20 20:20:50 +00:00
parent f3d73a6c15
commit dc68ebbaeb
4 changed files with 74 additions and 16 deletions

View File

@ -1,5 +1,6 @@
package net.i2p.router.web; package net.i2p.router.web;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -9,8 +10,12 @@ import java.util.Set;
import net.i2p.data.DataFormatException; import net.i2p.data.DataFormatException;
import net.i2p.router.startup.ClientAppConfig; import net.i2p.router.startup.ClientAppConfig;
import net.i2p.router.startup.LoadClientAppsJob;
import net.i2p.util.Log; import net.i2p.util.Log;
import org.mortbay.http.HttpListener;
import org.mortbay.jetty.Server;
/** /**
* Saves changes to clients.config or webapps.config * Saves changes to clients.config or webapps.config
*/ */
@ -18,13 +23,25 @@ public class ConfigClientsHandler extends FormHandler {
private Log _log; private Log _log;
private Map _settings; private Map _settings;
public ConfigClientsHandler() {} public ConfigClientsHandler() {
_log = ContextHelper.getContext(null).logManager().getLog(ConfigClientsHandler.class);
}
protected void processForm() { protected void processForm() {
if (_action.startsWith("Save Client")) { if (_action.startsWith("Save Client")) {
saveClientChanges(); saveClientChanges();
} else if (_action.startsWith("Save WebApp")) { } else if (_action.startsWith("Save WebApp")) {
saveWebAppChanges(); 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 { } else {
addFormError("Unsupported " + _action); addFormError("Unsupported " + _action);
} }
@ -44,6 +61,17 @@ public class ConfigClientsHandler extends FormHandler {
addFormNotice("Client configuration saved successfully - restart required to take effect"); 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() { private void saveWebAppChanges() {
Properties props = RouterConsoleRunner.webAppProperties(); Properties props = RouterConsoleRunner.webAppProperties();
Set keys = props.keySet(); Set keys = props.keySet();
@ -60,4 +88,28 @@ public class ConfigClientsHandler extends FormHandler {
RouterConsoleRunner.storeWebAppProperties(props); RouterConsoleRunner.storeWebAppProperties(props);
addFormNotice("WebApp configuration saved successfully - restart required to take effect"); 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");
}
} }

View File

@ -29,7 +29,7 @@ public class 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");
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); List clients = ClientAppConfig.getClientApps(_context);
for (int cur = 0; cur < clients.size(); cur++) { for (int cur = 0; cur < clients.size(); cur++) {
@ -44,7 +44,7 @@ public class ConfigClientsHelper {
public String getForm2() { public String getForm2() {
StringBuffer buf = new StringBuffer(1024); StringBuffer buf = new StringBuffer(1024);
buf.append("<table border=\"1\">\n"); 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(); Properties props = RouterConsoleRunner.webAppProperties();
Set keys = new TreeSet(props.keySet()); Set keys = new TreeSet(props.keySet());
for (Iterator iter = keys.iterator(); iter.hasNext(); ) { for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
@ -75,6 +75,10 @@ public class ConfigClientsHelper {
if (ro) if (ro)
buf.append("disabled=\"true\" "); buf.append("disabled=\"true\" ");
} }
buf.append("/><td>").append(desc).append("</td></tr>\n"); buf.append("/></td><td>&nbsp");
if (!enabled) {
buf.append("<button type=\"submit\" name=\"action\" value=\"Start ").append(index).append("\" />Start</button>");
}
buf.append("&nbsp</td><td>").append(desc).append("</td></tr>\n");
} }
} }

View File

@ -4,10 +4,10 @@
%>Service | <% } else { %><a href="configservice.jsp">Service</a> | <% } %>Service | <% } else { %><a href="configservice.jsp">Service</a> | <% }
if (request.getRequestURI().indexOf("configupdate.jsp") != -1) { if (request.getRequestURI().indexOf("configupdate.jsp") != -1) {
%>Update | <% } else { %><a href="configupdate.jsp">Update</a> | <% } %>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) { if (request.getRequestURI().indexOf("configtunnels.jsp") != -1) {
%>Tunnels | <% } else { %><a href="configtunnels.jsp">Tunnels</a> | <% } %>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) { if (request.getRequestURI().indexOf("configlogging.jsp") != -1) {
%>Logging | <% } else { %><a href="configlogging.jsp">Logging</a> | <% } %>Logging | <% } else { %><a href="configlogging.jsp">Logging</a> | <% }
if (request.getRequestURI().indexOf("configstats.jsp") != -1) { if (request.getRequestURI().indexOf("configstats.jsp") != -1) {

View File

@ -15,7 +15,7 @@ import net.i2p.util.Log;
* it'll get queued up for starting 2 minutes later. * it'll get queued up for starting 2 minutes later.
* *
*/ */
class LoadClientAppsJob extends JobImpl { public class LoadClientAppsJob extends JobImpl {
private Log _log; private Log _log;
private static boolean _loaded = false; private static boolean _loaded = false;
@ -36,7 +36,7 @@ class LoadClientAppsJob extends JobImpl {
String argVal[] = parseArgs(app.args); String argVal[] = parseArgs(app.args);
if (app.delay == 0) { if (app.delay == 0) {
// run this guy now // run this guy now
runClient(app.className, app.clientName, argVal); runClient(app.className, app.clientName, argVal, _log);
} else { } else {
// wait before firing it up // wait before firing it up
getContext().jobQueue().addJob(new DelayedRunClient(getContext(), app.className, app.clientName, argVal, app.delay)); 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 String getName() { return "Delayed client job"; }
public void runJob() { 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); List argList = new ArrayList(4);
if (args != null) { if (args != null) {
char data[] = args.toCharArray(); char data[] = args.toCharArray();
@ -109,9 +109,9 @@ class LoadClientAppsJob extends JobImpl {
return rv; return rv;
} }
private void runClient(String className, String clientName, String args[]) { public static void runClient(String className, String clientName, String args[], Log log) {
_log.info("Loading up the client application " + clientName + ": " + className + " " + args); log.info("Loading up the client application " + clientName + ": " + className + " " + args);
I2PThread t = new I2PThread(new RunApp(className, clientName, args)); I2PThread t = new I2PThread(new RunApp(className, clientName, args, log));
if (clientName == null) if (clientName == null)
clientName = className + " client"; clientName = className + " client";
t.setName(clientName); t.setName(clientName);
@ -119,17 +119,19 @@ class LoadClientAppsJob extends JobImpl {
t.start(); t.start();
} }
private final class RunApp implements Runnable { private final static class RunApp implements Runnable {
private String _className; private String _className;
private String _appName; private String _appName;
private String _args[]; 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; _className = className;
_appName = appName; _appName = appName;
if (args == null) if (args == null)
_args = new String[0]; _args = new String[0];
else else
_args = args; _args = args;
_log = log;
} }
public void run() { public void run() {
try { try {