3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2017 Kern Sibbald
8 * The main author of Baculum is Marcin Haba.
9 * The original author of Bacula is Kern Sibbald, with contributions
10 * from many others, a complete list can be found in the file AUTHORS.
12 * You may use this file and others of this release according to the
13 * license defined in the LICENSE file, which includes the Affero General
14 * Public License, v3.0 ("AGPLv3") and some additional permissions and
15 * terms pursuant to its AGPLv3 Section 7.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 class JobRun extends BaculumAPIServer {
25 public function create($params) {
27 if (property_exists($params, 'id')) {
28 $jobid = intval($params->id);
29 $job_row = $this->getModule('job')->getJobById($jobid);
30 $job = is_object($job_row) ? $job_row->name : null;
31 } elseif (property_exists($params, 'name') && $this->getModule('misc')->isValidName($params->name)) {
35 if (property_exists($params, 'level')) {
36 $level = $params->level;
39 if (property_exists($params, 'fileset') && $this->getModule('misc')->isValidName($params->fileset)) {
40 $fileset = $params->fileset;
43 if (property_exists($params, 'clientid')) {
44 $clientid = intval($params->clientid);
45 $client_row = $this->getModule('client')->getClientById($clientid);
46 $client = is_object($client_row) ? $client_row->name : null;
47 } elseif (property_exists($params, 'client') && $this->getModule('misc')->isValidName($params->client)) {
48 $client = $params->client;
51 if (property_exists($params, 'storageid')) {
52 $storageid = intval($params->storageid);
53 $storage_row = $this->getModule('storage')->getStorageById($storageid);
54 $storage = is_object($storage_row) ? $storage_row->name : null;
55 } elseif (property_exists($params, 'storage') && $this->getModule('misc')->isValidName($params->storage)) {
56 $storage = $params->storage;
59 if (property_exists($params, 'poolid')) {
60 $poolid = intval($params->poolid);
61 $pool_row = $this->getModule('pool')->getPoolById($poolid);
62 $pool = is_object($pool_row) ? $pool_row->name : null;
63 } elseif (property_exists($params, 'pool') && $this->getModule('misc')->isValidName($params->pool)) {
64 $pool = $params->pool;
66 $priority = property_exists($params, 'priority') ? intval($params->priority) : 10; // default priority is set to 10
68 $jobid = property_exists($params, 'jobid') ? 'jobid="' . intval($params->jobid) . '"' : '';
70 if (property_exists($params, 'verifyjob') && $this->getModule('misc')->isValidName($params->verifyjob)) {
71 $verifyjob = 'verifyjob="' . $params->verifyjob . '"';
75 $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
76 $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
80 $is_valid_level = $this->getModule('misc')->isValidJobLevel($params->level);
81 if(!$is_valid_level) {
82 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
83 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
87 if(is_null($fileset)) {
88 $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
89 $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS;
93 if(is_null($client)) {
94 $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
95 $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS;
99 if(is_null($storage)) {
100 $this->output = JobError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS;
101 $this->error = JobError::ERROR_STORAGE_DOES_NOT_EXISTS;
106 $this->output = JobError::MSG_ERROR_POOL_DOES_NOT_EXISTS;
107 $this->error = JobError::ERROR_POOL_DOES_NOT_EXISTS;
111 $joblevels = $this->getModule('misc')->getJobLevels();
114 'job="' . $job . '"',
115 'level="' . $joblevels[$level] . '"',
116 'fileset="' . $fileset . '"',
117 'client="' . $client . '"',
118 'storage="' . $storage . '"',
119 'pool="' . $pool . '"' ,
120 'priority="' . $priority . '"',
125 $run = $this->getModule('bconsole')->bconsoleCommand($this->director, $command);
126 $this->output = $run->output;
127 $this->error = $run->exitcode;