diff --git a/Classes/Utility/GeoUtility.php b/Classes/Utility/GeoUtility.php index 3bfe619..da947d4 100644 --- a/Classes/Utility/GeoUtility.php +++ b/Classes/Utility/GeoUtility.php @@ -59,6 +59,13 @@ class GeoUtility implements SingletonInterface */ protected $debug = false; + /** + * True if user IP is part of excludeIps and geolocation sould be disabled + * + * @var bool + */ + protected $excluded = false; + /** * IP addresses for which the debug position should be returned instead of the real position * @@ -66,6 +73,13 @@ class GeoUtility implements SingletonInterface */ protected $debugIps = []; + /** + * IP addresses to exclude from geolocation + * + * @var array + */ + protected $excludeIps = []; + /** * The debug position * @@ -108,8 +122,15 @@ public function __construct() // For TYPO3 v9+ $backendConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('tw_geo'); $this->debugIps = GeneralUtility::trimExplode(',', $backendConfiguration['debug']['ip']); + $this->excludeIps = GeneralUtility::trimExplode(',', $backendConfiguration['debug']['excludeIp']); - if (in_array($_SERVER['REMOTE_ADDR'], $this->debugIps)) { + // Check if geolocation should be disabled by excludeIPs + if($backendConfiguration['debug']['excludeIp'] === '*' || in_array($_SERVER['REMOTE_ADDR'], $this->excludeIps)) { + $this->excluded = true; + } + + // Check if geolocation should return the debug position because of IP + if ($backendConfiguration['debug']['ip'] === '*' || in_array($_SERVER['REMOTE_ADDR'], $this->debugIps)) { // @extensionScannerIgnoreLine $this->debug = true; $this->debugPosition = new Position(); @@ -194,6 +215,9 @@ public function getGeoLocation(): ?Position { $sessionUtility = GeneralUtility::makeInstance(SessionUtility::class); + // If excluded ip, return null + + // If debug position, return it if ($this->debugPosition) { // Store posision in session diff --git a/ext_conf_template.txt b/ext_conf_template.txt index f7470a5..2729277 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -1,7 +1,10 @@ debug { - # cat=basic/110; type=string; label=Debug IP Addresses:Comma separated list of IP adresses for which to return the debug position. + # cat=basic/110; type=string; label=Debug IP Addresses: Comma separated list of IP adresses for which to return the debug position. ip = 127.0.0.1 + # cat=basic/111; type=string; label=Exclude IP Addresses: Comma separated list of IP adresses to exclude from geocoding + excludeIp = + # cat=basic/120; type=string; label=Debug Country Code countryCode = DE