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 | |
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')
-rw-r--r-- | modules-available/dnbd3/baseconfig/getconfig.inc.php | 46 | ||||
-rw-r--r-- | modules-available/dnbd3/inc/dnbd3.inc.php | 17 | ||||
-rw-r--r-- | modules-available/dnbd3/inc/dnbd3util.inc.php | 29 |
3 files changed, 80 insertions, 12 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))); diff --git a/modules-available/dnbd3/inc/dnbd3.inc.php b/modules-available/dnbd3/inc/dnbd3.inc.php new file mode 100644 index 00000000..905bdc68 --- /dev/null +++ b/modules-available/dnbd3/inc/dnbd3.inc.php @@ -0,0 +1,17 @@ +<?php + +class Dnbd3 { + + const PROP_ENABLED = 'dnbd3.enabled'; + + public static function isEnabled() + { + return Property::get(self::PROP_ENABLED, 0) ? true : false; + } + + public static function setEnabled($bool) + { + Property::set(self::PROP_ENABLED, $bool ? 1 : 0); + } + +}
\ No newline at end of file diff --git a/modules-available/dnbd3/inc/dnbd3util.inc.php b/modules-available/dnbd3/inc/dnbd3util.inc.php index 48e887b3..722cc5e3 100644 --- a/modules-available/dnbd3/inc/dnbd3util.inc.php +++ b/modules-available/dnbd3/inc/dnbd3util.inc.php @@ -37,6 +37,10 @@ class Dnbd3Util { // IP address of the server itself in the list. Database::exec('DELETE FROM dnbd3_server WHERE fixedip = :serverip', array('serverip' => $satServerIp)); Database::exec("INSERT IGNORE INTO dnbd3_server (fixedip) VALUES ('<self>')"); + // Delete orphaned entires with machineuuid from dnbd3_server where we don't have a runmode entry + Database::exec('DELETE s FROM dnbd3_server s + LEFT JOIN runmode r USING (machineuuid) + WHERE s.machineuuid IS NOT NULL AND r.module IS NULL'); // Now query them all $NOW = time(); foreach ($servers as $server) { @@ -78,7 +82,10 @@ class Dnbd3Util { INNER JOIN dnbd3_server_x_location USING (serverid) WHERE machineuuid = :uuid', array('uuid' => $machineUuid)); - $assignedLocs = $res->fetchAll(PDO::FETCH_ASSOC); + $assignedLocs = array(); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $assignedLocs[] = $row['locationid']; + } if (!empty($assignedLocs)) { // Get all sub-locations too $recursiveLocs = $assignedLocs; @@ -89,8 +96,9 @@ class Dnbd3Util { } } $res = Database::simpleQuery('SELECT startaddr, endaddr FROM subnet WHERE locationid IN (:locs)', - array('locs' => $recursiveLocs)); + array('locs' => array_values($recursiveLocs))); // Got subnets, build whitelist + // TODO: Coalesce overlapping ranges $opt = ''; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $opt .= ' ' . self::range2Cidr($row['startaddr'], $row['endaddr']); @@ -126,6 +134,10 @@ class Dnbd3Util { ConfigHolder::add('SLX_DNBD3_PRIVATE', implode(' ', $private)); } ConfigHolder::add('SLX_ADDONS', '', 1000); + ConfigHolder::add('SLX_SHUTDOWN_TIMEOUT', '', 1000); + ConfigHolder::add('SLX_SHUTDOWN_SCHEDULE', '', 1000); + ConfigHolder::add('SLX_REBOOT_TIMEOUT', '', 1000); + ConfigHolder::add('SLX_REBOOT_SCHEDULE', '', 1000); } /** @@ -139,18 +151,11 @@ class Dnbd3Util { */ private static function range2Cidr($start, $end) { - $bin = decbin($start ^ $end); + $bin = decbin((int)$start ^ (int)$end); if ($bin === '0') - return $start; + return long2ip($start); $mask = 32 - strlen($bin); - return $start . '/' . $mask; + return long2ip($start) . '/' . $mask; } } - -class Dnbd3ProxyConfig -{ - - public $a; - -}
\ No newline at end of file |