]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add using multiple content values in filesets endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 18 Jan 2024 09:21:41 +0000 (10:21 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 18 Jan 2024 09:22:38 +0000 (10:22 +0100)
gui/baculum/protected/API/Modules/Database.php
gui/baculum/protected/API/Pages/API/FileSets.php
gui/baculum/protected/API/openapi_baculum.json
gui/baculum/protected/Common/Modules/Miscellaneous.php

index 3397b97259c2f60f80c50fbecb101ebc705c7623..1275743feb7589a3addd6e1045e04ba43c441350 100644 (file)
@@ -189,6 +189,14 @@ class Database extends APIModule {
                                                        }
                                                        $cond[] = "{$key} {$value[$i]['operator']} (" . implode(',', $tcond) . ')';
                                                        $value[$i]['operator'] = '';
+                                               } elseif ($value[$i]['operator'] == 'LIKE') {
+                                                       $tcond = [];
+                                                       for ($j = 0; $j < count($value[$i]['vals']); $j++) {
+                                                               $tcond[] = "{$key} {$value[$i]['operator']} :{$kval}{$i}{$j}";
+                                                               $vals[":{$kval}{$i}{$j}"] = $value[$i]['vals'][$j];
+                                                       }
+                                                       $cond[] = implode(' OR ', $tcond);
+                                                       $value[$i]['operator'] = '';
                                                } else {
                                                        // other operators
                                                        for ($j = 0; $j < count($value[$i]['vals']); $j++) {
index ffe5a3e286c8733a6ef2e6e8757fa5b955ab7eac..cce2a25508fed2fa04e6a6f9259278ff4b05239b 100644 (file)
@@ -34,7 +34,7 @@ class FileSets extends BaculumAPIServer {
 
        public function get() {
                $misc = $this->getModule('misc');
-               $content = $this->Request->contains('content') && $misc->isValidName($this->Request['content']) ? $this->Request['content'] : '';
+               $content = $this->Request->contains('content') && $misc->isValidNameList($this->Request['content']) ? $this->Request['content'] : '';
                $limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
                $offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
                $result = $this->getModule('bconsole')->bconsoleCommand(
@@ -58,9 +58,14 @@ class FileSets extends BaculumAPIServer {
                        ];
 
                        if (!empty($content)) {
+                               $cnts = explode(',', $content);
+                               $cb = function ($item) {
+                                       return ('%' . trim($item) . '%');
+                               };
+                               $cnts = array_map($cb, $cnts);
                                $params['FileSet.Content'][] = [
                                        'operator' => 'LIKE',
-                                       'vals' => '%' . $content . '%'
+                                       'vals' => $cnts
                                ];
                        }
 
index 32a75a718bec16e95e7b9242b92c316a51d0b7e4..3b58d33f5be540955fbc294ce90a810fc15ceeb0 100644 (file)
                                        {
                                                "name": "content",
                                                "in": "query",
-                                               "description": "Content property value. There is possible to provide whole content value or only a part",
+                                               "description": "Content property value. There is possible to provide whole content value or only a part. Multiple comma separated values are allowed. Example: 'postgresql,file' value searches for filesets with postgresql OR file OR both.",
                                                "required": false,
                                                "schema": {
                                                        "type": "string",
index 229ad29c3492e27c82ec43b4d6de10512c82d3f8..ce0cd337f34f11ce43945200151993be737f5b7e 100644 (file)
@@ -300,6 +300,10 @@ class Miscellaneous extends TModule {
                return (preg_match('/^[\d,]+$/', $list) === 1);
        }
 
+       public function isValidNameList($list) {
+               return (preg_match('/^[\w:\.\-\s,]+$/', $list) === 1);
+       }
+
        public function isValidBvfsPath($path) {
                return (preg_match('/^b2\d+$/', $path) === 1);
        }