]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Changes in api for the redesigned web interface
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 11 Apr 2018 08:20:42 +0000 (10:20 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Apr 2018 13:06:15 +0000 (15:06 +0200)
26 files changed:
gui/baculum/protected/API/Class/Bconsole.php
gui/baculum/protected/API/Class/JobManager.php
gui/baculum/protected/API/Class/VolumeManager.php
gui/baculum/protected/API/JavaScript/misc.js
gui/baculum/protected/API/Pages/API/Client.php
gui/baculum/protected/API/Pages/API/ClientShow.php
gui/baculum/protected/API/Pages/API/Clients.php
gui/baculum/protected/API/Pages/API/FileSet.php
gui/baculum/protected/API/Pages/API/FileSetsInfo.php
gui/baculum/protected/API/Pages/API/Job.php
gui/baculum/protected/API/Pages/API/JobShow.php
gui/baculum/protected/API/Pages/API/JobTasks.php
gui/baculum/protected/API/Pages/API/Jobs.php
gui/baculum/protected/API/Pages/API/JobsForClient.php
gui/baculum/protected/API/Pages/API/JobsOnVolume.php
gui/baculum/protected/API/Pages/API/Pool.php
gui/baculum/protected/API/Pages/API/PoolUpdateVolumes.php
gui/baculum/protected/API/Pages/API/Pools.php
gui/baculum/protected/API/Pages/API/Schedules.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/Storage.php
gui/baculum/protected/API/Pages/API/StorageMount.php
gui/baculum/protected/API/Pages/API/StorageRelease.php
gui/baculum/protected/API/Pages/API/StorageUmount.php
gui/baculum/protected/API/Pages/API/Storages.php
gui/baculum/protected/API/Pages/API/VolumesInPool.php [new file with mode: 0644]
gui/baculum/protected/API/endpoints.xml

index 4320c8baa9e068938a72c2789eec05af44024bab..255a50172e670b9001221b2518d635b7c3895156 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -28,7 +28,7 @@ class Bconsole extends APIModule {
 
        const SUDO = 'sudo';
 
-       const BCONSOLE_COMMAND_PATTERN = "%s%s -c %s %s 2>&1 <<END_OF_DATA\n%s\nquit\nEND_OF_DATA";
+       const BCONSOLE_COMMAND_PATTERN = "%s%s -c %s %s 2>&1 <<END_OF_DATA\ngui on\n%s\nquit\nEND_OF_DATA";
 
        const BCONSOLE_DIRECTORS_PATTERN = "%s%s -c %s -l 2>&1";
 
@@ -62,7 +62,8 @@ class Bconsole extends APIModule {
                '.fileset',
                '.storage',
                '.client',
-               '.pool'
+               '.pool',
+               '.schedule'
        );
 
        private $config;
@@ -129,6 +130,7 @@ class Bconsole extends APIModule {
        }
 
        private function prepareResult(array $output, $exitcode, $bconsole_command) {
+               array_shift($output); // deleted 'gui on'
                array_pop($output); // deleted 'quit' bconsole command
                for($i = 0; $i < count($output); $i++) {
                        if(strstr($output[$i], $bconsole_command) == false) {
index e138a71f665e08c7240c6a42552b0cdfac1c84da..bd645342de9362621ec2ec58a72054609f3b664e 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -26,7 +26,7 @@ Prado::using('Application.API.Class.Database');
 
 class JobManager extends APIModule {
 
-       public function getJobs($limit, $allowedJobs = array()) {
+       public function getJobs($limit, $params = array()) {
                $criteria = new TActiveRecordCriteria;
                $order = 'JobId';
                $db_params = $this->getModule('api_config')->getConfig('db');
@@ -38,17 +38,26 @@ class JobManager extends APIModule {
                        $criteria->Limit = $limit;
                }
 
-               if (count($allowedJobs) > 0) {
-                       $where = array();
-                       $names = array();
-                       for ($i = 0; $i < count($allowedJobs); $i++) {
-                               $where[] = "name = :name$i";
-                               $names[":name$i"] = $allowedJobs[$i];
-                       }
-                       $criteria->Condition = implode(' OR ', $where);
-                       foreach($names as $name => $jobname) {
-                               $criteria->Parameters[$name] = $jobname;
+               if (count($params) > 0) {
+                       $condition = array();
+                       foreach ($params as $key => $value) {
+                               $cond = array();
+                               $vals = array();
+                               if (is_array($value['vals'])) {
+                                       for ($i = 0; $i < count($value['vals']); $i++) {
+                                               $cond[] = "{$key} = :{$key}{$i}";
+                                               $vals[":{$key}{$i}"] = $value['vals'][$i];
+                                       }
+                               } else {
+                                       $cond[] = "$key = :$key";
+                                       $vals[":$key"] = $value['vals'];
+                               }
+                               $condition[] = implode(' ' . $value['operator'] . ' ', $cond);
+                               foreach ($vals as $pkey => $pval) {
+                                       $criteria->Parameters[$pkey] = $pval;
+                               }
                        }
+                       $criteria->Condition = '(' . implode(') AND (' , $condition) . ')';
                }
                return JobRecord::finder()->findAll($criteria);
        }
@@ -96,14 +105,14 @@ class JobManager extends APIModule {
                return $jobids;
        }
 
-       public function getJobTotals($allowedJobs = array()) {
+       public function getJobTotals($allowed_jobs = array()) {
                $jobtotals = array('bytes' => 0, 'files' => 0);
                $connection = JobRecord::finder()->getDbConnection();
                $connection->setActive(true);
 
                $where = '';
-               if (count($allowedJobs) > 0) {
-                       $where = " WHERE name='" . implode("' OR name='", $allowedJobs) . "'";
+               if (count($allowed_jobs) > 0) {
+                       $where = " WHERE name='" . implode("' OR name='", $allowed_jobs) . "'";
                }
 
                $sql = "SELECT sum(JobFiles) AS files, sum(JobBytes) AS bytes FROM Job $where";
index 35265beb9776b83129d0634c10f67d75ef8d02d8..cb0bf3a2bfe74a3e011f0b217b8cebdeae8d687c 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -26,7 +26,7 @@ Prado::using('Application.API.Class.Database');
 
 class VolumeManager extends APIModule {
 
-       public function getVolumes($limit, $with_pools = false) {
+       public function getVolumes($limit) {
                $criteria = new TActiveRecordCriteria;
                $orderPool = 'PoolId';
                $orderVolume = 'VolumeName';
@@ -41,35 +41,53 @@ class VolumeManager extends APIModule {
                        $criteria->Limit = $limit;
                }
                $volumes = VolumeRecord::finder()->findAll($criteria);
-               $this->setExtraVariables($volumes, $with_pools);
+               $this->setExtraVariables($volumes);
                return $volumes;
        }
 
        public function getVolumesByPoolId($poolid) {
-               return VolumeRecord::finder()->findBypoolid($poolid);
+               $volumes = VolumeRecord::finder()->findAllBypoolid($poolid);
+               $this->setExtraVariables($volumes);
+               return $volumes;
+       }
+
+       public function getVolumeByPoolId($poolid) {
+               $volume = VolumeRecord::finder()->findBypoolid($poolid);
+               $this->setExtraVariables($volume);
+               return $volume;
        }
 
        public function getVolumeByName($volumeName) {
-               return VolumeRecord::finder()->findByvolumename($volumeName);
+               $volume = VolumeRecord::finder()->findByvolumename($volumeName);
+               $this->setExtraVariables($volume);
+               return $volume;
        }
 
        public function getVolumeById($volumeId) {
-               return VolumeRecord::finder()->findBymediaid($volumeId);
+               $volume = VolumeRecord::finder()->findBymediaid($volumeId);
+               $this->setExtraVariables($volume);
+               return $volume;
        }
 
-       private function setExtraVariables(&$volumes, $with_pools) {
-               $pools = $this->Application->getModule('pool')->getPools(false);
-               foreach($volumes as $volume) {
-                       $volstatus = strtolower($volume->volstatus);
-                       $volume->whenexpire = ($volstatus == 'full' || $volstatus == 'used') ? date( 'Y-m-d H:i:s', (strtotime($volume->lastwritten) + $volume->volretention)) : 'no date';
-                       if ($with_pools === true) {
-                               foreach($pools as $pool) {
-                                       if($volume->poolid == $pool->poolid) {
-                                               $volume->pool = $pool;
-                                       }
-                               }
+       private function setExtraVariables(&$volumes) {
+               if (is_array($volumes)) {
+                       foreach($volumes as $volume) {
+                               $this->setWhenExpire($volume);
                        }
+               } else {
+                       $this->setWhenExpire($volumes);
+               }
+       }
+
+       private function setWhenExpire(&$volume) {
+               $volstatus = strtolower($volume->volstatus);
+               if ($volstatus == 'full' || $volstatus == 'used') {
+                       $whenexpire = strtotime($volume->lastwritten) + $volume->volretention;
+                       $whenexpire = date( 'Y-m-d H:i:s', $whenexpire);
+               } else{
+                       $whenexpire = 'no date';
                }
+               $volume->whenexpire = $whenexpire;
        }
 
        /**
index a1f38e0ff222f599d87cf7dac2084887c6c9c09d..af29a544bcbf90d1736b5ec2a070bd5cceb9502a 100644 (file)
@@ -17,6 +17,7 @@ var OAuth2Scopes = [
        'bvfs',
        'joblog',
        'filesets',
+       'schedules',
        'config'
 ];
 var set_scopes = function(field_id) {
index e66eec98aaddd12db44f704944ceaa5b61188832..a7be52ea9dc448f7be72895da235d73c71f385ab 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -24,9 +24,16 @@ class Client extends BaculumAPIServer {
 
        public function get() {
                $clientid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
-               $client = $this->getModule('client')->getClientById($clientid);
+               $client_name = $this->Request->contains('name') ? $this->Request['name'] : '';
+               $client = null;
+               if ($clientid > 0) {
+                       $client = $this->getModule('client')->getClientById($clientid);
+               } elseif (!empty($client_name)) {
+                       $client = $this->getModule('client')->getClientByName($client_name);
+               }
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        if(!is_null($client) && in_array($client->name, $result->output)) {
                                $this->output = $client;
                                $this->error = ClientError::ERROR_NO_ERRORS;
index c53e89226fffee705a46439b4ec271030e90776c..5cbe7406339dd13a3887563d4200e6c3c40b65c8 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -24,17 +24,25 @@ class ClientShow extends BaculumAPIServer {
 
        public function get() {
                $clientid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
-               $client = $this->getModule('client')->getClientById($clientid);
-               if(is_object($client)) {
-                       $result = $this->getModule('bconsole')->bconsoleCommand(
-                               $this->director,
-                               array('show', 'client="' . $client->name . '"')
-                       );
+
+               $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'));
+               if ($result->exitcode === 0) {
+                       array_shift($result->output);
+                       $client = $this->getModule('client')->getClientById($clientid);
+                       if(!is_null($client) && in_array($client->name, $result->output)) {
+                               $result = $this->getModule('bconsole')->bconsoleCommand(
+                                       $this->director,
+                                       array('show', 'client="' . $client->name . '"')
+                               );
+                               $this->output = $result->output;
+                               $this->error = $result->exitcode;
+                       } else {
+                               $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+                               $this->error = ClientError::ERROR_CLIENT_DOES_NOT_EXISTS;
+                       }
+               } else {
                        $this->output = $result->output;
                        $this->error = $result->exitcode;
-               } else {
-                       $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
-                       $this->error = ClientError::ERROR_CLIENT_DOES_NOT_EXISTS;
                }
        }
 }
index 329e57863caaffb3faf89e09899f245b5f2bdc8b..4a2d7d0e5bb84a1eafbda61c24c44ec378657bbd 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -27,6 +27,7 @@ class Clients extends BaculumAPIServer {
                $clients = $this->getModule('client')->getClients($limit);
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        $clients_output = array();
                        foreach($clients as $client) {
                                if(in_array($client->name, $result->output)) {
index a47e1bd99b6e34315974facbdce26f733013772b..c5758fb8e670e22a5afa3d8bf47db37614c15670 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 class FileSet extends BaculumAPIServer {
        public function get() {
                $filesetid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
-               $fileset = $this->getModule('fileset')->getFileSetById($filesetid);
+               $fileset_name = $this->Request->contains('name') ? $this->Request['name'] : '';
+               $fileset = null;
+               if ($filesetid > 0) {
+                       $fileset = $this->getModule('fileset')->getFileSetById($filesetid);
+               } elseif (!empty($fileset_name)) {
+                       // Not advised for many directors (filesets per director)
+                       $fileset = $this->getModule('fileset')->getFileSetByName($fileset_name);
+               }
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.fileset'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        if(!is_null($fileset) && in_array($fileset->fileset, $result->output)) {
                                $this->output = $fileset;
                                $this->error = FileSetError::ERROR_NO_ERRORS;
index 187357db025e74634ae780903425b06ac63662f9..608bf68d428e655f8a3bf37e8fd746391b84f59c 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -26,6 +26,7 @@ class FileSetsInfo extends BaculumAPIServer {
                $filesets = $this->getModule('fileset')->getFileSets();
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.fileset'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        if (is_array($filesets) && count($filesets) > 0) {
                                $fs = array();
                                for ($i = 0; $i < count($filesets); $i++) {
index 977e127b678863c2032910de6a52b55053c416fd..167af8a0482fecd4c5385ee053c5cc2d9ff996fa 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -26,6 +26,7 @@ class Job extends BaculumAPIServer {
                $job = $this->getModule('job')->getJobById($jobid);
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        if(!is_null($job) && in_array($job->name, $result->output)) {
                                $this->output = $job;
                                $this->error = JobError::ERROR_NO_ERRORS;
index 793b4279efa1f5436c233ee44f7d0075a0e0700f..019ed70f71b84f701a6f077982aa931858f135cf 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -33,6 +33,7 @@ class JobShow extends BaculumAPIServer {
                } elseif ($this->Request->contains('name')) {
                        $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
                        if ($result->exitcode === 0) {
+                               array_shift($result->output);
                                $jobname = in_array($this->Request['name'], $result->output) ? $this->Request['name'] : null;
                        } else {
                                $error_obj = $result;
index ba9e34ef2a206e266f815735ab9720732133efd3..779a03731397722439e8d051778b59efd00e23e8 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -56,6 +56,7 @@ class JobTasks extends BaculumAPIServer {
                                 * Checking by "show job" command is ugly way to be sure that is reading jobname but not some 
                                 * random output (eg. "You have messages." or debugging).
                                 * For now I did not find nothing better for be sure that output contains job.
+                                * @NOTE, now is used "gui on" so it is not necessarly @TODO: Rework it
                                 */
                                for($k = 0; $k < count($jobs_show->output); $k++) {
                                        if(preg_match('/^Job: name=' . $job_list->output[$j] . '.*/', $jobs_show->output[$k]) === 1) {
index b77c19e8728803ca9190e21100b7de8cf4cdee5b..185abad8968738b731f3eefc9f5558720dceb156 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 class Jobs extends BaculumAPIServer {
        public function get() {
                $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
+               $jobstatus = $this->Request->contains('jobstatus') ? $this->Request['jobstatus'] : '';
+               $params = array();
+               $jobstatuses = array_keys($this->getModule('misc')->getJobState());
+               $sts = str_split($jobstatus);
+               for ($i = 0; $i < count($sts); $i++) {
+                       if (in_array($sts[$i], $jobstatuses)) {
+                               if (!key_exists('jobstatus', $params)) {
+                                       $params['jobstatus'] = array('operator' => 'OR', 'vals' => array());
+                               }
+                               $params['jobstatus']['vals'][] = $sts[$i];
+                       }
+               }
                $allowed = array();
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
                if ($result->exitcode === 0) {
                        array_shift($result->output);
-                       $allowed = $result->output;
-                       $jobs = $this->getModule('job')->getJobs($limit, $allowed);
+                       $params['name']['operator'] = 'OR';
+                       $params['name']['vals'] = $result->output;
+                       $jobs = $this->getModule('job')->getJobs($limit, $params);
                        $this->output = $jobs;
                        $this->error = JobError::ERROR_NO_ERRORS;
                } else {
index e3f514cbbe8bfd9636238c0f20cb4561bc993b25..0dd0bc0f0f11f0aab05ba23dc80ab90108c02d72 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -28,6 +28,7 @@ class JobsForClient extends BaculumAPIServer {
                $error = false;
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        $allowed_jobs = $result->output;
                } else {
                        $error = true;
index ab52b1010d840bc1e05c25b8ae104eec3bb0be60..c0cd94b49dfe72e5fd9f6c7b562f2ca3bc9dad3d 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -27,6 +27,7 @@ class JobsOnVolume extends BaculumAPIServer {
                $error = false;
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        $allowed = $result->output;
                } else {
                        $error = true;
index 90b03074c571b7ca73601553284084ca409619df..2d627868a1daea1fd222950ecc23fd5a8666eaf8 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 class Pool extends BaculumAPIServer {
        public function get() {
                $poolid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
-               $pool = $this->getModule('pool')->getPoolById($poolid);
+               $pool_name = $this->Request->contains('name') ? $this->Request['name'] : '';
+               $pool = null;
+               if ($poolid > 0) {
+                       $pool = $this->getModule('pool')->getPoolById($poolid);
+               } elseif (!empty($pool_name)) {
+                       $pool = $this->getModule('pool')->getPoolByName($pool_name);
+               }
                $allowedPools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'));
                if ($allowedPools->exitcode === 0) {
+                       array_shift($allowedPools->output);
                        if(!is_null($pool) && in_array($pool->name, $allowedPools->output)) {
                                $this->output = $pool;
                                $this->error = PoolError::ERROR_NO_ERRORS;
index 08152fe8cece07a3c6655bdce78477262bf318b4..12771706e775b659b7891fc0e9a24e9e1679da2a 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -26,7 +26,7 @@ class PoolUpdateVolumes extends BaculumAPIServer {
                $poolid = intval($id);
                $pool = $this->getModule('pool')->getPoolById($poolid);
                if(is_object($pool)) {
-                       $voldata = $this->getModule('volume')->getVolumesByPoolId($pool->poolid);
+                       $voldata = $this->getModule('volume')->getVolumeByPoolId($pool->poolid);
                        if(is_object($voldata)) {
                                $result = $this->getModule('bconsole')->bconsoleCommand(
                                        $this->director,
index da3784fb1f1b16e0baa16a413bc04b01673ac77f..ff25056286182b50c43a39c9bfc3753baf319472 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -26,6 +26,7 @@ class Pools extends BaculumAPIServer {
                $pools = $this->getModule('pool')->getPools($limit);
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        $pools_output = array();
                        foreach($pools as $pool) {
                                if(in_array($pool->name, $result->output)) {
diff --git a/gui/baculum/protected/API/Pages/API/Schedules.php b/gui/baculum/protected/API/Pages/API/Schedules.php
new file mode 100644 (file)
index 0000000..3c0d0e6
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2018 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 Schedules extends BaculumAPIServer {
+       public function get() {
+               $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.schedule'));
+               if ($result->exitcode === 0) {
+                       array_shift($result->output);
+                       $this->output = $result->output;
+                       $this->error = PoolError::ERROR_NO_ERRORS;
+               } else {
+                       $this->output = $result->output;
+                       $this->error = $result->exitcode;
+               }
+       }
+}
+?>
index 6c1d3a121480d0f3b66d93bf6d33e76b2402dbf0..336da37990015c7701bb35c1f7f1bfa06911729f 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 class Storage extends BaculumAPIServer {
        public function get() {
                $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
-               $storage = $this->getModule('storage')->getStorageById($storageid);
+               $storage_name = $this->Request->contains('name') ? $this->Request['name'] : '';
+               $storage = null;
+               if ($storageid > 0) {
+                       $storage = $this->getModule('storage')->getStorageById($storageid);
+               } elseif (!empty($storage_name)) {
+                       $storage = $this->getModule('storage')->getStorageByName($storage_name);
+               }
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        if(!is_null($storage) && in_array($storage->name, $result->output)) {
                                $this->output = $storage;
                                $this->error =  StorageError::ERROR_NO_ERRORS;
index 80c777419320bc97a51bfb0d20bf3951b55687ac..c701b44babba2978c39f979915c40d37008278ed 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -24,12 +24,18 @@ class StorageMount extends BaculumAPIServer {
        public function get() {
                $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
                $drive = $this->Request->contains('drive') ? intval($this->Request['drive']) : 0;
+               $device = $this->Request->contains('device') ? $this->Request['device'] : null;
                $slot = $this->Request->contains('slot') ? intval($this->Request['slot']) : 0;
                $storage = $this->getModule('storage')->getStorageById($storageid);
                if(is_object($storage)) {
                        $result = $this->getModule('bconsole')->bconsoleCommand(
                                $this->director,
-                               array('mount', 'storage="' . $storage->name . '"', 'drive=' . $drive, 'slot=' . $slot)
+                               array(
+                                       'mount',
+                                       'storage="' . $storage->name . '"',
+                                       (is_string($device) ? 'device="' . $device . '" drive=0' : 'drive=' . $drive),
+                                       'slot=' . $slot
+                               )
                        );
                        $this->output = $result->output;
                        $this->error = $result->exitcode;
index c975e9b7e806a7fb6f0ff34d4b449371a6798c22..a33e4dd98c04cb9d79387265873d6332675a348f 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -24,11 +24,16 @@ class StorageRelease extends BaculumAPIServer {
        public function get() {
                $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
                $drive = $this->Request->contains('drive') ? intval($this->Request['drive']) : 0;
+               $device = $this->Request->contains('device') ? $this->Request['device'] : null;
                $storage = $this->getModule('storage')->getStorageById($storageid);
                if (is_object($storage)) {
                        $result = $this->getModule('bconsole')->bconsoleCommand(
                                $this->director,
-                               array('release', 'storage="' . $storage->name . '"', 'drive="' . $drive . '"')
+                               array(
+                                       'release',
+                                       'storage="' . $storage->name . '"',
+                                       (is_string($device) ? 'device="' . $device . '" drive=0 slot=0' : 'drive=' . $drive . ' slot=0')
+                               )
                        );
                        $this->output = $result->output;
                        $this->error = $result->exitcode;
index 2a58bcd008ce716b2cbfe719e3de3ba548d2580a..d023d838e7657602f08921b81fe830829fb3531b 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -24,11 +24,16 @@ class StorageUmount extends BaculumAPIServer {
        public function get() {
                $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0;
                $drive = $this->Request->contains('drive') ? intval($this->Request['drive']) : 0;
+               $device = $this->Request->contains('device') ? $this->Request['device'] : null;
                $storage = $this->getModule('storage')->getStorageById($storageid);
                if (is_object($storage)) {
                        $result = $this->getModule('bconsole')->bconsoleCommand(
                                $this->director,
-                               array('umount', 'storage="' . $storage->name . '"', 'drive=' . $drive)
+                               array(
+                                       'umount',
+                                       'storage="' . $storage->name . '"',
+                                       (is_string($device) ? 'device="' . $device . '" slot=0 drive=0' : 'drive=' . $drive . ' slot=0')
+                               )
                        );
                        $this->output = $result->output;
                        $this->error = $result->exitcode;
index dedc77fe356b9d319dd0ecc903d488caf3ef5f6d..c2b1a953c42fa696d02568a5de19235e7fa4bb48 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2017 Kern Sibbald
+ * Copyright (C) 2013-2018 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
@@ -27,6 +27,7 @@ class Storages extends BaculumAPIServer {
                $storages = $this->getModule('storage')->getStorages($limit);
                $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage'));
                if ($result->exitcode === 0) {
+                       array_shift($result->output);
                        $storages_output = array();
                        foreach($storages as $storage) {
                                if(in_array($storage->name, $result->output)) {
diff --git a/gui/baculum/protected/API/Pages/API/VolumesInPool.php b/gui/baculum/protected/API/Pages/API/VolumesInPool.php
new file mode 100644 (file)
index 0000000..00d4978
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2018 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 VolumesInPool extends BaculumAPIServer {
+       public function get() {
+               $poolid = $this->Request->contains('poolid') ? intval($this->Request['poolid']) : 0;
+               $result = $this->getModule('volume')->getVolumesByPoolId($poolid);
+               $this->output = $result;
+               $this->error = VolumeError::ERROR_NO_ERRORS;
+       }
+}
+?>
index a4f3a35ed79158420cb4f645f8346cfb317681d6..8fe795a985f4d98c97303053802e425c54932081 100644 (file)
@@ -19,6 +19,7 @@
        <!-- clients (file daemons) endpoints -->
        <url ServiceParameter="API.Clients" pattern="api/clients/" />
        <url ServiceParameter="API.Client" pattern="api/clients/{id}/" parameters.id="\d+" />
+       <url ServiceParameter="API.Client" pattern="api/clients/{name}/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="API.Clients" pattern="api/clients/limit/{limit}/" parameters.limit="\d+" />
        <url ServiceParameter="API.ClientsShow" pattern="api/clients/show/" />
        <url ServiceParameter="API.ClientShow" pattern="api/clients/show/{id}/" parameters.id="\d+" />
        <!-- storages (storage daemons) endpoints -->
        <url ServiceParameter="API.Storages" pattern="api/storages/" />
        <url ServiceParameter="API.Storage" pattern="api/storages/{id}/" parameters.id="\d+" />
+       <url ServiceParameter="API.Storage" pattern="api/storages/{name}/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="API.Storages" pattern="api/storages/limit/{limit}/" parameters.limit="\d+" />
        <url ServiceParameter="API.StoragesShow" pattern="api/storages/show/" />
        <url ServiceParameter="API.StorageShow" pattern="api/storages/show/{id}/" parameters.id="\d+" />
        <url ServiceParameter="API.StorageStatus" pattern="api/storages/status/{id}/" parameters.id="\d+" />
        <url ServiceParameter="API.StorageMount" pattern="api/storages/mount/{id}/{drive}/{slot}/" parameters.id="\d+" parameters.drive="\d+" parameters.slot="\d+" />
+       <url ServiceParameter="API.StorageMount" pattern="api/storages/mount/{id}/{device}/{slot}/" parameters.id="\d+" parameters.device="[a-zA-Z0-9:.\-_ ]+" parameters.slot="\d+" />
        <url ServiceParameter="API.StorageUmount" pattern="api/storages/umount/{id}/{drive}/" parameters.id="\d+" parameters.drive="\d+" />
+       <url ServiceParameter="API.StorageUmount" pattern="api/storages/umount/{id}/{device}/" parameters.id="\d+" parameters.device="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="API.StorageRelease" pattern="api/storages/release/{id}/{drive}/" parameters.id="\d+" parameters.drive="\d+" />
+       <url ServiceParameter="API.StorageRelease" pattern="api/storages/release/{id}/{device}/" parameters.id="\d+" parameters.device="[a-zA-Z0-9:.\-_ ]+" />
        <!-- volumes (media) endpoints-->
        <url ServiceParameter="API.Volumes" pattern="api/volumes/" />
        <url ServiceParameter="API.Volumes" pattern="api/volumes/limit/{limit}/" parameters.limit="\d+" />
@@ -45,6 +50,8 @@
        <!-- pools endpoints -->
        <url ServiceParameter="API.Pools" pattern="api/pools/" />
        <url ServiceParameter="API.Pool" pattern="api/pools/{id}/" parameters.id="\d+" />
+       <url ServiceParameter="API.Pool" pattern="api/pools/{name}/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
+       <url ServiceParameter="API.VolumesInPool" pattern="api/pools/{poolid}/volumes/" parameters.poolid="\d+" />
        <url ServiceParameter="API.Pools" pattern="api/pools/limit/{limit}/" parameters.limit="\d+" />
        <url ServiceParameter="API.PoolUpdate" pattern="api/pools/update/{id}/" parameters.id="\d+" />
        <url ServiceParameter="API.PoolUpdateVolumes" pattern="api/pools/update/volumes/{id}/" parameters.id="\d+" />
@@ -52,6 +59,7 @@
        <url ServiceParameter="API.PoolShow" pattern="api/pools/show/{id}/" parameters.id="\d+" />
        <!-- jobs endpoints-->
        <url ServiceParameter="API.Jobs" pattern="api/jobs/" />
+       <url ServiceParameter="API.Jobs" pattern="api/jobs/jobstatus/{jobstatus}/" parameters.jobstatus="[a-zA-Z]+" />
        <url ServiceParameter="API.JobTasks" pattern="api/jobs/tasks/" />
        <url ServiceParameter="API.JobTasks" pattern="api/jobs/tasks/type/{type}" parameters.type="[a-zA-Z]" />
        <url ServiceParameter="API.JobTasks" pattern="api/jobs/tasks/type/{type}/limit/{limit}/" parameters.type="[a-zA-Z]" parameters.limit="\d+" />
@@ -86,6 +94,9 @@
        <url ServiceParameter="API.FileSets" pattern="api/filesets/" />
        <url ServiceParameter="API.FileSet" pattern="api/filesets/{id}/" parameters.id="\d+" />
        <url ServiceParameter="API.FileSetsInfo" pattern="api/filesets/info/" />
+       <url ServiceParameter="API.FileSet" pattern="api/filesets/{name}/" parameters.name="[a-zA-Z0-9:.\-_ ]+" />
+       <!-- schedule endpoints -->
+       <url ServiceParameter="API.Schedules" pattern="api/schedules/" />
        <!-- Bacula config module endpoints -->
        <url ServiceParameter="API.Config" pattern="api/config/" />
        <url ServiceParameter="API.Config" pattern="api/config/{component_type}/" parameters.component_type="[a-z]+" />