Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

add setting for public facing port

Lukas Füllinge8a00007f615
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 @@
::<!-- 12 -->
<p><strong>The Peer Name is:</strong> <span class="settingsValue">#[peerName]#</span><br />
<strong>Your static Ip(or DynDns) is:</strong> <span class="settingsValue">#[staticIP]#</span>
+ <strong>Your public port is:</strong> <span class="settingsValue">#[publicPort]#</span>
</p>
::<!-- 13 -->
<p><strong>Seed Settings changed.#(success)#::You are now a principal peer.#(/success)#</strong></p>
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.</td>
</tr>
+ <tr valign="top">
+ <td><label for="publicPort">publicPort (optional):</label></td>
+ <td><input name="publicPort" id="publicPort" aria-describedby="publicPortInfo" type="text" size="32" maxlength="80" value="#[publicPort]#" /></td>
+ <td id="publicPortInfo"><strong>The publicPort can help that your peer can be reached by other peers in case that your
+ peer is behind a reverse proxy.</strong>
+ 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.<br />
+ </td>
+ </tr>
<tr valign="top">
<td><label for="fileHost">fileHost:</label></td>
<td><input name="fileHost" id="fileHost" aria-describedby="fileHostInfo" type="text" size="32" maxlength="80" value="#[fileHost]#" /><br />(requires restart)</td>
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<Seed>, Comparator<Seed>
}
}
}
+
+ /**
+ * 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<Seed>, Comparator<Seed>
* 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<Seed>, Comparator<Seed>
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<String, String> copymap = new ConcurrentHashMap<String, String>();
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";