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;
|
2008-07-16 13:42:54 +00:00
|
|
|
|
2008-06-16 12:31:14 +00:00
|
|
|
import net.i2p.router.RouterContext;
|
|
|
|
import net.i2p.router.startup.ClientAppConfig;
|
|
|
|
|
2009-01-29 02:16:18 +00:00
|
|
|
public class ConfigClientsHelper extends HelperBase {
|
2008-06-16 12:31:14 +00:00
|
|
|
public ConfigClientsHelper() {}
|
|
|
|
|
|
|
|
public String getForm1() {
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(1024);
|
2008-06-16 12:31:14 +00:00
|
|
|
buf.append("<table border=\"1\">\n");
|
2009-06-24 18:47:17 +00:00
|
|
|
buf.append("<tr><th>Client</th><th>Run at Startup?</th><th>Start Now</th><th>Class and arguments</th></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-10-19 21:45:04 +00:00
|
|
|
renderForm(buf, ""+cur, ca.clientName, false, !ca.disabled, "webConsole".equals(ca.clientName),
|
|
|
|
ca.className + ((ca.args != null) ? " " + ca.args : ""));
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf.append("</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getForm2() {
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(1024);
|
2008-06-16 12:31:14 +00:00
|
|
|
buf.append("<table border=\"1\">\n");
|
2009-06-24 18:47:17 +00:00
|
|
|
buf.append("<tr><th>WebApp</th><th>Run at Startup?</th><th>Start Now</th><th>Description</th></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();
|
|
|
|
}
|
|
|
|
|
2009-07-01 16:00:43 +00:00
|
|
|
private void renderForm(StringBuilder 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\" ");
|
|
|
|
}
|
2009-04-03 21:33:35 +00:00
|
|
|
buf.append("/></td><td> ");
|
2008-06-20 20:20:50 +00:00
|
|
|
if (!enabled) {
|
2009-04-03 21:33:35 +00:00
|
|
|
buf.append("<button type=\"submit\" name=\"action\" value=\"Start ").append(index).append("\" >Start<span class=hide> ").append(index).append("</span></button>");
|
2008-06-20 20:20:50 +00:00
|
|
|
}
|
2009-04-03 21:33:35 +00:00
|
|
|
buf.append(" </td><td>").append(desc).append("</td></tr>\n");
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
}
|