]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add enable and disable client, storage, job and schedule endpoints
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 21 Jun 2024 14:31:51 +0000 (16:31 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Fri, 21 Jun 2024 14:31:51 +0000 (16:31 +0200)
14 files changed:
gui/baculum/protected/API/Modules/Bconsole.php
gui/baculum/protected/API/Modules/DisableResource.php [new file with mode: 0644]
gui/baculum/protected/API/Modules/EnableResource.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/DisableClient.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/DisableJob.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/DisableSchedule.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/DisableStorage.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/EnableClient.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/EnableJob.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/EnableSchedule.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/EnableStorage.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/config.xml
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

index 0f32e0400630e529d1653c452e11bc6aecee35f1..203eb4f01e8789aac2e6543feb213e6825bd8ddd 100644 (file)
@@ -103,7 +103,9 @@ class Bconsole extends APIModule {
                '.search',
                '@putfile',
                'cloud',
-               'time'
+               'time',
+               'disable',
+               'enable'
        );
 
        private $config;
diff --git a/gui/baculum/protected/API/Modules/DisableResource.php b/gui/baculum/protected/API/Modules/DisableResource.php
new file mode 100644 (file)
index 0000000..74a7b42
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+
+namespace Baculum\API\Modules;
+
+/**
+ * Tools used to disable Bacula resources using disable bconsole command.
+ * Note: this setting is not persistent. It is lost after the component restart.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category Module
+ * @package Baculum API
+ */
+class DisableResource extends APIModule {
+
+       /**
+        * Resources allowed to disable.
+        * This resources support disabling/enabling.
+        */
+       const ALLOWED_RESOURCES = [
+               'dir' => [
+                       'Client',
+                       'Storage',
+                       'Job',
+                       'Schedule'
+               ],
+               'sd' => [
+                       'Storage'
+               ],
+               'fd' => [
+                       'FileDaemon'
+               ]
+       ];
+
+       public function isResourceSupported($component_type, $resource_type) {
+               return isset(self::ALLOWED_RESOURCES[$component_type][$resource_type]);
+       }
+
+       /**
+        * Disable resource.
+        *
+        * @param string $director Director name
+        * @param string $component_type component type
+        * @param string $resource_type resource type
+        * @param string $resource_name resource name
+        * @param array $params extra parameters
+        * @return object result and exitcode
+        */
+       public function disable($director, $component_type, $resource_type, $resource_name, $params = []) {
+               $ret = (object) ['output' => '','exitcode' => -1];
+               if ($this->isResourceSupported($component_type, $resource_type)) {
+                       $ret->output = 'Resource not supported';
+                       return $ret;
+               }
+
+               $key = strtolower($resource_type);
+               $value = $resource_name;
+               $cmd = ['disable', "$key=\"$value\""];
+               if (count($params) > 0) {
+                       $cmd = array_merge($cmd, $params);
+               }
+               $ret = $this->getModule('bconsole')->bconsoleCommand(
+                       $director,
+                       $cmd
+               );
+               return $ret;
+       }
+}
diff --git a/gui/baculum/protected/API/Modules/EnableResource.php b/gui/baculum/protected/API/Modules/EnableResource.php
new file mode 100644 (file)
index 0000000..e01fb39
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+
+namespace Baculum\API\Modules;
+
+/**
+ * Tool used to enable Bacula resources using enable bconsole command.
+ * Note: this setting is not persistent. It is lost after the component restart.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category Module
+ * @package Baculum API
+ */
+class EnableResource extends APIModule {
+
+       /**
+        * Resources allowed to enable.
+        * These resources support disabling/enabling.
+        */
+       const ALLOWED_RESOURCES = [
+               'dir' => [
+                       'Client',
+                       'Storage',
+                       'Job',
+                       'Schedule'
+               ],
+               'sd' => [
+                       'Storage'
+               ],
+               'fd' => [
+                       'FileDaemon'
+               ]
+       ];
+
+       public function isResourceSupported($component_type, $resource_type) {
+               return isset(self::ALLOWED_RESOURCES[$component_type][$resource_type]);
+       }
+
+       /**
+        * Enable resource.
+        *
+        * @param string $director Director name
+        * @param string $component_type component type
+        * @param string $resource_type resource type
+        * @param string $resource_name resource name
+        * @param array $params extra parameters
+        * @return bool|object result and exitcode
+        */
+       public function enable($director, $component_type, $resource_type, $resource_name, $params = []) {
+               $ret = (object) ['output' => '','exitcode' => -1];
+               if ($this->isResourceSupported($component_type, $resource_type)) {
+                       $ret->output = 'Resource not supported';
+                       return $ret;
+               }
+
+               $key = strtolower($resource_type);
+               $value = $resource_name;
+               $cmd = ['enable', "$key=\"$value\""];
+               if (count($params) > 0) {
+                       $cmd = array_merge($cmd, $params);
+               }
+               $ret = $this->getModule('bconsole')->bconsoleCommand(
+                       $director,
+                       $cmd
+               );
+               return $ret;
+       }
+}
diff --git a/gui/baculum/protected/API/Pages/API/DisableClient.php b/gui/baculum/protected/API/Pages/API/DisableClient.php
new file mode 100644 (file)
index 0000000..807bd22
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\ClientError;
+
+/**
+ * Disable Director Client resource endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class DisableClient extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $clientid = (int) $id;
+               $client_mod = $this->getModule('client');
+               $client = null;
+               if ($clientid > 0) {
+                       $client = $client_mod->getClientById($clientid);
+               }
+
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.client'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       if (is_object($client) && in_array($client->name, $result->output)) {
+                               $component_type = 'dir';
+                               $resource_type = 'client';
+                               $resource_name = $client->name;
+
+                               $result = $this->getModule('disable')->disable(
+                                       $this->director,
+                                       $component_type,
+                                       $resource_type,
+                                       $resource_name
+                               );
+                               $output = $result->output;
+                               $error = $result->exitcode;
+                               if ($error != 0) {
+                                       $output = ClientError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                                       $error = ClientError::ERROR_WRONG_EXITCODE;
+                               }
+                               $this->output = $output;
+                               $this->error = $error;
+                       } else {
+                               $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+                               $this->error = ClientError::ERROR_CLIENT_DOES_NOT_EXISTS;
+                       }
+               } else {
+                       $this->output = ClientError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                       $this->error = ClientError::ERROR_WRONG_EXITCODE;
+               }
+       }
+}
+?>
diff --git a/gui/baculum/protected/API/Pages/API/DisableJob.php b/gui/baculum/protected/API/Pages/API/DisableJob.php
new file mode 100644 (file)
index 0000000..9829e36
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\JobError;
+
+/**
+ * Disable Director Job resource endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class DisableJob extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $jobid = (int) $id;
+               $job_mod = $this->getModule('job');
+               $job = null;
+               if ($jobid > 0) {
+                       $job = $job_mod->getJobById($jobid);
+               }
+
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.jobs'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       if (is_object($job) && in_array($job->name, $result->output)) {
+                               $component_type = 'dir';
+                               $resource_type = 'job';
+                               $resource_name = $job->name;
+
+                               $result = $this->getModule('disable')->disable(
+                                       $this->director,
+                                       $component_type,
+                                       $resource_type,
+                                       $resource_name
+                               );
+                               $output = $result->output;
+                               $error = $result->exitcode;
+                               if ($error != 0) {
+                                       $output = JobError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                                       $error = JobError::ERROR_WRONG_EXITCODE;
+                               }
+                               $this->output = $output;
+                               $this->error = $error;
+                       } else {
+                               $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
+                               $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
+                       }
+               } else {
+                       $this->output = JobError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                       $this->error = JobError::ERROR_WRONG_EXITCODE;
+               }
+       }
+}
+?>
diff --git a/gui/baculum/protected/API/Pages/API/DisableSchedule.php b/gui/baculum/protected/API/Pages/API/DisableSchedule.php
new file mode 100644 (file)
index 0000000..8ff35bd
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\GenericError;
+
+/**
+ * Disable Director Schedule resource endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class DisableSchedule extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $misc = $this->getModule('misc');
+               $schedule_name = $this->Request->contains('name') && $misc->isValidName($this->Request['name']) ? $this->Request['name'] : '';
+
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.schedule'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       if (in_array($schedule_name, $result->output)) {
+                               $component_type = 'dir';
+                               $resource_type = 'schedule';
+                               $resource_name = $schedule_name;
+
+                               $result = $this->getModule('disable')->disable(
+                                       $this->director,
+                                       $component_type,
+                                       $resource_type,
+                                       $resource_name
+                               );
+                               $output = $result->output;
+                               $error = $result->exitcode;
+                               if ($error != 0) {
+                                       $output = GenericError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                                       $error = GenericError::ERROR_WRONG_EXITCODE;
+                               }
+                               $this->output = $output;
+                               $this->error = $error;
+                       } else {
+                               $this->output = GenericError::MSG_ERROR_INVALID_PROPERTY;
+                               $this->error = GenericError::ERROR_INVALID_PROPERTY;
+                       }
+               } else {
+                       $this->output = GenericError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                       $this->error = GenericError::ERROR_WRONG_EXITCODE;
+               }
+       }
+}
+?>
diff --git a/gui/baculum/protected/API/Pages/API/DisableStorage.php b/gui/baculum/protected/API/Pages/API/DisableStorage.php
new file mode 100644 (file)
index 0000000..c028cc5
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\StorageError;
+
+/**
+ * Disable Director Storage resource endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class DisableStorage extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $storageid = (int) $id;
+               $drive = $this->Request->contains('drive') ? (int) $this->Request['drive'] : 0;
+               $storage_mod = $this->getModule('storage');
+               $storage = null;
+               if ($storageid > 0) {
+                       $storage = $storage_mod->getStorageById($storageid);
+               }
+
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.storage'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       if (is_object($storage) && in_array($storage->name, $result->output)) {
+                               $component_type = 'dir';
+                               $resource_type = 'storage';
+                               $resource_name = $storage->name;
+                               $params = ["drive=\"$drive\""];
+
+                               $result = $this->getModule('disable')->disable(
+                                       $this->director,
+                                       $component_type,
+                                       $resource_type,
+                                       $resource_name,
+                                       $params
+                               );
+                               $output = $result->output;
+                               $error = $result->exitcode;
+                               if ($error != 0) {
+                                       $output = StorageError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                                       $error = StorageError::ERROR_WRONG_EXITCODE;
+                               }
+                               $this->output = $output;
+                               $this->error = $error;
+                       } else {
+                               $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS;
+                               $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS;
+                       }
+               } else {
+                       $this->output = StorageError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                       $this->error = StorageError::ERROR_WRONG_EXITCODE;
+               }
+       }
+}
+?>
diff --git a/gui/baculum/protected/API/Pages/API/EnableClient.php b/gui/baculum/protected/API/Pages/API/EnableClient.php
new file mode 100644 (file)
index 0000000..e25fd00
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\ClientError;
+
+/**
+ * Enable Director Client resource endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class EnableClient extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $clientid = (int) $id;
+               $client_mod = $this->getModule('client');
+               $client = null;
+               if ($clientid > 0) {
+                       $client = $client_mod->getClientById($clientid);
+               }
+
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.client'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       if (is_object($client) && in_array($client->name, $result->output)) {
+                               $component_type = 'dir';
+                               $resource_type = 'client';
+                               $resource_name = $client->name;
+
+                               $result = $this->getModule('enable')->enable(
+                                       $this->director,
+                                       $component_type,
+                                       $resource_type,
+                                       $resource_name
+                               );
+                               $output = $result->output;
+                               $error = $result->exitcode;
+                               if ($error != 0) {
+                                       $output = ClientError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                                       $error = ClientError::ERROR_WRONG_EXITCODE;
+                               }
+                               $this->output = $output;
+                               $this->error = $error;
+                       } else {
+                               $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+                               $this->error = ClientError::ERROR_CLIENT_DOES_NOT_EXISTS;
+                       }
+               } else {
+                       $this->output = ClientError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                       $this->error = ClientError::ERROR_WRONG_EXITCODE;
+               }
+       }
+}
+?>
diff --git a/gui/baculum/protected/API/Pages/API/EnableJob.php b/gui/baculum/protected/API/Pages/API/EnableJob.php
new file mode 100644 (file)
index 0000000..25af7e8
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\JobError;
+
+/**
+ * Enable Director Job resource endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class EnableJob extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $jobid = (int) $id;
+               $job_mod = $this->getModule('job');
+               $job = null;
+               if ($jobid > 0) {
+                       $job = $job_mod->getJobById($jobid);
+               }
+
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.jobs'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       if (is_object($job) && in_array($job->name, $result->output)) {
+                               $component_type = 'dir';
+                               $resource_type = 'job';
+                               $resource_name = $job->name;
+
+                               $result = $this->getModule('enable')->enable(
+                                       $this->director,
+                                       $component_type,
+                                       $resource_type,
+                                       $resource_name
+                               );
+                               $output = $result->output;
+                               $error = $result->exitcode;
+                               if ($error != 0) {
+                                       $output = JobError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                                       $error = JobError::ERROR_WRONG_EXITCODE;
+                               }
+                               $this->output = $output;
+                               $this->error = $error;
+                       } else {
+                               $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
+                               $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
+                       }
+               } else {
+                       $this->output = JobError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                       $this->error = JobError::ERROR_WRONG_EXITCODE;
+               }
+       }
+}
+?>
diff --git a/gui/baculum/protected/API/Pages/API/EnableSchedule.php b/gui/baculum/protected/API/Pages/API/EnableSchedule.php
new file mode 100644 (file)
index 0000000..59d3e6d
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\GenericError;
+
+/**
+ * Enable Director Schedule resource endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class EnableSchedule extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $misc = $this->getModule('misc');
+               $schedule_name = $this->Request->contains('name') && $misc->isValidName($this->Request['name']) ? $this->Request['name'] : '';
+
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.schedule'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       if (in_array($schedule_name, $result->output)) {
+                               $component_type = 'dir';
+                               $resource_type = 'schedule';
+                               $resource_name = $schedule_name;
+
+                               $result = $this->getModule('enable')->enable(
+                                       $this->director,
+                                       $component_type,
+                                       $resource_type,
+                                       $resource_name
+                               );
+                               $output = $result->output;
+                               $error = $result->exitcode;
+                               if ($error != 0) {
+                                       $output = GenericError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                                       $error = GenericError::ERROR_WRONG_EXITCODE;
+                               }
+                               $this->output = $output;
+                               $this->error = $error;
+                       } else {
+                               $this->output = GenericError::MSG_ERROR_INVALID_PROPERTY;
+                               $this->error = GenericError::ERROR_INVALID_PROPERTY;
+                       }
+               } else {
+                       $this->output = GenericError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                       $this->error = GenericError::ERROR_WRONG_EXITCODE;
+               }
+       }
+}
+?>
diff --git a/gui/baculum/protected/API/Pages/API/EnableStorage.php b/gui/baculum/protected/API/Pages/API/EnableStorage.php
new file mode 100644 (file)
index 0000000..8b6b311
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\StorageError;
+
+/**
+ * Enable Director Storage resource endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class EnableStorage extends BaculumAPIServer {
+
+       public function set($id, $params) {
+               $storageid = (int) $id;
+               $drive = $this->Request->contains('drive') ? (int) $this->Request['drive'] : 0;
+               $storage_mod = $this->getModule('storage');
+               $storage = null;
+               if ($storageid > 0) {
+                       $storage = $storage_mod->getStorageById($storageid);
+               }
+
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.storage'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       if (is_object($storage) && in_array($storage->name, $result->output)) {
+                               $component_type = 'dir';
+                               $resource_type = 'storage';
+                               $resource_name = $storage->name;
+
+                               $params = ["drive=\"$drive\""];
+                               $result = $this->getModule('enable')->enable(
+                                       $this->director,
+                                       $component_type,
+                                       $resource_type,
+                                       $resource_name,
+                                       $params
+                               );
+                               $output = $result->output;
+                               $error = $result->exitcode;
+                               if ($error != 0) {
+                                       $output = StorageError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                                       $error = StorageError::ERROR_WRONG_EXITCODE;
+                               }
+                               $this->output = $output;
+                               $this->error = $error;
+                       } else {
+                               $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS;
+                               $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS;
+                       }
+               } else {
+                       $this->output = StorageError::MSG_ERROR_WRONG_EXITCODE . 'Exitcode=>' . $result->exitcode. ', Output=>' . print_r($result->output, true);
+                       $this->error = StorageError::ERROR_WRONG_EXITCODE;
+               }
+       }
+}
+?>
index c1f8442a76c38ad39827777adec4f4babe718210..1b6fea87272ca9f068facda3a3c3ed796f01b9b5 100644 (file)
@@ -61,6 +61,8 @@
                <module id="list" class="Baculum\API\Modules\BList" />
                <module id="time" class="Baculum\API\Modules\TimeManager" />
                <module id="bacula_error" class="Baculum\API\Modules\BaculaError" />
+               <module id="disable" class="Baculum\API\Modules\DisableResource" />
+               <module id="enable" class="Baculum\API\Modules\EnableResource" />
                <!-- changer command modules -->
                <module id="changer_command" class="Baculum\API\Modules\ChangerCommand" />
                <!-- plugin modules -->
index cb07855a27d559f1b4e38649b4ccc5a93ca0ffdc..f853d388861100e1a49cd201641c4a270edf06c5 100644 (file)
@@ -29,6 +29,8 @@
        <url ServiceParameter="JobsForClient" pattern="api/v2/clients/{id}/jobs/" parameters.id="\d+" />
        <url ServiceParameter="ClientLs" pattern="api/v2/clients/{id}/ls/" parameters.id="\d+" />
        <url ServiceParameter="ClientBandwidthLimit" pattern="api/v2/clients/{id}/bandwidth/" parameters.id="\d+" />
+       <url ServiceParameter="DisableClient" pattern="api/v2/clients/{id}/disable/" parameters.id="\d+"/>
+       <url ServiceParameter="EnableClient" pattern="api/v2/clients/{id}/enable/" parameters.id="\d+"/>
        <!-- storages (storage daemons) endpoints -->
        <url ServiceParameter="Storages" pattern="api/v2/storages/" />
        <url ServiceParameter="Storage" pattern="api/v2/storages/{id}/" parameters.id="\d+" />
@@ -39,6 +41,8 @@
        <url ServiceParameter="StorageMount" pattern="api/v2/storages/{id}/mount/" parameters.id="\d+" />
        <url ServiceParameter="StorageUmount" pattern="api/v2/storages/{id}/umount/" parameters.id="\d+" />
        <url ServiceParameter="StorageRelease" pattern="api/v2/storages/{id}/release/" parameters.id="\d+" />
+       <url ServiceParameter="DisableStorage" pattern="api/v2/storages/{id}/disable/" parameters.id="\d+"/>
+       <url ServiceParameter="EnableStorage" pattern="api/v2/storages/{id}/enable/" parameters.id="\d+"/>
        <url ServiceParameter="StorageJobsCancel" pattern="api/v2/storages/{id}/jobs/cancel/" parameters.id="\d+" />
        <url ServiceParameter="StorageCloudTruncate" pattern="api/v2/storages/{id}/cloud/truncate/" parameters.id="\d+" />
        <url ServiceParameter="StorageCloudPrune" pattern="api/v2/storages/{id}/cloud/prune/" parameters.id="\d+" />
@@ -89,6 +93,8 @@
        <url ServiceParameter="JobCancel" pattern="api/v2/jobs/{id}/cancel/" parameters.id="\d+"/>
        <url ServiceParameter="JobTotals" pattern="api/v2/jobs/totals/" />
        <url ServiceParameter="JobListFiles" pattern="api/v2/jobs/{id}/files/" parameters.id="\d+" />
+       <url ServiceParameter="DisableJob" pattern="api/v2/jobs/{id}/disable/" parameters.id="\d+" />
+       <url ServiceParameter="EnableJob" pattern="api/v2/jobs/{id}/enable/" parameters.id="\d+" />
        <url ServiceParameter="JobFiles" pattern="api/v2/jobs/files/" />
        <url ServiceParameter="RestoreRun" pattern="api/v2/jobs/restore/" />
        <url ServiceParameter="LlistPluginRestoreConf" pattern="api/v2/jobs/restore/plugin/config" />
        <!-- schedule endpoints -->
        <url ServiceParameter="Schedules" pattern="api/v2/schedules/resnames/" />
        <url ServiceParameter="ScheduleStatus" pattern="api/v2/schedules/status/" />
+       <url ServiceParameter="DisableSchedule" pattern="api/v2/schedules/{name}/disable/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
+       <url ServiceParameter="EnableSchedule" pattern="api/v2/schedules/{name}/enable/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
        <!-- jobdefs endpoints -->
        <url ServiceParameter="JobDefsResNames" pattern="api/v2/jobdefs/resnames/" />
        <!-- Bacula config module endpoints -->
index f91fcc85332de9d6eee6e73ab7c4398e57fd8857..8234d59cb7d94a7349cf3db0c51c57c888c7a786 100644 (file)
                                ]
                        }
                },
+               "/api/v2/clients/{clientid}/enable": {
+                       "put": {
+                               "tags": ["clients"],
+                               "summary": "Enable client.",
+                               "description": "Enable client",
+                               "responses": {
+                                       "200": {
+                                               "description": "Enable client",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Enable client output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               },
+               "/api/v2/clients/{clientid}/disable": {
+                       "put": {
+                               "tags": ["clients"],
+                               "summary": "Disable client.",
+                               "description": "Disable client",
+                               "responses": {
+                                       "200": {
+                                               "description": "Disable client",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Disable client output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               },
                "/api/v2/clients/resnames": {
                        "get": {
                                "tags": ["clients"],
                                ]
                        }
                },
+               "/api/v2/jobs/{jobid}/enable": {
+                       "put": {
+                               "tags": ["jobs"],
+                               "summary": "Enable job.",
+                               "description": "Enable job",
+                               "responses": {
+                                       "200": {
+                                               "description": "Enable job",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Enable job output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 50, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               },
+               "/api/v2/jobs/{jobid}/disable": {
+                       "put": {
+                               "tags": ["jobs"],
+                               "summary": "Disable job.",
+                               "description": "Disable job",
+                               "responses": {
+                                       "200": {
+                                               "description": "Disable job",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Disable job output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 50, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               },
                "/api/v2/jobs/{jobid}/files": {
                        "get": {
                                "tags": ["jobs"],
                                ]
                        }
                },
+               "/api/v2/storages/{storageid}/enable": {
+                       "put": {
+                               "tags": ["storages"],
+                               "summary": "Enable storage.",
+                               "description": "Enable storage",
+                               "responses": {
+                                       "200": {
+                                               "description": "Enable storage",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Enable storage output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 20, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "parameters": [
+                                       {
+                                               "name": "drive",
+                                               "in": "query",
+                                               "description": "Storage drive (default 0)",
+                                               "required":  false,
+                                               "schema": {
+                                                       "type": "integer"
+                                               }
+                                       }
+                               ]
+                       }
+               },
+               "/api/v2/storages/{storageid}/disable": {
+                       "put": {
+                               "tags": ["storages"],
+                               "summary": "Disable storage.",
+                               "description": "Disable storage",
+                               "responses": {
+                                       "200": {
+                                               "description": "Disable storage",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Disable storage output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 20, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "parameters": [
+                                       {
+                                               "name": "drive",
+                                               "in": "query",
+                                               "description": "Storage drive (default 0)",
+                                               "required":  false,
+                                               "schema": {
+                                                       "type": "integer"
+                                               }
+                                       }
+                               ]
+                       }
+               },
                "/api/v2/storages/{storageid}/release": {
                        "get": {
                                "tags": ["storages"],
                                ]
                        }
                },
+               "/api/v2/schedules/{schedule_name}/enable": {
+                       "put": {
+                               "tags": ["schedules"],
+                               "summary": "Enable schedule.",
+                               "description": "Enable schedule",
+                               "responses": {
+                                       "200": {
+                                               "description": "Enable schedule",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Enable schedule output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 520, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               },
+               "/api/v2/schedules/{schedule_name}/disable": {
+                       "put": {
+                               "tags": ["schedules"],
+                               "summary": "Disable schedule.",
+                               "description": "Disable schedule",
+                               "responses": {
+                                       "200": {
+                                               "description": "Disable schedule",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Disable schedule output"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 4, 5, 6, 7, 520, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               },
                "/api/v2/bvfs/update": {
                        "put": {
                                "tags": ["bvfs"],