2008-06-16 12:31:14 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2015-04-16 15:07:08 +00:00
|
|
|
import java.text.Collator;
|
2010-02-08 16:15:23 +00:00
|
|
|
import java.text.SimpleDateFormat;
|
2010-12-24 16:52:23 +00:00
|
|
|
import java.util.ArrayList;
|
2015-04-16 15:07:08 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2010-02-08 16:15:23 +00:00
|
|
|
import java.util.Date;
|
2008-06-16 12:31:14 +00:00
|
|
|
import java.util.List;
|
2015-04-16 15:07:08 +00:00
|
|
|
import java.util.Locale;
|
2008-06-16 12:31:14 +00:00
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.TreeSet;
|
2008-07-16 13:42:54 +00:00
|
|
|
|
2013-04-16 14:59:18 +00:00
|
|
|
import net.i2p.app.ClientApp;
|
|
|
|
import net.i2p.app.ClientAppState;
|
2012-01-17 02:11:56 +00:00
|
|
|
import net.i2p.data.DataHelper;
|
2010-12-24 16:52:23 +00:00
|
|
|
import net.i2p.router.client.ClientManagerFacadeImpl;
|
2008-06-16 12:31:14 +00:00
|
|
|
import net.i2p.router.startup.ClientAppConfig;
|
2013-04-16 14:59:18 +00:00
|
|
|
import net.i2p.router.startup.LoadClientAppsJob;
|
2010-12-26 13:48:45 +00:00
|
|
|
import net.i2p.util.Addresses;
|
2008-06-16 12:31:14 +00:00
|
|
|
|
2009-01-29 02:16:18 +00:00
|
|
|
public class ConfigClientsHelper extends HelperBase {
|
2010-01-06 21:24:08 +00:00
|
|
|
private String _edit;
|
|
|
|
|
2010-12-24 16:52:23 +00:00
|
|
|
/** from ClientListenerRunner */
|
|
|
|
public static final String BIND_ALL_INTERFACES = "i2cp.tcp.bindAllInterfaces";
|
|
|
|
/** from ClientManager */
|
|
|
|
public static final String PROP_DISABLE_EXTERNAL = "i2cp.disableInterface";
|
|
|
|
public static final String PROP_ENABLE_SSL = "i2cp.SSL";
|
|
|
|
/** from ClientMessageEventListener */
|
|
|
|
public static final String PROP_AUTH = "i2cp.auth";
|
2014-08-03 13:58:51 +00:00
|
|
|
public static final String PROP_ENABLE_CLIENT_CHANGE = "routerconsole.enableClientChange";
|
|
|
|
public static final String PROP_ENABLE_PLUGIN_INSTALL = "routerconsole.enablePluginInstall";
|
2010-12-24 16:52:23 +00:00
|
|
|
|
2008-06-16 12:31:14 +00:00
|
|
|
public ConfigClientsHelper() {}
|
2010-12-24 16:52:23 +00:00
|
|
|
|
2014-08-03 13:58:51 +00:00
|
|
|
/** @since 0.9.14.1 */
|
|
|
|
public boolean isClientChangeEnabled() {
|
|
|
|
return _context.getBooleanProperty(PROP_ENABLE_CLIENT_CHANGE) || isAdvanced();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @since 0.9.14.1 */
|
|
|
|
public boolean isPluginInstallEnabled() {
|
|
|
|
return PluginStarter.pluginsEnabled(_context) &&
|
2014-08-30 16:14:41 +00:00
|
|
|
(_context.getBooleanPropertyDefaultTrue(PROP_ENABLE_PLUGIN_INSTALL) || isAdvanced());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @since 0.9.15 */
|
|
|
|
public boolean isPluginUpdateEnabled() {
|
|
|
|
return !PluginStarter.getPlugins().isEmpty();
|
2014-08-03 13:58:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 16:52:23 +00:00
|
|
|
/** @since 0.8.3 */
|
|
|
|
public String getPort() {
|
|
|
|
return _context.getProperty(ClientManagerFacadeImpl.PROP_CLIENT_PORT,
|
|
|
|
Integer.toString(ClientManagerFacadeImpl.DEFAULT_PORT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @since 0.8.3 */
|
|
|
|
public String i2cpModeChecked(int mode) {
|
|
|
|
boolean disabled = _context.getBooleanProperty(PROP_DISABLE_EXTERNAL);
|
|
|
|
boolean ssl = _context.getBooleanProperty(PROP_ENABLE_SSL);
|
|
|
|
if ((mode == 0 && disabled) ||
|
|
|
|
(mode == 1 && (!disabled) && (!ssl)) ||
|
|
|
|
(mode == 2 && (!disabled) && ssl))
|
2012-03-02 22:32:45 +00:00
|
|
|
return "checked=\"checked\"";
|
2010-12-24 16:52:23 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @since 0.8.3 */
|
|
|
|
public String getAuth() {
|
|
|
|
boolean enabled = _context.getBooleanProperty(PROP_AUTH);
|
|
|
|
if (enabled)
|
2012-03-02 22:32:45 +00:00
|
|
|
return "checked=\"checked\"";
|
2010-12-24 16:52:23 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @since 0.8.3 */
|
|
|
|
public String[] intfcAddresses() {
|
2013-11-21 11:31:50 +00:00
|
|
|
ArrayList<String> al = new ArrayList<String>(Addresses.getAllAddresses());
|
2010-12-26 15:07:59 +00:00
|
|
|
return al.toArray(new String[al.size()]);
|
2010-12-24 16:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @since 0.8.3 */
|
|
|
|
public boolean isIFSelected(String addr) {
|
|
|
|
boolean bindAll = _context.getBooleanProperty(BIND_ALL_INTERFACES);
|
|
|
|
if (bindAll && addr.equals("0.0.0.0") || addr.equals("::"))
|
|
|
|
return true;
|
|
|
|
String host = _context.getProperty(ClientManagerFacadeImpl.PROP_CLIENT_HOST,
|
|
|
|
ClientManagerFacadeImpl.DEFAULT_HOST);
|
|
|
|
return (host.equals(addr));
|
|
|
|
}
|
|
|
|
|
2010-01-06 21:24:08 +00:00
|
|
|
public void setEdit(String edit) {
|
|
|
|
if (edit == null)
|
|
|
|
return;
|
2015-09-25 19:55:36 +00:00
|
|
|
String xStart = _t("Edit");
|
2010-01-06 21:24:08 +00:00
|
|
|
if (edit.startsWith(xStart + "<span class=hide> ") &&
|
|
|
|
edit.endsWith("</span>")) {
|
|
|
|
// IE sucks
|
|
|
|
_edit = edit.substring(xStart.length() + 18, edit.length() - 7);
|
|
|
|
} else if (edit.startsWith("Edit ")) {
|
|
|
|
_edit = edit.substring(5);
|
|
|
|
} else if (edit.startsWith(xStart + ' ')) {
|
|
|
|
_edit = edit.substring(xStart.length() + 1);
|
2015-09-25 19:55:36 +00:00
|
|
|
} else if ((_t("Add Client")).equals(edit)) {
|
2010-01-06 21:24:08 +00:00
|
|
|
_edit = "new";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-07 14:21:30 +00:00
|
|
|
/** clients */
|
2008-06-16 12:31:14 +00:00
|
|
|
public String getForm1() {
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(1024);
|
2014-02-10 18:33:32 +00:00
|
|
|
buf.append("<table>\n" +
|
2015-09-25 19:55:36 +00:00
|
|
|
"<tr><th align=\"right\">").append(_t("Client")).append("</th><th>")
|
|
|
|
.append(_t("Run at Startup?")).append("</th><th>")
|
|
|
|
.append(_t("Control")).append("</th><th align=\"left\">")
|
|
|
|
.append(_t("Class and arguments")).append("</th></tr>\n");
|
2008-06-16 12:31:14 +00:00
|
|
|
|
2014-08-03 13:58:51 +00:00
|
|
|
boolean allowEdit = isClientChangeEnabled();
|
2010-01-06 21:24:08 +00:00
|
|
|
List<ClientAppConfig> clients = ClientAppConfig.getClientApps(_context);
|
2015-04-16 15:07:08 +00:00
|
|
|
List<CAC> cacs = new ArrayList<CAC>(clients.size());
|
2008-06-16 12:31:14 +00:00
|
|
|
for (int cur = 0; cur < clients.size(); cur++) {
|
2010-01-06 21:24:08 +00:00
|
|
|
ClientAppConfig ca = clients.get(cur);
|
2015-04-16 15:07:08 +00:00
|
|
|
String xname = ca.clientName;
|
|
|
|
if (xname.length() > 0)
|
2015-09-25 19:55:36 +00:00
|
|
|
xname = _t(xname);
|
2015-04-16 15:07:08 +00:00
|
|
|
cacs.add(new CAC(cur, ca, xname));
|
|
|
|
}
|
|
|
|
Collections.sort(cacs, new CACComparator());
|
|
|
|
for (CAC cac : cacs) {
|
|
|
|
ClientAppConfig ca = cac.config;
|
|
|
|
int cur = cac.index;
|
2013-04-16 14:59:18 +00:00
|
|
|
boolean isConsole = ca.className.equals("net.i2p.router.web.RouterConsoleRunner");
|
|
|
|
boolean showStart;
|
|
|
|
boolean showStop;
|
|
|
|
if (isConsole) {
|
|
|
|
showStart = false;
|
|
|
|
showStop = false;
|
|
|
|
} else {
|
2014-01-06 13:57:45 +00:00
|
|
|
ClientApp clientApp = _context.routerAppManager().getClientApp(ca.className, LoadClientAppsJob.parseArgs(ca.args));
|
2013-04-16 14:59:18 +00:00
|
|
|
showStart = clientApp == null;
|
|
|
|
showStop = clientApp != null && clientApp.getState() == ClientAppState.RUNNING;
|
|
|
|
}
|
|
|
|
renderForm(buf, ""+cur, ca.clientName,
|
|
|
|
// urlify, enabled
|
|
|
|
false, !ca.disabled,
|
2014-04-18 01:14:23 +00:00
|
|
|
// read only, preventDisable
|
2011-01-16 15:30:04 +00:00
|
|
|
// dangerous, but allow editing the console args too
|
|
|
|
//"webConsole".equals(ca.clientName) || "Web console".equals(ca.clientName),
|
2014-04-18 01:14:23 +00:00
|
|
|
false, RouterConsoleRunner.class.getName().equals(ca.className),
|
2014-08-03 13:58:51 +00:00
|
|
|
// description
|
2015-11-21 17:39:10 +00:00
|
|
|
DataHelper.escapeHTML(ca.className + ((ca.args != null) ? " " + ca.args : "")),
|
2014-08-03 13:58:51 +00:00
|
|
|
// edit
|
|
|
|
allowEdit && (""+cur).equals(_edit),
|
2013-04-16 14:59:18 +00:00
|
|
|
// show edit button, show update button
|
|
|
|
// Don't allow edit if it's running, or else we would lose the "handle" to the ClientApp to stop it.
|
2014-08-03 13:58:51 +00:00
|
|
|
allowEdit && !showStop, false,
|
2013-04-16 14:59:18 +00:00
|
|
|
// show stop button
|
|
|
|
showStop,
|
|
|
|
// show delete button, show start button
|
2014-08-10 12:18:18 +00:00
|
|
|
allowEdit && !isConsole, showStart);
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
|
2014-08-03 13:58:51 +00:00
|
|
|
if (allowEdit && "new".equals(_edit))
|
|
|
|
renderForm(buf, "" + clients.size(), "", false, false, false, false, "", true, false, false, false, false, false);
|
2008-06-16 12:31:14 +00:00
|
|
|
buf.append("</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2015-04-16 15:07:08 +00:00
|
|
|
/** @since 0.9.20 */
|
|
|
|
private static class CAC {
|
|
|
|
public final int index;
|
|
|
|
public final ClientAppConfig config;
|
|
|
|
public final String xname;
|
|
|
|
|
|
|
|
public CAC(int idx, ClientAppConfig cfg, String xn) {
|
|
|
|
index = idx; config = cfg; xname = xn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @since 0.9.20 */
|
|
|
|
private class CACComparator implements Comparator<CAC> {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private final Collator coll;
|
|
|
|
|
|
|
|
public CACComparator() {
|
|
|
|
super();
|
|
|
|
coll = Collator.getInstance(new Locale(Messages.getLanguage(_context)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public int compare(CAC l, CAC r) {
|
|
|
|
return coll.compare(l.xname, r.xname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-07 14:21:30 +00:00
|
|
|
/** webapps */
|
2008-06-16 12:31:14 +00:00
|
|
|
public String getForm2() {
|
2009-07-01 16:00:43 +00:00
|
|
|
StringBuilder buf = new StringBuilder(1024);
|
2014-02-10 18:33:32 +00:00
|
|
|
buf.append("<table>\n" +
|
2015-09-25 19:55:36 +00:00
|
|
|
"<tr><th align=\"right\">").append(_t("WebApp")).append("</th><th>")
|
|
|
|
.append(_t("Run at Startup?")).append("</th><th>")
|
|
|
|
.append(_t("Control")).append("</th><th align=\"left\">")
|
|
|
|
.append(_t("Description")).append("</th></tr>\n");
|
2012-10-13 13:06:22 +00:00
|
|
|
Properties props = RouterConsoleRunner.webAppProperties(_context);
|
2015-04-24 16:27:03 +00:00
|
|
|
Set<String> keys = new TreeSet<String>(props.stringPropertyNames());
|
2013-11-28 11:56:54 +00:00
|
|
|
for (String name : keys) {
|
2008-06-16 12:31:14 +00:00
|
|
|
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);
|
2013-09-21 16:11:55 +00:00
|
|
|
boolean isRunning = WebAppStarter.isWebAppRunning(app);
|
2010-01-06 21:24:08 +00:00
|
|
|
renderForm(buf, app, app, !"addressbook".equals(app),
|
2014-04-18 01:14:23 +00:00
|
|
|
"true".equals(val), RouterConsoleRunner.ROUTERCONSOLE.equals(app),
|
2015-11-21 17:39:10 +00:00
|
|
|
RouterConsoleRunner.ROUTERCONSOLE.equals(app), DataHelper.escapeHTML(app + ".war"),
|
2013-09-21 16:11:55 +00:00
|
|
|
false, false, false, isRunning, false, !isRunning);
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.append("</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2010-02-10 19:09:35 +00:00
|
|
|
public boolean showPlugins() {
|
|
|
|
return PluginStarter.pluginsEnabled(_context);
|
|
|
|
}
|
|
|
|
|
2012-12-07 14:21:30 +00:00
|
|
|
/** plugins */
|
2010-02-07 13:32:49 +00:00
|
|
|
public String getForm3() {
|
|
|
|
StringBuilder buf = new StringBuilder(1024);
|
2014-02-10 18:33:32 +00:00
|
|
|
buf.append("<table>\n" +
|
2015-09-25 19:55:36 +00:00
|
|
|
"<tr><th align=\"right\">").append(_t("Plugin")).append("</th><th>")
|
|
|
|
.append(_t("Run at Startup?")).append("</th><th>")
|
|
|
|
.append(_t("Control")).append("</th><th align=\"left\">")
|
|
|
|
.append(_t("Description")).append("</th></tr>\n");
|
2010-02-07 13:32:49 +00:00
|
|
|
Properties props = PluginStarter.pluginProperties();
|
2015-04-24 16:27:03 +00:00
|
|
|
Set<String> keys = new TreeSet<String>(props.stringPropertyNames());
|
2013-11-28 11:56:54 +00:00
|
|
|
for (String name : keys) {
|
2010-02-07 13:32:49 +00:00
|
|
|
if (name.startsWith(PluginStarter.PREFIX) && name.endsWith(PluginStarter.ENABLED)) {
|
|
|
|
String app = name.substring(PluginStarter.PREFIX.length(), name.lastIndexOf(PluginStarter.ENABLED));
|
|
|
|
String val = props.getProperty(name);
|
2014-04-30 14:22:25 +00:00
|
|
|
if (val.equals(PluginStarter.DELETED))
|
|
|
|
continue;
|
2010-02-08 16:15:23 +00:00
|
|
|
Properties appProps = PluginStarter.pluginProperties(_context, app);
|
2010-05-05 16:51:54 +00:00
|
|
|
if (appProps.isEmpty())
|
2010-02-17 18:12:46 +00:00
|
|
|
continue;
|
2010-02-08 16:15:23 +00:00
|
|
|
StringBuilder desc = new StringBuilder(256);
|
|
|
|
desc.append("<table border=\"0\">")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append("<tr><td><b>").append(_t("Version")).append("</b></td><td>").append(stripHTML(appProps, "version"))
|
2010-02-08 16:15:23 +00:00
|
|
|
.append("<tr><td><b>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Signed by")).append("</b></td><td>");
|
2010-02-17 18:12:46 +00:00
|
|
|
String s = stripHTML(appProps, "signer");
|
|
|
|
if (s != null) {
|
|
|
|
if (s.indexOf("@") > 0)
|
|
|
|
desc.append("<a href=\"mailto:").append(s).append("\">").append(s).append("</a>");
|
|
|
|
else
|
|
|
|
desc.append(s);
|
|
|
|
}
|
2010-02-08 23:28:09 +00:00
|
|
|
s = stripHTML(appProps, "date");
|
2010-02-08 16:15:23 +00:00
|
|
|
if (s != null) {
|
|
|
|
long ms = 0;
|
|
|
|
try {
|
|
|
|
ms = Long.parseLong(s);
|
|
|
|
} catch (NumberFormatException nfe) {}
|
|
|
|
if (ms > 0) {
|
|
|
|
String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(ms));
|
|
|
|
desc.append("<tr><td><b>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Date")).append("</b></td><td>").append(date);
|
2010-02-08 16:15:23 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-08 23:28:09 +00:00
|
|
|
s = stripHTML(appProps, "author");
|
2010-02-08 16:15:23 +00:00
|
|
|
if (s != null) {
|
|
|
|
desc.append("<tr><td><b>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Author")).append("</b></td><td>");
|
2010-02-08 23:28:09 +00:00
|
|
|
if (s.indexOf("@") > 0)
|
|
|
|
desc.append("<a href=\"mailto:").append(s).append("\">").append(s).append("</a>");
|
|
|
|
else
|
|
|
|
desc.append(s);
|
2010-02-08 16:15:23 +00:00
|
|
|
}
|
2010-02-08 23:28:09 +00:00
|
|
|
s = stripHTML(appProps, "description_" + Messages.getLanguage(_context));
|
2010-02-08 16:15:23 +00:00
|
|
|
if (s == null)
|
2010-02-08 23:28:09 +00:00
|
|
|
s = stripHTML(appProps, "description");
|
2010-02-08 16:15:23 +00:00
|
|
|
if (s != null) {
|
|
|
|
desc.append("<tr><td><b>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Description")).append("</b></td><td>").append(s);
|
2010-02-08 16:15:23 +00:00
|
|
|
}
|
2010-02-08 23:28:09 +00:00
|
|
|
s = stripHTML(appProps, "license");
|
2010-02-08 16:15:23 +00:00
|
|
|
if (s != null) {
|
|
|
|
desc.append("<tr><td><b>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("License")).append("</b></td><td>").append(s);
|
2010-02-08 16:15:23 +00:00
|
|
|
}
|
2010-02-08 23:28:09 +00:00
|
|
|
s = stripHTML(appProps, "websiteURL");
|
2010-02-08 16:15:23 +00:00
|
|
|
if (s != null) {
|
|
|
|
desc.append("<tr><td>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append("<a href=\"").append(s).append("\">").append(_t("Website")).append("</a><td> ");
|
2010-02-08 16:15:23 +00:00
|
|
|
}
|
2014-08-07 19:27:53 +00:00
|
|
|
String updateURL = stripHTML(appProps, "updateURL.su3");
|
|
|
|
if (updateURL == null)
|
|
|
|
updateURL = stripHTML(appProps, "updateURL");
|
2010-02-08 19:04:46 +00:00
|
|
|
if (updateURL != null) {
|
2010-02-08 16:15:23 +00:00
|
|
|
desc.append("<tr><td>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append("<a href=\"").append(updateURL).append("\">").append(_t("Update link")).append("</a><td> ");
|
2010-02-08 16:15:23 +00:00
|
|
|
}
|
|
|
|
desc.append("</table>");
|
2014-11-13 20:12:55 +00:00
|
|
|
boolean isRunning = PluginStarter.isPluginRunning(app, _context);
|
|
|
|
boolean enableStop = isRunning && !Boolean.parseBoolean(appProps.getProperty("disableStop"));
|
|
|
|
boolean enableStart = !isRunning;
|
2010-02-08 16:15:23 +00:00
|
|
|
renderForm(buf, app, app, false,
|
2014-04-18 01:14:23 +00:00
|
|
|
"true".equals(val), false, false, desc.toString(), false, false,
|
2010-04-16 03:58:48 +00:00
|
|
|
updateURL != null, enableStop, true, enableStart);
|
2010-02-07 13:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.append("</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2012-12-07 14:21:30 +00:00
|
|
|
/**
|
|
|
|
* Misnamed, renders a single line in a table for a single client/webapp/plugin.
|
|
|
|
*
|
2015-11-21 17:39:10 +00:00
|
|
|
* @param name will be escaped here
|
|
|
|
* @param ro trumps edit and showEditButton
|
|
|
|
* @param escapedDesc description, must be HTML escaped, except for plugins
|
2012-12-07 14:21:30 +00:00
|
|
|
*/
|
2010-01-06 21:24:08 +00:00
|
|
|
private void renderForm(StringBuilder buf, String index, String name, boolean urlify,
|
2015-11-21 17:39:10 +00:00
|
|
|
boolean enabled, boolean ro, boolean preventDisable, String escapedDesc, boolean edit,
|
2010-02-22 18:17:11 +00:00
|
|
|
boolean showEditButton, boolean showUpdateButton, boolean showStopButton,
|
2010-03-29 21:20:48 +00:00
|
|
|
boolean showDeleteButton, boolean showStartButton) {
|
2015-11-12 20:39:58 +00:00
|
|
|
String escapedName = DataHelper.escapeHTML(name);
|
2009-08-01 03:28:42 +00:00
|
|
|
buf.append("<tr><td class=\"mediumtags\" align=\"right\" width=\"25%\">");
|
2008-06-16 12:31:14 +00:00
|
|
|
if (urlify && enabled) {
|
|
|
|
String link = "/";
|
|
|
|
if (! RouterConsoleRunner.ROUTERCONSOLE.equals(name))
|
2015-11-12 20:39:58 +00:00
|
|
|
link += escapedName + "/";
|
|
|
|
buf.append("<a href=\"").append(link).append("\">").append(_t(escapedName)).append("</a>");
|
2010-01-06 21:24:08 +00:00
|
|
|
} else if (edit && !ro) {
|
2015-11-12 20:39:58 +00:00
|
|
|
buf.append("<input type=\"text\" name=\"nofilter_name").append(index).append("\" value=\"");
|
2010-01-18 14:51:39 +00:00
|
|
|
if (name.length() > 0)
|
2015-11-12 20:39:58 +00:00
|
|
|
buf.append(_t(escapedName));
|
2010-01-06 21:24:08 +00:00
|
|
|
buf.append("\" >");
|
2008-06-16 12:31:14 +00:00
|
|
|
} else {
|
2010-01-18 14:51:39 +00:00
|
|
|
if (name.length() > 0)
|
2015-11-12 20:39:58 +00:00
|
|
|
buf.append(_t(escapedName));
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
2015-11-12 20:39:58 +00:00
|
|
|
buf.append("</td><td align=\"center\" width=\"10%\"><input type=\"checkbox\" class=\"optbox\" name=\"").append(index).append(".enabled\"");
|
2008-06-16 12:31:14 +00:00
|
|
|
if (enabled) {
|
2012-03-02 22:32:45 +00:00
|
|
|
buf.append("checked=\"checked\" ");
|
2014-04-18 01:14:23 +00:00
|
|
|
if (ro || preventDisable)
|
2012-03-02 22:32:45 +00:00
|
|
|
buf.append("disabled=\"disabled\" ");
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
2010-02-10 19:09:35 +00:00
|
|
|
buf.append("></td><td align=\"center\" width=\"15%\">");
|
2011-12-04 18:52:17 +00:00
|
|
|
// The icons were way too much, so there's an X in each button class,
|
|
|
|
// remove if you wnat to put them back
|
2010-03-29 21:20:48 +00:00
|
|
|
if (showStartButton && (!ro) && !edit) {
|
2014-02-10 18:33:32 +00:00
|
|
|
buf.append("<button type=\"submit\" class=\"Xaccept\" name=\"action\" value=\"Start ").append(index).append("\" >")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Start")).append("<span class=hide> ").append(index).append("</span></button>");
|
2008-06-20 20:20:50 +00:00
|
|
|
}
|
2010-02-08 20:57:30 +00:00
|
|
|
if (showStopButton && (!edit))
|
2014-02-10 18:33:32 +00:00
|
|
|
buf.append("<button type=\"submit\" class=\"Xstop\" name=\"action\" value=\"Stop ").append(index).append("\" >")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Stop")).append("<span class=hide> ").append(index).append("</span></button>");
|
2014-08-03 13:58:51 +00:00
|
|
|
if (isClientChangeEnabled() && showEditButton && (!edit) && !ro)
|
|
|
|
buf.append("<button type=\"submit\" class=\"Xadd\" name=\"edit\" value=\"Edit ").append(index).append("\" >")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Edit")).append("<span class=hide> ").append(index).append("</span></button>");
|
2010-02-08 19:04:46 +00:00
|
|
|
if (showUpdateButton && (!edit) && !ro) {
|
2014-02-10 18:33:32 +00:00
|
|
|
buf.append("<button type=\"submit\" class=\"Xcheck\" name=\"action\" value=\"Check ").append(index).append("\" >")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Check for updates")).append("<span class=hide> ").append(index).append("</span></button>");
|
2014-02-10 18:33:32 +00:00
|
|
|
buf.append("<button type=\"submit\" class=\"Xdownload\" name=\"action\" value=\"Update ").append(index).append("\" >")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Update")).append("<span class=hide> ").append(index).append("</span></button>");
|
2010-01-06 21:24:08 +00:00
|
|
|
}
|
2010-02-22 18:17:11 +00:00
|
|
|
if (showDeleteButton && (!edit) && !ro) {
|
2011-12-04 18:52:17 +00:00
|
|
|
buf.append("<button type=\"submit\" class=\"Xdelete\" name=\"action\" value=\"Delete ").append(index)
|
2010-02-22 18:17:11 +00:00
|
|
|
.append("\" onclick=\"if (!confirm('")
|
2015-11-12 20:39:58 +00:00
|
|
|
.append(_t("Are you sure you want to delete {0}?", _t(escapedName)))
|
2010-02-22 18:17:11 +00:00
|
|
|
.append("')) { return false; }\">")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Delete")).append("<span class=hide> ").append(index).append("</span></button>");
|
2010-02-22 18:17:11 +00:00
|
|
|
}
|
2010-01-06 21:24:08 +00:00
|
|
|
buf.append("</td><td align=\"left\" width=\"50%\">");
|
|
|
|
if (edit && !ro) {
|
2015-11-12 20:39:58 +00:00
|
|
|
buf.append("<input type=\"text\" size=\"80\" spellcheck=\"false\" name=\"nofilter_desc").append(index).append("\" value=\"");
|
|
|
|
buf.append(escapedDesc);
|
2010-01-06 21:24:08 +00:00
|
|
|
buf.append("\" >");
|
|
|
|
} else {
|
2015-11-12 20:39:58 +00:00
|
|
|
buf.append(escapedDesc);
|
2010-01-06 21:24:08 +00:00
|
|
|
}
|
|
|
|
buf.append("</td></tr>\n");
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|
2010-02-08 23:28:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Like in DataHelper but doesn't convert null to ""
|
|
|
|
* There's a lot worse things a plugin could do but...
|
|
|
|
*/
|
Big refactor of the router console update subsystem, in preparation for
implementing out-of-console updaters like i2psnark.
- Add new update interfaces in net.i2p.update
- All update implementations moved to routerconsole update/
- Implement an UpdateManager that registers with the RouterContext
- UpdateManager handles multiple types of things to update
(router, plugins, news, ...) and methods of updating (HTTP, ...)
- UpdateManager maintains list of installed, downloaded, and available versions of everything
- Define Updaters that can check for a new version and/or download an item
- Individual Updaters register with the UpdateManager obtained from
I2PAppContext, identifying the type of update item and
update method they can handle.
- Updaters need only core libs, no router.jar or routerconsole access required.
- All checks and updates are initiated via the UpdateManager.
- All status on checks and updates in-progress or completed are
obtained from the UpdateManager. No more use of System properties
to broadcast update state.
- All update and checker tasks are intantiated on demand and threaded;
no more static references left over.
- Split out the Runners and Checkers from the Handlers and make the inheritance more sane.
- No more permanent NewsFetcher thread; run on the SimpleScheduler queue
and thread a checker task only to fetch the news.
- No more static NewsFetcher instance in routerconsole.
All helper methods that are still required are moved to NewsHelper.
The UpdateManager implements the policy for when to check and download.
All requests go through the UpdateManager.
For each update type, there's several parts:
- The xxxUpdateHandler implements the Updater
- The xxxUpdateChecker implements the UpdateTask for checking
- The xxxUpdateRunner implements the UpdateTask for downloading
New and moved classes:
web/ update/
---- -------
new ConsoleUpdateManager.java
new PluginUpdateChecker.java from PluginUpdateChecker
PluginUpdateChecker -> PluginUpdateHandler.java
PluginUpdateHandler.java -> PluginUpdateRunner
new UnsignedUpdateHandler.java
UnsignedUpdateHandler -> UnsignedUpdateRunner.java
new UnsignedUpdateChecker from NewsFetcher
UpdateHandler.java remains
new UpdateHandler.java
new UpdateRunner.java from UpdateHandler
move NewsHandler from NewsFetcher
new NewsFetcher
new NewsTimerTask
new DummyHandler
Initial checkin. Unfinished, untested, unpolished.
2012-06-18 22:09:45 +00:00
|
|
|
public static String stripHTML(Properties props, String key) {
|
2010-02-08 23:28:09 +00:00
|
|
|
String orig = props.getProperty(key);
|
|
|
|
if (orig == null) return null;
|
|
|
|
String t1 = orig.replace('<', ' ');
|
|
|
|
String rv = t1.replace('>', ' ');
|
|
|
|
return rv;
|
|
|
|
}
|
2008-06-16 12:31:14 +00:00
|
|
|
}
|