Disabled Bukkit/Sponge webserver if Proxy in db

This commit is contained in:
Rsl1122 2019-09-21 12:17:04 +03:00
parent 3c2b73794a
commit f27aece88b
8 changed files with 104 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.api.PlanAPI;
import com.djrapitops.plan.capability.CapabilityServiceImplementation;
import com.djrapitops.plan.delivery.DeliveryUtilities;
import com.djrapitops.plan.delivery.export.ExportSystem;
import com.djrapitops.plan.delivery.webserver.NonProxyWebserverDisableChecker;
import com.djrapitops.plan.delivery.webserver.WebServer;
import com.djrapitops.plan.delivery.webserver.WebServerSystem;
import com.djrapitops.plan.exceptions.EnableException;
@ -40,6 +41,7 @@ import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.version.VersionCheckSystem;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
@ -76,6 +78,7 @@ public class PlanSystem implements SubSystem {
private final ExtensionServiceImplementation extensionService;
private final QueryServiceImplementation queryService;
private final SettingsServiceImplementation settingsService;
private final PluginLogger logger;
private final ErrorHandler errorHandler;
@Inject
@ -97,6 +100,7 @@ public class PlanSystem implements SubSystem {
ExtensionServiceImplementation extensionService,
QueryServiceImplementation queryService,
SettingsServiceImplementation settingsService,
PluginLogger logger,
ErrorHandler errorHandler,
PlanAPI.PlanAPIHolder apiHolder
) {
@ -117,6 +121,7 @@ public class PlanSystem implements SubSystem {
this.extensionService = extensionService;
this.queryService = queryService;
this.settingsService = settingsService;
this.logger = logger;
this.errorHandler = errorHandler;
}
@ -149,6 +154,14 @@ public class PlanSystem implements SubSystem {
listenerSystem,
taskSystem
);
// Disables Webserver if Proxy is detected in the database
if (serverInfo.getServer().isNotProxy()) {
processing.submitNonCritical(new NonProxyWebserverDisableChecker(
configSystem.getConfig(), databaseSystem, webServerSystem, logger, errorHandler
));
}
settingsService.register();
queryService.register();
extensionService.register();

View File

@ -0,0 +1,83 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.delivery.webserver;
import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.PluginSettings;
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import java.io.IOException;
/**
* In charge of disabling Webserver if a Proxy server is detected in the database.
*
* @author Rsl1122
*/
public class NonProxyWebserverDisableChecker implements Runnable {
private final PlanConfig config;
private final DBSystem dbSystem;
private final WebServerSystem webServerSystem;
private final PluginLogger logger;
private final ErrorHandler errorHandler;
public NonProxyWebserverDisableChecker(
PlanConfig config,
DBSystem dbSystem,
WebServerSystem webServerSystem,
PluginLogger logger,
ErrorHandler errorHandler
) {
this.config = config;
this.dbSystem = dbSystem;
this.webServerSystem = webServerSystem;
this.logger = logger;
this.errorHandler = errorHandler;
}
@Override
public void run() {
if (config.isFalse(PluginSettings.PROXY_COPY_CONFIG)) return;
dbSystem.getDatabase().query(ServerQueries.fetchProxyServerInformation()).ifPresent(proxy -> {
logger.info("Proxy server detected in the database - Proxy Webserver address is '" + proxy.getWebAddress() + "'.");
WebServer webServer = webServerSystem.getWebServer();
if (webServer.isEnabled()) {
disableWebserver(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.");
webServer.disable();
try {
config.set(WebserverSettings.DISABLED, true);
config.save();
logger.warn("Note: Set '" + WebserverSettings.DISABLED.getPath() + "' to true");
} catch (IOException e) {
errorHandler.log(L.WARN, this.getClass(), e);
}
}
}

View File

@ -62,7 +62,7 @@ public class BukkitConfigSystem extends ConfigSystem {
@Override
public void enable() throws EnableException {
super.enable();
if (config.isTrue(PluginSettings.BUNGEE_COPY_CONFIG)) {
if (config.isTrue(PluginSettings.PROXY_COPY_CONFIG)) {
serverSettingsManager.enable();
}
}

View File

@ -136,7 +136,8 @@ public class ConfigUpdater {
new ConfigChange.Removed("Display_options.Show_player_IPs"),
new ConfigChange.Removed("Export.Parts.JavaScript_and_CSS"),
new ConfigChange.Moved("Plugins.LiteBans", "Plugins.Litebans"),
new ConfigChange.Moved("Plugins.BuyCraft", "Plugins.Buycraft")
new ConfigChange.Moved("Plugins.BuyCraft", "Plugins.Buycraft"),
new ConfigChange.Moved("Plugin.Configuration.Allow_bungeecord_to_manage_settings", "Plugin.Configuration.Allow_proxy_to_manage_settings")
};
}

View File

@ -36,7 +36,7 @@ public class PluginSettings {
public static final Setting<Integer> KEEP_LOGS_DAYS = new IntegerSetting("Plugin.Logging.Delete_logs_after_days", Setting::timeValidator);
public static final Setting<Boolean> CHECK_FOR_UPDATES = new BooleanSetting("Plugin.Update_notifications.Check_for_updates");
public static final Setting<Boolean> NOTIFY_ABOUT_DEV_RELEASES = new BooleanSetting("Plugin.Update_notifications.Notify_about_DEV_releases");
public static final Setting<Boolean> BUNGEE_COPY_CONFIG = new BooleanSetting("Plugin.Configuration.Allow_bungeecord_to_manage_settings");
public static final Setting<Boolean> PROXY_COPY_CONFIG = new BooleanSetting("Plugin.Configuration.Allow_proxy_to_manage_settings");
private PluginSettings() {
/* static variable class */

View File

@ -179,6 +179,6 @@ Export:
# If a plugin is causing issues the integration can be disabled by setting Plugin_name.Enabled: false
# -----------------------------------------------------
Plugins:
BuyCraft:
Buycraft:
# http://help.buycraft.net/article/36-where-to-find-the-secret-key
Secret: "-"

View File

@ -20,7 +20,7 @@ Plugin:
Check_for_updates: true
Notify_about_DEV_releases: false
Configuration:
Allow_bungeecord_to_manage_settings: true
Allow_proxy_to_manage_settings: true
# -----------------------------------------------------
# Supported databases: SQLite, H2, MySQL
# -----------------------------------------------------
@ -185,7 +185,7 @@ Export:
# If a plugin is causing issues the integration can be disabled by setting Plugin_name.Enabled: false
# -----------------------------------------------------
Plugins:
BuyCraft:
Buycraft:
# http://help.buycraft.net/article/36-where-to-find-the-secret-key
Secret: '-'
Factions:

View File

@ -112,7 +112,7 @@ public class ConfigSettingKeyTest {
// Server settings contained in the key classes, remove
settings.remove(PluginSettings.SERVER_NAME);
settings.remove(PluginSettings.BUNGEE_COPY_CONFIG);
settings.remove(PluginSettings.PROXY_COPY_CONFIG);
settings.remove(DatabaseSettings.TYPE);
settings.remove(DisplaySettings.WORLD_ALIASES);
return settings;