From 9a8569775996b4b2441b69e06a09b9ab8284519e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 7 Mar 2019 15:23:42 +0100 Subject: [dnbd3] Support specifying port, IPv6 addresses --- modules-available/dnbd3/inc/dnbd3util.inc.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'modules-available/dnbd3/inc/dnbd3util.inc.php') 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('/^(?:\[(?[a-f0-9:]+)\]|(?[a-f0-9:]+)|(?[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+))(?:\d+)?$/i', + $server, $out)) { + return false; + } + foreach (['v6a', 'v6b'] as $k) { + if (isset($out[$k])) { + $out['v6'] = $out[$k]; + unset($out[$k]); + } + } + return $out; + } + } -- cgit v1.2.3-55-g7522