From 5020983af505f8defbf38e1e818f90086b8a5369 Mon Sep 17 00:00:00 2001 From: pop4959 Date: Fri, 10 Jan 2020 23:10:40 -0800 Subject: [PATCH] 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 --- Essentials/src/messages_en.properties | 1 + .../geoip/EssentialsGeoIPPlayerListener.java | 15 +++++++++++---- EssentialsGeoIP/src/config.yml | 6 ++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 8ad92d8f9..966d5abe0 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -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. diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 86175e6ad..da3467d81 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -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); diff --git a/EssentialsGeoIP/src/config.yml b/EssentialsGeoIP/src/config.yml index 5cae35de0..581907095 100644 --- a/EssentialsGeoIP/src/config.yml +++ b/EssentialsGeoIP/src/config.yml @@ -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