]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add status schedule API endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 2 May 2019 07:32:12 +0000 (09:32 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 2 May 2019 09:11:23 +0000 (11:11 +0200)
gui/baculum/protected/API/Pages/API/ScheduleStatus.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/Volume.php
gui/baculum/protected/API/endpoints.xml
gui/baculum/protected/Common/Class/Miscellaneous.php

diff --git a/gui/baculum/protected/API/Pages/API/ScheduleStatus.php b/gui/baculum/protected/API/Pages/API/ScheduleStatus.php
new file mode 100644 (file)
index 0000000..4b8acf9
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+class ScheduleStatus extends BaculumAPIServer {
+
+       public function get() {
+               $misc = $this->getModule('misc');
+               $cmd = array('status', 'schedule');
+               if ($this->Request->contains('job') && $misc->isValidName($this->Request['job'])) {
+                       $cmd[] = 'job="' . $this->Request['job'] . '"';
+               }
+               if ($this->Request->contains('client') && $misc->isValidName($this->Request['client'])) {
+                       $cmd[] = 'client="' . $this->Request['client'] . '"';
+               }
+               if ($this->Request->contains('schedule') && $misc->isValidName($this->Request['schedule'])) {
+                       $cmd[] = 'schedule="' . $this->Request['schedule'] . '"';
+               }
+               if ($this->Request->contains('days') && $misc->isValidInteger($this->Request['days'])) {
+                       $cmd[] = 'days="' . $this->Request['days'] . '"';
+               }
+               if ($this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit'])) {
+                       $cmd[] = 'limit="' . $this->Request['limit'] . '"';
+               }
+               if ($this->Request->contains('time') && $misc->isValidBDateAndTime($this->Request['time'])) {
+                       $cmd[] = 'time="' . $this->Request['time'] . '"';
+               }
+
+               $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, true);
+               if ($result->exitcode === 0) {
+                       array_shift($result->output);
+                       $this->output = $this->formatSchedules($result->output);
+                       $this->error = PoolError::ERROR_NO_ERRORS;
+               } else {
+                       $this->output = $result->output;
+                       $this->error = $result->exitcode;
+               }
+       }
+
+       private function formatSchedules(array $output) {
+               $items = $item = array();
+               for ($i = 0; $i < count($output); $i++) {
+                       if (preg_match('/^(?P<key>\w+)=(?P<val>[\s\S]*)$/', $output[$i], $match) === 1) {
+                               $item[$match['key']] = $match['val'];
+                       } elseif (empty($output[$i]) && count($item) > 0) {
+                               $items[] = $item;
+                               $item = array();
+                       }
+               }
+               return $items;
+       }
+}
+?>
index c4ea347e1f57b6f1bee898ec9f3893aeec1f5d0a..c1b76db2dad747c00bf5874033d4324bb0306d82 100644 (file)
@@ -47,22 +47,22 @@ class Volume extends BaculumAPIServer {
                                        $cmd[] = 'pool="' . $pool->name . '"';
                                }
                        }
-                       if(property_exists($params, 'volretention') && $misc->isValidNumber($params->volretention)) {
+                       if(property_exists($params, 'volretention') && $misc->isValidInteger($params->volretention)) {
                                $cmd[] = 'volretention="' . $params->volretention . '"';
                        }
-                       if(property_exists($params, 'voluseduration') && $misc->isValidNumber($params->voluseduration)) {
+                       if(property_exists($params, 'voluseduration') && $misc->isValidInteger($params->voluseduration)) {
                                $cmd[] = 'voluseduration="' . $params->voluseduration . '"';
                        }
-                       if(property_exists($params, 'maxvoljobs') && $misc->isValidNumber($params->maxvoljobs)) {
+                       if(property_exists($params, 'maxvoljobs') && $misc->isValidInteger($params->maxvoljobs)) {
                                $cmd[] = 'maxvoljobs="' . $params->maxvoljobs . '"';
                        }
-                       if(property_exists($params, 'maxvolfiles') && $misc->isValidNumber($params->maxvolfiles)) {
+                       if(property_exists($params, 'maxvolfiles') && $misc->isValidInteger($params->maxvolfiles)) {
                                $cmd[] = 'maxvolfiles="' . $params->maxvolfiles . '"';
                        }
-                       if(property_exists($params, 'maxvolbytes') && $misc->isValidNumber($params->maxvolbytes)) {
+                       if(property_exists($params, 'maxvolbytes') && $misc->isValidInteger($params->maxvolbytes)) {
                                $cmd[] = 'maxvolbytes="' . $params->maxvolbytes . '"';
                        }
-                       if(property_exists($params, 'slot') && $misc->isValidNumber($params->slot)) {
+                       if(property_exists($params, 'slot') && $misc->isValidInteger($params->slot)) {
                                $cmd[] = 'slot="' . $params->slot . '"';
                        }
                        if(property_exists($params, 'recycle') && $misc->isValidBoolean($params->recycle)) {
index a7f1af0157285cccea88044de0d6e2cc6045791d..4dbb0d8b3f44c195b01197b4cb734c6b03f0ea8f 100644 (file)
@@ -79,6 +79,7 @@
        <url ServiceParameter="API.FileSetResNames" pattern="api/v1/filesets/resnames/" />
        <!-- schedule endpoints -->
        <url ServiceParameter="API.Schedules" pattern="api/v1/schedules/resnames/" />
+       <url ServiceParameter="API.ScheduleStatus" pattern="api/v1/schedules/status/" />
        <!-- Bacula config module endpoints -->
        <url ServiceParameter="API.Config" pattern="api/v1/config/" />
        <url ServiceParameter="API.Config" pattern="api/v1/config/{component_type}/" parameters.component_type="[a-z]+" />
index 21f64439a547c1cb004f3d7e769ba82196fb2ce4..8a9ded6329ad1f8a1776f05a5caa037de419bccb 100644 (file)
@@ -199,7 +199,7 @@ class Miscellaneous extends TModule {
                return (preg_match('/^\w+$/', $state) === 1);
        }
 
-       public function isValidNumber($num) {
+       public function isValidInteger($num) {
                return (preg_match('/^\d+$/', $num) === 1);
        }
 
@@ -235,6 +235,10 @@ class Miscellaneous extends TModule {
                return (preg_match('/^b2\d+$/', $path) === 1);
        }
 
+       public function isValidBDateAndTime($time) {
+               return (preg_match('/^\d{4}-\d{2}-\d{2} \d{1,2}:\d{2}:\d{2}$/', $time) === 1);
+       }
+
        /**
         * Writing INI-style configuration file.
         *