From: Marcin Haba Date: Sat, 2 Dec 2017 15:04:40 +0000 (+0100) Subject: baculum: API endpoints code refactor X-Git-Tag: Release-9.0.7~16 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2e793c9b32d91e8a44344ac7bd40d82b3769340c;p=bacula%2Fbacula baculum: API endpoints code refactor --- diff --git a/gui/baculum/protected/API/Pages/API/BVFSClearCache.php b/gui/baculum/protected/API/Pages/API/BVFSClearCache.php index 4f8da7f609..830935b5fe 100644 --- a/gui/baculum/protected/API/Pages/API/BVFSClearCache.php +++ b/gui/baculum/protected/API/Pages/API/BVFSClearCache.php @@ -22,8 +22,8 @@ class BVFSClearCache extends BaculumAPIServer { - public function set($ids, $params) { - $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.bvfs_clear_cache', 'yes'), $this->user); + public function set($id, $params) { + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.bvfs_clear_cache', 'yes')); $this->output = $result->output; $this->error = $result->exitcode; } diff --git a/gui/baculum/protected/API/Pages/API/BVFSGetJobids.php b/gui/baculum/protected/API/Pages/API/BVFSGetJobids.php index 51c04df6bb..cff9790ce5 100644 --- a/gui/baculum/protected/API/Pages/API/BVFSGetJobids.php +++ b/gui/baculum/protected/API/Pages/API/BVFSGetJobids.php @@ -23,16 +23,15 @@ class BVFSGetJobids extends BaculumAPIServer { public function get() { - $jobid = intval($this->Request['id']); - $job = $this->getModule('job')->getJobById($jobid); - if(!is_null($job)) { - $cmd = array('.bvfs_get_jobids', 'jobid="' . $job->jobid . '"'); - $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user); + $jobid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; + if ($jobid > 0) { + $cmd = array('.bvfs_get_jobids', 'jobid="' . $jobid . '"'); + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd); $this->output = $result->output; $this->error = $result->exitcode; } else { - $this->output = BVFSError::MSG_ERROR_JOB_DOES_NOT_EXISTS; - $this->error = BVFSError::ERROR_JOB_DOES_NOT_EXISTS; + $this->output = BVFSError::MSG_ERROR_INVALID_JOBID; + $this->error = BVFSError::ERROR_INVALID_JOBID; } } } diff --git a/gui/baculum/protected/API/Pages/API/BVFSLsDirs.php b/gui/baculum/protected/API/Pages/API/BVFSLsDirs.php index b4a1c7c2c7..af6e65c18c 100644 --- a/gui/baculum/protected/API/Pages/API/BVFSLsDirs.php +++ b/gui/baculum/protected/API/Pages/API/BVFSLsDirs.php @@ -22,49 +22,42 @@ class BVFSLsDirs extends BaculumAPIServer { - public function set($param, $ids) { - $limit = intval($this->Request['limit']); - $offset = intval($this->Request['offset']); - $is_valid = true; - if (property_exists($ids, 'jobids')) { - $jobids = explode(',', $ids->jobids); - for($i = 0; $i < count($jobids); $i++) { - $job = $this->getModule('job')->getJobById($jobids[$i]); - if(is_null($job)) { - $is_valid = false; - break; - } - } - } else { - $is_valid = false; + public function set($id, $params) { + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; + $offset = $this->Request->contains('offset') ? intval($this->Request['offset']) : 0; + $jobids = null; + if (property_exists($params, 'jobids') && $this->getModule('misc')->isValidIdsList($params->jobids)) { + $jobids = $params->jobids; } $path = null; - if (property_exists($ids, 'path')) { - $path = $ids->path; + if (property_exists($params, 'path') && $this->getModule('misc')->isValidPath($params->path)) { + $path = $params->path; } - if($is_valid === true) { - if (!is_null($path)) { - $cmd = array('.bvfs_lsdirs', 'jobid="' . $ids->jobids . '"', 'path="' . $path . '"'); + if (is_null($jobids)) { + $this->output = BVFSError::MSG_ERROR_INVALID_JOBID_LIST; + $this->error = BVFSError::ERROR_INVALID_JOBID_LIST; + return; + } + + if (is_null($path)) { + $this->output = BVFSError::ERROR_INVALID_RESTORE_PATH; + $this->error = BVFSError::MSG_ERROR_INVALID_RESTORE_PATH; + return; + } - if($offset > 0) { - array_push($cmd, 'offset="' . $offset . '"'); - } - if($limit > 0) { - array_push($cmd, 'limit="' . $limit . '"'); - } - $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user); - $this->output = $result->output; - $this->error = $result->exitcode; - } else { - $this->output = BVFSError::ERROR_INVALID_RESTORE_PATH; - $this->error = BVFSError::MSG_ERROR_INVALID_RESTORE_PATH; - } - } else { - $this->output = BVFSError::MSG_ERROR_JOB_DOES_NOT_EXISTS; - $this->error = BVFSError::ERROR_JOB_DOES_NOT_EXISTS; + $cmd = array('.bvfs_lsdirs', 'jobid="' . $jobids . '"', 'path="' . $path . '"'); + + if ($offset > 0) { + array_push($cmd, 'offset="' . $offset . '"'); + } + if ($limit > 0) { + array_push($cmd, 'limit="' . $limit . '"'); } + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd); + $this->output = $result->output; + $this->error = $result->exitcode; } } ?> diff --git a/gui/baculum/protected/API/Pages/API/BVFSLsFiles.php b/gui/baculum/protected/API/Pages/API/BVFSLsFiles.php index 86e63fca6a..2970199cb3 100644 --- a/gui/baculum/protected/API/Pages/API/BVFSLsFiles.php +++ b/gui/baculum/protected/API/Pages/API/BVFSLsFiles.php @@ -22,48 +22,42 @@ class BVFSLsFiles extends BaculumAPIServer { - public function set($param, $ids) { - $limit = intval($this->Request['limit']); - $offset = intval($this->Request['offset']); - $is_valid = true; - if (property_exists($ids, 'jobids')) { - $jobids = explode(',', $ids->jobids); - for($i = 0; $i < count($jobids); $i++) { - $job = $this->getModule('job')->getJobById($jobids[$i]); - if(is_null($job)) { - $is_valid = false; - break; - } - } - } else { - $is_valid = false; + public function set($id, $params) { + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; + $offset = $this->Request->contains('offset') ? intval($this->Request['offset']) : 0; + $jobids = null; + if (property_exists($params, 'jobids') && $this->getModule('misc')->isValidIdsList($params->jobids)) { + $jobids = $params->jobids; } $path = null; - if (property_exists($ids, 'path')) { - $path = $ids->path; + if (property_exists($params, 'path') && $this->getModule('misc')->isValidPath($params->path)) { + $path = $params->path; } - if($is_valid === true) { - if (!is_null($path)) { - $cmd = array('.bvfs_lsfiles', 'jobid="' . $ids->jobids . '"', 'path="' . $path . '"'); - if($offset > 0) { - array_push($cmd, 'offset="' . $offset . '"'); - } - if($limit > 0) { - array_push($cmd, 'limit="' . $limit . '"'); - } - $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user); - $this->output = $result->output; - $this->error = $result->exitcode; - } else { - $this->output = BVFSError::ERROR_INVALID_RESTORE_PATH; - $this->error = BVFSError::MSG_ERROR_INVALID_RESTORE_PATH; - } - } else { - $this->output = BVFSError::MSG_ERROR_JOB_DOES_NOT_EXISTS; - $this->error = BVFSError::ERROR_JOB_DOES_NOT_EXISTS; + if (is_null($jobids)) { + $this->output = BVFSError::MSG_ERROR_INVALID_JOBID_LIST; + $this->error = BVFSError::ERROR_INVALID_JOBID_LIST; + return; } + + if (is_null($path)) { + $this->output = BVFSError::ERROR_INVALID_RESTORE_PATH; + $this->error = BVFSError::MSG_ERROR_INVALID_RESTORE_PATH; + return; + } + + $cmd = array('.bvfs_lsfiles', 'jobid="' . $jobids . '"', 'path="' . $path . '"'); + + if ($offset > 0) { + array_push($cmd, 'offset="' . $offset . '"'); + } + if ($limit > 0) { + array_push($cmd, 'limit="' . $limit . '"'); + } + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd); + $this->output = $result->output; + $this->error = $result->exitcode; } } ?> diff --git a/gui/baculum/protected/API/Pages/API/BVFSRestore.php b/gui/baculum/protected/API/Pages/API/BVFSRestore.php index f94c1d0b95..7e12d94b9e 100644 --- a/gui/baculum/protected/API/Pages/API/BVFSRestore.php +++ b/gui/baculum/protected/API/Pages/API/BVFSRestore.php @@ -68,7 +68,7 @@ class BVFSRestore extends BaculumAPIServer { array_push($cmd, 'hardlink="' . $findexes . '"'); } - $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user); + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd); $this->output = $result->output; $this->error = $result->exitcode; } diff --git a/gui/baculum/protected/API/Pages/API/BVFSUpdate.php b/gui/baculum/protected/API/Pages/API/BVFSUpdate.php index 760bbb66ff..7e4fc99aab 100644 --- a/gui/baculum/protected/API/Pages/API/BVFSUpdate.php +++ b/gui/baculum/protected/API/Pages/API/BVFSUpdate.php @@ -22,33 +22,24 @@ class BVFSUpdate extends BaculumAPIServer { - public function set($param, $ids) { - $isValid = true; - if (property_exists($ids, 'jobids')) { - $jobids = explode(',', $ids->jobids); - for($i = 0; $i < count($jobids); $i++) { - $job = $this->getModule('job')->getJobById($jobids[$i]); - if(is_null($job)) { - $isValid = false; - break; - } - } - } else { - $isValid = false; + public function set($id, $params) { + $jobids = null; + if (property_exists($params, 'jobids') && $this->getModule('misc')->isValidIdsList($params->jobids)) { + $jobids = $params->jobids; } - if($isValid === true) { - $result = $this->getModule('bconsole')->bconsoleCommand( - $this->director, - array('.bvfs_update', 'jobid="' . $ids->jobids . '"'), - $this->user - ); - $this->output = $result->output; - $this->error = $result->exitcode; - } else { - $this->output = BVFSError::MSG_ERROR_JOB_DOES_NOT_EXISTS; - $this->error = BVFSError::ERROR_JOB_DOES_NOT_EXISTS; + if (is_null($jobids)) { + $this->output = BVFSError::MSG_ERROR_INVALID_JOBID_LIST; + $this->error = BVFSError::ERROR_INVALID_JOBID_LIST; + return; } + + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('.bvfs_update', 'jobid="' . $jobids . '"') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } } ?> diff --git a/gui/baculum/protected/API/Pages/API/BVFSVersions.php b/gui/baculum/protected/API/Pages/API/BVFSVersions.php index 2a1d10f190..1d71185c14 100644 --- a/gui/baculum/protected/API/Pages/API/BVFSVersions.php +++ b/gui/baculum/protected/API/Pages/API/BVFSVersions.php @@ -23,26 +23,30 @@ class BVFSVersions extends BaculumAPIServer { public function get() { - $jobid = intval($this->Request['jobid']); - $pathid = $this->Request['pathid']; - $filenameid = intval($this->Request['filenameid']); - $client = $this->Request['client']; - $job = $this->getModule('job')->getJobById($jobid); - if(!is_null($job)) { - $cmd = array( - '.bvfs_versions', - 'client="' . $client . '"', - 'jobid="' . $job->jobid . '"', - 'pathid="' . $pathid . '"', - 'fnid="' . $filenameid . '"' - ); - $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user); - $this->output = $result->output; - $this->error = $result->exitcode; - } else { - $this->output = BVFSError::MSG_ERROR_JOB_DOES_NOT_EXISTS; - $this->error = BVFSError::ERROR_JOB_DOES_NOT_EXISTS; + $jobid = $this->Request->contains('jobid') ? intval($this->Request['jobid']) : 0; + $pathid = $this->Request->contains('pathid') ? intval($this->Request['pathid']) : 0; + $filenameid = $this->Request->contains('filenameid') ? intval($this->Request['filenameid']) : 0; + $client = null; + if ($this->Request->contains('client') && $this->getModule('misc')->isValidName($this->Request['client'])) { + $client = $this->Request['client']; } + + if (is_null($client)) { + $this->output = BVFSError::MSG_ERROR_INVALID_CLIENT; + $this->error = BVFSError::ERROR_INVALID_CLIENT; + return; + } + + $cmd = array( + '.bvfs_versions', + 'client="' . $client . '"', + 'jobid="' . $jobid . '"', + 'pathid="' . $pathid . '"', + 'fnid="' . $filenameid . '"' + ); + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd); + $this->output = $result->output; + $this->error = $result->exitcode; } } ?> diff --git a/gui/baculum/protected/API/Pages/API/Catalog.php b/gui/baculum/protected/API/Pages/API/Catalog.php index cfbd715c54..cc3499d104 100644 --- a/gui/baculum/protected/API/Pages/API/Catalog.php +++ b/gui/baculum/protected/API/Pages/API/Catalog.php @@ -21,9 +21,10 @@ */ class Catalog extends BaculumAPIServer { + public function get() { $result = $this->getModule('db')->testCatalog(); - if ($result === true) { + if ($result) { $this->output = DatabaseError::MSG_ERROR_NO_ERRORS; $this->error = DatabaseError::ERROR_NO_ERRORS; } else { diff --git a/gui/baculum/protected/API/Pages/API/Client.php b/gui/baculum/protected/API/Pages/API/Client.php index f850be892d..e66eec98aa 100644 --- a/gui/baculum/protected/API/Pages/API/Client.php +++ b/gui/baculum/protected/API/Pages/API/Client.php @@ -23,11 +23,11 @@ class Client extends BaculumAPIServer { public function get() { - $clientid = intval($this->Request['id']); + $clientid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $client = $this->getModule('client')->getClientById($clientid); - $allowed_clients = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'), $this->user); - if ($allowed_clients->exitcode === 0) { - if(!is_null($client) && in_array($client->name, $allowed_clients->output)) { + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client')); + if ($result->exitcode === 0) { + if(!is_null($client) && in_array($client->name, $result->output)) { $this->output = $client; $this->error = ClientError::ERROR_NO_ERRORS; } else { @@ -35,8 +35,8 @@ class Client extends BaculumAPIServer { $this->error =ClientError::ERROR_CLIENT_DOES_NOT_EXISTS; } } else { - $this->output = $allowed_clients->output; - $this->error = $allowed_clients->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/ClientShow.php b/gui/baculum/protected/API/Pages/API/ClientShow.php index eeb3e55878..c53e89226f 100644 --- a/gui/baculum/protected/API/Pages/API/ClientShow.php +++ b/gui/baculum/protected/API/Pages/API/ClientShow.php @@ -23,12 +23,15 @@ class ClientShow extends BaculumAPIServer { public function get() { - $clientid = intval($this->Request['id']); + $clientid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $client = $this->getModule('client')->getClientById($clientid); - if(!is_null($client)) { - $client_show = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'client="' . $client->name . '"'), $this->user); - $this->output = $client_show->output; - $this->error = $client_show->exitcode; + if(is_object($client)) { + $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; diff --git a/gui/baculum/protected/API/Pages/API/ClientStatus.php b/gui/baculum/protected/API/Pages/API/ClientStatus.php index cf81abe729..1a8e3618ff 100644 --- a/gui/baculum/protected/API/Pages/API/ClientStatus.php +++ b/gui/baculum/protected/API/Pages/API/ClientStatus.php @@ -23,12 +23,15 @@ class ClientStatus extends BaculumAPIServer { public function get() { - $clientid = intval($this->Request['id']); + $clientid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $client = $this->getModule('client')->getClientById($clientid); - if(!is_null($client)) { - $client_status = $this->getModule('bconsole')->bconsoleCommand($this->director, array('status', 'client="' . $client->name . '"'), $this->user); - $this->output = $client_status->output; - $this->error = (integer)$client_status->exitcode; + if(is_object($client)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('status', '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; diff --git a/gui/baculum/protected/API/Pages/API/Clients.php b/gui/baculum/protected/API/Pages/API/Clients.php index 89d0fcc1fc..329e57863c 100644 --- a/gui/baculum/protected/API/Pages/API/Clients.php +++ b/gui/baculum/protected/API/Pages/API/Clients.php @@ -20,44 +20,16 @@ * Bacula(R) is a registered trademark of Kern Sibbald. */ -/** - * Clients resources. - * - * Data format: - * { - * "output": [ - * { - * "clientid": client ID, - * "name": "client name", - * "uname": "client name and environment (uname -a)", - * "autoprune": 0 for disabled, 1 for enabled, - * "fileretention": file retention period in seconds, - * "jobretention": job retention period in seconds, - * }, - * { - * "clientid": client ID, - * "name": "client name", - * "uname": "client name and environment (uname -a)", - * "autoprune": 0 for disabled, 1 for enabled, - * "fileretention": file retention period in seconds, - * "jobretention": job retention period in seconds, - * } - * etc... - * ], - * "error": 0 for no errors, 1 for error - * } - */ - class Clients extends BaculumAPIServer { public function get() { - $limit = intval($this->Request['limit']); + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; $clients = $this->getModule('client')->getClients($limit); - $allowed_clients = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'), $this->user); - if ($allowed_clients->exitcode === 0) { + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client')); + if ($result->exitcode === 0) { $clients_output = array(); foreach($clients as $client) { - if(in_array($client->name, $allowed_clients->output)) { + if(in_array($client->name, $result->output)) { $clients_output[] = $client; } } @@ -65,8 +37,8 @@ class Clients extends BaculumAPIServer { $this->error = ClientError::ERROR_NO_ERRORS; } else { - $this->output = $allowed_clients->output; - $this->error = $allowed_clients->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/ClientsShow.php b/gui/baculum/protected/API/Pages/API/ClientsShow.php index dda7c9bd05..b423562258 100644 --- a/gui/baculum/protected/API/Pages/API/ClientsShow.php +++ b/gui/baculum/protected/API/Pages/API/ClientsShow.php @@ -23,13 +23,12 @@ class ClientsShow extends BaculumAPIServer { public function get() { - $clients = $this->getModule('bconsole')->bconsoleCommand( + $result = $this->getModule('bconsole')->bconsoleCommand( $this->director, - array('show', 'clients'), - $this->user + array('show', 'clients') ); - $this->output = $clients->output; - $this->error = $clients->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } ?> diff --git a/gui/baculum/protected/API/Pages/API/Config.php b/gui/baculum/protected/API/Pages/API/Config.php index f1c04d248c..1cec6dfa0c 100644 --- a/gui/baculum/protected/API/Pages/API/Config.php +++ b/gui/baculum/protected/API/Pages/API/Config.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions diff --git a/gui/baculum/protected/API/Pages/API/ConsoleCommand.php b/gui/baculum/protected/API/Pages/API/ConsoleCommand.php index d76432e1b2..bff7985e21 100644 --- a/gui/baculum/protected/API/Pages/API/ConsoleCommand.php +++ b/gui/baculum/protected/API/Pages/API/ConsoleCommand.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -24,10 +24,10 @@ class ConsoleCommand extends BaculumAPIServer { public function set($id, $params) { $params = (array)$params; - $console = $this->getModule('bconsole')->bconsoleCommand($this->director, $params, $this->user); - $this->output = $console->output; - $this->error = (integer)$console->exitcode; + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $params); + $this->output = $result->output; + $this->error = $result->exitcode; } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/DbSize.php b/gui/baculum/protected/API/Pages/API/DbSize.php index acbdd36f23..1dfe3ee38d 100644 --- a/gui/baculum/protected/API/Pages/API/DbSize.php +++ b/gui/baculum/protected/API/Pages/API/DbSize.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions diff --git a/gui/baculum/protected/API/Pages/API/Directors.php b/gui/baculum/protected/API/Pages/API/Directors.php index 4050eea08f..b9fb3d44a7 100644 --- a/gui/baculum/protected/API/Pages/API/Directors.php +++ b/gui/baculum/protected/API/Pages/API/Directors.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,13 +22,13 @@ class Directors extends BaculumAPIServer { public function get() { - $directors = $this->getModule('bconsole')->getDirectors(); - if($directors->exitcode === 0) { - $this->output = $directors->output; + $result = $this->getModule('bconsole')->getDirectors(); + if($result->exitcode === 0) { + $this->output = $result->output; $this->error = BconsoleError::ERROR_NO_ERRORS; } else { - $this->output = $directors->output; - $this->error = $directors->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/FileSet.php b/gui/baculum/protected/API/Pages/API/FileSet.php index 73639ed062..a47e1bd99b 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,11 +22,11 @@ class FileSet extends BaculumAPIServer { public function get() { - $filesetid = intval($this->Request['id']); + $filesetid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $fileset = $this->getModule('fileset')->getFileSetById($filesetid); - $allowedFileSets = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.fileset'), $this->user); - if ($allowedFileSets->exitcode === 0) { - if(!is_null($fileset) && in_array($fileset->fileset, $allowedFileSets->output)) { + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.fileset')); + if ($result->exitcode === 0) { + if(!is_null($fileset) && in_array($fileset->fileset, $result->output)) { $this->output = $fileset; $this->error = FileSetError::ERROR_NO_ERRORS; } else { @@ -34,8 +34,8 @@ class FileSet extends BaculumAPIServer { $this->error = FileSetError::ERROR_FILESET_DOES_NOT_EXISTS; } } else { - $this->output = $allowedFileSets->output; - $this->error = $allowedFileSets->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/FileSets.php b/gui/baculum/protected/API/Pages/API/FileSets.php index c040635642..cb59e7be92 100644 --- a/gui/baculum/protected/API/Pages/API/FileSets.php +++ b/gui/baculum/protected/API/Pages/API/FileSets.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,36 +23,37 @@ class FileSets extends BaculumAPIServer { public function get() { $directors = $this->getModule('bconsole')->getDirectors(); - if($directors->exitcode === 0) { - $filesets = array(); - $error = false; - $error_obj = null; - for($i = 0; $i < count($directors->output); $i++) { - $filesetsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'fileset'), $this->user); - if ($filesetsshow->exitcode != 0) { - $error_obj = $filesetsshow; - $error = true; - break; - } - $filesets[$directors->output[$i]] = array(); - - for($j = 0; $j < count($filesetsshow->output); $j++) { - if(preg_match('/^FileSet:\ name=(.+?(?=\s\S+\=.+)|.+$)/i', $filesetsshow->output[$j], $match) === 1) { - $filesets[$directors->output[$i]][] = $match[1]; - } - } + if($directors->exitcode != 0) { + $this->output = $directors->output; + $this->error = $directors->exitcode; + return; + } + + $filesets = array(); + $error = false; + $error_obj = null; + for($i = 0; $i < count($directors->output); $i++) { + $result = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'fileset')); + if ($result->exitcode != 0) { + $error_obj = $result; + $error = true; + break; } + $filesets[$directors->output[$i]] = array(); - if ($error === true) { - $this->output = $error_obj->output; - $this->error = $error_obj->exitcode; - } else { - $this->output = $filesets; - $this->error = BconsoleError::ERROR_NO_ERRORS; + for($j = 0; $j < count($result->output); $j++) { + if(preg_match('/^FileSet:\ name=(.+?(?=\s\S+\=.+)|.+$)/i', $result->output[$j], $match) === 1) { + $filesets[$directors->output[$i]][] = $match[1]; + } } + } + + if ($error === true) { + $this->output = $error_obj->output; + $this->error = $error_obj->exitcode; } else { - $this->output = $directors->output; - $this->error = $directors->exitcode; + $this->output = $filesets; + $this->error = BconsoleError::ERROR_NO_ERRORS; } } } diff --git a/gui/baculum/protected/API/Pages/API/FileSetsInfo.php b/gui/baculum/protected/API/Pages/API/FileSetsInfo.php index e361548b83..187357db02 100644 --- a/gui/baculum/protected/API/Pages/API/FileSetsInfo.php +++ b/gui/baculum/protected/API/Pages/API/FileSetsInfo.php @@ -24,12 +24,12 @@ class FileSetsInfo extends BaculumAPIServer { public function get() { $filesets = $this->getModule('fileset')->getFileSets(); - $allowed_filesets = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.fileset'), $this->user); - if ($allowed_filesets->exitcode === 0) { + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.fileset')); + if ($result->exitcode === 0) { if (is_array($filesets) && count($filesets) > 0) { $fs = array(); for ($i = 0; $i < count($filesets); $i++) { - if(in_array($filesets[$i]->fileset, $allowed_filesets->output)) { + if(in_array($filesets[$i]->fileset, $result->output)) { $fs[] = $filesets[$i]; } } @@ -40,8 +40,8 @@ class FileSetsInfo extends BaculumAPIServer { $this->error = FileSetError::ERROR_FILESET_DOES_NOT_EXISTS; } } else { - $this->output = $allowed_filesets->output; - $this->error = $allowed_filesets->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/Job.php b/gui/baculum/protected/API/Pages/API/Job.php index f81292da56..977e127b67 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,11 +22,11 @@ class Job extends BaculumAPIServer { public function get() { - $jobid = intval($this->Request['id']); + $jobid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $job = $this->getModule('job')->getJobById($jobid); - $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user); - if ($allowedJobs->exitcode === 0) { - if(!is_null($job) && in_array($job->name, $allowedJobs->output)) { + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs')); + if ($result->exitcode === 0) { + if(!is_null($job) && in_array($job->name, $result->output)) { $this->output = $job; $this->error = JobError::ERROR_NO_ERRORS; } else { @@ -34,8 +34,8 @@ class Job extends BaculumAPIServer { $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS; } } else { - $this->output = $allowedJobs->output; - $this->error = $allowedJobs->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } @@ -43,7 +43,10 @@ class Job extends BaculumAPIServer { $jobid = intval($id); $job = $this->getModule('job')->getJobById($jobid); if(!is_null($job)) { - $delete = $this->getModule('bconsole')->bconsoleCommand($this->director, array('delete', 'jobid="' . $job->jobid . '"'), $this->user); + $delete = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('delete', 'jobid="' . $job->jobid . '"') + ); $this->output = $delete->output; $this->error = (integer)$delete->exitcode; } else { diff --git a/gui/baculum/protected/API/Pages/API/JobCancel.php b/gui/baculum/protected/API/Pages/API/JobCancel.php index a3d344d731..b43afce00f 100644 --- a/gui/baculum/protected/API/Pages/API/JobCancel.php +++ b/gui/baculum/protected/API/Pages/API/JobCancel.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -26,10 +26,13 @@ class JobCancel extends BaculumAPIServer { $jobid = intval($id); $job = $this->getModule('job')->getJobById($jobid); - if(!is_null($job)) { - $cancel = $this->getModule('bconsole')->bconsoleCommand($this->director, array('cancel', 'jobid="' . $job->jobid . '"'), $this->user); + if(is_object($job)) { + $cancel = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('cancel', 'jobid="' . $job->jobid . '"') + ); $this->output = $cancel->output; - $this->error = (integer)$cancel->exitcode; + $this->error = $cancel->exitcode; } else { $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS; $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS; @@ -37,4 +40,4 @@ class JobCancel extends BaculumAPIServer { } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/JobEstimate.php b/gui/baculum/protected/API/Pages/API/JobEstimate.php index f42caada9e..eb733c2ef8 100644 --- a/gui/baculum/protected/API/Pages/API/JobEstimate.php +++ b/gui/baculum/protected/API/Pages/API/JobEstimate.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -53,39 +53,43 @@ class JobEstimate extends BaculumAPIServer { $accurate = $accurate_job === 1 ? 'yes' : 'no'; } - if (!is_null($job)) { - $is_valid_level = $this->getModule('misc')->isValidJobLevel($params->level); - if ($is_valid_level === true) { - if (!is_null($fileset)) { - if (!is_null($client)) { - $joblevels = $this->getModule('misc')->getJobLevels(); - $cmd = array( - 'estimate', - 'job="' . $job . '"', - 'level="' . $joblevels[$level] . '"', - 'fileset="' . $fileset. '"', - 'client="' . $client . '"', - 'accurate="' . $accurate . '"' - ); - $estimation = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user); - $this->output = $estimation->output; - $this->error = (integer)$estimation->exitcode; - } else { - $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS; - } - } else { - $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS; - } - } else { - $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL; - $this->error = JobError::ERROR_INVALID_JOBLEVEL; - } - } else { + if (is_null($job)) { $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS; $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS; + return; } + + $is_valid_level = $this->getModule('misc')->isValidJobLevel($params->level); + if (!$is_valid_level) { + $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL; + $this->error = JobError::ERROR_INVALID_JOBLEVEL; + return; + } + + if (is_null($fileset)) { + $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS; + return; + } + + if (is_null($client)) { + $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS; + return; + } + + $joblevels = $this->getModule('misc')->getJobLevels(); + $cmd = array( + 'estimate', + 'job="' . $job . '"', + 'level="' . $joblevels[$level] . '"', + 'fileset="' . $fileset. '"', + 'client="' . $client . '"', + 'accurate="' . $accurate . '"' + ); + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd); + $this->output = $result->output; + $this->error = $result->exitcode; } } diff --git a/gui/baculum/protected/API/Pages/API/JobLog.php b/gui/baculum/protected/API/Pages/API/JobLog.php index 46bb7aabc3..4b2019bc78 100644 --- a/gui/baculum/protected/API/Pages/API/JobLog.php +++ b/gui/baculum/protected/API/Pages/API/JobLog.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,9 +22,9 @@ class JobLog extends BaculumAPIServer { public function get() { - $jobid = intval($this->Request['id']); + $jobid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $job = $this->getModule('job')->getJobById($jobid); - if(!is_null($job)) { + if(is_object($job)) { $log = $this->getModule('joblog')->getLogByJobId($job->jobid); $log = array_map('trim', $log); // Output may contain national characters. diff --git a/gui/baculum/protected/API/Pages/API/JobRun.php b/gui/baculum/protected/API/Pages/API/JobRun.php index 36d9436bc2..1e10844c06 100644 --- a/gui/baculum/protected/API/Pages/API/JobRun.php +++ b/gui/baculum/protected/API/Pages/API/JobRun.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -71,54 +71,60 @@ class JobRun extends BaculumAPIServer { $verifyjob = 'verifyjob="' . $params->verifyjob . '"'; } - if(!is_null($job)) { - $is_valid_level = $this->getModule('misc')->isValidJobLevel($params->level); - if($is_valid_level === true) { - if(!is_null($fileset)) { - if(!is_null($client)) { - if(!is_null($storage)) { - if(!is_null($pool)) { - $joblevels = $this->getModule('misc')->getJobLevels(); - $command = array( - 'run', - 'job="' . $job . '"', - 'level="' . $joblevels[$level] . '"', - 'fileset="' . $fileset . '"', - 'client="' . $client . '"', - 'storage="' . $storage . '"', - 'pool="' . $pool . '"' , - 'priority="' . $priority . '"', - $jobid, - $verifyjob, - 'yes' - ); - $run = $this->getModule('bconsole')->bconsoleCommand($this->director, $command, $this->user); - $this->output = $run->output; - $this->error = (integer)$run->exitcode; - } else { - $this->output = JobError::MSG_ERROR_POOL_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_POOL_DOES_NOT_EXISTS; - } - } else { - $this->output = JobError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_STORAGE_DOES_NOT_EXISTS; - } - } else { - $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS; - } - } else { - $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS; - } - } else { - $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL; - $this->error = JobError::ERROR_INVALID_JOBLEVEL; - } - } else { + if(is_null($job)) { $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS; $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS; + return; } + + $is_valid_level = $this->getModule('misc')->isValidJobLevel($params->level); + if(!$is_valid_level) { + $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL; + $this->error = JobError::ERROR_INVALID_JOBLEVEL; + return; + } + + if(is_null($fileset)) { + $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS; + return; + } + + if(is_null($client)) { + $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS; + return; + } + + if(is_null($storage)) { + $this->output = JobError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_STORAGE_DOES_NOT_EXISTS; + return; + } + + if(is_null($pool)) { + $this->output = JobError::MSG_ERROR_POOL_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_POOL_DOES_NOT_EXISTS; + return; + } + + $joblevels = $this->getModule('misc')->getJobLevels(); + $command = array( + 'run', + 'job="' . $job . '"', + 'level="' . $joblevels[$level] . '"', + 'fileset="' . $fileset . '"', + 'client="' . $client . '"', + 'storage="' . $storage . '"', + 'pool="' . $pool . '"' , + 'priority="' . $priority . '"', + $jobid, + $verifyjob, + 'yes' + ); + $run = $this->getModule('bconsole')->bconsoleCommand($this->director, $command); + $this->output = $run->output; + $this->error = $run->exitcode; } } diff --git a/gui/baculum/protected/API/Pages/API/JobShow.php b/gui/baculum/protected/API/Pages/API/JobShow.php index f096918f93..793b4279ef 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -26,25 +26,28 @@ class JobShow extends BaculumAPIServer { $error = false; $error_obj = null; - if (isset($this->Request['id'])) { + if ($this->Request->contains('id')) { $jobid = intval($this->Request['id']); $job = $this->getModule('job')->getJobById($jobid); $jobname = property_exists($job, 'name') ? $job->name : null; - } elseif (isset($this->Request['name'])) { - $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user); - if ($allowedJobs->exitcode === 0) { - $jobname = in_array($this->Request['name'], $allowedJobs->output) ? $this->Request['name'] : null; + } elseif ($this->Request->contains('name')) { + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs')); + if ($result->exitcode === 0) { + $jobname = in_array($this->Request['name'], $result->output) ? $this->Request['name'] : null; } else { - $error_obj = $allowedJobs; + $error_obj = $result; $error = true; } } if ($error === false) { - if(!is_null($jobname)) { - $jobShow = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'job="' . $jobname . '"'), $this->user); - $this->output = $jobShow->output; - $this->error = (integer)$jobShow->exitcode; + if(is_string($jobname)) { + $job_show = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('show', 'job="' . $jobname . '"') + ); + $this->output = $job_show->output; + $this->error = $job_show->exitcode; } else { $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS; $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS; @@ -55,5 +58,4 @@ class JobShow extends BaculumAPIServer { } } } - ?> diff --git a/gui/baculum/protected/API/Pages/API/JobTasks.php b/gui/baculum/protected/API/Pages/API/JobTasks.php index 4b83a9bcb7..ba9e34ef2a 100644 --- a/gui/baculum/protected/API/Pages/API/JobTasks.php +++ b/gui/baculum/protected/API/Pages/API/JobTasks.php @@ -22,59 +22,59 @@ class JobTasks extends BaculumAPIServer { public function get() { - $limit = intval($this->Request['limit']); + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; $jobs_cmd = array('.jobs'); if ($this->Request->contains('type') && array_key_exists($this->Request['type'], $this->getModule('misc')->job_types)) { array_push($jobs_cmd, 'type="' . $this->Request['type']. '"'); } $directors = $this->getModule('bconsole')->getDirectors(); - if($directors->exitcode === 0) { - $jobs = array(); - $error = false; - $error_obj = null; - for($i = 0; $i < count($directors->output); $i++) { - $jobsList = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], $jobs_cmd, $this->user); - if ($jobsList->exitcode != 0) { - $error_obj = $jobsList; - $error = true; - break; - } - $jobsshow = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'jobs'), $this->user); - if ($jobsshow->exitcode != 0) { - $error_obj = $jobsshow; - $error = true; - break; - } - $jobs[$directors->output[$i]] = array(); - for($j = 0; $j < count($jobsList->output); $j++) { - /** - * 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. - */ - for($k = 0; $k < count($jobsshow->output); $k++) { - if(preg_match('/^Job: name=' . $jobsList->output[$j] . '.*/', $jobsshow->output[$k]) === 1) { - $jobs[$directors->output[$i]][] = $jobsList->output[$j]; - break; - } - } - // limit per director, not for entire elements - if($limit > 0 && count($jobs[$directors->output[$i]]) === $limit) { + if($directors->exitcode != 0) { + $this->output = $directors->output; + $this->error = $directors->exitcode; + return; + } + $jobs = array(); + $error = false; + $error_obj = null; + for($i = 0; $i < count($directors->output); $i++) { + $job_list = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], $jobs_cmd); + if ($job_list->exitcode != 0) { + $error_obj = $job_list; + $error = true; + break; + } + $jobs_show = $this->getModule('bconsole')->bconsoleCommand($directors->output[$i], array('show', 'jobs')); + if ($jobs_show->exitcode != 0) { + $error_obj = $jobs_show; + $error = true; + break; + } + $jobs[$directors->output[$i]] = array(); + for($j = 0; $j < count($job_list->output); $j++) { + /** + * 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. + */ + for($k = 0; $k < count($jobs_show->output); $k++) { + if(preg_match('/^Job: name=' . $job_list->output[$j] . '.*/', $jobs_show->output[$k]) === 1) { + $jobs[$directors->output[$i]][] = $job_list->output[$j]; break; } } + // limit per director, not for entire elements + if($limit > 0 && count($jobs[$directors->output[$i]]) === $limit) { + break; + } } - if ($error === true) { - $this->output = $error_obj->output; - $this->error = $error_obj->exitcode; - } else { - $this->output = $jobs; - $this->error = BconsoleError::ERROR_NO_ERRORS; - } + } + if ($error === true) { + $this->output = $error_obj->output; + $this->error = $error_obj->exitcode; } else { - $this->output = $directors->output; - $this->error = $directors->exitcode; + $this->output = $jobs; + $this->error = BconsoleError::ERROR_NO_ERRORS; } } } diff --git a/gui/baculum/protected/API/Pages/API/JobTotals.php b/gui/baculum/protected/API/Pages/API/JobTotals.php index 29d800b7a2..c69723414e 100644 --- a/gui/baculum/protected/API/Pages/API/JobTotals.php +++ b/gui/baculum/protected/API/Pages/API/JobTotals.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -24,16 +24,14 @@ class JobTotals extends BaculumAPIServer { public function get() { $error = false; $allowed = array(); - if (!is_null($this->user)) { - $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user); - if ($allowedJobs->exitcode === 0) { - array_shift($allowedJobs->output); - $allowed = $allowedJobs->output; - } else { - $error = true; - $this->output = $allowedJobs->output; - $this->error = $allowedJobs->error; - } + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs')); + if ($result->exitcode === 0) { + array_shift($result->output); + $allowed = $result->output; + } else { + $error = true; + $this->output = $result->output; + $this->error = $result->error; } if ($error === false) { diff --git a/gui/baculum/protected/API/Pages/API/Jobs.php b/gui/baculum/protected/API/Pages/API/Jobs.php index e7a7bb6b82..b77c19e872 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,18 +22,18 @@ class Jobs extends BaculumAPIServer { public function get() { - $limit = intval($this->Request['limit']); + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; $allowed = array(); - $allowedJobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user); - if ($allowedJobs->exitcode === 0) { - array_shift($allowedJobs->output); - $allowed = $allowedJobs->output; + $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); $this->output = $jobs; $this->error = JobError::ERROR_NO_ERRORS; } else { - $this->output = $allowedJobs->output; - $this->error = $allowedJobs->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/JobsForClient.php b/gui/baculum/protected/API/Pages/API/JobsForClient.php index 99ce061d9f..e3f514cbbe 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -21,23 +21,22 @@ */ class JobsForClient extends BaculumAPIServer { + public function get() { - $allowed = array(); - $clientid = intval($this->Request['id']); + $allowed_jobs = array(); + $clientid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $error = false; - if (!is_null($this->user)) { - $allowed_jobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user); - if ($allowed_jobs->exitcode === 0) { - $allowed = $allowed_jobs->output; - } else { - $error = true; - $this->output = $allowed_jobs->output; - $this->error = $allowed_jobs->exitcode; - } + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs')); + if ($result->exitcode === 0) { + $allowed_jobs = $result->output; + } else { + $error = true; + $this->output = $result->output; + $this->error = $result->exitcode; } if ($error === false) { - $jobs = $this->getModule('job')->getJobsForClient($clientid, $allowed); + $jobs = $this->getModule('job')->getJobsForClient($clientid, $allowed_jobs); $this->output = $jobs; $this->error = JobError::ERROR_NO_ERRORS; } diff --git a/gui/baculum/protected/API/Pages/API/JobsOnVolume.php b/gui/baculum/protected/API/Pages/API/JobsOnVolume.php index 8c3b509e49..ab52b1010d 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,17 +23,15 @@ class JobsOnVolume extends BaculumAPIServer { public function get() { $allowed = array(); - $mediaid = intval($this->Request['id']); + $mediaid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $error = false; - if (!is_null($this->user)) { - $allowed_jobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs'), $this->user); - if ($allowed_jobs->exitcode === 0) { - $allowed = $allowed_jobs->output; - } else { - $error = true; - $this->output = $allowed_jobs->output; - $this->error = $allowed_jobs->exitcode; - } + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.jobs')); + if ($result->exitcode === 0) { + $allowed = $result->output; + } else { + $error = true; + $this->output = $result->output; + $this->error = $result->exitcode; } if ($error === false) { diff --git a/gui/baculum/protected/API/Pages/API/JobsRecent.php b/gui/baculum/protected/API/Pages/API/JobsRecent.php index 9048c029c8..5e04234963 100644 --- a/gui/baculum/protected/API/Pages/API/JobsRecent.php +++ b/gui/baculum/protected/API/Pages/API/JobsRecent.php @@ -22,7 +22,7 @@ class JobsRecent extends BaculumAPIServer { public function get() { - $jobname = $this->Request['name']; + $jobname = $this->Request->contains('name') ? $this->Request['name'] : ''; $clientid = null; if ($this->Request->contains('clientid')) { $clientid = intval($this->Request['clientid']); diff --git a/gui/baculum/protected/API/Pages/API/JobsShow.php b/gui/baculum/protected/API/Pages/API/JobsShow.php index 216857ccc5..e7cbb925de 100644 --- a/gui/baculum/protected/API/Pages/API/JobsShow.php +++ b/gui/baculum/protected/API/Pages/API/JobsShow.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,9 +23,9 @@ class JobsShow extends BaculumAPIServer { public function get() { - $jobs = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'jobs'), $this->user); - $this->output = $jobs->output; - $this->error = (integer)$jobs->exitcode; + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'jobs')); + $this->output = $result->output; + $this->error = $result->exitcode; } } diff --git a/gui/baculum/protected/API/Pages/API/Pool.php b/gui/baculum/protected/API/Pages/API/Pool.php index 3148f836ac..90b03074c5 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,9 +22,9 @@ class Pool extends BaculumAPIServer { public function get() { - $poolid = intval($this->Request['id']); + $poolid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $pool = $this->getModule('pool')->getPoolById($poolid); - $allowedPools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'), $this->user); + $allowedPools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool')); if ($allowedPools->exitcode === 0) { if(!is_null($pool) && in_array($pool->name, $allowedPools->output)) { $this->output = $pool; diff --git a/gui/baculum/protected/API/Pages/API/PoolShow.php b/gui/baculum/protected/API/Pages/API/PoolShow.php index cdfc6bb965..ae3af1f836 100644 --- a/gui/baculum/protected/API/Pages/API/PoolShow.php +++ b/gui/baculum/protected/API/Pages/API/PoolShow.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,12 +22,15 @@ class PoolShow extends BaculumAPIServer { public function get() { - $poolid = intval($this->Request['id']); + $poolid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $pool = $this->getModule('pool')->getPoolById($poolid); - if(!is_null($pool)) { - $poolShow = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'pool="' . $pool->name . '"'), $this->user); - $this->output = $poolShow->output; - $this->error = (integer)$poolShow->exitcode; + if (is_object($pool)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('show', 'pool="' . $pool->name . '"') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = PoolError::MSG_ERROR_POOL_DOES_NOT_EXISTS; $this->error = PoolError::ERROR_POOL_DOES_NOT_EXISTS; @@ -35,4 +38,4 @@ class PoolShow extends BaculumAPIServer { } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/PoolUpdate.php b/gui/baculum/protected/API/Pages/API/PoolUpdate.php index 394f82ad74..300e8d090e 100644 --- a/gui/baculum/protected/API/Pages/API/PoolUpdate.php +++ b/gui/baculum/protected/API/Pages/API/PoolUpdate.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,11 +23,15 @@ class PoolUpdate extends BaculumAPIServer { public function set($id, $params) { - $pool = $this->getModule('pool')->getPoolById($id); - if(!is_null($pool)) { - $poolUpdate = $this->getModule('bconsole')->bconsoleCommand($this->director, array('update', 'pool="' . $pool->name . '"'), $this->user); - $this->output = $poolUpdate->output; - $this->error = (integer)$poolUpdate->exitcode; + $poolid = intval($id); + $pool = $this->getModule('pool')->getPoolById($poolid); + if(is_object($pool)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('update', 'pool="' . $pool->name . '"') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = PoolError::MSG_ERROR_POOL_DOES_NOT_EXISTS; $this->error = PoolError::ERROR_POOL_DOES_NOT_EXISTS; diff --git a/gui/baculum/protected/API/Pages/API/PoolUpdateVolumes.php b/gui/baculum/protected/API/Pages/API/PoolUpdateVolumes.php index d18a52721c..08152fe8ce 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,13 +23,17 @@ class PoolUpdateVolumes extends BaculumAPIServer { public function set($id, $params) { - $pool = $this->getModule('pool')->getPoolById($id); - if(!is_null($pool)) { + $poolid = intval($id); + $pool = $this->getModule('pool')->getPoolById($poolid); + if(is_object($pool)) { $voldata = $this->getModule('volume')->getVolumesByPoolId($pool->poolid); - if(!is_null($voldata)) { - $poolUpdateVolumes = $this->getModule('bconsole')->bconsoleCommand($this->director, array('update', 'volume="' . $voldata->volumename . '"', 'allfrompool="' . $pool->name . '"'), $this->user); - $this->output = $poolUpdateVolumes->output; - $this->error = (integer)$poolUpdateVolumes->exitcode; + if(is_object($voldata)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('update', 'volume="' . $voldata->volumename . '"', 'allfrompool="' . $pool->name . '"') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = PoolError::MSG_ERROR_NO_VOLUMES_IN_POOL_TO_UPDATE; $this->error = PoolError::ERROR_NO_VOLUMES_IN_POOL_TO_UPDATE; @@ -41,4 +45,4 @@ class PoolUpdateVolumes extends BaculumAPIServer { } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/Pools.php b/gui/baculum/protected/API/Pages/API/Pools.php index e418de9bbd..da3784fb1f 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,21 +22,21 @@ class Pools extends BaculumAPIServer { public function get() { - $limit = intval($this->Request['limit']); + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; $pools = $this->getModule('pool')->getPools($limit); - $allowedPools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool'), $this->user); - if ($allowedPools->exitcode === 0) { - $poolsOutput = array(); + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.pool')); + if ($result->exitcode === 0) { + $pools_output = array(); foreach($pools as $pool) { - if(in_array($pool->name, $allowedPools->output)) { - $poolsOutput[] = $pool; + if(in_array($pool->name, $result->output)) { + $pools_output[] = $pool; } } - $this->output = $poolsOutput; + $this->output = $pools_output; $this->error = PoolError::ERROR_NO_ERRORS; } else { - $this->output = $allowedPools->output; - $this->error = $allowedPools->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/PoolsShow.php b/gui/baculum/protected/API/Pages/API/PoolsShow.php index 2d40a5f432..64747149ee 100644 --- a/gui/baculum/protected/API/Pages/API/PoolsShow.php +++ b/gui/baculum/protected/API/Pages/API/PoolsShow.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,9 +23,9 @@ class PoolsShow extends BaculumAPIServer { public function get() { - $pools = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'pools'), $this->user); - $this->output = $pools->output; - $this->error = (integer)$pools->exitcode; + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'pools')); + $this->output = $result->output; + $this->error = $result->exitcode; } } ?> diff --git a/gui/baculum/protected/API/Pages/API/RestoreRun.php b/gui/baculum/protected/API/Pages/API/RestoreRun.php index 5a5c9837e4..b01d138c3f 100644 --- a/gui/baculum/protected/API/Pages/API/RestoreRun.php +++ b/gui/baculum/protected/API/Pages/API/RestoreRun.php @@ -114,10 +114,10 @@ class RestoreRun extends BaculumAPIServer { } $command[] = 'yes'; - $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, $command, $this->user); + $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, $command); $this->removeTmpRestoreTable($rfile); $this->output = $restore->output; - $this->error = (integer)$restore->exitcode; + $this->error = $restore->exitcode; } private function removeTmpRestoreTable($tableName) { diff --git a/gui/baculum/protected/API/Pages/API/Storage.php b/gui/baculum/protected/API/Pages/API/Storage.php index 47d212c13e..6c1d3a1214 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,11 +22,11 @@ class Storage extends BaculumAPIServer { public function get() { - $storageid = intval($this->Request['id']); + $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $storage = $this->getModule('storage')->getStorageById($storageid); - $allowedStorages = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage'), $this->user); - if ($allowedStorages->exitcode === 0) { - if(!is_null($storage) && in_array($storage->name, $allowedStorages->output)) { + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage')); + if ($result->exitcode === 0) { + if(!is_null($storage) && in_array($storage->name, $result->output)) { $this->output = $storage; $this->error = StorageError::ERROR_NO_ERRORS; } else { @@ -34,8 +34,8 @@ class Storage extends BaculumAPIServer { $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS; } } else { - $this->output = $allowedStorages->output; - $this->error = $allowedStorages->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/StorageMount.php b/gui/baculum/protected/API/Pages/API/StorageMount.php index c62ae9f276..80c7774193 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,14 +22,17 @@ class StorageMount extends BaculumAPIServer { public function get() { - $storageid = intval($this->Request['id']); - $drive = intval($this->Request['drive']); - $slot = intval($this->Request['slot']); + $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; + $drive = $this->Request->contains('drive') ? intval($this->Request['drive']) : 0; + $slot = $this->Request->contains('slot') ? intval($this->Request['slot']) : 0; $storage = $this->getModule('storage')->getStorageById($storageid); - if(!is_null($storage)) { - $storageMount = $this->getModule('bconsole')->bconsoleCommand($this->director, array('mount', 'storage="' . $storage->name . '"', 'drive=' . $drive, 'slot=' . $slot), $this->user); - $this->output = $storageMount->output; - $this->error = (integer)$storageMount->exitcode; + if(is_object($storage)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('mount', 'storage="' . $storage->name . '"', 'drive=' . $drive, 'slot=' . $slot) + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS; $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS; @@ -38,4 +41,4 @@ class StorageMount extends BaculumAPIServer { } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/StorageRelease.php b/gui/baculum/protected/API/Pages/API/StorageRelease.php index 5e61e5a076..c975e9b7e8 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,14 +22,16 @@ class StorageRelease extends BaculumAPIServer { public function get() { - $storageid = intval($this->Request['id']); - $drive = intval($this->Request['drive']); - + $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; + $drive = $this->Request->contains('drive') ? intval($this->Request['drive']) : 0; $storage = $this->getModule('storage')->getStorageById($storageid); - if(!is_null($storage)) { - $storageRelease = $this->getModule('bconsole')->bconsoleCommand($this->director, array('release', 'storage="' . $storage->name . '"', 'drive="' . $drive . '"'), $this->user); - $this->output = $storageRelease->output; - $this->error = (integer)$storageRelease->exitcode; + if (is_object($storage)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('release', 'storage="' . $storage->name . '"', 'drive="' . $drive . '"') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS; $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS; diff --git a/gui/baculum/protected/API/Pages/API/StorageShow.php b/gui/baculum/protected/API/Pages/API/StorageShow.php index 0d49971709..cc7c81b6eb 100644 --- a/gui/baculum/protected/API/Pages/API/StorageShow.php +++ b/gui/baculum/protected/API/Pages/API/StorageShow.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,12 +22,15 @@ class StorageShow extends BaculumAPIServer { public function get() { - $storageid = intval($this->Request['id']); + $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $storage = $this->getModule('storage')->getStorageById($storageid); - if(!is_null($storage)) { - $storageShow = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'storage="' . $storage->name . '"'), $this->user); - $this->output = $storageShow->output; - $this->error = (integer)$storageShow->exitcode; + if(is_object($storage)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('show', 'storage="' . $storage->name . '"') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS; $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS; @@ -35,4 +38,4 @@ class StorageShow extends BaculumAPIServer { } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/StorageStatus.php b/gui/baculum/protected/API/Pages/API/StorageStatus.php index b449e3bae4..f96bd248f8 100644 --- a/gui/baculum/protected/API/Pages/API/StorageStatus.php +++ b/gui/baculum/protected/API/Pages/API/StorageStatus.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,12 +22,15 @@ class StorageStatus extends BaculumAPIServer { public function get() { - $storageid = intval($this->Request['id']); + $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $storage = $this->getModule('storage')->getStorageById($storageid); - if(!is_null($storage)) { - $storageStatus = $this->getModule('bconsole')->bconsoleCommand($this->director, array('status', 'storage="' . $storage->name . '"'), $this->user); - $this->output = $storageStatus->output; - $this->error = (integer)$storageStatus->exitcode; + if(is_object($storage)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('status', 'storage="' . $storage->name . '"') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS; $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS; @@ -35,4 +38,4 @@ class StorageStatus extends BaculumAPIServer { } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/StorageUmount.php b/gui/baculum/protected/API/Pages/API/StorageUmount.php index 82d383f3b4..2a58bcd008 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,13 +22,16 @@ class StorageUmount extends BaculumAPIServer { public function get() { - $storageid = intval($this->Request['id']); - $drive = intval($this->Request['drive']); + $storageid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; + $drive = $this->Request->contains('drive') ? intval($this->Request['drive']) : 0; $storage = $this->getModule('storage')->getStorageById($storageid); - if(!is_null($storage)) { - $storageUmount = $this->getModule('bconsole')->bconsoleCommand($this->director, array('umount', 'storage="' . $storage->name . '"', 'drive=' . $drive), $this->user); - $this->output = $storageUmount->output; - $this->error = (integer)$storageUmount->exitcode; + if (is_object($storage)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('umount', 'storage="' . $storage->name . '"', 'drive=' . $drive) + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = StorageError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS; $this->error = StorageError::ERROR_STORAGE_DOES_NOT_EXISTS; @@ -36,4 +39,4 @@ class StorageUmount extends BaculumAPIServer { } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/Storages.php b/gui/baculum/protected/API/Pages/API/Storages.php index 1065b51dab..dedc77fe35 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-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,21 +23,21 @@ class Storages extends BaculumAPIServer { public function get() { - $limit = intval($this->Request['limit']); + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; $storages = $this->getModule('storage')->getStorages($limit); - $allowedStorages = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage'), $this->user); - if ($allowedStorages->exitcode === 0) { - $storagesOutput = array(); + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.storage')); + if ($result->exitcode === 0) { + $storages_output = array(); foreach($storages as $storage) { - if(in_array($storage->name, $allowedStorages->output)) { - $storagesOutput[] = $storage; + if(in_array($storage->name, $result->output)) { + $storages_output[] = $storage; } } - $this->output = $storagesOutput; + $this->output = $storages_output; $this->error = StorageError::ERROR_NO_ERRORS; } else { - $this->output = $allowedStorages->output; - $this->error = $allowedStorages->exitcode; + $this->output = $result->output; + $this->error = $result->exitcode; } } } diff --git a/gui/baculum/protected/API/Pages/API/StoragesShow.php b/gui/baculum/protected/API/Pages/API/StoragesShow.php index ea8fb01601..17357d3ee7 100644 --- a/gui/baculum/protected/API/Pages/API/StoragesShow.php +++ b/gui/baculum/protected/API/Pages/API/StoragesShow.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -23,9 +23,9 @@ class StoragesShow extends BaculumAPIServer { public function get() { - $storages = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'storages'), $this->user); - $this->output = $storages->output; - $this->error = (integer)$storages->exitcode; + $result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('show', 'storages')); + $this->output = $result->output; + $this->error = $result->exitcode; } } ?> diff --git a/gui/baculum/protected/API/Pages/API/Volume.php b/gui/baculum/protected/API/Pages/API/Volume.php index aa569afff7..c4ea347e1f 100644 --- a/gui/baculum/protected/API/Pages/API/Volume.php +++ b/gui/baculum/protected/API/Pages/API/Volume.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,9 +22,9 @@ class Volume extends BaculumAPIServer { public function get() { - $mediaid = intval($this->Request['id']); + $mediaid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $volume = $this->getModule('volume')->getVolumeById($mediaid); - if(!is_null($volume)) { + if(is_object($volume)) { $this->output = $volume; $this->error = VolumeError::ERROR_NO_ERRORS; } else { @@ -36,41 +36,42 @@ class Volume extends BaculumAPIServer { public function set($id, $params) { $volume = $this->getModule('volume')->getVolumeById($id); if (is_object($volume)) { + $misc = $this->getModule('misc'); $cmd = array('update', 'volume="' . $volume->volumename . '"'); - if(property_exists($params, 'volstatus')) { + if(property_exists($params, 'volstatus') && $misc->isValidState($params->volstatus)) { $cmd[] = 'volstatus="' . $params->volstatus . '"'; } - if(property_exists($params, 'poolid')) { + if(property_exists($params, 'poolid') && $misc->isValidId($params->poolid)) { $pool = $this->getModule('pool')->getPoolById($params->poolid); if (is_object($pool)) { $cmd[] = 'pool="' . $pool->name . '"'; } } - if(property_exists($params, 'volretention')) { + if(property_exists($params, 'volretention') && $misc->isValidNumber($params->volretention)) { $cmd[] = 'volretention="' . $params->volretention . '"'; } - if(property_exists($params, 'voluseduration')) { + if(property_exists($params, 'voluseduration') && $misc->isValidNumber($params->voluseduration)) { $cmd[] = 'voluseduration="' . $params->voluseduration . '"'; } - if(property_exists($params, 'maxvoljobs')) { + if(property_exists($params, 'maxvoljobs') && $misc->isValidNumber($params->maxvoljobs)) { $cmd[] = 'maxvoljobs="' . $params->maxvoljobs . '"'; } - if(property_exists($params, 'maxvolfiles')) { + if(property_exists($params, 'maxvolfiles') && $misc->isValidNumber($params->maxvolfiles)) { $cmd[] = 'maxvolfiles="' . $params->maxvolfiles . '"'; } - if(property_exists($params, 'maxvolbytes')) { + if(property_exists($params, 'maxvolbytes') && $misc->isValidNumber($params->maxvolbytes)) { $cmd[] = 'maxvolbytes="' . $params->maxvolbytes . '"'; } - if(property_exists($params, 'slot')) { + if(property_exists($params, 'slot') && $misc->isValidNumber($params->slot)) { $cmd[] = 'slot="' . $params->slot . '"'; } - if(property_exists($params, 'recycle')) { + if(property_exists($params, 'recycle') && $misc->isValidBoolean($params->recycle)) { $cmd[] = 'recycle="' . ($params->recycle ? 'yes' : 'no') . '"'; } - if(property_exists($params, 'enabled')) { + if(property_exists($params, 'enabled') && $misc->isValidBoolean($params->enabled)) { $cmd[] = 'enabled="' . ($params->enabled ? 'yes' : 'no') . '"'; } - if(property_exists($params, 'inchanger')) { + if(property_exists($params, 'inchanger') && $misc->isValidBoolean($params->inchanger)) { $cmd[] = 'inchanger="' . ($params->inchanger ? 'yes' : 'no') . '"'; } $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd); diff --git a/gui/baculum/protected/API/Pages/API/VolumePrune.php b/gui/baculum/protected/API/Pages/API/VolumePrune.php index 283a996d2c..fe22c65781 100644 --- a/gui/baculum/protected/API/Pages/API/VolumePrune.php +++ b/gui/baculum/protected/API/Pages/API/VolumePrune.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,12 +22,15 @@ class VolumePrune extends BaculumAPIServer { public function get() { - $mediaid = intval($this->Request['id']); + $mediaid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $volume = $this->getModule('volume')->getVolumeById($mediaid); - if(!is_null($volume)) { - $prune = $this->getModule('bconsole')->bconsoleCommand($this->director, array('prune', 'volume="' . $volume->volumename . '"', 'yes'), $this->user); - $this->output = $prune->output; - $this->error = (integer)$prune->exitcode; + if(is_object($volume)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('prune', 'volume="' . $volume->volumename . '"', 'yes') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = VolumeError::MSG_ERROR_VOLUME_DOES_NOT_EXISTS; $this->error = VolumeError::ERROR_VOLUME_DOES_NOT_EXISTS; @@ -35,4 +38,4 @@ class VolumePrune extends BaculumAPIServer { } } -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/VolumePurge.php b/gui/baculum/protected/API/Pages/API/VolumePurge.php index 6ffef758e8..9ac876e973 100644 --- a/gui/baculum/protected/API/Pages/API/VolumePurge.php +++ b/gui/baculum/protected/API/Pages/API/VolumePurge.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,17 +22,19 @@ class VolumePurge extends BaculumAPIServer { public function get() { - $mediaid = intval($this->Request['id']); + $mediaid = $this->Request->contains('id') ? intval($this->Request['id']) : 0; $volume = $this->getModule('volume')->getVolumeById($mediaid); - if(!is_null($volume)) { - $purge = $this->getModule('bconsole')->bconsoleCommand($this->director, array('purge', 'volume="' . $volume->volumename . '"', 'yes'), $this->user); - $this->output = $purge->output; - $this->error = (integer)$purge->exitcode; + if(is_object($volume)) { + $result = $this->getModule('bconsole')->bconsoleCommand( + $this->director, + array('purge', 'volume="' . $volume->volumename . '"', 'yes') + ); + $this->output = $result->output; + $this->error = $result->exitcode; } else { $this->output = VolumeError::MSG_ERROR_VOLUME_DOES_NOT_EXISTS; $this->error = VolumeError::ERROR_VOLUME_DOES_NOT_EXISTS; } } } - -?> \ No newline at end of file +?> diff --git a/gui/baculum/protected/API/Pages/API/Volumes.php b/gui/baculum/protected/API/Pages/API/Volumes.php index 565ebe5108..1572a6636c 100644 --- a/gui/baculum/protected/API/Pages/API/Volumes.php +++ b/gui/baculum/protected/API/Pages/API/Volumes.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -22,9 +22,9 @@ class Volumes extends BaculumAPIServer { public function get() { - $limit = intval($this->Request['limit']); - $volumes = $this->getModule('volume')->getVolumes($limit); - $this->output = $volumes; + $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0; + $result = $this->getModule('volume')->getVolumes($limit); + $this->output = $result; $this->error = VolumeError::ERROR_NO_ERRORS; } } diff --git a/gui/baculum/protected/Common/Class/Errors.php b/gui/baculum/protected/Common/Class/Errors.php index b0b7304f7c..7844a3c4b5 100644 --- a/gui/baculum/protected/Common/Class/Errors.php +++ b/gui/baculum/protected/Common/Class/Errors.php @@ -42,9 +42,11 @@ class BconsoleError extends GenericError { const ERROR_BCONSOLE_CONNECTION_PROBLEM = 4; const ERROR_INVALID_DIRECTOR = 5; + const ERROR_BCONSOLE_DISABLED = 11; const MSG_ERROR_BCONSOLE_CONNECTION_PROBLEM = 'Problem with connection to bconsole.'; const MSG_ERROR_INVALID_DIRECTOR = 'Invalid director.'; + const MSG_ERROR_BCONSOLE_DISABLED = 'Bconsole support is disabled.'; } class AuthorizationError extends GenericError { @@ -111,19 +113,21 @@ class FileSetError extends GenericError { } class BVFSError extends GenericError { - const ERROR_INVALID_JOBID_LIST = 70; const ERROR_INVALID_RPATH = 71; const ERROR_INVALID_RESTORE_PATH = 72; - const ERROR_INVALID_FILEID_LIST = 73; - const ERROR_INVALID_FILEINDEX_LIST = 74; - const ERROR_INVALID_DIRID_LIST = 75; + const ERROR_INVALID_JOBID_LIST = 73; + const ERROR_INVALID_FILEID_LIST = 74; + const ERROR_INVALID_FILEINDEX_LIST = 75; + const ERROR_INVALID_DIRID_LIST = 76; + const ERROR_INVALID_CLIENT = 77; - const MSG_ERROR_INVALID_JOBID_LIST = 'Invalid jobid list.'; const MSG_ERROR_INVALID_RPATH = 'Inputted path for restore is invalid. Proper format is b2[0-9]+.'; const MSG_ERROR_INVALID_RESTORE_PATH = 'Inputted BVFS path param is invalid.'; + const MSG_ERROR_INVALID_JOBID_LIST = 'Invalid jobid list.'; const MSG_ERROR_INVALID_FILEID_LIST = 'Invalid fileid list.'; const MSG_ERROR_INVALID_FILEINDEX_LIST = 'Invalid file index list.'; const MSG_ERROR_INVALID_DIRID_LIST = 'Invalid dirid list.'; + const MSG_ERROR_INVALID_CLIENT = 'Invalid client name.'; } class JSONToolsError extends GenericError {