Changeset f00bf7d for core


Ignore:
Timestamp:
Feb 20, 2018 8:19:34 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3159c51
Parents:
33ea4cf
Message:

Console: Redirect to HTTPS if available (ticket #2160)
Show console links as HTTPS if available
Extend blacklisted ports to cover HTTPS console and eepsite

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/PortMapper.java

    r33ea4cf rf00bf7d  
    2020public class PortMapper {
    2121    private final ConcurrentHashMap<String, InetSocketAddress> _dir;
     22    public static final String PROP_PREFER_HTTPS = "routerconsole.preferHTTPS";
    2223
    2324    public static final String SVC_CONSOLE = "console";
     
    178179    }
    179180
    180     /*
     181    /**
     182     *  If PROP_PREFER_HTTPS is true or unset,
     183     *  return https URL unless console is http only. Default https://127.0.0.1:7667/
     184     *  If PROP_PREFER_HTTPS is set to false,
     185     *  return http URL unless console is https only. Default http://127.0.0.1:7657/
     186     *
     187     *  @since 0.9.33 consolidated from i2ptunnel and desktopgui
     188     */
     189    public String getConsoleURL() {
     190        return getConsoleURL(I2PAppContext.getGlobalContext().getBooleanPropertyDefaultTrue(PROP_PREFER_HTTPS));
     191    }
     192
     193    /**
     194     *  If preferHTTPS is true,
     195     *  return https URL unless console is http only. Default https://127.0.0.1:7667/
     196     *  If preferHTTPS is false,
     197     *  return http URL unless console is https only. Default http://127.0.0.1:7657/
     198     *
     199     *  @since 0.9.34
     200     */
     201    public String getConsoleURL(boolean preferHTTPS) {
     202        return preferHTTPS ? getHTTPSConsoleURL() : getHTTPConsoleURL();
     203    }
     204
     205    /**
    181206     *  @return http URL unless console is https only. Default http://127.0.0.1:7657/
    182      *  @since 0.9.33 consolidated from i2ptunnel and desktopgui
    183      */
    184     public String getConsoleURL() {
     207     */
     208    private String getHTTPConsoleURL() {
    185209        String unset = "*unset*";
    186210        String httpHost = getActualHost(SVC_CONSOLE, unset);
    187211        String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset);
    188212        int httpPort = getPort(SVC_CONSOLE, 7657);
    189         int httpsPort = getPort(SVC_HTTPS_CONSOLE, -1);
     213        int httpsPort = getPort(SVC_HTTPS_CONSOLE);
    190214        boolean httpsOnly = httpsPort > 0 && httpHost.equals(unset) && !httpsHost.equals(unset);
    191215        if (httpsOnly)
     
    194218            httpHost = "127.0.0.1";
    195219        return "http://" + httpHost + ':' + httpPort + '/';
     220    }
     221
     222    /**
     223     *  @return https URL unless console is http only. Default https://127.0.0.1:7667/
     224     *  @since 0.9.34
     225     */
     226    private String getHTTPSConsoleURL() {
     227        String unset = "*unset*";
     228        String httpHost = getActualHost(SVC_CONSOLE, unset);
     229        String httpsHost = getActualHost(SVC_HTTPS_CONSOLE, unset);
     230        int httpPort = getPort(SVC_CONSOLE);
     231        int httpsPort = getPort(SVC_HTTPS_CONSOLE, 7667);
     232        boolean httpOnly = httpPort > 0 && httpsHost.equals(unset) && !httpHost.equals(unset);
     233        if (httpOnly)
     234            return "http://" + httpHost + ':' + httpPort + '/';
     235        if (httpsHost.equals(unset))
     236            httpsHost = "127.0.0.1";
     237        return "https://" + httpsHost + ':' + httpsPort + '/';
    196238    }
    197239
Note: See TracChangeset for help on using the changeset viewer.