*/
class BVFSRestore extends BaculumAPIServer {
+
public function create($params) {
+ $misc = $this->getModule('misc');
$jobids = property_exists($params, 'jobids') ? $params->jobids : null;
$fileids = property_exists($params, 'fileid') ? $params->fileid : null;
$dirids = property_exists($params, 'dirid') ? $params->dirid : null;
+ $findexes = property_exists($params, 'findex') ? $params->findex : null;
$path = property_exists($params, 'path') ? $params->path : null;
- $is_valid = true;
- if (!is_null($jobids)) {
- $jobidsList = explode(',', $jobids);
- if(is_array($jobidsList)) {
- for($i = 0; $i < count($jobidsList); $i++) {
- $job = $this->getModule('job')->getJobById($jobidsList[$i]);
- if(is_null($job)) {
- $is_valid = false;
- break;
- }
- }
- } else {
- $is_valid = false;
- }
- } else {
- $is_valid = false;
+ if (!is_null($jobids) && !$misc->isValidIdsList($jobids)) {
+ $this->output = BVFSError::MSG_ERROR_INVALID_JOBID_LIST;
+ $this->error = BVFSError::ERROR_INVALID_JOBID_LIST;
+ return;
+ }
+ if (!is_null($fileids) && !$misc->isValidIdsList($fileids)) {
+ $this->output = BVFSError::MSG_ERROR_INVALID_FILEID_LIST;
+ $this->error = BVFSError::ERROR_INVALID_FILEID_LIST;
+ return;
+ }
+ if (!is_null($dirids) && !$misc->isValidIdsList($dirids)) {
+ $this->output = BVFSError::MSG_ERROR_INVALID_DIRID_LIST;
+ $this->error = BVFSError::ERROR_INVALID_DIRID_LIST;
+ return;
+ }
+ if (!is_null($findexes) && !$misc->isValidIdsList($findexes)) {
+ $this->output = BVFSError::MSG_ERROR_INVALID_FILEINDEX_LIST;
+ $this->error = BVFSError::ERROR_INVALID_FILEINDEX_LIST;
+ return;
}
- if($is_valid === true) {
- if(!is_null($path)) {
- $cmd = array('.bvfs_restore', 'jobid="' . $jobids . '"', 'path="' . $path . '"');
- if(!is_null($fileids)) {
- array_push($cmd, 'fileid="' . $fileids . '"');
- }
- if(!is_null($dirids)) {
- array_push($cmd, 'dirid="' . $dirids . '"');
- }
+ if (!is_null($path) && !$misc->isValidBvfsPath($path)) {
+ $this->output = BVFSError::MSG_ERROR_INVALID_RPATH;
+ $this->error = BVFSError::ERROR_INVALID_RPATH;
+ return;
+ }
- $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user);
- $this->output = $result->output;
- $this->error = $result->exitcode;
- } else {
- $this->output = BVFSError::MSG_ERROR_INVALID_RPATH;
- $this->error = BVFSError::ERROR_INVALID_RPATH;
- }
- } else {
- $this->output = BVFSError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
- $this->error = BVFSError::ERROR_JOB_DOES_NOT_EXISTS;
+ $cmd = array('.bvfs_restore', 'jobid="' . $jobids . '"', 'path="' . $path . '"');
+ if (is_string($fileids)) {
+ array_push($cmd, 'fileid="' . $fileids . '"');
+ }
+ if (is_string($dirids)) {
+ array_push($cmd, 'dirid="' . $dirids . '"');
}
+ if (is_string($findexes)) {
+ array_push($cmd, 'hardlink="' . $findexes . '"');
+ }
+
+ $result = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user);
+ $this->output = $result->output;
+ $this->error = $result->exitcode;
}
}
?>
'd' => 'DiskToCatalog'
);
- private $jobStates = array(
+ public $jobStates = array(
'C' => array('value' => 'Created', 'description' =>'Created but not yet running'),
'R' => array('value' => 'Running', 'description' => 'Running'),
'B' => array('value' => 'Blocked', 'description' => 'Blocked'),
'bcons' => array('full_name' => 'Console', 'main_resource' => 'Director')
);
+ private $replace_opts = array(
+ 'always',
+ 'ifnewer',
+ 'ifolder',
+ 'never'
+ );
+
+
/**
* Getting the licence from file.
*
return $statesByType;
}
+ /*
+ * @TODO: Move it to separate validation module.
+ */
public function isValidJobLevel($jobLevel) {
return array_key_exists($jobLevel, $this->getJobLevels());
}
return (preg_match('/^[\w:\.\-\s]{1,127}$/', $name) === 1);
}
+ public function isValidPath($path) {
+ return (preg_match('/^[\p{L}\p{N}\p{Z}\[\]\(\)\-\+\/\\\:\.#~_,{}!]{1,1000}$/', $path) === 1);
+ }
+
+ public function isValidReplace($replace) {
+ return in_array($replace, $this->replace_opts);
+ }
+
+ public function isValidIdsList($list) {
+ return (preg_match('/^[\d,]+$/', $list) === 1);
+ }
+
+ public function isValidBvfsPath($path) {
+ return (preg_match('/^b2\d+$/', $path) === 1);
+ }
+
/**
* Writing INI-style configuration file.
*
$base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
$lstat = trim($lstat);
$lstat_fields = explode(' ', $lstat);
-
- if(count($lstat_fields) !== 16) {
- die('Błąd! Niepoprawna ilość pól wartości LStat. Proszę upewnić się, że podany ciąg znaków jest poprawną wartością LStat');
+ $lstat_len = count($lstat_fields);
+ if ($lstat_len < 16) {
+ // not known or empty lstat value
+ return;
+ } elseif ($lstat_len > 16) {
+ // cut off unknown fields
+ array_splice($lstat_fields, 16);
}
- list($dev, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $blocksize, $blocks, $atime, $mtime, $ctime, $linkfi, $flags, $data) = $lstat_fields;
- $encoded_values = array('dev' => $dev, 'inode' => $inode, 'mode' => $mode, 'nlink' => $nlink, 'uid' => $uid, 'gid' => $gid, 'rdev' => $rdev, 'size' => $size, 'blocksize' => $blocksize, 'blocks' => $blocks, 'atime' => $atime, 'mtime' => $mtime, 'ctime' => $ctime, 'linkfi' => $linkfi, 'flags' => $flags, 'data' => $data);
+ list(
+ $dev,
+ $inode,
+ $mode,
+ $nlink,
+ $uid,
+ $gid,
+ $rdev,
+ $size,
+ $blocksize,
+ $blocks,
+ $atime,
+ $mtime,
+ $ctime,
+ $linkfi,
+ $flags,
+ $data
+ ) = $lstat_fields;
+ $encoded_values = array(
+ 'dev' => $dev,
+ 'inode' => $inode,
+ 'mode' => $mode,
+ 'nlink' => $nlink,
+ 'uid' => $uid,
+ 'gid' => $gid,
+ 'rdev' => $rdev,
+ 'size' => $size,
+ 'blocksize' => $blocksize,
+ 'blocks' => $blocks,
+ 'atime' => $atime,
+ 'mtime' => $mtime,
+ 'ctime' => $ctime,
+ 'linkfi' => $linkfi,
+ 'flags' => $flags,
+ 'data' => $data
+ );
$ret = array();
foreach($encoded_values as $key => $val) {
} elseif($match['name'] != '..') {
$match['name'] .= '/';
}
- $elements[] = array('pathid' => $match['pathid'], 'filenameid' => $match['filenameid'], 'fileid' => $match['fileid'], 'jobid' => $match['jobid'], 'lstat' => $match['lstat'], 'name' => $match['name'], 'type' => 'dir');
+ $elements[] = array(
+ 'pathid' => $match['pathid'],
+ 'filenameid' => $match['filenameid'],
+ 'fileid' => $match['fileid'],
+ 'jobid' => $match['jobid'],
+ 'lstat' => $this->decode_bacula_lstat($match['lstat']),
+ 'name' => $match['name'],
+ 'type' => 'dir'
+ );
} elseif(preg_match('/^(?P<pathid>\d+)\t(?P<filenameid>\d+)\t(?P<fileid>\d+)\t(?P<jobid>\d+)\t(?P<lstat>[a-zA-z0-9\+\/\ ]+)\t(?P<name>[^\/]+)$/', $list[$i], $match) == 1) {
if($match['name'] == '.') {
continue;
}
- $elements[] = array('pathid' => $match['pathid'], 'filenameid' => $match['filenameid'], 'fileid' => $match['fileid'], 'jobid' => $match['jobid'], 'lstat' => $match['lstat'], 'name' => $match['name'], 'type' => 'file');
+ $elements[] = array(
+ 'pathid' => $match['pathid'],
+ 'filenameid' => $match['filenameid'],
+ 'fileid' => $match['fileid'],
+ 'jobid' => $match['jobid'],
+ 'lstat' => $this->decode_bacula_lstat($match['lstat']),
+ 'name' => $match['name'],
+ 'type' => 'file'
+ );
}
}
usort($elements, 'sortFilesListByName');
$elements = array();
for($i = 0; $i < count($list); $i++) {
if(preg_match('/^(?P<pathid>\d+)\t(?P<filenameid>\d+)\t(?P<fileid>\d+)\t(?P<jobid>\d+)\t(?P<lstat>[a-zA-Z0-9\+\/\ ]+)\t(?P<md5>.+)\t(?P<volname>.+)\t(?P<inchanger>\d+)$/', $list[$i], $match) == 1) {
- $elements[$match['fileid']] = array('name' => $filename, 'pathid' => $match['pathid'], 'filenameid' => $match['filenameid'], 'fileid' => $match['fileid'], 'jobid' => $match['jobid'], 'lstat' => $this->decode_bacula_lstat($match['lstat']), 'md5' => $match['md5'], 'volname' => $match['volname'], 'inchanger' => $match['inchanger'], 'type' => 'file');
+ $elements[$match['fileid']] = array(
+ 'name' => $filename,
+ 'pathid' => $match['pathid'],
+ 'filenameid' => $match['filenameid'],
+ 'fileid' => $match['fileid'],
+ 'jobid' => $match['jobid'],
+ 'lstat' => $this->decode_bacula_lstat($match['lstat']),
+ 'md5' => $match['md5'],
+ 'volname' => $match['volname'],
+ 'inchanger' => $match['inchanger'],
+ 'type' => 'file'
+ );
}
}
return $elements;