]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/baculum/protected/API/Pages/API/Volume.php
baculum: API endpoints code refactor
[bacula/bacula] / gui / baculum / protected / API / Pages / API / Volume.php
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);