From 47f3476078b086688b4b57af10f7565e2874e4ac Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Sat, 21 Mar 2015 04:29:32 +0000 Subject: [PATCH] More I2PTunnel UI logic into GeneralHelper --- .../net/i2p/i2ptunnel/ui/GeneralHelper.java | 22 ++++++++++++++++++- .../src/net/i2p/i2ptunnel/web/EditBean.java | 18 +++------------ .../src/net/i2p/i2ptunnel/web/IndexBean.java | 21 ++++-------------- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java index 77eaa8cba8..6405e98d41 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java @@ -260,7 +260,7 @@ public class GeneralHelper { public String getSpoofedHost(int tunnel) { TunnelController tun = getController(tunnel); - return (tun != null && tun.getSpoofedHost() != null) ? tun.getSpoofedHost() :""; + return (tun != null && tun.getSpoofedHost() != null) ? tun.getSpoofedHost() : ""; } public String getPrivateKeyFile(int tunnel) { @@ -286,6 +286,18 @@ public class GeneralHelper { return "127.0.0.1"; } + public int getClientPort(int tunnel) { + TunnelController tun = getController(tunnel); + if (tun != null && tun.getListenPort() != null) { + try { + return Integer.parseInt(tun.getListenPort()); + } catch (NumberFormatException e) { + return -1; + } + } else + return -1; + } + public int getTunnelStatus(int tunnel) { TunnelController tun = getController(tunnel); if (tun == null) return NOT_RUNNING; @@ -463,6 +475,10 @@ public class GeneralHelper { return getBooleanProperty(tunnel, I2PTunnelIRCClient.PROP_DCC); } + public boolean isSSLEnabled(int tunnel) { + return getBooleanProperty(tunnel, I2PTunnelServer.PROP_USE_SSL); + } + public String getEncryptKey(int tunnel) { return getProperty(tunnel, "i2cp.leaseSetKey", ""); } @@ -608,6 +624,10 @@ public class GeneralHelper { return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_TOTAL_BAN_TIME, I2PTunnelHTTPServer.DEFAULT_POST_TOTAL_BAN_TIME) / 60; } + public boolean getRejectInproxy(int tunnel) { + return getBooleanProperty(tunnel, I2PTunnelHTTPServer.OPT_REJECT_INPROXY); + } + public boolean getUniqueLocal(int tunnel) { return getBooleanProperty(tunnel, I2PTunnelServer.PROP_UNIQUE_LOCAL); } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java index 3f7c6c01e0..ebc4950981 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/EditBean.java @@ -60,11 +60,7 @@ public class EditBean extends IndexBean { } public String getSpoofedHost(int tunnel) { - TunnelController tun = getController(tunnel); - if (tun != null && tun.getSpoofedHost() != null) - return DataHelper.escapeHTML(tun.getSpoofedHost()); - else - return ""; + return DataHelper.escapeHTML(_helper.getSpoofedHost(tunnel)); } public String getPrivateKeyFile(int tunnel) { @@ -97,19 +93,11 @@ public class EditBean extends IndexBean { } public boolean startAutomatically(int tunnel) { - TunnelController tun = getController(tunnel); - if (tun != null) - return tun.getStartOnLoad(); - else - return false; + return _helper.shouldStartAutomatically(tunnel); } public boolean isSharedClient(int tunnel) { - TunnelController tun = getController(tunnel); - if (tun != null) - return Boolean.parseBoolean(tun.getSharedClient()); - else - return false; + return _helper.isSharedClient(tunnel); } public boolean shouldDelay(int tunnel) { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java index 81511e89cb..0480527f4a 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java @@ -329,11 +329,8 @@ public class IndexBean { * No validation */ public String getClientPort(int tunnel) { - TunnelController tun = getController(tunnel); - if (tun != null && tun.getListenPort() != null) - return tun.getListenPort(); - else - return ""; + int port = _helper.getClientPort(tunnel); + return port > 0 ? Integer.toString(port) : ""; } /** @@ -667,12 +664,7 @@ public class IndexBean { /** @since 0.9.9 */ public boolean isSSLEnabled(int tunnel) { - TunnelController tun = getController(tunnel); - if (tun != null) { - Properties opts = tun.getClientOptionProps(); - return Boolean.parseBoolean(opts.getProperty(I2PTunnelServer.PROP_USE_SSL)); - } - return false; + return _helper.isSSLEnabled(tunnel); } /** @since 0.9.12 */ @@ -682,12 +674,7 @@ public class IndexBean { /** @since 0.9.12 */ public boolean isRejectInproxy(int tunnel) { - TunnelController tun = getController(tunnel); - if (tun != null) { - Properties opts = tun.getClientOptionProps(); - return Boolean.parseBoolean(opts.getProperty(I2PTunnelHTTPServer.OPT_REJECT_INPROXY)); - } - return false; + return _helper.getRejectInproxy(tunnel); } /** @since 0.9.13 */ -- GitLab