From f46409bf74e42de6490a7d80f319c132c3d6a43c Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 5 Sep 2017 15:56:17 +0200 Subject: [locations] fix missing locationId on ip/uuid ... ... when the client's ip falls within a known range but its uuid has not been recorded yet and the client requests its config by uuid. --- modules-available/locations/inc/location.inc.php | 37 ++++++++++++------------ 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'modules-available/locations') diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php index 8b2ef262..e3fd35b7 100644 --- a/modules-available/locations/inc/location.inc.php +++ b/modules-available/locations/inc/location.inc.php @@ -285,29 +285,28 @@ class Location { $locationId = false; $ipLoc = self::getFromIp($ip); - if ($ipLoc !== false && $uuid !== false) { - // Machine ip maps to a location, and we have a client supplied uuid - $uuidLoc = self::getFromMachineUuid($uuid); - if ($uuidLoc === $ipLoc) { - $locationId = $uuidLoc; - } else if ($uuidLoc !== false) { - // Validate that the location the IP maps to is in the chain we get using the - // location determined by the uuid - $uuidLocations = self::getLocationRootChain($uuidLoc); - $ipLocations = self::getLocationRootChain($ipLoc); - if (in_array($uuidLoc, $ipLocations) // UUID loc is further up, OK - || (in_array($ipLoc, $uuidLocations) && count($ipLocations) + 1 >= count($uuidLocations)) // UUID is max one level deeper than IP loc, accept as well - ) { - // Close enough, allow + if ($ipLoc !== false) { + // Set locationId to ipLoc for now, it will be overwritten later if another case applies. + $locationId = $ipLoc; + if ($uuid !== false) { + // Machine ip maps to a location, and we have a client supplied uuid (which might not be known if the client boots for the first time) + $uuidLoc = self::getFromMachineUuid($uuid); + if ($uuidLoc === $ipLoc) { $locationId = $uuidLoc; - } else { + } else if ($uuidLoc !== false) { + // Validate that the location the IP maps to is in the chain we get using the + // location determined by the uuid + $uuidLocations = self::getLocationRootChain($uuidLoc); + $ipLocations = self::getLocationRootChain($ipLoc); + if (in_array($uuidLoc, $ipLocations) // UUID loc is further up, OK + || (in_array($ipLoc, $uuidLocations) && count($ipLocations) + 1 >= count($uuidLocations)) // UUID is max one level deeper than IP loc, accept as well + ) { + // Close enough, allow + $locationId = $uuidLoc; + } // UUID and IP disagree too much, play safe and ignore the UUID - $locationId = $ipLoc; } } - } else if ($ipLoc !== false) { - // No uuid, but ip maps to location; use that - $locationId = $ipLoc; } return $locationId; } -- cgit v1.2.3-55-g7522