]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Add strip_prefix, add_prefix, add_suffix and regex_where restore options...
authorMarcin Haba <marcin.haba@bacula.pl>
Mon, 27 Nov 2017 20:02:03 +0000 (21:02 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 9 Dec 2017 11:00:34 +0000 (12:00 +0100)
gui/baculum/protected/API/Pages/API/RestoreRun.php

index c3b107d6ad05d8a8670114877e13f167f784d1b1..5a5c9837e40ebc9fda74f2203d1516ea6be46ba5 100644 (file)
@@ -25,59 +25,99 @@ Prado::using('Application.API.Class.APIDbModule');
 class RestoreRun extends BaculumAPIServer {
 
        public function create($params) {
-               $rfile = property_exists($params, 'rpath') ? $params->rpath : null;
+               $misc = $this->getModule('misc');
                $client = null;
                if (property_exists($params, 'clientid')) {
                        $clientid = intval($params->clientid);
                        $client_row = $this->getModule('client')->getClientById($clientid);
                        $client = is_object($client_row) ? $client_row->name : null;
-               } elseif (property_exists($params, 'client') && $this->getModule('misc')->isValidName($params->client)) {
+               } elseif (property_exists($params, 'client') && $misc->isValidName($params->client)) {
                        $client = $params->client;
                }
+
+               $rfile = property_exists($params, 'rpath') ? $params->rpath : null;
                $priority = property_exists($params, 'priority') ? intval($params->priority) : 10; // default priority is set to 10
                $where = property_exists($params, 'where') ? $params->where : null;
                $replace = property_exists($params, 'replace') ? $params->replace : null;
+
                $restorejob = null;
-               if (property_exists($params, 'restorejob') && $this->getModule('misc')->isValidName($params->restorejob)) {
+               if (property_exists($params, 'restorejob') && $misc->isValidName($params->restorejob)) {
                        $restorejob = $params->restorejob;
                }
-               $misc = $this->getModule('misc');
+               $strip_prefix = null;
+               if (property_exists($params, 'strip_prefix') && $misc->isValidPath($params->strip_prefix)) {
+                       $strip_prefix = $params->strip_prefix;
+               }
+               $add_prefix = null;
+               if (property_exists($params, 'add_prefix') && $misc->isValidPath($params->add_prefix)) {
+                       $add_prefix = $params->add_prefix;
+               }
+               $add_suffix = null;
+               if (property_exists($params, 'add_suffix') && $misc->isValidPath($params->add_suffix)) {
+                       $add_suffix = $params->add_suffix;
+               }
+               $regex_where = null;
+               if (property_exists($params, 'regex_where') && $misc->isValidPath($params->regex_where)) {
+                       $regex_where = $params->regex_where;
+               }
 
-               if(!is_null($client)) {
-                       if(preg_match($misc::RPATH_PATTERN, $rfile) === 1) {
-                               if(!is_null($where)) {
-                                       if(!is_null($replace)) {
-                                               $command = array('restore',
-                                                       'file="?' . $rfile . '"',
-                                                       'client="' . $client . '"',
-                                                       'where="' . $where . '"',
-                                                       'replace="' . $replace . '"',
-                                                       'priority="' . $priority . '"'
-                                               );
-                                               if (!is_null($restorejob)) {
-                                                       $command[] = 'restorejob="' . $restorejob . '"';
-                                               }
-                                               $command[] = 'yes';
-                                               $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, $command, $this->user);
-                                               $this->removeTmpRestoreTable($rfile);
-                                               $this->output = $restore->output;
-                                               $this->error = (integer)$restore->exitcode;
-                                       } else {
-                                               $this->output = JobError::MSG_ERROR_INVALID_REPLACE_OPTION;
-                                               $this->error = JobError::ERROR_INVALID_REPLACE_OPTION;
-                                       }
-                               } else {
-                                       $this->output = JobError::MSG_ERROR_INVALID_WHERE_OPTION;
-                                       $this->error = JobError::ERROR_INVALID_WHERE_OPTION;
-                               }
-                       } else {
-                               $this->output = JobError::MSG_ERROR_INVALID_RPATH;
-                               $this->error = JobError::ERROR_INVALID_RPATH;
-                       }
-               } else {
+               if(is_null($client)) {
                        $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
                        $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS;
+                       return;
+               }
+
+               if(preg_match($misc::RPATH_PATTERN, $rfile) !== 1) {
+                       $this->output = JobError::MSG_ERROR_INVALID_RPATH;
+                       $this->error = JobError::ERROR_INVALID_RPATH;
+                       return;
                }
+               if(!is_null($where) && !$misc->isValidPath($where)) {
+                       $this->output = JobError::MSG_ERROR_INVALID_WHERE_OPTION;
+                       $this->error = JobError::ERROR_INVALID_WHERE_OPTION;
+                       return;
+               }
+
+               if(!is_null($replace) && !$misc->isValidReplace($replace)) {
+                       $this->output = JobError::MSG_ERROR_INVALID_REPLACE_OPTION;
+                       $this->error = JobError::ERROR_INVALID_REPLACE_OPTION;
+                       return;
+               }
+
+               $command = array('restore',
+                       'file="?' . $rfile . '"',
+                       'client="' . $client . '"'
+               );
+
+               if (is_string($replace)) {
+                       $command[] = 'replace="' . $replace . '"';
+               }
+               if (is_int($priority)) {
+                       $command[] = 'priority="' . $priority . '"';
+               }
+               if (is_string($restorejob)) {
+                       $command[] = 'restorejob="' . $restorejob . '"';
+               }
+               if (is_string($strip_prefix)) {
+                       $command[] = 'strip_prefix="' . $strip_prefix . '"';
+               }
+               if (is_string($add_prefix)) {
+                       $command[] = 'add_prefix="' . $add_prefix . '"';
+               } elseif (is_string($where)) {
+                       $command[] = 'where="' . $where . '"';
+               }
+               if (is_string($add_suffix)) {
+                       $command[] = 'add_suffix="' . $add_suffix . '"';
+               }
+               if (is_string($regex_where)) {
+                       $command[] = 'regexwhere="' . $regex_where . '"';
+               }
+               $command[] = 'yes';
+
+               $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, $command, $this->user);
+               $this->removeTmpRestoreTable($rfile);
+               $this->output = $restore->output;
+               $this->error = (integer)$restore->exitcode;
        }
 
        private function removeTmpRestoreTable($tableName) {