From: Marcin Haba Date: Wed, 11 Apr 2018 08:20:42 +0000 (+0200) Subject: baculum: Changes in api for the redesigned web interface X-Git-Tag: Release-9.2.0~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=540306db46cd8d4e969aef943cb308eb14e5de75;p=thirdparty%2Fbacula.git baculum: Changes in api for the redesigned web interface --- diff --git a/gui/baculum/protected/API/Class/Bconsole.php b/gui/baculum/protected/API/Class/Bconsole.php index 4320c8baa9..255a50172e 100644 --- a/gui/baculum/protected/API/Class/Bconsole.php +++ b/gui/baculum/protected/API/Class/Bconsole.php @@ -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 <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"; diff --git a/gui/baculum/protected/API/Class/VolumeManager.php b/gui/baculum/protected/API/Class/VolumeManager.php index 35265beb97..cb0bf3a2bf 100644 --- a/gui/baculum/protected/API/Class/VolumeManager.php +++ b/gui/baculum/protected/API/Class/VolumeManager.php @@ -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; } /** diff --git a/gui/baculum/protected/API/JavaScript/misc.js b/gui/baculum/protected/API/JavaScript/misc.js index a1f38e0ff2..af29a544bc 100644 --- a/gui/baculum/protected/API/JavaScript/misc.js +++ b/gui/baculum/protected/API/JavaScript/misc.js @@ -17,6 +17,7 @@ var OAuth2Scopes = [ 'bvfs', 'joblog', 'filesets', + 'schedules', 'config' ]; var set_scopes = function(field_id) { diff --git a/gui/baculum/protected/API/Pages/API/Client.php b/gui/baculum/protected/API/Pages/API/Client.php index e66eec98aa..a7be52ea9d 100644 --- a/gui/baculum/protected/API/Pages/API/Client.php +++ b/gui/baculum/protected/API/Pages/API/Client.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/ClientShow.php b/gui/baculum/protected/API/Pages/API/ClientShow.php index c53e89226f..5cbe740633 100644 --- a/gui/baculum/protected/API/Pages/API/ClientShow.php +++ b/gui/baculum/protected/API/Pages/API/ClientShow.php @@ -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; } } } diff --git a/gui/baculum/protected/API/Pages/API/Clients.php b/gui/baculum/protected/API/Pages/API/Clients.php index 329e57863c..4a2d7d0e5b 100644 --- a/gui/baculum/protected/API/Pages/API/Clients.php +++ b/gui/baculum/protected/API/Pages/API/Clients.php @@ -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)) { diff --git a/gui/baculum/protected/API/Pages/API/FileSet.php b/gui/baculum/protected/API/Pages/API/FileSet.php index a47e1bd99b..c5758fb8e6 100644 --- a/gui/baculum/protected/API/Pages/API/FileSet.php +++ b/gui/baculum/protected/API/Pages/API/FileSet.php @@ -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 @@ -23,9 +23,17 @@ 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; diff --git a/gui/baculum/protected/API/Pages/API/FileSetsInfo.php b/gui/baculum/protected/API/Pages/API/FileSetsInfo.php index 187357db02..608bf68d42 100644 --- a/gui/baculum/protected/API/Pages/API/FileSetsInfo.php +++ b/gui/baculum/protected/API/Pages/API/FileSetsInfo.php @@ -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++) { diff --git a/gui/baculum/protected/API/Pages/API/Job.php b/gui/baculum/protected/API/Pages/API/Job.php index 977e127b67..167af8a048 100644 --- a/gui/baculum/protected/API/Pages/API/Job.php +++ b/gui/baculum/protected/API/Pages/API/Job.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/JobShow.php b/gui/baculum/protected/API/Pages/API/JobShow.php index 793b4279ef..019ed70f71 100644 --- a/gui/baculum/protected/API/Pages/API/JobShow.php +++ b/gui/baculum/protected/API/Pages/API/JobShow.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/JobTasks.php b/gui/baculum/protected/API/Pages/API/JobTasks.php index ba9e34ef2a..779a037313 100644 --- a/gui/baculum/protected/API/Pages/API/JobTasks.php +++ b/gui/baculum/protected/API/Pages/API/JobTasks.php @@ -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) { diff --git a/gui/baculum/protected/API/Pages/API/Jobs.php b/gui/baculum/protected/API/Pages/API/Jobs.php index b77c19e872..185abad896 100644 --- a/gui/baculum/protected/API/Pages/API/Jobs.php +++ b/gui/baculum/protected/API/Pages/API/Jobs.php @@ -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 @@ -23,12 +23,25 @@ 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 { diff --git a/gui/baculum/protected/API/Pages/API/JobsForClient.php b/gui/baculum/protected/API/Pages/API/JobsForClient.php index e3f514cbbe..0dd0bc0f0f 100644 --- a/gui/baculum/protected/API/Pages/API/JobsForClient.php +++ b/gui/baculum/protected/API/Pages/API/JobsForClient.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/JobsOnVolume.php b/gui/baculum/protected/API/Pages/API/JobsOnVolume.php index ab52b1010d..c0cd94b49d 100644 --- a/gui/baculum/protected/API/Pages/API/JobsOnVolume.php +++ b/gui/baculum/protected/API/Pages/API/JobsOnVolume.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/Pool.php b/gui/baculum/protected/API/Pages/API/Pool.php index 90b03074c5..2d627868a1 100644 --- a/gui/baculum/protected/API/Pages/API/Pool.php +++ b/gui/baculum/protected/API/Pages/API/Pool.php @@ -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 @@ -23,9 +23,16 @@ 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; diff --git a/gui/baculum/protected/API/Pages/API/PoolUpdateVolumes.php b/gui/baculum/protected/API/Pages/API/PoolUpdateVolumes.php index 08152fe8ce..12771706e7 100644 --- a/gui/baculum/protected/API/Pages/API/PoolUpdateVolumes.php +++ b/gui/baculum/protected/API/Pages/API/PoolUpdateVolumes.php @@ -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, diff --git a/gui/baculum/protected/API/Pages/API/Pools.php b/gui/baculum/protected/API/Pages/API/Pools.php index da3784fb1f..ff25056286 100644 --- a/gui/baculum/protected/API/Pages/API/Pools.php +++ b/gui/baculum/protected/API/Pages/API/Pools.php @@ -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 index 0000000000..3c0d0e67c8 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/Schedules.php @@ -0,0 +1,36 @@ +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; + } + } +} +?> diff --git a/gui/baculum/protected/API/Pages/API/Storage.php b/gui/baculum/protected/API/Pages/API/Storage.php index 6c1d3a1214..336da37990 100644 --- a/gui/baculum/protected/API/Pages/API/Storage.php +++ b/gui/baculum/protected/API/Pages/API/Storage.php @@ -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 @@ -23,9 +23,16 @@ 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; diff --git a/gui/baculum/protected/API/Pages/API/StorageMount.php b/gui/baculum/protected/API/Pages/API/StorageMount.php index 80c7774193..c701b44bab 100644 --- a/gui/baculum/protected/API/Pages/API/StorageMount.php +++ b/gui/baculum/protected/API/Pages/API/StorageMount.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/StorageRelease.php b/gui/baculum/protected/API/Pages/API/StorageRelease.php index c975e9b7e8..a33e4dd98c 100644 --- a/gui/baculum/protected/API/Pages/API/StorageRelease.php +++ b/gui/baculum/protected/API/Pages/API/StorageRelease.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/StorageUmount.php b/gui/baculum/protected/API/Pages/API/StorageUmount.php index 2a58bcd008..d023d838e7 100644 --- a/gui/baculum/protected/API/Pages/API/StorageUmount.php +++ b/gui/baculum/protected/API/Pages/API/StorageUmount.php @@ -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; diff --git a/gui/baculum/protected/API/Pages/API/Storages.php b/gui/baculum/protected/API/Pages/API/Storages.php index dedc77fe35..c2b1a953c4 100644 --- a/gui/baculum/protected/API/Pages/API/Storages.php +++ b/gui/baculum/protected/API/Pages/API/Storages.php @@ -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 index 0000000000..00d497887c --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/VolumesInPool.php @@ -0,0 +1,31 @@ +Request->contains('poolid') ? intval($this->Request['poolid']) : 0; + $result = $this->getModule('volume')->getVolumesByPoolId($poolid); + $this->output = $result; + $this->error = VolumeError::ERROR_NO_ERRORS; + } +} +?> diff --git a/gui/baculum/protected/API/endpoints.xml b/gui/baculum/protected/API/endpoints.xml index a4f3a35ed7..8fe795a985 100644 --- a/gui/baculum/protected/API/endpoints.xml +++ b/gui/baculum/protected/API/endpoints.xml @@ -19,6 +19,7 @@ + @@ -27,13 +28,17 @@ + + + + @@ -45,6 +50,8 @@ + + @@ -52,6 +59,7 @@ + @@ -86,6 +94,9 @@ + + +