From 47d354711e058379aeca11f70c9569d68e80b6fe Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Wed, 25 Oct 2017 09:33:20 +0000
Subject: [PATCH] /configui: Add option to embed Susimail and I2PSnark in
 console

---
 .../java/src/net/i2p/router/web/CSSHelper.java      |  9 +++++++++
 .../src/net/i2p/router/web/ConfigUIHandler.java     | 13 ++++++++++---
 .../java/src/net/i2p/router/web/ConfigUIHelper.java |  9 +++++++++
 .../java/src/net/i2p/router/web/HomeHelper.java     |  6 +++---
 .../src/net/i2p/router/web/SummaryBarRenderer.java  |  4 ++--
 apps/routerconsole/jsp/torrents.jsp                 |  3 ++-
 apps/routerconsole/jsp/webmail.jsp                  |  3 ++-
 history.txt                                         |  1 +
 .../resources/themes/console/light/console.css      |  8 ++++----
 9 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/apps/routerconsole/java/src/net/i2p/router/web/CSSHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/CSSHelper.java
index 2218f06a7d..552d051843 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/CSSHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/CSSHelper.java
@@ -26,6 +26,7 @@ public class CSSHelper extends HelperBase {
     public static final String PROP_DISABLE_REFRESH = "routerconsole.summaryDisableRefresh";
     private static final String PROP_XFRAME = "routerconsole.disableXFrame";
     public static final String PROP_FORCE_MOBILE_CONSOLE = "routerconsole.forceMobileConsole";
+    public static final String PROP_EMBED_APPS = "routerconsole.embedApps";
 
     private static final String _consoleNonce = Long.toString(RandomSource.getInstance().nextLong());
 
@@ -51,6 +52,14 @@ public class CSSHelper extends HelperBase {
         return url;
     }
 
+    /**
+     * Returns whether app embedding is enabled or disabled
+     * @since 0.9.32
+     */
+    public boolean embedApps() {
+        return _context.getBooleanProperty(PROP_EMBED_APPS);
+    }
+
     /**
      * change default language for the router AND save it
      * @param lang xx OR xx_XX OR xxx OR xxx_XX
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHandler.java
index afe897b3ba..7b319237fc 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHandler.java
@@ -12,8 +12,9 @@ public class ConfigUIHandler extends FormHandler {
     private boolean _shouldSave;
     private boolean _universalTheming;
     private boolean _forceMobileConsole;
+    private boolean _embedApps;
     private String _config;
-    
+
     @Override
     protected void processForm() {
         if (_shouldSave) {
@@ -24,17 +25,19 @@ public class ConfigUIHandler extends FormHandler {
             addUser();
         }
     }
-    
+
     public void setShouldsave(String moo) { _shouldSave = true; }
 
     public void setUniversalTheming(String baa) { _universalTheming = true; }
 
     public void setForceMobileConsole(String baa) { _forceMobileConsole = true; }
 
+    public void setEmbedApps(String baa) { _embedApps = true; }
+
     public void setTheme(String val) {
         _config = val;
     }
-    
+
     /** note - lang change is handled in CSSHelper but we still need to save it here */
     private void saveChanges() {
         if (_config == null || _config.length() <= 0)
@@ -59,6 +62,10 @@ public class ConfigUIHandler extends FormHandler {
             changes.put(CSSHelper.PROP_FORCE_MOBILE_CONSOLE, "true");
         else
             removes.add(CSSHelper.PROP_FORCE_MOBILE_CONSOLE);
+        if (_embedApps)
+            changes.put(CSSHelper.PROP_EMBED_APPS, "true");
+        else
+            removes.add(CSSHelper.PROP_EMBED_APPS);
         boolean ok = _context.router().saveConfig(changes, removes);
         if (ok) {
             if (!oldTheme.equals(_config))
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHelper.java
index d117dc438f..707c7a3532 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHelper.java
@@ -43,6 +43,15 @@ public class ConfigUIHelper extends HelperBase {
             buf.append(CHECKED);
         buf.append("value=\"1\">")
            .append(_t("Force the mobile console to be used"))
+           .append("</label></br>\n");
+        boolean embedApps = _context.getBooleanProperty(CSSHelper.PROP_EMBED_APPS);
+        buf.append("<label title=\"")
+           .append(_t("Enabling the Universal Themeing option is recommended when embedding these applications"))
+           .append("\"><input type=\"checkbox\" name=\"embedApps\" ");
+        if (embedApps)
+            buf.append(CHECKED);
+        buf.append("value=\"1\">")
+           .append(_t("Embed I2PSnark and I2PMail in the console"))
            .append("</label></div>\n");
         return buf.toString();
     }
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/HomeHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/HomeHelper.java
index 95acea127c..3e017e2eed 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/HomeHelper.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/HomeHelper.java
@@ -17,7 +17,7 @@ import net.i2p.util.PortMapper;
  *  @since 0.9
  */
 public class HomeHelper extends HelperBase {
-    
+
     private static final char S = ',';
     private static final String I = "/themes/console/images/";
     static final String PROP_SERVICES = "routerconsole.services";
@@ -33,11 +33,11 @@ public class HomeHelper extends HelperBase {
         _x("Configure UI") + S + _x("Select console theme & language & set optional console password").replace("&", "&amp;") + S + "/configui" + S + I + "info/ui.png" + S +
         _x("Customize Home Page") + S + _x("I2P Home Page Configuration") + S + "/confighome" + S + I + "home_page.png" + S +
         _x("Customize Sidebar") + S + _x("Customize the sidebar by adding or removing or repositioning elements") + S + "/configsidebar" + S + I + "info/sidebar.png" + S +
-        _x("Email") + S + _x("Anonymous webmail client") + S + "/susimail/susimail" + S + I + "email.png" + S +
+        _x("Email") + S + _x("Anonymous webmail client") + S + "/webmail" + S + I + "email.png" + S +
         _x("Help") + S + _x("I2P Router Help") + S + "/help" + S + I + "support.png" + S +
         _x("Manage Plugins") + S + _x("Install and configure I2P plugins") + S + "/configplugins" + S + I + "plugin.png" + S +
         _x("Router Console") + S + _x("I2P Router Console") + S + "/console" + S + I + "info/console.png" + S +
-        _x("Torrents") + S + _x("Built-in anonymous BitTorrent Client") + S + "/i2psnark/" + S + I + "i2psnark.png" + S +
+        _x("Torrents") + S + _x("Built-in anonymous BitTorrent Client") + S + "/torrents" + S + I + "i2psnark.png" + S +
         _x("Web Server") + S + _x("Local web server for hosting your own content on I2P") + S + "http://127.0.0.1:7658/" + S + I + "server_32x32.png" + S +
         "";
 
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java
index 32da250f6b..2d15fdb9bd 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/SummaryBarRenderer.java
@@ -208,13 +208,13 @@ class SummaryBarRenderer {
 
                    "<hr class=\"b\"><table id=\"sb_services\"><tr><td>" +
 
-                   "<a href=\"/susimail/susimail\" target=\"_blank\" title=\"")
+                   "<a href=\"/webmail\" target=\"_top\" title=\"")
            .append(_t("Anonymous webmail client"))
            .append("\">")
            .append(nbsp(_t("Email")))
            .append("</a>\n" +
 
-                   "<a href=\"/i2psnark/\" target=\"_blank\" title=\"")
+                   "<a href=\"/torrents\" target=\"_top\" title=\"")
            .append(_t("Built-in anonymous BitTorrent Client"))
            .append("\">")
            .append(nbsp(_t("Torrents")))
diff --git a/apps/routerconsole/jsp/torrents.jsp b/apps/routerconsole/jsp/torrents.jsp
index 96c7df907b..eaa9d408cf 100644
--- a/apps/routerconsole/jsp/torrents.jsp
+++ b/apps/routerconsole/jsp/torrents.jsp
@@ -6,7 +6,8 @@
 <%
     // CSSHelper is also pulled in by css.jsi below...
     boolean testIFrame = tester.allowIFrame(request.getHeader("User-Agent"));
-    if (!testIFrame) {
+    boolean embedApp = tester.embedApps();
+    if (!testIFrame || !embedApp) {
         response.setStatus(302);
         response.setHeader("Location", "/i2psnark/");
     } else {
diff --git a/apps/routerconsole/jsp/webmail.jsp b/apps/routerconsole/jsp/webmail.jsp
index 0138a946d2..0b3be3a5d6 100644
--- a/apps/routerconsole/jsp/webmail.jsp
+++ b/apps/routerconsole/jsp/webmail.jsp
@@ -6,7 +6,8 @@
 <%
     // CSSHelper is also pulled in by css.jsi below...
     boolean testIFrame = tester.allowIFrame(request.getHeader("User-Agent"));
-    if (!testIFrame) {
+    boolean embedApp = tester.embedApps();
+    if (!testIFrame || !embedApp) {
         response.setStatus(302);
         response.setHeader("Location", "/susimail/susimail");
     } else {
diff --git a/history.txt b/history.txt
index 96b500f79e..2affe7baa9 100644
--- a/history.txt
+++ b/history.txt
@@ -22,6 +22,7 @@
      - Add additional reachability states for clockskew and vmcomm (with icons)
    - Homepage: Add 'Customize Sidebar' link to signpost the feature now that
      there are more optional sections available (ticket #1996)
+   - /configui: Add option to embed Susimail and I2PSnark in console
  * I2PTunnel: Add hostname / destination (b32) information to server section on
    index page (for parity with client tunnels section)
  * SusiDNS:
diff --git a/installer/resources/themes/console/light/console.css b/installer/resources/themes/console/light/console.css
index 96a1f91c69..73a6362204 100644
--- a/installer/resources/themes/console/light/console.css
+++ b/installer/resources/themes/console/light/console.css
@@ -688,21 +688,21 @@ p:empty + .sb_notice {
      background-color: #ffe;
 }
 
-#sb_services a[href="/susimail/susimail"] {
+#sb_services a[href="/susimail/susimail"], #sb_services a[href="/webmail"] {
      background: #f8f8ff url(images/inbox.png) 3px center no-repeat;
      background: rgba(248, 248, 255, 0.8) url(images/inbox.png) 3px center no-repeat;
 }
 
-#sb_services a[href="/susimail/susimail"]:hover {
+#sb_services a[href="/susimail/susimail"]:hover, #sb_services a[href="/webmail"]:hover {
      background: #ffe url(images/inbox.png) 3px center no-repeat;
 }
 
-#sb_services a[href="/i2psnark/"] {
+#sb_services a[href="/i2psnark/"], #sb_services a[href="/torrents"] {
      background: #f8f8ff url(/themes/console/images/i2psnark.png) 3px center no-repeat;
      background: rgba(248, 248, 255, 0.8) url(/themes/console/images/i2psnark.png) 3px center no-repeat;
 }
 
-#sb_services a[href="/i2psnark/"]:hover {
+#sb_services a[href="/i2psnark/"]:hover, #sb_services a[href="/torrents"]:hover {
      background: #ffe url(/themes/console/images/i2psnark.png) 3px center no-repeat;
 }
 
-- 
GitLab