]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: API endpoints code refactor
authorMarcin Haba <marcin.haba@bacula.pl>
Sat, 2 Dec 2017 15:04:40 +0000 (16:04 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 9 Dec 2017 14:06:53 +0000 (15:06 +0100)
53 files changed:
gui/baculum/protected/API/Pages/API/BVFSClearCache.php
gui/baculum/protected/API/Pages/API/BVFSGetJobids.php
gui/baculum/protected/API/Pages/API/BVFSLsDirs.php
gui/baculum/protected/API/Pages/API/BVFSLsFiles.php
gui/baculum/protected/API/Pages/API/BVFSRestore.php
gui/baculum/protected/API/Pages/API/BVFSUpdate.php
gui/baculum/protected/API/Pages/API/BVFSVersions.php
gui/baculum/protected/API/Pages/API/Catalog.php
gui/baculum/protected/API/Pages/API/Client.php
gui/baculum/protected/API/Pages/API/ClientShow.php
gui/baculum/protected/API/Pages/API/ClientStatus.php
gui/baculum/protected/API/Pages/API/Clients.php
gui/baculum/protected/API/Pages/API/ClientsShow.php
gui/baculum/protected/API/Pages/API/Config.php
gui/baculum/protected/API/Pages/API/ConsoleCommand.php
gui/baculum/protected/API/Pages/API/DbSize.php
gui/baculum/protected/API/Pages/API/Directors.php
gui/baculum/protected/API/Pages/API/FileSet.php
gui/baculum/protected/API/Pages/API/FileSets.php
gui/baculum/protected/API/Pages/API/FileSetsInfo.php
gui/baculum/protected/API/Pages/API/Job.php
gui/baculum/protected/API/Pages/API/JobCancel.php
gui/baculum/protected/API/Pages/API/JobEstimate.php
gui/baculum/protected/API/Pages/API/JobLog.php
gui/baculum/protected/API/Pages/API/JobRun.php
gui/baculum/protected/API/Pages/API/JobShow.php
gui/baculum/protected/API/Pages/API/JobTasks.php
gui/baculum/protected/API/Pages/API/JobTotals.php
gui/baculum/protected/API/Pages/API/Jobs.php
gui/baculum/protected/API/Pages/API/JobsForClient.php
gui/baculum/protected/API/Pages/API/JobsOnVolume.php
gui/baculum/protected/API/Pages/API/JobsRecent.php
gui/baculum/protected/API/Pages/API/JobsShow.php
gui/baculum/protected/API/Pages/API/Pool.php
gui/baculum/protected/API/Pages/API/PoolShow.php
gui/baculum/protected/API/Pages/API/PoolUpdate.php
gui/baculum/protected/API/Pages/API/PoolUpdateVolumes.php
gui/baculum/protected/API/Pages/API/Pools.php
gui/baculum/protected/API/Pages/API/PoolsShow.php
gui/baculum/protected/API/Pages/API/RestoreRun.php
gui/baculum/protected/API/Pages/API/Storage.php
gui/baculum/protected/API/Pages/API/StorageMount.php
gui/baculum/protected/API/Pages/API/StorageRelease.php
gui/baculum/protected/API/Pages/API/StorageShow.php
gui/baculum/protected/API/Pages/API/StorageStatus.php
gui/baculum/protected/API/Pages/API/StorageUmount.php
gui/baculum/protected/API/Pages/API/Storages.php
gui/baculum/protected/API/Pages/API/StoragesShow.php
gui/baculum/protected/API/Pages/API/Volume.php
gui/baculum/protected/API/Pages/API/VolumePrune.php
gui/baculum/protected/API/Pages/API/VolumePurge.php
gui/baculum/protected/API/Pages/API/Volumes.php
gui/baculum/protected/Common/Class/Errors.php

index 4f8da7f6096df1aa603cfaf9c4ae7f9ba1971d6d..830935b5feca16e511f6021c7a5426652c506f13 100644 (file)
@@ -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;
        }
index 51c04df6bb9dc691bf74f5600cdf18cc9a53f2a5..cff9790ce55e4ddb7e6f69f0e7eaf8cffcd46280 100644 (file)
 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;
                }
        }
 }
index b4a1c7c2c7437d252bf56f9bf645fa363e6b4456..af6e65c18ce47ed3cc37e0301aa8109264bc3c5f 100644 (file)
  
 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;
        }
 }
 ?>
index 86e63fca6afd1bdef282e8efe2c8bcc1124265d7..2970199cb3ce1eead300d1f3e57a1b78c0a012b8 100644 (file)
  
 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;
        }
 }
 ?>
index f94c1d0b9538deb49add698b7bdb853a415cbb25..7e12d94b9e3dcdf8144ab790b0a9c62c647517c0 100644 (file)
@@ -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;
        }
index 760bbb66ff2eae495029d8f7640311eb0f6ecbca..7e4fc99aab2e07619b741ff5ab7ddf14e3f384cf 100644 (file)
 
 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;
        }
 }
 ?>
index 2a1d10f190ab2556eec19ced2bbbbcf4302552d3..1d71185c1412b31282bc207dd1dfd9ed31c49d2f 100644 (file)
 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;
        }
 }
 ?>
index cfbd715c54d686ac635ea2c73e50e5907406047d..cc3499d1047a8ffd80a1f75167dbcf25dd75ee17 100644 (file)
  */
  
 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 {
index f850be892d104d57d55b80319b5bad17f28d78ea..e66eec98aaddd12db44f704944ceaa5b61188832 100644 (file)
 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;
                }
        }
 }
index eeb3e55878218f61fbf1331fbd75b9166b03d6b0..c53e89226fffee705a46439b4ec271030e90776c 100644 (file)
 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;
index cf81abe72997e4545e7c939347bbcffc905cd2f9..1a8e3618ffa7159370d4fb513193314dca281d15 100644 (file)
 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;
index 89d0fcc1fc4254b6b40aa64329a8f9f34b7421f2..329e57863caaffb3faf89e09899f245b5f2bdc8b 100644 (file)
  * 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;
                }
        }
 }
index dda7c9bd05c48a4dd0a870bc92dac6aa7b582e3c..b423562258e98a1880cc5a7fbe03366369c83df8 100644 (file)
 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;
        }
 }
 ?>
index f1c04d248c019ae2ebe9b9bb3ca89ee5a39a3f08..1cec6dfa0c77ebe010fd7c406f0d97d43c941ef3 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
index d76432e1b2ff3dee556daf90ec60a436db3ad801..bff7985e2137f602abca852201f3ff111ddd2132 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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
+?>
index acbdd36f23c5c47c19cebe67ac39ba9d96bbc61a..1dfe3ee38dcabd51da8239dcec7136e4eba5bb96 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
index 4050eea08fc2fb518ec9b2c1e47f2a952e8a4b91..b9fb3d44a71809bd0a6d503bb7bb329747c0bde0 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 
 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;
                }
        }
 }
index 73639ed0622ad6aac1cf4a033822ce23d49568a8..a47e1bd99b6e34315974facbdce26f733013772b 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 class FileSet extends BaculumAPIServer {
        public function get() {
-               $filesetid = 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;
                }
        }
 }
index c0406356428103723eed6f5628a569dc385f228a..cb59e7be922df4b17b39facc6d800136aad89fb6 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 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;
                }
        }
 }
index e361548b830e2ea949d076fdcd7eb9ba505d5650..187357db025e74634ae780903425b06ac63662f9 100644 (file)
@@ -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;
                }
        }
 }
index f81292da561b36b6f64120f34671e661c2d12632..977e127b678863c2032910de6a52b55053c416fd 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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 {
index a3d344d7310706beb77e534abc9ea89bbdd6193f..b43afce00f6cf97124ffb51f40a2e1f83580f00d 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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
+?>
index f42caada9ee8a5781d85abc01e8c699f9282c9dc..eb733c2ef8709910a17f81b4186570d840cd9441 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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;
        }
 }
 
index 46bb7aabc38cef385011d752aa04ed03c3e4507f..4b2019bc78674ef48553757ab58d22251d391bde 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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.
index 36d9436bc20ea582dfb6523e8d5f35197c5e95e7..1e10844c06974b25791bdd1a90e4d31e95c47028 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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;
        }
 }
 
index f096918f931a70278430e1adeeaaf4de1e0d61ec..793b4279efa1f5436c233ee44f7d0075a0e0700f 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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 {
                }
        }
 }
-
 ?>
index 4b83a9bcb7d50c00c893d3467d1f2f55914938dc..ba9e34ef2a206e266f815735ab9720732133efd3 100644 (file)
  
 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;
                }
        }
 }
index 29d800b7a2755ede892a703448c7b41494c014df..c69723414e5950311ed2b759faf3d8207a173c40 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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) {
index e7a7bb6b822c2b017ca6dba442b4124ad5a70bfc..b77c19e8728803ca9190e21100b7de8cf4cdee5b 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 class Jobs extends BaculumAPIServer {
        public function get() {
-               $limit = 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;
                }
        }
 }
index 99ce061d9fdcea06118009cee3fc21e042458b0e..e3f514cbbe8bfd9636238c0f20cb4561bc993b25 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  */
  
 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;
                }
index 8c3b509e49867f85eb2e0134b62d318b7fbca9e3..ab52b1010d840bc1e05c25b8ae104eec3bb0be60 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 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) {
index 9048c029c8ac38fe68aa3e1d4d2414b9af5fba05..5e04234963edd65ce02b79abaaf5be4bca6bed1f 100644 (file)
@@ -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']);
index 216857ccc5bf31551b953b374abfc3d27359d527..e7cbb925de211305c7f00186c5f394e20d92c704 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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;
        }
 }
 
index 3148f836ac26ea5f02c1a36b2cbed16df17fac56..90b03074c571b7ca73601553284084ca409619df 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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;
index cdfc6bb9656eae5cafedd2917b371df9eaaa9854..ae3af1f836dbf2cf66e41281a933d8f82b1eade2 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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
+?>
index 394f82ad744f66c91cdea4c4c6527b178373b764..300e8d090ed61e9b3c4b2fd4299f103b2c116308 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 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;
index d18a52721c09f61b4e946acd32b8bca86b083b28..08152fe8cece07a3c6655bdce78477262bf318b4 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 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
+?>
index e418de9bbd98a32c6ab1d3c4b3f258a06e47c45c..da3784fb1f1b16e0baa16a413bc04b01673ac77f 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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;
                }
        }
 }
index 2d40a5f4321182fb06c924cc9941db2ce12d1810..64747149ee4d088f3a9f9e5c23aff543d2939f6a 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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;
        }
 }
 ?>
index 5a5c9837e40ebc9fda74f2203d1516ea6be46ba5..b01d138c3fc50b9481a405f9c722f51486f910ff 100644 (file)
@@ -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) {
index 47d212c13e093635c2e4a88a68b8b1b9a9461cb6..6c1d3a121480d0f3b66d93bf6d33e76b2402dbf0 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 class Storage extends BaculumAPIServer {
        public function get() {
-               $storageid = 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;
                }
        }
 }
index c62ae9f2767d582b360dd3f475c3b481a501421e..80c777419320bc97a51bfb0d20bf3951b55687ac 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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
+?>
index 5e61e5a076419577eb5609b958b03d8d121589da..c975e9b7e806a7fb6f0ff34d4b449371a6798c22 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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;
index 0d4997170964e0be5c806234c02f05f258cf27e9..cc7c81b6eb90f75f78fb8d67c3ead01153be56bc 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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
+?>
index b449e3bae48abad5b25dc079a8ba1f8483f0eaf1..f96bd248f87f5792546804e7e8ff5574a9d7a208 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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
+?>
index 82d383f3b40242c89ec0292e171ea50b718bc8e8..2a58bcd008ce716b2cbfe719e3de3ba548d2580a 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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
+?>
index 1065b51dab2103c25dea3cf32e0f88831daf9b67..dedc77fe356b9d319dd0ecc903d488caf3ef5f6d 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
 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;
                }
        }
 }
index ea8fb01601085f0505240b0b7ab674b5a647397c..17357d3ee7de2e3df0e98f82c05ee08a779cbfb3 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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;
        }
 }
 ?>
index aa569afff75221f83b7df226d88121520bcbc212..c4ea347e1f57b6f1bee898ec9f3893aeec1f5d0a 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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);
index 283a996d2cdfa5128a649e6069c67d15bc8c8afe..fe22c65781cd379810a59b6036ec165f583a2f69 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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
+?>
index 6ffef758e82e298868c3d63ae6016be1b60511a6..9ac876e9738fbde02d427cd528e1bbb5dbd697b8 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-2017 Kern Sibbald
  *
  * The main author of Baculum is Marcin Haba.
  * The original author of Bacula is Kern Sibbald, with contributions
  
 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
+?>
index 565ebe5108628ee25ea39116899be75801296fd9..1572a6636cfeefeb5201cf0bc8ad538cf66bc1e1 100644 (file)
@@ -3,7 +3,7 @@
  * Bacula(R) - The Network Backup Solution
  * Baculum   - Bacula web interface
  *
- * Copyright (C) 2013-2016 Kern Sibbald
+ * Copyright (C) 2013-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;
        }
 }
index b0b7304f7c362000356c173d1ea36f0bcc4c3fe2..7844a3c4b58276ea67ab082de048c574019d7ea0 100644 (file)
@@ -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 {