From 12c7871640047a39d46006a5300beed974a61401 Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 19 Feb 2018 23:12:06 +0000 Subject: [PATCH] i2ptunnel, systray: Replace hardcoded console URL in more places (ticket #2160) --- .../i2p/i2ptunnel/I2PTunnelHTTPClient.java | 22 +++---------------- .../localServer/LocalHTTPServer.java | 6 +++-- .../src/net/i2p/apps/systray/UrlLauncher.java | 4 ++-- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index f40c5072a..26649a657 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -766,23 +766,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn Hash h1 = ConvertToHash.getHash(requestURI.getHost()); Hash h2 = ConvertToHash.getHash(ahelperKey); if (h1 != null && h2 != null) { - // Do we need to replace http://127.0.0.1:7657 - // Get the registered host and port from the PortMapper. - final String unset = "*unset*"; - final String httpHost = _context.portMapper().getActualHost(PortMapper.SVC_CONSOLE, unset); - final String httpsHost = _context.portMapper().getActualHost(PortMapper.SVC_HTTPS_CONSOLE, unset); - final int httpPort = _context.portMapper().getPort(PortMapper.SVC_CONSOLE, 7657); - final int httpsPort = _context.portMapper().getPort(PortMapper.SVC_HTTPS_CONSOLE, -1); - final boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset); - final int cport = httpsOnly ? httpsPort : httpPort; - String chost = httpsOnly ? httpsHost : httpHost; - if (chost.equals(unset)) - chost = "127.0.0.1"; - String chostport; - if (httpsOnly || cport != 7657 || !chost.equals("127.0.0.1")) - chostport = (httpsOnly ? "https://" : "http://") + chost + ':' + cport; - else - chostport = "http://127.0.0.1:7657"; + String conURL = _context.portMapper().getConsoleURL(); out.write(("\n\n\n
" + "").getBytes("UTF-8")); out.write(_t("Destination for {0} in address book", requestURI.getHost()).getBytes("UTF-8")); @@ -792,13 +776,13 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn out.write(("
" + "" + "\n").getBytes("UTF-8")); out.write(("" + "" + "\n").getBytes("UTF-8")); out.write("
".getBytes("UTF-8")); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/localServer/LocalHTTPServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/localServer/LocalHTTPServer.java index eff898aae..82cca3769 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/localServer/LocalHTTPServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/localServer/LocalHTTPServer.java @@ -198,6 +198,8 @@ public abstract class LocalHTTPServer { tbook = _t("private"); else tbook = book; + + String conURL = I2PAppContext.getGlobalContext().portMapper().getConsoleURL(); out.write(("HTTP/1.1 200 OK\r\n"+ "Content-Type: text/html; charset=UTF-8\r\n"+ "Referrer-Policy: no-referrer\r\n"+ @@ -211,8 +213,8 @@ public abstract class LocalHTTPServer { "\n" + "\n" + "" + "
\n" + "

" + diff --git a/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java b/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java index dabd1ed8e..badcbdc3d 100644 --- a/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java +++ b/apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java @@ -89,7 +89,7 @@ public class UrlLauncher implements ClientApp { _context = context; _mgr = mgr; if (args == null || args.length <= 0) - args = new String[] {"http://127.0.0.1:7657/index.jsp"}; + args = new String[] { context.portMapper().getConsoleURL() }; _args = args; _shellCommand = new ShellCommand(); _state = INITIALIZED; @@ -355,7 +355,7 @@ public class UrlLauncher implements ClientApp { if (args.length > 0) launcher.openUrl(args[0]); else - launcher.openUrl("http://127.0.0.1:7657/index.jsp"); + launcher.openUrl(I2PAppContext.getGlobalContext().portMapper().getConsoleURL()); } catch (IOException e) {} } }