]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Pages/ConfigurationWizard.php
Add Baculum
[bacula/bacula] / gui / baculum / protected / Pages / ConfigurationWizard.php
1 <?php
2 /**
3  * Bacula® - The Network Backup Solution
4  * Baculum - Bacula web interface
5  *
6  * Copyright (C) 2013-2014 Marcin Haba
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The main author of Bacula is Kern Sibbald, with contributions from many
10  * 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  * Bacula® is a registered trademark of Kern Sibbald.
18  */
19  
20 Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList');
21 Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
22 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
23 Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
24 Prado::using('System.Web.UI.ActiveControls.TActiveButton');
25 Prado::using('System.Web.UI.ActiveControls.TActiveImage');
26 Prado::using('System.Web.UI.ActiveControls.TActiveTableCell');
27
28 class ConfigurationWizard extends BaculumPage
29 {
30         public $firstRun;
31         public $applicationConfig;
32
33         const DEFAULT_DB_NAME = 'bacula';
34         const DEFAULT_DB_LOGIN = 'bacula';
35         const DEFAULT_BCONSOLE_BIN = '/usr/sbin/bconsole';
36         const DEFAULT_BCONSOLE_CONF = '/etc/bacula/bconsole.conf';
37
38         public function onInit($param) {
39                 parent::onInit($param);
40                 $this->Lang->SelectedValue = $this->Session['language'];
41                 $this->firstRun = !$this->getModule('configuration')->isApplicationConfig();
42                 $this->applicationConfig = $this->getModule('configuration')->getApplicationConfig();
43         }
44
45         public function onLoad($param) {
46                 parent::onLoad($param);
47                 $this->Licence->Text = $this->getModule('misc')->getLicence();
48                 $this->Port->setViewState('port', $this->Port->Text);
49                 if(!$this->IsPostBack && !$this->IsCallBack) {
50                         if($this->firstRun === true) {
51                                 $this->DBName->Text = self::DEFAULT_DB_NAME;
52                                 $this->Login->Text = self::DEFAULT_DB_LOGIN;
53                                 $this->BconsolePath->Text = self::DEFAULT_BCONSOLE_BIN;
54                                 $this->BconsoleConfigPath->Text = self::DEFAULT_BCONSOLE_CONF;
55                         } else {
56                                 $this->DBType->SelectedValue = $this->getPage()->applicationConfig['db']['type'];
57                                 $this->DBName->Text = $this->applicationConfig['db']['name'];
58                                 $this->Login->Text = $this->applicationConfig['db']['login'];
59                                 $this->Password->Text = $this->applicationConfig['db']['password'];
60                                 $this->IP->Text = $this->applicationConfig['db']['ip_addr'];
61                                 $this->Port->Text = $this->applicationConfig['db']['port'];
62                                 $this->Port->setViewState('port', $this->applicationConfig['db']['port']);
63                                 $this->DBPath->Text = $this->applicationConfig['db']['path'];
64                                 $this->BconsolePath->Text = $this->applicationConfig['bconsole']['bin_path'];
65                                 $this->BconsoleConfigPath->Text = $this->applicationConfig['bconsole']['cfg_path'];
66                                 $this->UseSudo->Checked = $this->getPage()->applicationConfig['bconsole']['use_sudo'] == 1;
67                                 $this->PanelLogin->Text = $this->applicationConfig['baculum']['login'];
68                                 $this->PanelPassword->Text = $this->applicationConfig['baculum']['password'];
69                                 $this->RetypePanelPassword->Text = $this->applicationConfig['baculum']['password'];
70                         }
71                 }
72         }
73
74         public function NextStep($sender, $param) {
75         }
76         
77         public function PreviousStep($sender, $param) {
78         }
79
80         public function wizardStop($sender, $param) {
81                 $this->goToDefaultPage();
82         }
83
84         public function wizardCompleted() {
85                 $cfgData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
86                 $cfgData['db']['type'] = $this->DBType->SelectedValue;
87                 $cfgData['db']['name'] = $this->DBName->Text;
88                 $cfgData['db']['login'] = $this->Login->Text;
89                 $cfgData['db']['password'] = $this->Password->Text;
90                 $cfgData['db']['ip_addr'] = $this->IP->Text;
91                 $cfgData['db']['port'] = $this->Port->Text;
92                 $cfgData['db']['path'] = $this->Application->getModule('configuration')->isSQLiteType($cfgData['db']['type']) ? $this->DBPath->Text : '';
93                 $cfgData['bconsole']['bin_path'] = $this->BconsolePath->Text;
94                 $cfgData['bconsole']['cfg_path'] = $this->BconsoleConfigPath->Text;
95                 $cfgData['bconsole']['use_sudo'] = (integer)($this->UseSudo->Checked === true);
96                 $cfgData['baculum']['login'] = $this->PanelLogin->Text;
97                 $cfgData['baculum']['password'] = $this->PanelPassword->Text;
98                 $cfgData['baculum']['debug'] = isset($this->applicationConfig['baculum']['debug']) ? $this->applicationConfig['baculum']['debug'] : "0";
99                 $ret = $this->getModule('configuration')->setApplicationConfig($cfgData);
100                 if($ret === true) {
101                         $this->goToDefaultPage();
102                 }
103         }
104
105         public function setDBType($sender, $param) {
106                 $db = $this->DBType->SelectedValue;
107                 $this->setLogin($db);
108                 $this->setPassword($db);
109                 $this->setIP($db);
110                 $this->setDefaultPort($db);
111                 $this->setDBPath($db);
112         }
113
114         public function setLogin($db) {
115                 $this->Login->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
116         }
117
118         public function setPassword($db) {
119                 $this->Password->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
120         }
121
122         public function setIP($db) {
123                 $this->IP->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
124         }
125
126         public function setDefaultPort($db) {
127                 $configuration = $this->Application->getModule('configuration');
128                 $port = null;
129                 if($configuration->isPostgreSQLType($db) === true) {
130                         $port = $configuration::PGSQL_PORT;
131                 } elseif($configuration->isMySQLType($db) === true) {
132                         $port = $configuration::MYSQL_PORT;
133                 } elseif($configuration->isSQLiteType($db) === true) {
134                         $port = $configuration::SQLITE_PORT;
135                 }
136
137                 $prevPort = $this->Port->getViewState('port');
138
139                 if(is_null($port)) {
140                         $this->Port->Text = '';
141                         $this->Port->Enabled = false;
142                 } else {
143                         $this->Port->Enabled = true;
144                         $this->Port->Text = (empty($prevPort)) ? $port : $prevPort;
145                 }
146                 $this->Port->setViewState('port', '');
147         }
148
149         public function setDBPath($db) {
150                 if($this->getModule('configuration')->isSQLiteType($db) === true) {
151                         $this->DBPath->Enabled = true;
152                         $this->DBPathField->Display = 'Fixed';
153                 } else {
154                         $this->DBPath->Enabled = false;
155                         $this->DBPathField->Display = 'Hidden';
156                 }
157         }
158
159         public function setLang($sender, $param) {
160                 $this->Session['language'] = $sender->SelectedValue;
161                 $this->goToPage('ConfigurationWizard');
162         }
163
164         public function validateAdministratorPassword($sender, $param) {
165                 $sender->Display = ($this->RetypePasswordRequireValidator->IsValid === true && $this->RetypePasswordRegexpValidator->IsValid === true) ? 'Dynamic' : 'None';
166                 $param->IsValid = ($param->Value === $this->PanelPassword->Text);
167         }
168
169          public function renderPanel($sender, $param) {
170                 $this->LoginValidator->Display = ($this->Login->Enabled === true) ? 'Dynamic' : 'None';
171                 $this->PortValidator->Display = ($this->Port->Enabled === true) ? 'Dynamic' : 'None';
172                 $this->IPValidator->Display = ($this->IP->Enabled === true) ? 'Dynamic' : 'None';
173                 $this->DBPathValidator->Display = ($this->DBPath->Enabled === true) ? 'Dynamic' : 'None';
174                 $this->DbTestResultOk->Display = 'None';
175                 $this->DbTestResultErr->Display = 'None';
176                 $this->Step2Content->render($param->NewWriter);
177         }
178         
179         public function connectionDBTest($sender, $param) {
180                 $validation = false;
181                 $configuration = $this->getModule('configuration');
182                 $dbParams = array();
183                 $dbParams['type'] = $this->DBType->SelectedValue;
184                 if($configuration->isMySQLType($dbParams['type']) === true || $configuration->isPostgreSQLType($dbParams['type']) === true) {
185                         $dbParams['name'] = $this->DBName->Text;
186                         $dbParams['login'] = $this->Login->Text;
187                         $dbParams['password'] = $this->Password->Text;
188                         $dbParams['host'] = $this->IP->Text;
189                         $dbParams['port'] = $this->Port->Text;
190                         $validation = true;
191                 } elseif($configuration->isSQLiteType($dbParams['type']) === true && !empty($this->DBPath->Text)) {
192                         $dbParams['path'] = $this->DBPath->Text;
193                         $validation = true;
194                 }
195                 
196                 $isValidate = ($validation === true) ? $this->getModule('db')->testDbConnection($dbParams) : false;
197                 $this->DbTestResultOk->Display = ($isValidate === true) ? 'Dynamic' : 'None';
198                 $this->DbTestResultErr->Display = ($isValidate === false) ? 'Dynamic' : 'None';
199                 $this->Step2Content->render($param->NewWriter);
200
201         }
202
203         public function connectionBconsoleTest($sender, $param) {
204                 $result = $this->getModule('bconsole')->testBconsoleCommand(array('version'), $this->BconsolePath->Text, $this->BconsoleConfigPath->Text, $this->UseSudo->Checked)->exitcode;
205                 $isValidate = ($result === 0);
206                 $this->BconsoleTestResultOk->Display = ($isValidate === true) ? 'Dynamic' : 'None';
207                 $this->BconsoleTestResultErr->Display = ($isValidate === false) ? 'Dynamic' : 'None';
208                 $this->Step4Content->render($param->NewWriter);
209         }
210 }
211 ?>