Skip to content

Commit

Permalink
Extension-Konfiguration: excludeIp hinzuefuegen
Browse files Browse the repository at this point in the history
  • Loading branch information
kftw committed Aug 20, 2020
1 parent f790091 commit 3969233
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 25 additions & 1 deletion Classes/Utility/GeoUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,27 @@ 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
*
* @var array
*/
protected $debugIps = [];

/**
* IP addresses to exclude from geolocation
*
* @var array
*/
protected $excludeIps = [];

/**
* The debug position
*
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 3969233

Please sign in to comment.