From adb3c06f51da1b192ce5056950b52d6377180421 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Wed, 22 Aug 2018 16:56:14 +0200 Subject: [PATCH] Fix #1617 Dinstinct invalid countries ("--") from localhost addresses ("LOCALHOST"), allow localhost access by default. --- .../java/fr/xephi/authme/service/GeoIpService.java | 13 ++++++++++--- .../settings/properties/ProtectionSettings.java | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/xephi/authme/service/GeoIpService.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java index be274687..deaa55c1 100644 --- a/src/main/java/fr/xephi/authme/service/GeoIpService.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -268,9 +268,13 @@ public class GeoIpService { * Get the country code of the given IP address. * * @param ip textual IP address to lookup. - * @return two-character ISO 3166-1 alpha code for the country or "--" if it cannot be fetched. + * @return two-character ISO 3166-1 alpha code for the country, "LOCALHOST" for local addresses + * or "--" if it cannot be fetched. */ public String getCountryCode(String ip) { + if(InternetProtocolUtils.isLocalAddress(ip)) { + return "LOCALHOST"; + } return getCountry(ip).map(Country::getIsoCode).orElse("--"); } @@ -278,9 +282,12 @@ public class GeoIpService { * Get the country name of the given IP address. * * @param ip textual IP address to lookup. - * @return The name of the country or "N/A" if it cannot be fetched. + * @return The name of the country, "LocalHost" for local addresses, or "N/A" if it cannot be fetched. */ public String getCountryName(String ip) { + if(InternetProtocolUtils.isLocalAddress(ip)) { + return "LocalHost"; + } return getCountry(ip).map(Country::getName).orElse("N/A"); } @@ -297,7 +304,7 @@ public class GeoIpService { * */ private Optional getCountry(String ip) { - if (ip == null || ip.isEmpty() || InternetProtocolUtils.isLocalAddress(ip) || !isDataAvailable()) { + if (ip == null || ip.isEmpty() || !isDataAvailable()) { return Optional.empty(); } diff --git a/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java b/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java index cc715d0c..ba724afa 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/ProtectionSettings.java @@ -23,9 +23,10 @@ public final class ProtectionSettings implements SettingsHolder { @Comment({ "Countries allowed to join the server and register. For country codes, see", "https://dev.maxmind.com/geoip/legacy/codes/iso3166/", + "Use \"LOCALHOST\" for local addresses.", "PLEASE USE QUOTES!"}) public static final Property> COUNTRIES_WHITELIST = - newListProperty("Protection.countries", "US", "GB"); + newListProperty("Protection.countries", "US", "GB", "LOCALHOST"); @Comment({ "Countries not allowed to join the server and register",