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 Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
24 Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
25 Prado::using('Application.Portlets.Portlets');
27 class PoolConfiguration extends Portlets {
29 public function configure($poolId) {
30 $pooldata = $this->Application->getModule('api')->get(array('pools', $poolId))->output;
31 $this->PoolName->Text = $pooldata->name;
32 $this->PoolID->Text = $pooldata->poolid;
33 $this->Enabled->Checked = $pooldata->enabled == 1;
34 $this->MaxVolumes->Text = $pooldata->maxvols;
35 $this->MaxVolJobs->Text = $pooldata->maxvoljobs;
36 $this->MaxVolBytes->Text = $pooldata->maxvolbytes;
37 $this->UseDuration->Text = intval($pooldata->voluseduration / 3600); // conversion to hours;
38 $this->RetentionPeriod->Text = intval($pooldata->volretention / 3600); // conversion to hours;
39 $this->LabelFormat->Text = $pooldata->labelformat;
40 $pools = $this->Application->getModule('api')->get(array('pools'))->output;
41 $poolList = array('none' => Prado::localize('select pool'));
42 foreach($pools as $pool) {
43 $poolList[$pool->poolid] = $pool->name;
45 $this->ScratchPool->dataSource = $poolList;
46 $this->ScratchPool->SelectedValue = $pooldata->scratchpoolid;
47 $this->ScratchPool->dataBind();
48 $this->RecyclePool->dataSource = $poolList;
49 $this->RecyclePool->SelectedValue = $pooldata->recyclepoolid;
50 $this->RecyclePool->dataBind();
51 $this->Recycle->Checked = $pooldata->recycle == 1;
52 $this->AutoPrune->Checked = $pooldata->autoprune == 1;
53 $this->ActionOnPurge->Checked = $pooldata->actiononpurge == 1;
56 public function restore_configuration($sender, $param) {
57 $this->Application->getModule('api')->set(array('pools', 'update', $this->PoolID->Text), array(''));
60 public function update_volumes($sender, $param) {
61 if($this->MaxVolumesValidator->IsValid === false || $this->MaxVolJobsValidator->IsValid === false || $this->MaxVolBytesValidator->IsValid === false || $this->UseDurationValidator->IsValid === false || $this->RetentionPeriodValidator->IsValid === false || $this->LabelFormatValidator->IsValid === false) {
65 $pooldata['poolid'] = $this->PoolID->Text;
66 $pooldata['enabled'] = (integer)$this->Enabled->Checked;
67 $pooldata['maxvols'] = $this->MaxVolumes->Text;
68 $pooldata['maxvoljobs'] = $this->MaxVolJobs->Text;
69 $pooldata['maxvolbytes'] = $this->MaxVolBytes->Text;
70 $pooldata['voluseduration'] = $this->UseDuration->Text * 3600; // conversion to seconds
71 $pooldata['volretention'] = $this->RetentionPeriod->Text * 3600; // conversion to seconds
72 $pooldata['labelformat'] = $this->LabelFormat->Text;
73 $pooldata['scratchpoolid'] = (integer)$this->ScratchPool->SelectedValue;
74 $pooldata['recyclepoolid'] = (integer)$this->RecyclePool->SelectedValue;
75 $pooldata['recycle'] = (integer)$this->Recycle->Checked;
76 $pooldata['autoprune'] = (integer)$this->AutoPrune->Checked;
77 $pooldata['actiononpurge'] = (integer)$this->ActionOnPurge->Checked;
78 $this->Application->getModule('api')->set(array('pools', $this->PoolID->Text), $pooldata);
79 $this->Application->getModule('api')->set(array('pools', 'update', 'volumes', $this->PoolID->Text), array(''));
82 public function apply($sender, $param) {
83 if($this->MaxVolumesValidator->IsValid === false || $this->MaxVolJobsValidator->IsValid === false || $this->MaxVolBytesValidator->IsValid === false || $this->UseDurationValidator->IsValid === false || $this->RetentionPeriodValidator->IsValid === false || $this->LabelFormatValidator->IsValid === false) {
87 $pooldata['poolid'] = $this->PoolID->Text;
88 $pooldata['enabled'] = (integer)$this->Enabled->Checked;
89 $pooldata['maxvols'] = $this->MaxVolumes->Text;
90 $pooldata['maxvoljobs'] = $this->MaxVolJobs->Text;
91 $pooldata['maxvolbytes'] = $this->MaxVolBytes->Text;
92 $pooldata['voluseduration'] = $this->UseDuration->Text * 3600; // conversion to seconds
93 $pooldata['volretention'] = $this->RetentionPeriod->Text * 3600; // conversion to seconds
94 $pooldata['labelformat'] = $this->LabelFormat->Text;
95 $pooldata['scratchpoolid'] = (integer)$this->ScratchPool->SelectedValue;
96 $pooldata['recyclepoolid'] = (integer)$this->RecyclePool->SelectedValue;
97 $pooldata['recycle'] = (integer)$this->Recycle->Checked;
98 $pooldata['autoprune'] = (integer)$this->AutoPrune->Checked;
99 $pooldata['actiononpurge'] = (integer)$this->ActionOnPurge->Checked;
100 $this->Application->getModule('api')->set(array('pools', $this->PoolID->Text), $pooldata);
104 public function maxVolumesValidator($sender, $param) {
105 $isValid = preg_match('/^\d+$/', $this->MaxVolumes->Text) && $this->MaxVolumes->Text >= 0;
106 $param->setIsValid($isValid);
109 public function maxVolJobsValidator($sender, $param) {
110 $isValid = preg_match('/^\d+$/', $this->MaxVolJobs->Text) && $this->MaxVolJobs->Text >= 0;
111 $param->setIsValid($isValid);
114 public function maxVolBytesValidator($sender, $param) {
115 $isValid = preg_match('/^\d+$/', $this->MaxVolBytes->Text) && $this->MaxVolBytes->Text >= 0;
116 $param->setIsValid($isValid);
119 public function useDurationValidator($sender, $param) {
120 $isValid = preg_match('/^\d+$/', $this->UseDuration->Text) && $this->UseDuration->Text >= 0;
121 $param->setIsValid($isValid);
124 public function retentionPeriodValidator($sender, $param) {
125 $isValid = preg_match('/^\d+$/', $this->RetentionPeriod->Text) && $this->RetentionPeriod->Text >= 0;
126 $param->setIsValid($isValid);
129 public function labelFormatValidator($sender, $param) {
130 $value = trim($this->LabelFormat->Text);
131 $isValid = !empty($value);
132 $param->setIsValid($isValid);