mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-12 14:49:56 +01:00
Fix webserver disabling always by accident
This commit is contained in:
parent
176c090f39
commit
b92dfdb127
@ -189,7 +189,7 @@ public class PlanSystem implements SubSystem {
|
|||||||
// Disables Webserver if Proxy is detected in the database
|
// Disables Webserver if Proxy is detected in the database
|
||||||
if (serverInfo.getServer().isNotProxy()) {
|
if (serverInfo.getServer().isNotProxy()) {
|
||||||
processing.submitNonCritical(new NonProxyWebserverDisableChecker(
|
processing.submitNonCritical(new NonProxyWebserverDisableChecker(
|
||||||
configSystem.getConfig(), webServerSystem.getAddresses(), webServerSystem, logger, errorLogger
|
configSystem.getConfig(), localeSystem.getLocale(), webServerSystem.getAddresses(), webServerSystem, logger, errorLogger
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class Addresses {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<String> getMainAddress() {
|
public Optional<String> getMainAddress() {
|
||||||
Optional<String> proxyServerAddress = getProxyServerAddress();
|
Optional<String> proxyServerAddress = getAnyValidServerAddress();
|
||||||
return proxyServerAddress.isPresent() ? proxyServerAddress : getAccessAddress();
|
return proxyServerAddress.isPresent() ? proxyServerAddress : getAccessAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +105,14 @@ public class Addresses {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<String> getProxyServerAddress() {
|
public Optional<String> getProxyServerAddress() {
|
||||||
|
return dbSystem.getDatabase().query(ServerQueries.fetchProxyServers())
|
||||||
|
.stream()
|
||||||
|
.map(Server::getWebAddress)
|
||||||
|
.filter(this::isValidAddress)
|
||||||
|
.findAny();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getAnyValidServerAddress() {
|
||||||
return dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection())
|
return dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection())
|
||||||
.stream()
|
.stream()
|
||||||
.map(Server::getWebAddress)
|
.map(Server::getWebAddress)
|
||||||
|
@ -20,6 +20,8 @@ import com.djrapitops.plan.delivery.webserver.http.WebServer;
|
|||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
||||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||||
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
|
import com.djrapitops.plan.settings.locale.lang.PluginLang;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||||
import net.playeranalytics.plugin.server.PluginLogger;
|
import net.playeranalytics.plugin.server.PluginLogger;
|
||||||
@ -34,6 +36,7 @@ import java.io.IOException;
|
|||||||
public class NonProxyWebserverDisableChecker implements Runnable {
|
public class NonProxyWebserverDisableChecker implements Runnable {
|
||||||
|
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
|
private final Locale locale;
|
||||||
private final Addresses addresses;
|
private final Addresses addresses;
|
||||||
private final WebServerSystem webServerSystem;
|
private final WebServerSystem webServerSystem;
|
||||||
private final PluginLogger logger;
|
private final PluginLogger logger;
|
||||||
@ -41,12 +44,14 @@ public class NonProxyWebserverDisableChecker implements Runnable {
|
|||||||
|
|
||||||
public NonProxyWebserverDisableChecker(
|
public NonProxyWebserverDisableChecker(
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
|
Locale locale,
|
||||||
Addresses addresses,
|
Addresses addresses,
|
||||||
WebServerSystem webServerSystem,
|
WebServerSystem webServerSystem,
|
||||||
PluginLogger logger,
|
PluginLogger logger,
|
||||||
ErrorLogger errorLogger
|
ErrorLogger errorLogger
|
||||||
) {
|
) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.locale = locale;
|
||||||
this.addresses = addresses;
|
this.addresses = addresses;
|
||||||
this.webServerSystem = webServerSystem;
|
this.webServerSystem = webServerSystem;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -58,7 +63,7 @@ public class NonProxyWebserverDisableChecker implements Runnable {
|
|||||||
if (config.isFalse(PluginSettings.PROXY_COPY_CONFIG)) return;
|
if (config.isFalse(PluginSettings.PROXY_COPY_CONFIG)) return;
|
||||||
|
|
||||||
addresses.getProxyServerAddress().ifPresent(address -> {
|
addresses.getProxyServerAddress().ifPresent(address -> {
|
||||||
logger.info("Proxy server detected in the database - Proxy Webserver address is '" + address + "'.");
|
logger.info(locale.getString(PluginLang.ENABLE_NOTIFY_PROXY_ADDRESS, address));
|
||||||
WebServer webServer = webServerSystem.getWebServer();
|
WebServer webServer = webServerSystem.getWebServer();
|
||||||
|
|
||||||
if (webServer.isEnabled()) {
|
if (webServer.isEnabled()) {
|
||||||
@ -68,12 +73,12 @@ public class NonProxyWebserverDisableChecker implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void disableWebserver(WebServer webServer) {
|
private void disableWebserver(WebServer webServer) {
|
||||||
logger.warn("Disabling Webserver on this server - You can override this behavior by setting '" + PluginSettings.PROXY_COPY_CONFIG.getPath() + "' to false.");
|
logger.warn(locale.getString(PluginLang.ENABLE_NOTIFY_PROXY_DISABLED_WEBSERVER, PluginSettings.PROXY_COPY_CONFIG.getPath()));
|
||||||
webServer.disable();
|
webServer.disable();
|
||||||
try {
|
try {
|
||||||
config.set(WebserverSettings.DISABLED, true);
|
config.set(WebserverSettings.DISABLED, true);
|
||||||
config.save();
|
config.save();
|
||||||
logger.warn("Note: Set '" + WebserverSettings.DISABLED.getPath() + "' to true");
|
logger.warn(locale.getString(PluginLang.ENABLE_NOTIFY_SETTING_CHANGE, WebserverSettings.DISABLED.getPath(), "true"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
errorLogger.warn(e, ErrorContext.builder()
|
errorLogger.warn(e, ErrorContext.builder()
|
||||||
.whatToDo("Set '" + WebserverSettings.DISABLED.getPath() + "' to true manually.")
|
.whatToDo("Set '" + WebserverSettings.DISABLED.getPath() + "' to true manually.")
|
||||||
|
@ -29,6 +29,9 @@ public enum PluginLang implements Lang {
|
|||||||
API_ADD_RESOURCE_CSS("plugin.apiCSSAdded", "API - css+", "PageExtension: ${0} added stylesheet(s) to ${1}, ${2}"),
|
API_ADD_RESOURCE_CSS("plugin.apiCSSAdded", "API - css+", "PageExtension: ${0} added stylesheet(s) to ${1}, ${2}"),
|
||||||
RELOAD_LOCALE("plugin.localeReloaded", "API - locale reload", "Custom locale.yml was modified so it was reloaded and is now in use."),
|
RELOAD_LOCALE("plugin.localeReloaded", "API - locale reload", "Custom locale.yml was modified so it was reloaded and is now in use."),
|
||||||
|
|
||||||
|
ENABLE_NOTIFY_PROXY_ADDRESS("plugin.enable.notify.proxyAddress", "Enable - Notify proxy address", "Proxy server detected in the database - Proxy Webserver address is '${0}'."),
|
||||||
|
ENABLE_NOTIFY_PROXY_DISABLED_WEBSERVER("plugin.enable.notify.proxyDisabledWebserver", "Enable - Notify proxy disabled webserver", "Disabling Webserver on this server - You can override this behavior by setting '${0}' to false."),
|
||||||
|
ENABLE_NOTIFY_SETTING_CHANGE("plugin.enable.notify.settingChange", "Enable - Notify settingChange", "Note: Set '${0}' to ${1}"),
|
||||||
ENABLE_NOTIFY_STORING_PRESERVED_SESSIONS("plugin.enable.notify.storeSessions", "Enable - Storing preserved sessions", "Storing sessions that were preserved before previous shutdown."),
|
ENABLE_NOTIFY_STORING_PRESERVED_SESSIONS("plugin.enable.notify.storeSessions", "Enable - Storing preserved sessions", "Storing sessions that were preserved before previous shutdown."),
|
||||||
ENABLE_NOTIFY_EMPTY_IP("plugin.enable.notify.emptyIP", "Enable - Notify Empty IP", "IP in server.properties is empty & Alternative_IP is not in use. Incorrect links might be given!"),
|
ENABLE_NOTIFY_EMPTY_IP("plugin.enable.notify.emptyIP", "Enable - Notify Empty IP", "IP in server.properties is empty & Alternative_IP is not in use. Incorrect links might be given!"),
|
||||||
ENABLE_NOTIFY_BAD_IP("plugin.enable.notify.badIP", "Enable - Notify Bad IP", "0.0.0.0 is not a valid address, set up Alternative_IP settings. Incorrect links might be given!"),
|
ENABLE_NOTIFY_BAD_IP("plugin.enable.notify.badIP", "Enable - Notify Bad IP", "0.0.0.0 is not a valid address, set up Alternative_IP settings. Incorrect links might be given!"),
|
||||||
|
Loading…
Reference in New Issue
Block a user