summaryrefslogtreecommitdiffstats
path: root/modules-available/dnbd3/inc
diff options
context:
space:
mode:
authorSimon Rettberg2019-03-07 15:23:42 +0100
committerSimon Rettberg2019-03-07 15:23:42 +0100
commit9a8569775996b4b2441b69e06a09b9ab8284519e (patch)
tree4712384eedcb4a67eace6eff9f2c78dabec616df /modules-available/dnbd3/inc
parent[locationinfo] Introduce timeouts for curl operations (diff)
downloadslx-admin-9a8569775996b4b2441b69e06a09b9ab8284519e.tar.gz
slx-admin-9a8569775996b4b2441b69e06a09b9ab8284519e.tar.xz
slx-admin-9a8569775996b4b2441b69e06a09b9ab8284519e.zip
[dnbd3] Support specifying port, IPv6 addresses
Diffstat (limited to 'modules-available/dnbd3/inc')
-rw-r--r--modules-available/dnbd3/inc/dnbd3rpc.inc.php17
-rw-r--r--modules-available/dnbd3/inc/dnbd3util.inc.php22
2 files changed, 32 insertions, 7 deletions
diff --git a/modules-available/dnbd3/inc/dnbd3rpc.inc.php b/modules-available/dnbd3/inc/dnbd3rpc.inc.php
index cdcda508..6ed43254 100644
--- a/modules-available/dnbd3/inc/dnbd3rpc.inc.php
+++ b/modules-available/dnbd3/inc/dnbd3rpc.inc.php
@@ -19,13 +19,24 @@ class Dnbd3Rpc {
* @param bool $altservers list of alt servers with status
* @return int|array the queried data as an array, or false on error
*/
- public static function query($server, $port, $stats, $clients, $images, $diskSpace = false, $config = false, $altservers = false)
+ public static function query($server, $stats, $clients, $images, $diskSpace = false, $config = false, $altservers = false)
{
// Special case - local server
if ($server === '<self>') {
- $server = '127.0.0.1';
+ $server = '127.0.0.1:5003';
+ } elseif (($out = Dnbd3Util::matchAddress($server))) {
+ if (isset($out['v4'])) {
+ $server = $out['v4'];
+ } else {
+ $server = '[' . $out['v6'] . ']';
+ }
+ if (isset($out['port'])) {
+ $server .= $out['port'];
+ } else {
+ $server .= ':5003';
+ }
}
- $url = 'http://' . $server . ':' . $port . '/query?';
+ $url = 'http://' . $server . '/query?';
if ($stats) {
$url .= 'q=stats&';
}
diff --git a/modules-available/dnbd3/inc/dnbd3util.inc.php b/modules-available/dnbd3/inc/dnbd3util.inc.php
index 33581b77..35fad8b3 100644
--- a/modules-available/dnbd3/inc/dnbd3util.inc.php
+++ b/modules-available/dnbd3/inc/dnbd3util.inc.php
@@ -52,12 +52,11 @@ class Dnbd3Util {
// Now query them all
$NOW = time();
foreach ($servers as $server) {
- $port = 5003;
- $data = Dnbd3Rpc::query($server['addr'], $port, true, false, false, true);
+ $data = Dnbd3Rpc::query($server['addr'], true, false, false, true);
if ($data === Dnbd3Rpc::QUERY_UNREACHABLE) {
- $error = 'No (HTTP) reply on port ' . $port;
+ $error = 'No (HTTP) reply from ' . $server['addr'];
} elseif ($data === Dnbd3Rpc::QUERY_NOT_200) {
- $error = 'No HTTP 200 OK on port ' . $port;
+ $error = 'No HTTP 200 OK from ' . $server['addr'];
} elseif ($data === Dnbd3Rpc::QUERY_NOT_JSON) {
$error = 'Reply to status query is not JSON';
} elseif (!is_array($data) || !isset($data['runId'])) {
@@ -247,4 +246,19 @@ class Dnbd3Util {
);
}
+ public static function matchAddress($server)
+ {
+ if (!preg_match('/^(?:\[(?<v6a>[a-f0-9:]+)\]|(?<v6b>[a-f0-9:]+)|(?<v4>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+))(?<port>:\d+)?$/i',
+ $server, $out)) {
+ return false;
+ }
+ foreach (['v6a', 'v6b'] as $k) {
+ if (isset($out[$k])) {
+ $out['v6'] = $out[$k];
+ unset($out[$k]);
+ }
+ }
+ return $out;
+ }
+
}