diff --git a/defaults/yacy.init b/defaults/yacy.init index 25ede5a9b..bf639f6cb 100644 --- a/defaults/yacy.init +++ b/defaults/yacy.init @@ -543,6 +543,9 @@ debug.snippets.statistics.enabled=false #staticIP if you have a static IP, you can use this setting staticIP= +#publicPort if you use a different port to access YaCy than the one it listens on, you can use this setting +publicPort= + # each time YaCy starts up, it can trigger the local browser to show the # status page. This is active by default, to make it easier for first-time # users to understand what this application does. You can disable browser diff --git a/htroot/SettingsAck_p.html b/htroot/SettingsAck_p.html index 9e91137ed..7f26ca30e 100644 --- a/htroot/SettingsAck_p.html +++ b/htroot/SettingsAck_p.html @@ -63,6 +63,7 @@ ::

The Peer Name is: #[peerName]#
Your static Ip(or DynDns) is: #[staticIP]# + Your public port is: #[publicPort]#

::

Seed Settings changed.#(success)#::You are now a principal peer.#(/success)#

diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.java index 1ca89cb56..10fb19c1e 100644 --- a/htroot/SettingsAck_p.java +++ b/htroot/SettingsAck_p.java @@ -211,6 +211,19 @@ public class SettingsAck_p { sb.peers.mySeed().setIP(""); env.setConfig(SwitchboardConstants.SERVER_STATICIP, ""); } + + // publicPort + String publicPort = (post.get("publicPort")).trim(); + try { + Integer pport = Integer.parseInt(publicPort); + if(pport < 65535 && pport >= 0) { + serverCore.usePublicPort = true; + sb.peers.mySeed().setPort(pport); + env.setConfig(SwitchboardConstants.SERVER_PUBLIC_PORT, publicPort); + } + } catch (NumberFormatException e) { + // noop + } // server access data String filter = (post.get("serverfilter")).trim(); diff --git a/htroot/Settings_ServerAccess.inc b/htroot/Settings_ServerAccess.inc index 314873437..9be7909fa 100644 --- a/htroot/Settings_ServerAccess.inc +++ b/htroot/Settings_ServerAccess.inc @@ -30,6 +30,15 @@ If the value you enter here does not match with this IP, you will not be able to access the server pages anymore. + + + + The publicPort can help that your peer can be reached by other peers in case that your + peer is behind a reverse proxy. + If the port used to access YaCy is the same port the application is listening on, + you don't need to set anything here, please leave it blank.
+ +
(requires restart) diff --git a/source/net/yacy/peers/Seed.java b/source/net/yacy/peers/Seed.java index 1d182139d..7ef4f5ead 100644 --- a/source/net/yacy/peers/Seed.java +++ b/source/net/yacy/peers/Seed.java @@ -568,6 +568,15 @@ public class Seed implements Cloneable, Comparable, Comparator } } } + + /** + * Set the public facing port. + * @param port the port to use + */ + public final void setPort(Integer port) { + if (!isProperPort(port)) return; + this.dna.put(Seed.PORT, String.valueOf(port)); + } /** * Set several local IPs which are good to access this peer. @@ -1373,7 +1382,7 @@ public class Seed implements Cloneable, Comparable, Comparator * check if the given string containing an IP is proper. This checks also if the IP is within the given * range of the network definition * @param ipString - * @return true iff the IP is proper + * @return true if the IP is proper */ public static final boolean isProperIP(final String ipString) { if (ipString == null) return false; @@ -1384,6 +1393,16 @@ public class Seed implements Cloneable, Comparable, Comparator return islocal == Switchboard.getSwitchboard().isIntranetMode(); } + /** + * checks if the given port is within the allowed range (1-65535). + * @param port the port to check + * @return true if the port is valid + */ + public static final boolean isProperPort(final Integer port) { + if (port <= 0) return false; + return port <= 65535; + } + @Override public final String toString() { final ConcurrentMap copymap = new ConcurrentHashMap(); diff --git a/source/net/yacy/search/SwitchboardConstants.java b/source/net/yacy/search/SwitchboardConstants.java index 421b9e6ac..6a04a6ea0 100644 --- a/source/net/yacy/search/SwitchboardConstants.java +++ b/source/net/yacy/search/SwitchboardConstants.java @@ -61,6 +61,7 @@ public final class SwitchboardConstants { public static final String SERVER_SSLPORT = "port.ssl"; // port for https public static final String SERVER_SHUTDOWNPORT = "port.shutdown"; // local port to listen for a shutdown signal (0 <= disabled) public static final String SERVER_STATICIP = "staticIP"; // static IP of http server + public static final String SERVER_PUBLICPORT = "publicPort"; public static final String PUBLIC_SEARCHPAGE = "publicSearchpage";