From 63c6613261dc52e9c77171f7191e65bf8ec88d72 Mon Sep 17 00:00:00 2001 From: zzz Date: Fri, 24 Dec 2010 16:52:23 +0000 Subject: [PATCH] * configclients.jsp: - Add form for I2CP options - Fix HTML errors --- .../i2p/router/web/ConfigClientsHandler.java | 40 +++++++- .../i2p/router/web/ConfigClientsHelper.java | 94 +++++++++++++++++-- apps/routerconsole/jsp/configclients.jsp | 46 ++++++++- .../themes/console/classic/console.css | 4 +- .../resources/themes/console/dark/console.css | 6 +- .../themes/console/light/console.css | 4 +- .../themes/console/midnight/console.css | 6 +- 7 files changed, 181 insertions(+), 19 deletions(-) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java index 91ac9726f..9a5d6bbf9 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import net.i2p.router.client.ClientManagerFacadeImpl; import net.i2p.router.startup.ClientAppConfig; import net.i2p.router.startup.LoadClientAppsJob; @@ -35,6 +36,10 @@ public class ConfigClientsHandler extends FormHandler { saveClientChanges(); return; } + if (_action.equals(_("Save Interface Configuration"))) { + saveInterfaceChanges(); + return; + } if (_action.equals(_("Save WebApp Configuration"))) { saveWebAppChanges(); return; @@ -193,7 +198,7 @@ public class ConfigClientsHandler extends FormHandler { String[] arr = (String[]) _settings.get(key); if (arr == null) return null; - return arr[0]; + return arr[0].trim(); } private void startClient(int i) { @@ -337,4 +342,37 @@ public class ConfigClientsHandler extends FormHandler { _log.error("Error starting plugin " + app, e); } } + + /** + * Handle interface form + * @since 0.8.3 + */ + private void saveInterfaceChanges() { + String port = getJettyString("port"); + if (port != null) + _context.router().setConfigSetting(ClientManagerFacadeImpl.PROP_CLIENT_PORT, port); + String intfc = getJettyString("interface"); + if (intfc != null) + _context.router().setConfigSetting(ClientManagerFacadeImpl.PROP_CLIENT_HOST, intfc); + String user = getJettyString("user"); + if (user != null) + _context.router().setConfigSetting(ConfigClientsHelper.PROP_USER, user); + String pw = getJettyString("pw"); + if (pw != null) + _context.router().setConfigSetting(ConfigClientsHelper.PROP_PW, pw); + String mode = getJettyString("mode"); + boolean disabled = "0".equals(mode); + boolean ssl = "2".equals(mode); + _context.router().setConfigSetting(ConfigClientsHelper.PROP_DISABLE_EXTERNAL, + Boolean.toString(disabled)); + _context.router().setConfigSetting(ConfigClientsHelper.PROP_ENABLE_SSL, + Boolean.toString(ssl)); + _context.router().setConfigSetting(ConfigClientsHelper.PROP_AUTH, + Boolean.toString((_settings.get("auth") != null))); + boolean all = "0.0.0.0".equals(intfc) || "0:0:0:0:0:0:0:0".equals(intfc) || + "::".equals(intfc); + _context.router().setConfigSetting(ConfigClientsHelper.BIND_ALL_INTERFACES, Boolean.toString(all)); + _context.router().saveConfig(); + addFormNotice(_("Interface configuration saved successfully - restart required to take effect.")); + } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java index 049b5a02a..7cd2c8cb7 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java @@ -1,6 +1,9 @@ package net.i2p.router.web; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -8,13 +11,90 @@ import java.util.Properties; import java.util.Set; import java.util.TreeSet; +import net.i2p.router.client.ClientManagerFacadeImpl; import net.i2p.router.startup.ClientAppConfig; +import net.i2p.router.transport.Addresses; public class ConfigClientsHelper extends HelperBase { private String _edit; + /** 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"; + public static final String PROP_USER = "i2cp.username"; + public static final String PROP_PW = "i2cp.password"; + public ConfigClientsHelper() {} - + + /** @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 getUser() { + return _context.getProperty(PROP_USER, ""); + } + + /** @since 0.8.3 */ + public String getPw() { + return _context.getProperty(PROP_PW, ""); + } + + /** @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)) + return "checked=\"true\""; + return ""; + } + + /** @since 0.8.3 */ + public String getAuth() { + boolean enabled = _context.getBooleanProperty(PROP_AUTH); + if (enabled) + return "checked=\"true\""; + return ""; + } + + /** @since 0.8.3 */ + public String[] intfcAddresses() { + String[] addrs = Addresses.getAllAddresses(); + List aList = new ArrayList(); + aList.addAll(Arrays.asList(addrs)); + boolean ipv6 = false; + for (String a : aList) { + if (a.indexOf(':') >= 0) { + ipv6 = true; + break; + } + } + if (!aList.contains("0.0.0.0")) + aList.add("0.0.0.0"); + if (ipv6 && !aList.contains("0:0:0:0:0:0:0:0")) + aList.add("0:0:0:0:0:0:0:0"); // we could do "::" but all the other ones are probably in long form + Collections.sort(aList); + return aList.toArray(addrs); + } + + /** @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)); + } + public void setEdit(String edit) { if (edit == null) return; @@ -92,9 +172,9 @@ public class ConfigClientsHelper extends HelperBase { continue; StringBuilder desc = new StringBuilder(256); desc.append("") - .append("
").append(_("Version")).append("").append(stripHTML(appProps, "version")) + .append("
").append(_("Version")).append("").append(stripHTML(appProps, "version")) .append("
") - .append(_("Signed by")).append(""); + .append(_("Signed by")).append(""); String s = stripHTML(appProps, "signer"); if (s != null) { if (s.indexOf("@") > 0) @@ -111,13 +191,13 @@ public class ConfigClientsHelper extends HelperBase { if (ms > 0) { String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(ms)); desc.append("
") - .append(_("Date")).append("").append(date); + .append(_("Date")).append("").append(date); } } s = stripHTML(appProps, "author"); if (s != null) { desc.append("
") - .append(_("Author")).append(""); + .append(_("Author")).append(""); if (s.indexOf("@") > 0) desc.append("").append(s).append(""); else @@ -128,12 +208,12 @@ public class ConfigClientsHelper extends HelperBase { s = stripHTML(appProps, "description"); if (s != null) { desc.append("
") - .append(_("Description")).append("").append(s); + .append(_("Description")).append("").append(s); } s = stripHTML(appProps, "license"); if (s != null) { desc.append("
") - .append(_("License")).append("").append(s); + .append(_("License")).append("").append(s); } s = stripHTML(appProps, "websiteURL"); if (s != null) { diff --git a/apps/routerconsole/jsp/configclients.jsp b/apps/routerconsole/jsp/configclients.jsp index 4f633c894..a4d670295 100644 --- a/apps/routerconsole/jsp/configclients.jsp +++ b/apps/routerconsole/jsp/configclients.jsp @@ -47,7 +47,51 @@ button span.hide{ " /> <% } %> " /> -

<%=intl._("WebApp Configuration")%>

+ + +

<%=intl._("Advanced Client Interface Configuration")%>

+<%=intl._("External I2CP (I2P Client Protocol) Interface Configuration")%>
+ > +<%=intl._("Enabled without SSL")%>
+ > +<%=intl._("Enabled with SSL required")%>
+ > +<%=intl._("Disabled - Clients outside this Java process may not connect")%>
+<%=intl._("I2CP Port")%>: +" >
+<%=intl._("I2CP Interface")%>: +
+<%=intl._("Authorization")%>
+ > +<%=intl._("Requre username and password")%>
+<%=intl._("Username")%>: +" >
+<%=intl._("Password")%>: +" >
+

<%=intl._("The default settings will work for most people.")%> +<%=intl._("Any changes made here must also be configured in the external client.")%> +<%=intl._("Many clients do not support SSL or authorization.")%> +<%=intl._("All changes require restart to take effect.")%> +


+" /> +" /> +
+ +

<%=intl._("WebApp Configuration")%>

<%=intl._("The Java web applications listed below are started by the webConsole client and run in the same JVM as the router. They are usually web applications accessible through the router console. They may be complete applications (e.g. i2psnark),front-ends to another client or application which must be separately enabled (e.g. susidns, i2ptunnel), or have no web interface at all (e.g. addressbook).")%>

<%=intl._("A web app may also be disabled by removing the .war file from the webapps directory; however the .war file and web app will reappear when you update your router to a newer version, so disabling the web app here is the preferred method.")%> diff --git a/installer/resources/themes/console/classic/console.css b/installer/resources/themes/console/classic/console.css index 3aa0c1424..2c2768053 100644 --- a/installer/resources/themes/console/classic/console.css +++ b/installer/resources/themes/console/classic/console.css @@ -714,7 +714,7 @@ input { vertical-align: middle; } -input[type=text] { +input[type=text], input[type=password] { margin: 3px 5px 3px 5px; vertical-align: middle; } @@ -910,4 +910,4 @@ div.footnote hr{ margin-top: -8px; margin-bottom: -5px; margin-right: 5px; -} \ No newline at end of file +} diff --git a/installer/resources/themes/console/dark/console.css b/installer/resources/themes/console/dark/console.css index c2a16245c..827002d53 100644 --- a/installer/resources/themes/console/dark/console.css +++ b/installer/resources/themes/console/dark/console.css @@ -843,7 +843,7 @@ input:active { color: #EE9; } -input[type=text] { +input[type=text], input[type=password] { background: #000; color: #EE9; margin: 5px 10px; @@ -859,7 +859,7 @@ input[type=text] { box-shadow: inset 1px 1px 1px 0px #000; } -input[type=text]:active, input[type=text]:hover { +input[type=text]:active, input[type=text]:hover, input[type=password]:active, input[type=password]:hover { background: #000; } @@ -1058,4 +1058,4 @@ div.footnote hr{ margin-top: -5px; margin-bottom: -5px; margin-right: 5px; -} \ No newline at end of file +} diff --git a/installer/resources/themes/console/light/console.css b/installer/resources/themes/console/light/console.css index 94dc14f3f..67cef2734 100644 --- a/installer/resources/themes/console/light/console.css +++ b/installer/resources/themes/console/light/console.css @@ -911,7 +911,7 @@ input:active { -moz-box-shadow: inset 0px 0px 0px 1px #f60; } -input[type=text] { +input[type=text], input[type=password] { background: #ffe; color: #001; margin: 5px 10px 5px 10px; @@ -1166,4 +1166,4 @@ div.footnote hr{ margin-top: 0px; margin-bottom: -18px; margin-right: 5px; -} \ No newline at end of file +} diff --git a/installer/resources/themes/console/midnight/console.css b/installer/resources/themes/console/midnight/console.css index 996259149..372364b74 100644 --- a/installer/resources/themes/console/midnight/console.css +++ b/installer/resources/themes/console/midnight/console.css @@ -750,7 +750,7 @@ input { vertical-align: middle; } -input[type=text] { +input[type=text], input[type=password] { margin: 3px 5px 3px 5px; vertical-align: middle; } @@ -760,7 +760,7 @@ select { vertical-align: middle; } -input[type=text], select { +input[type=text], input[type=password] select { background: #001; color: #eef; border: 1px solid #99f; @@ -959,4 +959,4 @@ div.footnote hr{ margin-top: -5px; margin-bottom: -10px; margin-right: 5px; -} \ No newline at end of file +}