]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum :Split client overview endpoint into reachable and unreachable clients
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 2 Nov 2023 07:25:12 +0000 (08:25 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 2 Nov 2023 07:35:13 +0000 (08:35 +0100)
gui/baculum/protected/API/Modules/Database.php
gui/baculum/protected/API/Pages/API/Clients.php

index 78528ccbbc55aec2f0356fba536183acf7370532..3397b97259c2f60f80c50fbecb101ebc705c7623 100644 (file)
@@ -211,6 +211,14 @@ class Database extends APIModule {
                                                $cond[] = "{$key} {$value[$i]['operator']} :{$kval}{$i}";
                                                $vals[":{$kval}{$i}"] = $value[$i]['vals'];
                                                $value[$i]['operator'] = '';
+                                       } elseif ($value[$i]['operator'] == '=') {
+                                               $cond[] = "$key = :{$kval}{$i}";
+                                               $vals[":{$kval}{$i}"] = $value[$i]['vals'];
+                                               $value[$i]['operator'] = '';
+                                       } elseif ($value[$i]['operator'] == '!=') {
+                                               $cond[] = "$key != :{$kval}{$i}";
+                                               $vals[":{$kval}{$i}"] = $value[$i]['vals'];
+                                               $value[$i]['operator'] = '';
                                        } else {
                                                $cond[] = "$key = :{$kval}{$i}";
                                                $vals[":{$kval}{$i}"] = $value[$i]['vals'];
index 59fa0c37b299943eb1dc3f0eb863e974ba8a831b..eaffe5734d9d5dd389c63a02cea2196f9c9867e2 100644 (file)
@@ -132,14 +132,54 @@ class Clients extends BaculumAPIServer {
                                $sort = [[$order_by_lc, $order_direction]];
                        }
 
-                       $clients = $this->getModule('client')->getClients(
-                               $limit,
-                               $offset,
-                               $sort,
-                               $params,
-                               $jobs,
-                               $mode
-                       );
+                       $clients = [];
+                       if ($mode == ClientManager::CLIENT_RESULT_MODE_OVERVIEW) {
+                               if (!in_array('Client.Uname', $params)) {
+                                       $params['Client.Uname'] = [];
+                               }
+
+                               // reachable clients (uname exists)
+                               $params['Client.Uname'][] = [
+                                       'operator' => '!=',
+                                       'vals' => ''
+                               ];
+                               $clients_reached = $this->getModule('client')->getClients(
+                                       $limit,
+                                       $offset,
+                                       $sort,
+                                       $params,
+                                       $jobs,
+                                       $mode
+                               );
+
+                               // unreachable clients (uname not exists)
+                               array_pop($params['Client.Uname']);
+                               $params['Client.Uname'][] = [
+                                       'operator' => '=',
+                                       'vals' => ''
+                               ];
+                               $clients_unreached = $this->getModule('client')->getClients(
+                                       $limit,
+                                       $offset,
+                                       $sort,
+                                       $params,
+                                       $jobs,
+                                       $mode
+                               );
+                               $clients = [
+                                       'reachable' => $clients_reached,
+                                       'unreachable' => $clients_unreached
+                               ];
+                       } else {
+                               $clients = $this->getModule('client')->getClients(
+                                       $limit,
+                                       $offset,
+                                       $sort,
+                                       $params,
+                                       $jobs,
+                                       $mode
+                               );
+                       }
                        $this->output = $clients;
                        $this->error = ClientError::ERROR_NO_ERRORS;
                } else {