]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Pages/API/JobRun.php
baculum: Assign Baculum copyright to Kern Sibbald
[bacula/bacula] / gui / baculum / protected / Pages / API / JobRun.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 JobRun extends BaculumAPI {
24
25         public function get() {}
26
27         public function create($params) {
28                 $jobid = property_exists($params, 'id') ? intval($params->id) : 0;
29                 $job = $jobid > 0 ? $this->getModule('job')->getJobById($jobid)->name : (property_exists($params, 'name') ? $params->name : null);
30                 $level = $params->level;
31                 $fileset = property_exists($params, 'fileset') ? $params->fileset : null;
32                 $clientid = property_exists($params, 'clientid') ? intval($params->clientid) : null;
33                 $client = $this->getModule('client')->getClientById($clientid);
34                 $storageid = property_exists($params, 'storageid') ? intval($params->storageid) : null;
35                 $storage = $this->getModule('storage')->getStorageById($storageid);
36                 $poolid = property_exists($params, 'poolid') ? intval($params->poolid) : null;
37                 $pool = $this->getModule('pool')->getPoolById($poolid);
38                 $priority = property_exists($params, 'priority') ? intval($params->priority) : 10; // default priority is set to 10
39                 $jobid = property_exists($params, 'jobid') ? 'jobid="' . intval($params->jobid) . '"' : '';
40                 // @TODO: Move Job name pattern in more appropriate place
41                 $verifyjob = property_exists($params, 'verifyjob')  && preg_match('/^[\w\d\.\-\s]+$/', $params->verifyjob) === 1 ? 'verifyjob="' . ($params->verifyjob) . '"' : '';
42                 
43                 if(!is_null($job)) {
44                         $isValidLevel = $this->getModule('misc')->isValidJobLevel($params->level);
45                         if($isValidLevel === true) {
46                                 if(!is_null($fileset)) {
47                                         if(!is_null($client)) {
48                                                 if(!is_null($storage)) {
49                                                         if(!is_null($pool)) {
50                                                                 $joblevels  = $this->getModule('misc')->getJobLevels();
51                                                                 $command = array(
52                                                                         'run',
53                                                                         'job="' . $job . '"',
54                                                                         'level="' . $joblevels[$level] . '"',
55                                                                         'fileset="' . $fileset . '"',
56                                                                         'client="' . $client->name . '"',
57                                                                         'storage="' . $storage->name . '"',
58                                                                         'pool="' . $pool->name . '"' ,
59                                                                         'priority="' . $priority . '"',
60                                                                         $jobid,
61                                                                         $verifyjob,
62                                                                         'yes'
63                                                                 );
64                                                                 $run = $this->getModule('bconsole')->bconsoleCommand($this->director, $command, $this->user);
65                                                                 $this->output = $run->output;
66                                                                 $this->error = (integer)$run->exitcode;
67                                                         } else {
68                                                                 $this->output = JobError::MSG_ERROR_POOLID_DOES_NOT_EXISTS;
69                                                                 $this->error = JobError::ERROR_POOLID_DOES_NOT_EXISTS;
70                                                         }
71                                                 } else {
72                                                         $this->output = JobError::MSG_ERROR_STORAGEID_DOES_NOT_EXISTS;
73                                                         $this->error = JobError::ERROR_STORAGEID_DOES_NOT_EXISTS;
74                                                 }
75                                         } else {
76                                                 $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
77                                                 $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
78                                         }
79                                 } else {
80                                         $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
81                                         $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
82                                 }
83                         } else {
84                                 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
85                                 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
86                         }
87                 } else {
88                         $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
89                         $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
90                 }
91         }
92 }
93
94 ?>