mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-23 16:41:22 +01:00
WebServer and Geolocation Cache Locale stuff
This commit is contained in:
parent
8b2f38eb5f
commit
5da4b043c4
@ -12,7 +12,7 @@ import com.djrapitops.plan.system.PlanSystem;
|
||||
public class BungeeCacheSystem extends CacheSystem {
|
||||
|
||||
public BungeeCacheSystem(PlanSystem system) {
|
||||
super(new BungeeDataCache(system));
|
||||
super(new BungeeDataCache(system), system);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ public class CacheSystem implements SubSystem {
|
||||
private final GeolocationCache geolocationCache;
|
||||
|
||||
public CacheSystem(PlanSystem system) {
|
||||
this(new DataCache(system));
|
||||
this(new DataCache(system), system);
|
||||
}
|
||||
|
||||
protected CacheSystem(DataCache dataCache) {
|
||||
protected CacheSystem(DataCache dataCache, PlanSystem system) {
|
||||
this.dataCache = dataCache;
|
||||
geolocationCache = new GeolocationCache();
|
||||
geolocationCache = new GeolocationCache(() -> system.getLocaleSystem().getLocale());
|
||||
}
|
||||
|
||||
public static CacheSystem getInstance() {
|
||||
@ -38,7 +38,6 @@ public class CacheSystem implements SubSystem {
|
||||
public void enable() throws EnableException {
|
||||
dataCache.enable();
|
||||
geolocationCache.enable();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,8 @@ package com.djrapitops.plan.system.cache;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.file.FileSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
@ -21,6 +23,7 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
@ -33,10 +36,12 @@ import java.util.zip.GZIPInputStream;
|
||||
*/
|
||||
public class GeolocationCache implements SubSystem {
|
||||
|
||||
private final Supplier<Locale> locale;
|
||||
private final Map<String, String> geolocationCache;
|
||||
private File geolocationDB;
|
||||
|
||||
public GeolocationCache() {
|
||||
public GeolocationCache(Supplier<Locale> locale) {
|
||||
this.locale = locale;
|
||||
geolocationCache = new HashMap<>();
|
||||
}
|
||||
|
||||
@ -47,10 +52,12 @@ public class GeolocationCache implements SubSystem {
|
||||
try {
|
||||
GeolocationCache.checkDB();
|
||||
} catch (UnknownHostException e) {
|
||||
Log.error("Plan Requires internet access on first run to download GeoLite2 Geolocation database.");
|
||||
Log.error(locale.get().getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_INTERNET_REQUIRED));
|
||||
} catch (IOException e) {
|
||||
throw new EnableException("Something went wrong saving the downloaded GeoLite2 Geolocation database", e);
|
||||
throw new EnableException(locale.get().getString(PluginLang.ENABLE_FAIL_GEODB_WRITE), e);
|
||||
}
|
||||
} else {
|
||||
Log.infoColor("§e" + locale.get().getString(PluginLang.ENABLE_NOTIFY_GEOLOCATIONS_DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,11 +12,21 @@ public enum PluginLang implements Lang {
|
||||
|
||||
ENABLE_NOTIFY_EMPTY_IP("Enable - Notify Empty IP", "IP in server.properties is empty & AlternativeIP is not in use. Incorrect links will be given!"),
|
||||
ENABLE_NOTIFY_WEB_SERVER_DISABLED("Enable - Notify Webserver disabled", "WebServer was not initialized. (WebServer.DisableWebServer: true)"),
|
||||
ENABLE_NOTIFY_GEOLOCATIONS_INTERNET_REQUIRED("Enable - Notify Geolocations Internet Required", "Plan Requires internet access on first run to download GeoLite2 Geolocation database."),
|
||||
ENABLE_NOTIFY_GEOLOCATIONS_DISABLED("Enable - Notify Geolocations disabled", "Geolocation gathering is not active. (Data.Geolocations: false)"),
|
||||
ENABLE_NOTIFY_ADDRESS_CONFIRMATION("Enable - Notify Address Confirmation", "Make sure that this address points to THIS Bukkit Server: ${0}"),
|
||||
|
||||
ENABLE_FAIL_DB("Enable FAIL - Database", "${0}-Database Connection failed: ${1}"),
|
||||
ENABLE_FAIL_WRONG_DB("Enable FAIL - Wrong Database Type", "${0} is not a supported Database"),
|
||||
ENABLE_FAIL_NO_WEB_SERVER_BUNGEE("Enable FAIL - WebServer (Bungee)", "WebServer did not initialize!"),
|
||||
ENABLE_FAIL_GEODB_WRITE("Enable FAIL - GeoDB Write", "Something went wrong saving the downloaded GeoLite2 Geolocation database"),
|
||||
|
||||
WEB_SERVER_FAIL_PORT_BIND("WebServer FAIL - Port Bind", "WebServer was not initialized successfully. Is the port (${0}) in use?"),
|
||||
WEB_SERVER_FAIL_SSL_CONTEXT("WebServer FAIL - SSL Context", "WebServer: SSL Context Initialization Failed."),
|
||||
WEB_SERVER_FAIL_STORE_LOAD("WebServer FAIL - Store Load", "WebServer: SSL Certificate loading Failed."),
|
||||
WEB_SERVER_NOTIFY_NO_CERT_FILE("WebServer - Notify no Cert file", "WebServer: Certificate KeyStore File not Found: ${0}"),
|
||||
WEB_SERVER_NOTIFY_HTTP("WebServer - Notify HTTP", "WebServer: No Certificate -> Using HTTP-server for Visualization."),
|
||||
WEB_SERVER_NOTIFY_HTTP_USER_AUTH("WebServer - Notify HTTP User Auth", "WebServer: User Authorization Disabled! (Not secure over HTTP)"),
|
||||
|
||||
DISABLED("Disable", "Player Analytics Disabled."),
|
||||
DISABLED_WEB_SERVER("Disable - WebServer", "Webserver has been disabled.");
|
||||
|
@ -73,12 +73,12 @@ public class WebServer implements SubSystem {
|
||||
|
||||
if (!isEnabled()) {
|
||||
if (Check.isBungeeAvailable()) {
|
||||
throw new EnableException("WebServer did not initialize!");
|
||||
throw new EnableException(locale.get().getString(PluginLang.ENABLE_FAIL_NO_WEB_SERVER_BUNGEE));
|
||||
}
|
||||
if (Settings.WEBSERVER_DISABLED.isTrue()) {
|
||||
Log.warn("WebServer was not initialized. (WebServer.DisableWebServer: true)");
|
||||
Log.warn(locale.get().getString(PluginLang.ENABLE_NOTIFY_WEB_SERVER_DISABLED));
|
||||
} else {
|
||||
Log.error("WebServer was not initialized successfully. Is the port (" + Settings.WEBSERVER_PORT.getNumber() + ") in use?");
|
||||
Log.error(locale.get().getString(PluginLang.WEB_SERVER_FAIL_PORT_BIND, port));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,7 +103,7 @@ public class WebServer implements SubSystem {
|
||||
Log.debug(usingHttps ? "Https Start Successful." : "Https Start Failed.");
|
||||
|
||||
if (!usingHttps) {
|
||||
Log.infoColor("§eUser Authorization Disabled! (Not possible over http)");
|
||||
Log.infoColor("§e" + locale.get().getString(PluginLang.WEB_SERVER_NOTIFY_HTTP_USER_AUTH));
|
||||
server = HttpServer.create(new InetSocketAddress(Settings.WEBSERVER_IP.toString(), port), 10);
|
||||
}
|
||||
server.createContext("/", requestHandler);
|
||||
@ -137,6 +137,10 @@ public class WebServer implements SubSystem {
|
||||
keystore.load(fIn, storepass);
|
||||
Certificate cert = keystore.getCertificate(alias);
|
||||
|
||||
if (cert == null) {
|
||||
throw new IllegalStateException("Certificate with Alias: " + alias + " was not found in the Keystore.");
|
||||
}
|
||||
|
||||
Log.info("Found Certificate: " + cert.getType());
|
||||
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
|
||||
@ -163,17 +167,20 @@ public class WebServer implements SubSystem {
|
||||
}
|
||||
});
|
||||
startSuccessful = true;
|
||||
} catch (IllegalStateException e) {
|
||||
Log.error(e.getMessage());
|
||||
Log.toLog(this.getClass(), e);
|
||||
} catch (KeyManagementException | NoSuchAlgorithmException e) {
|
||||
Log.error("WebServer: SSL Context Initialization Failed.");
|
||||
Log.error(locale.get().getString(PluginLang.WEB_SERVER_FAIL_SSL_CONTEXT));
|
||||
Log.toLog(this.getClass(), e);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.infoColor("§eWebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
|
||||
Log.info("No Certificate -> Using Http server for Visualization.");
|
||||
Log.infoColor("§e" + locale.get().getString(PluginLang.WEB_SERVER_NOTIFY_NO_CERT_FILE, keyStorePath));
|
||||
Log.info(locale.get().getString(PluginLang.WEB_SERVER_NOTIFY_HTTP));
|
||||
} catch (IOException e) {
|
||||
Log.error("WebServer: " + e);
|
||||
Log.toLog(this.getClass(), e);
|
||||
} catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) {
|
||||
Log.error("WebServer: SSL Certificate loading Failed.");
|
||||
Log.error(locale.get().getString(PluginLang.WEB_SERVER_FAIL_STORE_LOAD));
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
return startSuccessful;
|
||||
|
Loading…
Reference in New Issue
Block a user