diff options
author | Simon Rettberg | 2017-10-11 13:19:19 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-10-11 13:19:19 +0200 |
commit | df6fdbdb110ea28de4f5b9f540e01313ec217407 (patch) | |
tree | 9ea97c240fb2e154a90a1e6d191885a1bad9ebb2 /modules-available/dnbd3/baseconfig | |
parent | [dnbd3] More progress, manage location restrictions for proxies (diff) | |
download | slx-admin-df6fdbdb110ea28de4f5b9f540e01313ec217407.tar.gz slx-admin-df6fdbdb110ea28de4f5b9f540e01313ec217407.tar.xz slx-admin-df6fdbdb110ea28de4f5b9f540e01313ec217407.zip |
[dnbd3] Fix CIDR generation for proxies, add baseconfig hook for clients
Diffstat (limited to 'modules-available/dnbd3/baseconfig')
-rw-r--r-- | modules-available/dnbd3/baseconfig/getconfig.inc.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/modules-available/dnbd3/baseconfig/getconfig.inc.php b/modules-available/dnbd3/baseconfig/getconfig.inc.php new file mode 100644 index 00000000..ae4d2924 --- /dev/null +++ b/modules-available/dnbd3/baseconfig/getconfig.inc.php @@ -0,0 +1,46 @@ +<?php + +if (!Dnbd3::isEnabled()) return; + +// Locations from closest to furthest (order) +$locations = ConfigHolder::get('SLX_LOCATIONS'); +if ($locations === false) { + $locationIds = [0]; +} else { + $locationIds = explode(' ', $locations); + if (empty($locationIds)) { + $locationIds[] = 0; + } +} + +$res = Database::simpleQuery('SELECT s.fixedip, m.clientip, sxl.locationid FROM dnbd3_server s + LEFT JOIN machine m USING (machineuuid) + LEFT JOIN dnbd3_server_x_location sxl USING (serverid) + WHERE sxl.locationid IS NULL OR sxl.locationid IN (:lids)', array('lids' => $locationIds)); +// Lookup of priority - first index (0) will be closest location in chain +$locationsAssoc = array_flip($locationIds); +$servers = array(); +while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if ($row['fixedip'] === '<self>') { + $row['fixedip'] = Property::getServerIp(); + $defPrio = 2000; + } else { + $defPrio = 1000; + } + $ip = $row['clientip'] ? $row['clientip'] : $row['fixedip']; + if ($defPrio === 1000 && is_null($row['locationid'])) { + $serverLoc = Location::getFromIp($ip); + if ($serverLoc !== false) { + $row['locationid'] = $serverLoc; + } + } + $old = isset($servers[$ip]) ? $servers[$ip] : $defPrio; + if (is_null($row['locationid']) || !isset($locationsAssoc[$row['locationid']])) { + $servers[$ip] = min($defPrio, $old); + } else { + $servers[$ip] = min($locationsAssoc[$row['locationid']], $old); + } +} + +asort($servers, SORT_NUMERIC | SORT_ASC); +ConfigHolder::add('SLX_DNBD3_SERVERS', implode(' ', array_keys($servers))); |