add setting for public facing port

pull/440/head
Lukas Fülling 3 years ago
parent c94b9b8197
commit e8a00007f6

@ -543,6 +543,9 @@ debug.snippets.statistics.enabled=false
#staticIP if you have a static IP, you can use this setting #staticIP if you have a static IP, you can use this setting
staticIP= 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 # 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 # 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 # users to understand what this application does. You can disable browser

@ -63,6 +63,7 @@
::<!-- 12 --> ::<!-- 12 -->
<p><strong>The Peer Name is:</strong> <span class="settingsValue">#[peerName]#</span><br /> <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 static Ip(or DynDns) is:</strong> <span class="settingsValue">#[staticIP]#</span>
<strong>Your public port is:</strong> <span class="settingsValue">#[publicPort]#</span>
</p> </p>
::<!-- 13 --> ::<!-- 13 -->
<p><strong>Seed Settings changed.#(success)#::You are now a principal peer.#(/success)#</strong></p> <p><strong>Seed Settings changed.#(success)#::You are now a principal peer.#(/success)#</strong></p>

@ -211,6 +211,19 @@ public class SettingsAck_p {
sb.peers.mySeed().setIP(""); sb.peers.mySeed().setIP("");
env.setConfig(SwitchboardConstants.SERVER_STATICIP, ""); 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 // server access data
String filter = (post.get("serverfilter")).trim(); String filter = (post.get("serverfilter")).trim();

@ -30,6 +30,15 @@
If the value you enter here does not match with this IP, If the value you enter here does not match with this IP,
you will not be able to access the server pages anymore.</td> you will not be able to access the server pages anymore.</td>
</tr> </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"> <tr valign="top">
<td><label for="fileHost">fileHost:</label></td> <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> <td><input name="fileHost" id="fileHost" aria-describedby="fileHostInfo" type="text" size="32" maxlength="80" value="#[fileHost]#" /><br />(requires restart)</td>

@ -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. * 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 * 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 * range of the network definition
* @param ipString * @param ipString
* @return true iff the IP is proper * @return true if the IP is proper
*/ */
public static final boolean isProperIP(final String ipString) { public static final boolean isProperIP(final String ipString) {
if (ipString == null) return false; if (ipString == null) return false;
@ -1384,6 +1393,16 @@ public class Seed implements Cloneable, Comparable<Seed>, Comparator<Seed>
return islocal == Switchboard.getSwitchboard().isIntranetMode(); 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 @Override
public final String toString() { public final String toString() {
final ConcurrentMap<String, String> copymap = new ConcurrentHashMap<String, String>(); final ConcurrentMap<String, String> copymap = new ConcurrentHashMap<String, String>();

@ -61,6 +61,7 @@ public final class SwitchboardConstants {
public static final String SERVER_SSLPORT = "port.ssl"; // port for https 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_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_STATICIP = "staticIP"; // static IP of http server
public static final String SERVER_PUBLICPORT = "publicPort";
public static final String PUBLIC_SEARCHPAGE = "publicSearchpage"; public static final String PUBLIC_SEARCHPAGE = "publicSearchpage";

Loading…
Cancel
Save