forked from I2P_Developers/i2p.i2p
Util: Consolidate console URL generation in PortMapper
This commit is contained in:
@ -438,21 +438,7 @@ class InternalTrayManager extends TrayManager {
|
||||
* @since 0.9.26
|
||||
*/
|
||||
private void launchBrowser() {
|
||||
String unset = "*unset*";
|
||||
PortMapper pm = _context.portMapper();
|
||||
String httpHost = pm.getActualHost(PortMapper.SVC_CONSOLE, unset);
|
||||
String httpsHost = pm.getActualHost(PortMapper.SVC_HTTPS_CONSOLE, unset);
|
||||
int httpPort = pm.getPort(PortMapper.SVC_CONSOLE, 7657);
|
||||
int httpsPort = pm.getPort(PortMapper.SVC_HTTPS_CONSOLE, -1);
|
||||
boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset);
|
||||
String url;
|
||||
if (httpsOnly) {
|
||||
url = "https://" + httpsHost + ':' + httpsPort + '/';
|
||||
} else {
|
||||
if (httpHost.equals(unset))
|
||||
httpHost = "127.0.0.1";
|
||||
url = "http://" + httpHost + ':' + httpPort + '/';
|
||||
}
|
||||
String url = _context.portMapper().getConsoleURL();
|
||||
try {
|
||||
I2PDesktop.browse(url);
|
||||
} catch (BrowseException e1) {
|
||||
|
@ -550,19 +550,9 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
String rv = out.toString();
|
||||
// Do we need to replace http://127.0.0.1:7657 console links in the error page?
|
||||
// Get the registered host and port from the PortMapper.
|
||||
final String unset = "*unset*";
|
||||
final String httpHost = ctx.portMapper().getActualHost(PortMapper.SVC_CONSOLE, unset);
|
||||
final String httpsHost = ctx.portMapper().getActualHost(PortMapper.SVC_HTTPS_CONSOLE, unset);
|
||||
final int httpPort = ctx.portMapper().getPort(PortMapper.SVC_CONSOLE, 7657);
|
||||
final int httpsPort = ctx.portMapper().getPort(PortMapper.SVC_HTTPS_CONSOLE, -1);
|
||||
final boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset);
|
||||
final int port = httpsOnly ? httpsPort : httpPort;
|
||||
String host = httpsOnly ? httpsHost : httpHost;
|
||||
if (host.equals(unset))
|
||||
host = "127.0.0.1";
|
||||
if (httpsOnly || port != 7657 || !host.equals("127.0.0.1")) {
|
||||
String url = (httpsOnly ? "https://" : "http://") + host + ':' + port;
|
||||
rv = rv.replace("http://127.0.0.1:7657", url);
|
||||
String url = ctx.portMapper().getConsoleURL();
|
||||
if (!url.equals("http://127.0.0.1:7657/")) {
|
||||
rv = rv.replace("http://127.0.0.1:7657/", url);
|
||||
}
|
||||
return rv;
|
||||
} finally {
|
||||
|
@ -219,6 +219,13 @@ public class ConfigServiceHandler extends FormHandler {
|
||||
(sdtg == null && (SystemVersion.isWindows() || SystemVersion.isMac()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.33
|
||||
*/
|
||||
public String getConsoleURL() {
|
||||
return _context.portMapper().getConsoleURL();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processForm() {
|
||||
if (_action == null) return;
|
||||
@ -348,9 +355,9 @@ public class ConfigServiceHandler extends FormHandler {
|
||||
}
|
||||
// releases <= 0.6.5 deleted the entry completely
|
||||
if (shouldLaunchBrowser && !found) {
|
||||
int port = _context.portMapper().getPort(PortMapper.SVC_CONSOLE, RouterConsoleRunner.DEFAULT_LISTEN_PORT);
|
||||
String url = _context.portMapper().getConsoleURL();
|
||||
ClientAppConfig ca = new ClientAppConfig(UrlLauncher.class.getName(), "consoleBrowser",
|
||||
"http://127.0.0.1:" + port + '/', 5, false);
|
||||
url, 5, false);
|
||||
clients.add(ca);
|
||||
}
|
||||
ClientAppConfig.writeClientAppConfig(_context, clients);
|
||||
|
@ -190,7 +190,7 @@ public class HomeHelper extends HelperBase {
|
||||
String url;
|
||||
if (app.name.equals(website) && app.url.equals("http://127.0.0.1:7658/")) {
|
||||
// fixup eepsite link
|
||||
url = "http://" + _context.portMapper().getHost(PortMapper.SVC_EEPSITE, "127.0.0.1") +
|
||||
url = "http://" + _context.portMapper().getActualHost(PortMapper.SVC_EEPSITE, "127.0.0.1") +
|
||||
':' + _context.portMapper().getPort(PortMapper.SVC_EEPSITE, 7658) + '/';
|
||||
} else {
|
||||
url = app.url;
|
||||
|
@ -226,7 +226,7 @@ class SummaryBarRenderer {
|
||||
.append("</a>\n" +
|
||||
|
||||
"<a href=\"http://")
|
||||
.append(_context.portMapper().getHost(PortMapper.SVC_EEPSITE, "127.0.0.1"))
|
||||
.append(_context.portMapper().getActualHost(PortMapper.SVC_EEPSITE, "127.0.0.1"))
|
||||
.append(':')
|
||||
.append(_context.portMapper().getPort(PortMapper.SVC_EEPSITE, 7658))
|
||||
.append("/\" target=\"_blank\" title=\"")
|
||||
|
@ -83,7 +83,8 @@
|
||||
|
||||
<h3 class="ptitle" id="browseronstart"><%=intl._t("Launch browser on router startup?")%></h3>
|
||||
<p class="infohelp">
|
||||
<%=intl._t("I2P''s main configuration interface is this web console, so for your convenience I2P can launch a web browser on startup pointing at {0}.", "<a href=\"http://127.0.0.1:7657/\">http://127.0.0.1:7657/</a>")%>
|
||||
<% String consoleURL = formhandler.getConsoleURL(); %>
|
||||
<%=intl._t("I2P''s main configuration interface is this web console, so for your convenience I2P can launch a web browser on startup pointing at {0}.", "<a href=\"" + consoleURL + "\">" + consoleURL + "</a>")%>
|
||||
</p>
|
||||
<hr><div class="formaction" id="browserstart">
|
||||
<input type="submit" class="check" name="action" value="<%=intl._t("View console on startup")%>" >
|
||||
|
@ -173,6 +173,24 @@ public class PortMapper {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* @return http URL unless console is https only. Default http://127.0.0.1:7657/
|
||||
* @since 0.9.33 consolidated from i2ptunnel and desktopgui
|
||||
*/
|
||||
public String getConsoleURL() {
|
||||
String unset = "*unset*";
|
||||
String httpHost = getActualHost(SVC_CONSOLE, unset);
|
||||
String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset);
|
||||
int httpPort = getPort(SVC_CONSOLE, 7657);
|
||||
int httpsPort = getPort(SVC_HTTPS_CONSOLE, -1);
|
||||
boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset);
|
||||
if (httpsOnly)
|
||||
return "https://" + httpsHost + ':' + httpsPort + '/';
|
||||
if (httpHost.equals(unset))
|
||||
httpHost = "127.0.0.1";
|
||||
return "http://" + httpHost + ':' + httpPort + '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* For debugging only
|
||||
* @since 0.9.20
|
||||
|
Reference in New Issue
Block a user