3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 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 JobEstimate 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, 'accurate')) {
52 $accurate_job = intval($params->accurate);
53 $accurate = $accurate_job === 1 ? 'yes' : 'no';
57 $is_valid_level = $this->getModule('misc')->isValidJobLevel($params->level);
58 if ($is_valid_level === true) {
59 if (!is_null($fileset)) {
60 if (!is_null($client)) {
61 $joblevels = $this->getModule('misc')->getJobLevels();
65 'level="' . $joblevels[$level] . '"',
66 'fileset="' . $fileset. '"',
67 'client="' . $client . '"',
68 'accurate="' . $accurate . '"'
70 $estimation = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user);
71 $this->output = $estimation->output;
72 $this->error = (integer)$estimation->exitcode;
74 $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
75 $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS;
78 $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
79 $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS;
82 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
83 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
86 $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
87 $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;