From c4f1dbb6071808d8c20c1149b249d9d526b56d46 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 28 Jun 2021 09:26:17 +0200 Subject: [server] Make webserver listen on every address in Docker setup --- .../org/openslx/bwlp/sat/util/Configuration.java | 20 ++++++++++++++++++++ .../java/org/openslx/bwlp/sat/web/WebServer.java | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'dozentenmodulserver/src') diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java index 8b6caf3d..58134cfc 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Configuration.java @@ -20,6 +20,8 @@ public class Configuration { private static final Logger LOGGER = Logger.getLogger(Configuration.class); private static final DateTimeFormatter subdirDate = DateTimeFormat.forPattern("yy-MM"); + private static final String DEFAULT_WEBSERVER_BIND_ADDRESS_LOCAL = "127.0.0.1"; + private static File vmStoreBasePath; private static File vmStoreProdPath; private static String dbUri; @@ -28,6 +30,7 @@ public class Configuration { private static String masterAddress; private static boolean masterSsl = true; private static int masterPort = 9091; + private static boolean webServerBindLocalhost = true; private static String dbLocationTable; private static SSLContext ctx = null; @@ -56,6 +59,10 @@ public class Configuration { } catch (Exception e) { } + if (!Util.isEmptyString(prop.getProperty("webserver.bindLocalhost"))) { + webServerBindLocalhost = Boolean.parseBoolean(prop.getProperty("webserver.bindLocalhost")); + } + // Currently all fields are mandatory but there might be optional settings in the future return vmStoreBasePath != null && dbUri != null && dbUsername != null && dbPassword != null; } @@ -104,6 +111,19 @@ public class Configuration { return masterPort; } + public static boolean getWebServerBindLocalhost() { + return webServerBindLocalhost; + } + + public static String getWebServerBindAddressLocal() { + if (getWebServerBindLocalhost()) { + return DEFAULT_WEBSERVER_BIND_ADDRESS_LOCAL; + } else { + // do not bind to the localhost address + return null; + } + } + // Dynamically Computed fields public static File getCurrentVmStorePath() { diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java index 9840a4c2..a3d9d293 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java @@ -25,6 +25,7 @@ import org.openslx.bwlp.sat.database.mappers.DbLecture; import org.openslx.bwlp.sat.database.mappers.DbLecture.LaunchData; import org.openslx.bwlp.sat.database.mappers.DbLecture.RunScript; import org.openslx.bwlp.sat.fileserv.FileServer; +import org.openslx.bwlp.sat.util.Configuration; import org.openslx.bwlp.thrift.iface.NetRule; import org.openslx.bwlp.thrift.iface.NetShare; import org.openslx.bwlp.thrift.iface.NetShareAuth; @@ -47,7 +48,7 @@ public class WebServer extends NanoHTTPD { private static final Serializer serializer = new Persister(); public WebServer(int port) { - super("127.0.0.1", port); + super(Configuration.getWebServerBindAddressLocal(), port); super.maxRequestSize = 65535; } -- cgit v1.2.3-55-g7522