I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit dc68ebba authored by zzz's avatar zzz
Browse files

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

parent f3d73a6c
No related branches found
No related tags found
No related merge requests found
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");
}
}
......@@ -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>&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");
}
}
......@@ -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) {
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment