forked from I2P_Developers/i2p.i2p
Console: Properly register listen hosts with PortMapper
I2PTunnel: Fixup console links in error pages if console is on a non-standard host or port, or on https PortMapper: Add method to convert wildcard host to actual host
This commit is contained in:
@@ -41,6 +41,7 @@ import net.i2p.util.EventDispatcher;
|
||||
import net.i2p.util.InternalSocket;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.PasswordManager;
|
||||
import net.i2p.util.PortMapper;
|
||||
import net.i2p.util.Translate;
|
||||
import net.i2p.util.TranslateReader;
|
||||
|
||||
@@ -535,7 +536,24 @@ public abstract class I2PTunnelHTTPClientBase extends I2PTunnelClientBase implem
|
||||
while((len = reader.read(buf)) > 0) {
|
||||
out.append(buf, 0, len);
|
||||
}
|
||||
return out.toString();
|
||||
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);
|
||||
}
|
||||
return rv;
|
||||
} finally {
|
||||
try {
|
||||
if(reader != null)
|
||||
|
Reference in New Issue
Block a user