2008-06-16 12:31:14 +00:00
|
|
|
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("<table border=\"1\">\n");
|
2008-06-20 20:20:50 +00:00
|
|
|
buf.append("<tr><td>Client</td><td>Run at Startup?</td><td>Start Now</td><td>Class and arguments</td></tr>\n");
|
2008-06-16 12:31:14 +00:00
|
|
|
|
|
|
|
List clients = ClientAppConfig.getClientApps(_context);
|
|
|
|
for (int cur = 0; cur < clients.size(); cur++) {
|
|
|
|
ClientAppConfig ca = (ClientAppConfig) clients.get(cur);
|
2008-06-17 13:48:41 +00:00
|
|
|
renderForm(buf, ""+cur, ca.clientName, false, !ca.disabled, "webConsole".equals(ca.clientName), ca.className + " " + ca.args);
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf.append("</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getForm2() {
|
|
|
|
StringBuffer buf = new StringBuffer(1024);
|
|
|
|
buf.append("<table border=\"1\">\n");
|
2008-06-20 20:20:50 +00:00
|
|
|
buf.append("<tr><td>WebApp</td><td>Run at Startup?</td><td>Start Now</td><td>Description</td></tr>\n");
|
2008-06-16 12:31:14 +00:00
|
|
|
Properties props = RouterConsoleRunner.webAppProperties();
|
|
|
|
Set keys = new TreeSet(props.keySet());
|
|
|
|
for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
|
|
|
|
String name = (String)iter.next();
|
|
|
|
if (name.startsWith(RouterConsoleRunner.PREFIX) && name.endsWith(RouterConsoleRunner.ENABLED)) {
|
2008-06-17 13:48:41 +00:00
|
|
|
String app = name.substring(RouterConsoleRunner.PREFIX.length(), name.lastIndexOf(RouterConsoleRunner.ENABLED));
|
2008-06-16 12:31:14 +00:00
|
|
|
String val = props.getProperty(name);
|
2008-06-17 13:48:41 +00:00
|
|
|
renderForm(buf, app, app, !"addressbook".equals(app), "true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app), app + ".war");
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.append("</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2008-06-17 13:48:41 +00:00
|
|
|
private void renderForm(StringBuffer buf, String index, String name, boolean urlify, boolean enabled, boolean ro, String desc) {
|
2008-06-16 12:31:14 +00:00
|
|
|
buf.append("<tr><td>");
|
|
|
|
if (urlify && enabled) {
|
|
|
|
String link = "/";
|
|
|
|
if (! RouterConsoleRunner.ROUTERCONSOLE.equals(name))
|
|
|
|
link += name + "/";
|
|
|
|
buf.append("<a href=\"").append(link).append("\">").append(name).append("</a>");
|
|
|
|
} else {
|
|
|
|
buf.append(name);
|
|
|
|
}
|
2008-06-17 13:48:41 +00:00
|
|
|
buf.append("</td><td align=\"center\"><input type=\"checkbox\" name=\"").append(index).append(".enabled\" value=\"true\" ");
|
2008-06-16 12:31:14 +00:00
|
|
|
if (enabled) {
|
|
|
|
buf.append("checked=\"true\" ");
|
|
|
|
if (ro)
|
|
|
|
buf.append("disabled=\"true\" ");
|
|
|
|
}
|
2008-06-20 20:20:50 +00:00
|
|
|
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");
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
}
|