]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/API/Pages/API/JobEstimate.php
f42caada9ee8a5781d85abc01e8c699f9282c9dc
[bacula/bacula] / gui / baculum / protected / API / Pages / API / JobEstimate.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 Kern Sibbald
7  *
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.
11  *
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.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22  
23 class JobEstimate extends BaculumAPIServer {
24
25         public function create($params) {
26                 $job = null;
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)) {
32                         $job = $params->name;
33                 }
34                 $level = null;
35                 if (property_exists($params, 'level')) {
36                         $level = $params->level;
37                 }
38                 $fileset = null;
39                 if (property_exists($params, 'fileset') && $this->getModule('misc')->isValidName($params->fileset)) {
40                         $fileset = $params->fileset;
41                 }
42                 $client = null;
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;
49                 }
50                 $accurate = null;
51                 if (property_exists($params, 'accurate')) {
52                         $accurate_job = intval($params->accurate);
53                         $accurate = $accurate_job === 1 ? 'yes' : 'no';
54                 }
55
56                 if (!is_null($job)) {
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();
62                                                 $cmd = array(
63                                                         'estimate',
64                                                         'job="' . $job . '"',
65                                                         'level="' . $joblevels[$level] . '"',
66                                                         'fileset="' . $fileset. '"',
67                                                         'client="' . $client . '"',
68                                                         'accurate="' . $accurate . '"'
69                                                 );
70                                                 $estimation = $this->getModule('bconsole')->bconsoleCommand($this->director, $cmd, $this->user);
71                                                 $this->output = $estimation->output;
72                                                 $this->error = (integer)$estimation->exitcode;
73                                         } else {
74                                                 $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
75                                                 $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS;
76                                         }
77                                 } else {
78                                         $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS;
79                                         $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS;
80                                 }
81                         } else {
82                                 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
83                                 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
84                         }
85                 } else {
86                         $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
87                         $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
88                 }
89         }
90 }
91
92 ?>