PortMapper: HTTPS console fallback to HTTP

Console port constants
This commit is contained in:
zzz
2018-03-04 12:30:36 +00:00
parent 3bc9053a86
commit c6e401a64f
2 changed files with 18 additions and 11 deletions

View File

@ -127,8 +127,7 @@ public class RouterConsoleRunner implements RouterApp {
public static final String ENABLED = ".startOnLoad"; public static final String ENABLED = ".startOnLoad";
private static final String PROP_KEYSTORE_PASSWORD = "routerconsole.keystorePassword"; private static final String PROP_KEYSTORE_PASSWORD = "routerconsole.keystorePassword";
private static final String PROP_KEY_PASSWORD = "routerconsole.keyPassword"; private static final String PROP_KEY_PASSWORD = "routerconsole.keyPassword";
public static final int DEFAULT_LISTEN_PORT = 7657; public static final int DEFAULT_LISTEN_PORT = PortMapper.DEFAULT_CONSOLE_PORT;
private static final String DEFAULT_LISTEN_HOST = "127.0.0.1";
private static final String DEFAULT_WEBAPPS_DIR = "./webapps/"; private static final String DEFAULT_WEBAPPS_DIR = "./webapps/";
private static final String USAGE = "Bad RouterConsoleRunner arguments, check clientApp.0.args in your clients.config file! " + private static final String USAGE = "Bad RouterConsoleRunner arguments, check clientApp.0.args in your clients.config file! " +
"Usage: [[port host[,host]] [-s sslPort [host[,host]]] [webAppsDir]]"; "Usage: [[port host[,host]] [-s sslPort [host[,host]]] [webAppsDir]]";
@ -199,7 +198,7 @@ public class RouterConsoleRunner implements RouterApp {
} }
} }
if (_listenHost == null) if (_listenHost == null)
_listenHost = DEFAULT_LISTEN_HOST; _listenHost = PortMapper.DEFAULT_HOST;
if (_sslListenHost == null) if (_sslListenHost == null)
_sslListenHost = _listenHost; _sslListenHost = _listenHost;
if (_webAppsDir == null) if (_webAppsDir == null)
@ -748,7 +747,7 @@ public class RouterConsoleRunner implements RouterApp {
} }
} }
if (error) { if (error) {
String port = (_listenPort != null) ? _listenPort : ((_sslListenPort != null) ? _sslListenPort : "7657"); String port = (_listenPort != null) ? _listenPort : ((_sslListenPort != null) ? _sslListenPort : Integer.toString(DEFAULT_LISTEN_PORT));
System.err.println("WARNING: Error starting one or more listeners of the Router Console server.\n" + System.err.println("WARNING: Error starting one or more listeners of the Router Console server.\n" +
"If your console is still accessible at http://127.0.0.1:" + port + "/,\n" + "If your console is still accessible at http://127.0.0.1:" + port + "/,\n" +
"this may be a problem only with binding to the IPV6 address ::1.\n" + "this may be a problem only with binding to the IPV6 address ::1.\n" +

View File

@ -46,6 +46,14 @@ public class PortMapper {
/** @since 0.9.34 */ /** @since 0.9.34 */
public static final String SVC_HTTPS_I2PCONTROL = "https_i2pcontrol"; public static final String SVC_HTTPS_I2PCONTROL = "https_i2pcontrol";
/** @since 0.9.34 */
public static final int DEFAULT_CONSOLE_PORT = 7657;
/** @since 0.9.34 */
public static final int DEFAULT_HTTPS_CONSOLE_PORT = 7667;
/** @since 0.9.34 */
public static final String DEFAULT_HOST = "127.0.0.1";
/** /**
* @param context unused for now * @param context unused for now
*/ */
@ -59,7 +67,7 @@ public class PortMapper {
* @return success, false if already registered * @return success, false if already registered
*/ */
public boolean register(String service, int port) { public boolean register(String service, int port) {
return register(service, "127.0.0.1", port); return register(service, DEFAULT_HOST, port);
} }
/** /**
@ -209,18 +217,18 @@ public class PortMapper {
String unset = "*unset*"; String unset = "*unset*";
String httpHost = getActualHost(SVC_CONSOLE, unset); String httpHost = getActualHost(SVC_CONSOLE, unset);
String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset); String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset);
int httpPort = getPort(SVC_CONSOLE, 7657); int httpPort = getPort(SVC_CONSOLE, DEFAULT_CONSOLE_PORT);
int httpsPort = getPort(SVC_HTTPS_CONSOLE); int httpsPort = getPort(SVC_HTTPS_CONSOLE);
boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset); boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset);
if (httpsOnly) if (httpsOnly)
return "https://" + httpsHost + ':' + httpsPort + '/'; return "https://" + httpsHost + ':' + httpsPort + '/';
if (httpHost.equals(unset)) if (httpHost.equals(unset))
httpHost = "127.0.0.1"; httpHost = DEFAULT_HOST;
return "http://" + httpHost + ':' + httpPort + '/'; return "http://" + httpHost + ':' + httpPort + '/';
} }
/** /**
* @return https URL unless console is http only. Default https://127.0.0.1:7667/ * @return https URL unless console is http only. Default http://127.0.0.1:7657/
* @since 0.9.34 * @since 0.9.34
*/ */
private String getHTTPSConsoleURL() { private String getHTTPSConsoleURL() {
@ -228,12 +236,12 @@ public class PortMapper {
String httpHost = getActualHost(SVC_CONSOLE, unset); String httpHost = getActualHost(SVC_CONSOLE, unset);
String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset); String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset);
int httpPort = getPort(SVC_CONSOLE); int httpPort = getPort(SVC_CONSOLE);
int httpsPort = getPort(SVC_HTTPS_CONSOLE, 7667); int httpsPort = getPort(SVC_HTTPS_CONSOLE, DEFAULT_HTTPS_CONSOLE_PORT);
boolean httpOnly = httpPort > 0 && httpsHost.equals(unset) && !httpHost.equals(unset); boolean httpOnly = httpPort > 0 && httpsHost.equals(unset) && !httpHost.equals(unset);
if (httpOnly) if (httpOnly)
return "http://" + httpHost + ':' + httpPort + '/'; return "http://" + httpHost + ':' + httpPort + '/';
if (httpsHost.equals(unset)) if (httpsHost.equals(unset))
httpsHost = "127.0.0.1"; return "http://" + DEFAULT_HOST + ':' + DEFAULT_CONSOLE_PORT + '/';
return "https://" + httpsHost + ':' + httpsPort + '/'; return "https://" + httpsHost + ':' + httpsPort + '/';
} }
@ -249,7 +257,7 @@ public class PortMapper {
InetSocketAddress ia = _dir.get(s); InetSocketAddress ia = _dir.get(s);
if (ia == null) if (ia == null)
continue; continue;
out.write("<tr><td>" + s + "<td>" + convertWildcard(ia.getHostName(), "127.0.0.1") + "<td>" + ia.getPort() + '\n'); out.write("<tr><td>" + s + "<td>" + convertWildcard(ia.getHostName(), DEFAULT_HOST) + "<td>" + ia.getPort() + '\n');
} }
out.write("</table>\n"); out.write("</table>\n");
} }