From a12cff0605cc9da29ee8d266cefb28c0c7405179 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 24 Jun 2022 14:06:21 +0200 Subject: [dnbd3] Rename/refactor RPC methods/constants --- modules-available/dnbd3/page.inc.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'modules-available/dnbd3/page.inc.php') diff --git a/modules-available/dnbd3/page.inc.php b/modules-available/dnbd3/page.inc.php index a373d0ed..7173fc10 100644 --- a/modules-available/dnbd3/page.inc.php +++ b/modules-available/dnbd3/page.inc.php @@ -263,7 +263,8 @@ class Page_Dnbd3 extends Page Module::isAvailable('js_stupidtable'); $server = $this->getServerById(); Render::addTemplate('page-proxy-header', $server); - $stats = Dnbd3Rpc::query($server['ip'], true, true, true, true, true, true); + $stats = Dnbd3Rpc::query($server['ip'], [Dnbd3Rpc::QUERY_STATS, Dnbd3Rpc::QUERY_CLIENTS, + Dnbd3Rpc::QUERY_IMAGES, Dnbd3Rpc::QUERY_SPACE, Dnbd3Rpc::QUERY_CONFIG, Dnbd3Rpc::QUERY_ALTSERVERS]); if (!is_array($stats) || !isset($stats['runId'])) { Message::addError('server-unreachable'); return; @@ -515,12 +516,12 @@ class Page_Dnbd3 extends Page if ($res !== false) die('{"error": "Server with this IP already exists", "fatal": true}'); // Query - $reply = Dnbd3Rpc::query($ip,true, false, false, true); - if ($reply === Dnbd3Rpc::QUERY_UNREACHABLE) + $reply = Dnbd3Rpc::query($ip, [Dnbd3Rpc::QUERY_STATS, Dnbd3Rpc::QUERY_SPACE]); + if ($reply === Dnbd3Rpc::ERROR_UNREACHABLE) die('{"error": "Could not reach server"}'); - if ($reply === Dnbd3Rpc::QUERY_NOT_200) + if ($reply === Dnbd3Rpc::ERROR_NOT_200) die('{"error": "Server did not reply with 200 OK"}'); - if ($reply === Dnbd3Rpc::QUERY_NOT_JSON) + if ($reply === Dnbd3Rpc::ERROR_NOT_JSON) die('{"error": "No JSON received from server"}'); if (!is_array($reply) || !isset($reply['uptime']) || !isset($reply['clientCount'])) die('{"error": "Reply does not suggest this is a dnbd3 server"}'); @@ -607,11 +608,11 @@ class Page_Dnbd3 extends Page die('Invalid/no image id'); } $data = Dnbd3Rpc::getCacheMap($server['ip'], $imgId); - if ($data === Dnbd3Rpc::QUERY_UNREACHABLE) { + if ($data === Dnbd3Rpc::ERROR_UNREACHABLE) { Header('HTTP/1.1 504 Gateway Timeout'); die('Proxy not reachable'); } - if ($data === Dnbd3Rpc::QUERY_NOT_200) { + if ($data === Dnbd3Rpc::ERROR_NOT_200) { Header('HTTP/1.1 503 Service Unavailable'); die("Proxy didn't reply with 200 OK"); } @@ -621,14 +622,7 @@ class Page_Dnbd3 extends Page private function ajaxStats() { - $res = Database::simpleQuery('SELECT s.serverid, m.clientip, s.fixedip - FROM dnbd3_server s - LEFT JOIN machine m ON (s.machineuuid = m.machineuuid) - WHERE s.lastseen > :cutoff', ['cutoff' => time() - 310]); - $lookup = []; - foreach ($res as $row) { - $lookup[$row['fixedip'] ?? $row['clientip'] ?? ''] = $row['serverid']; - } + $lookup = Dnbd3::getActiveServers(); $result = Dnbd3Rpc::getStatsMulti(array_keys($lookup)); $return = []; foreach ($result as $ip => $data) { -- cgit v1.2.3-55-g7522