diff options
author | Simon Rettberg | 2019-08-01 11:14:17 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-08-01 11:14:17 +0200 |
commit | 393d1562a03e0446e0e004b95dd7a5c8710ad341 (patch) | |
tree | 3be97d0405dfbcf23f02e835e7f9735996d2004a /modules-available/locations/inc/location.inc.php | |
parent | [locations] Add warnings/cleanup for bad machine to roomplan mappings (diff) | |
download | slx-admin-393d1562a03e0446e0e004b95dd7a5c8710ad341.tar.gz slx-admin-393d1562a03e0446e0e004b95dd7a5c8710ad341.tar.xz slx-admin-393d1562a03e0446e0e004b95dd7a5c8710ad341.zip |
[locations] Refine location matching checks
Diffstat (limited to 'modules-available/locations/inc/location.inc.php')
-rw-r--r-- | modules-available/locations/inc/location.inc.php | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php index e35670cc..ac866cbc 100644 --- a/modules-available/locations/inc/location.inc.php +++ b/modules-available/locations/inc/location.inc.php @@ -329,7 +329,7 @@ class Location 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 (self::isUuidLocationValid($uuidLoc, $ipLoc)) { + if (self::isFixedLocationValid($uuidLoc, $ipLoc)) { $locationId = $uuidLoc; } } @@ -337,20 +337,22 @@ class Location return $locationId; } - public static function isUuidLocationValid($uuidLoc, $ipLoc) + public static function isFixedLocationValid($uuidLoc, $ipLoc) { - if ($ipLoc !== false && $uuidLoc !== false && $uuidLoc !== $ipLoc) { - // 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 (count($ipLocations) + 2 >= count($uuidLocations) && in_array($ipLoc, $uuidLocations)) { - // UUID is max one level deeper than IP loc, accept - return true; - } - // UUID and IP disagree too much, play safe and ignore the UUID - } - return false; + $uuidLoc = (int)$uuidLoc; + $ipLoc = (int)$ipLoc; + if ($uuidLoc === $ipLoc || $uuidLoc === 0) + return true; + if ($ipLoc === 0) + return false; // roomplanner assignment, but no subnet - deny + // Validate that the location the IP maps to is in the chain we get using the + // location determined by roomplanner + $uuidLocations = self::getLocationRootChain($uuidLoc); + if (!empty(self::$assocLocationCache[$uuidLoc]['children'])) + return false; // roomplanner location isn't actually leaf node, this is not valid + $idx = array_search($ipLoc, $uuidLocations); + // If roomplanner loc is max two levels deeper than IP loc, accept + return $idx !== false && $idx <= 2; } /** |