From e8a00007f6156ca356bf635af7dcda4b07c748c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20F=C3=BClling?= Date: Tue, 11 Jan 2022 17:10:48 +0100 Subject: [PATCH 1/4] add setting for public facing port --- defaults/yacy.init | 3 +++ htroot/SettingsAck_p.html | 1 + htroot/SettingsAck_p.java | 13 ++++++++++++ htroot/Settings_ServerAccess.inc | 9 ++++++++ source/net/yacy/peers/Seed.java | 21 ++++++++++++++++++- .../net/yacy/search/SwitchboardConstants.java | 1 + 6 files changed, 47 insertions(+), 1 deletion(-) 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"; From 111cf4864293419233e5a2e3cb87e4c63a0294c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20F=C3=BClling?= Date: Sat, 29 Jan 2022 19:28:57 +0100 Subject: [PATCH 2/4] add missing prop --- source/net/yacy/server/serverCore.java | 1 + 1 file changed, 1 insertion(+) diff --git a/source/net/yacy/server/serverCore.java b/source/net/yacy/server/serverCore.java index f02bd4934..4a7acdf48 100644 --- a/source/net/yacy/server/serverCore.java +++ b/source/net/yacy/server/serverCore.java @@ -39,5 +39,6 @@ public final class serverCore { public static final String LF_STRING = UTF8.String(new byte[]{LF}); public static boolean useStaticIP = false; + public static boolean usePublicPort = false; } From e0fd3d4f1044a2b6177f9688412b645b850dbab6 Mon Sep 17 00:00:00 2001 From: Burkhard <11603289+reger24@users.noreply.github.com> Date: Fri, 11 Feb 2022 08:02:24 +0100 Subject: [PATCH 3/4] Update Settings_p.java missing setting to display the value --- htroot/Settings_p.java | 1 + 1 file changed, 1 insertion(+) diff --git a/htroot/Settings_p.java b/htroot/Settings_p.java index 4f66d296c..329843394 100644 --- a/htroot/Settings_p.java +++ b/htroot/Settings_p.java @@ -93,6 +93,7 @@ public final class Settings_p { prop.putHTML("peerName", sb.peers.mySeed().getName()); prop.putHTML("staticIP", env.getConfig("staticIP", "")); + prop.putHTML("publicPort", env.getConfig("publicPort","")); prop.putHTML("fileHost", env.getConfig("fileHost", "localpeer")); String peerLang = env.getConfig("locale.language", "default"); if (peerLang.equals("default")) peerLang = "en"; From 4219d729c3fde239ad9b283780a8c99f0fa1dc4a Mon Sep 17 00:00:00 2001 From: Burkhard <11603289+reger24@users.noreply.github.com> Date: Fri, 11 Feb 2022 08:04:55 +0100 Subject: [PATCH 4/4] Update SettingsAck_p.java type in SwitchboardConstants.SERVER_PUBLICPORT --- htroot/SettingsAck_p.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htroot/SettingsAck_p.java b/htroot/SettingsAck_p.java index 10fb19c1e..953e506ee 100644 --- a/htroot/SettingsAck_p.java +++ b/htroot/SettingsAck_p.java @@ -219,7 +219,7 @@ public class SettingsAck_p { if(pport < 65535 && pport >= 0) { serverCore.usePublicPort = true; sb.peers.mySeed().setPort(pport); - env.setConfig(SwitchboardConstants.SERVER_PUBLIC_PORT, publicPort); + env.setConfig(SwitchboardConstants.SERVER_PUBLICPORT, publicPort); } } catch (NumberFormatException e) { // noop