Update GeoIP (#2926)

This implements the fix suggested by @Bobcat00 in #2919

Users of GeoIP will now be required to register a MaxMind account and create a license to download the database required by the plugin. This license is entered into the new license-key field in the configuration.

---

* Update GeoIP

* Simplify branch

* Update old config detection

* Update geoIpLicenseMissing to point to the EssX wiki
This commit is contained in:
pop4959 2020-01-10 23:10:40 -08:00 committed by md678685
parent f4496b6977
commit 5020983af5
3 changed files with 16 additions and 6 deletions

View File

@ -142,6 +142,7 @@ gctotal=§6Allocated memory\:§c {0} MB.
gcWorld=§6{0} "§c{1}§6"\: §c{2}§6 chunks, §c{3}§6 entities, §c{4}§6 tiles.
geoipJoinFormat=§6Player §c{0} §6comes from §c{1}§6.
geoipCantFind=§6Player §c{0} §6comes from §aan unknown country§6.
geoIpLicenseMissing=No license key found! Please visit https://essentialsx.cf/geoip for first time setup instructions.
geoIpUrlEmpty=GeoIP download url is empty.
geoIpUrlInvalid=GeoIP download url is invalid.
givenSkull=§6You have been given the skull of §c{0}§6.

View File

@ -117,8 +117,9 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
// detect and update the old config.yml. migrate from legacy GeoIP to GeoIP2.
if (!config.isSet("enable-locale")) {
config.set("database.download-url", "https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz");
config.set("database.download-url-city", "https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz");
config.set("database.download-url", "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key={LICENSEKEY}&suffix=tar.gz");
config.set("database.download-url-city", "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key={LICENSEKEY}&suffix=tar.gz");
config.set("database.license-key", "");
config.set("database.update.enable", true);
config.set("database.update.by-every-x-days", 30);
config.set("enable-locale", true);
@ -175,6 +176,12 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
logger.log(Level.SEVERE, tl("geoIpUrlEmpty"));
return;
}
String licenseKey = config.getString("database.license-key", "");
if (licenseKey == null || licenseKey.isEmpty()) {
logger.log(Level.SEVERE, tl("geoIpLicenseMissing"));
return;
}
url = url.replace("{LICENSEKEY}", licenseKey);
logger.log(Level.INFO, tl("downloadingGeoIp"));
URL downloadUrl = new URL(url);
URLConnection conn = downloadUrl.openConnection();
@ -183,9 +190,9 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
InputStream input = conn.getInputStream();
OutputStream output = new FileOutputStream(databaseFile);
byte[] buffer = new byte[2048];
if (url.endsWith(".gz")) {
if (url.contains("gz")) {
input = new GZIPInputStream(input);
if (url.endsWith(".tar.gz")) {
if (url.contains("tar.gz")) {
// The new GeoIP2 uses tar.gz to pack the db file along with some other txt. So it makes things a bit complicated here.
String filename;
TarInputStream tarInputStream = new TarInputStream(input);

View File

@ -2,9 +2,11 @@ database:
show-cities: false
download-if-missing: true
# Url for country
download-url: "https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz"
download-url: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key={LICENSEKEY}&suffix=tar.gz"
# Url for cities
download-url-city: "https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz"
download-url-city: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key={LICENSEKEY}&suffix=tar.gz"
# License key for downloads
license-key: ""
update:
enable: true
by-every-x-days: 30