]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Pages/ConfigurationWizard.php
baculum: Tweak change license statements
[bacula/bacula] / gui / baculum / protected / Pages / ConfigurationWizard.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2015 Marcin Haba
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 Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList');
24 Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
25 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
26 Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
27 Prado::using('System.Web.UI.ActiveControls.TActiveButton');
28 Prado::using('System.Web.UI.ActiveControls.TActiveImage');
29 Prado::using('System.Web.UI.ActiveControls.TActiveTableCell');
30
31 class ConfigurationWizard extends BaculumPage
32 {
33         public $firstRun;
34         public $applicationConfig;
35
36         const DEFAULT_DB_NAME = 'bacula';
37         const DEFAULT_DB_LOGIN = 'bacula';
38         const DEFAULT_BCONSOLE_BIN = '/usr/sbin/bconsole';
39         const DEFAULT_BCONSOLE_CONF = '/etc/bacula/bconsole.conf';
40         const DEFAULT_BCONSOLE_CONF_CUSTOM = '/etc/bacula/bconsole-{user}.conf';
41
42         public function onInit($param) {
43                 parent::onInit($param);
44                 $this->Lang->SelectedValue = $_SESSION['language'];
45                 $this->firstRun = !$this->getModule('configuration')->isApplicationConfig();
46                 $this->applicationConfig = $this->getModule('configuration')->getApplicationConfig();
47                 if($this->firstRun === false && $this->User->getIsAdmin() === false) {
48                         die('Access denied.');
49                 }
50         }
51
52         public function onLoad($param) {
53                 parent::onLoad($param);
54                 $this->Licence->Text = $this->getModule('misc')->getLicence();
55                 $this->Port->setViewState('port', $this->Port->Text);
56                 if(!$this->IsPostBack && !$this->IsCallBack) {
57                         if($this->firstRun === true) {
58                                 $this->DBName->Text = self::DEFAULT_DB_NAME;
59                                 $this->Login->Text = self::DEFAULT_DB_LOGIN;
60                                 $this->BconsolePath->Text = self::DEFAULT_BCONSOLE_BIN;
61                                 $this->BconsoleConfigPath->Text = self::DEFAULT_BCONSOLE_CONF;
62                                 $this->BconsoleConfigCustomPath->Text = self::DEFAULT_BCONSOLE_CONF_CUSTOM;
63                         } else {
64                                 $this->DBType->SelectedValue = $this->getPage()->applicationConfig['db']['type'];
65                                 $this->DBName->Text = $this->applicationConfig['db']['name'];
66                                 $this->Login->Text = $this->applicationConfig['db']['login'];
67                                 $this->Password->Text = $this->applicationConfig['db']['password'];
68                                 $this->IP->Text = $this->applicationConfig['db']['ip_addr'];
69                                 $this->Port->Text = $this->applicationConfig['db']['port'];
70                                 $this->Port->setViewState('port', $this->applicationConfig['db']['port']);
71                                 $this->DBPath->Text = $this->applicationConfig['db']['path'];
72                                 $this->BconsolePath->Text = $this->applicationConfig['bconsole']['bin_path'];
73                                 $this->BconsoleConfigPath->Text = $this->applicationConfig['bconsole']['cfg_path'];
74                                 $this->BconsoleConfigCustomPath->Text = array_key_exists('cfg_custom_path', $this->applicationConfig['bconsole']) ? $this->applicationConfig['bconsole']['cfg_custom_path'] : self::DEFAULT_BCONSOLE_CONF_CUSTOM;
75                                 $this->UseSudo->Checked = $this->getPage()->applicationConfig['bconsole']['use_sudo'] == 1;
76                                 $this->PanelLogin->Text = $this->applicationConfig['baculum']['login'];
77                                 $this->PanelPassword->Text = $this->applicationConfig['baculum']['password'];
78                                 $this->RetypePanelPassword->Text = $this->applicationConfig['baculum']['password'];
79                         }
80                 }
81         }
82
83         public function NextStep($sender, $param) {
84         }
85         
86         public function PreviousStep($sender, $param) {
87         }
88
89         public function wizardStop($sender, $param) {
90                 $this->goToDefaultPage();
91         }
92
93         public function wizardCompleted() {
94                 $cfgData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
95                 $cfgData['db']['type'] = $this->DBType->SelectedValue;
96                 $cfgData['db']['name'] = $this->DBName->Text;
97                 $cfgData['db']['login'] = $this->Login->Text;
98                 $cfgData['db']['password'] = $this->Password->Text;
99                 $cfgData['db']['ip_addr'] = $this->IP->Text;
100                 $cfgData['db']['port'] = $this->Port->Text;
101                 $cfgData['db']['path'] = $this->Application->getModule('configuration')->isSQLiteType($cfgData['db']['type']) ? $this->DBPath->Text : '';
102                 $cfgData['bconsole']['bin_path'] = $this->BconsolePath->Text;
103                 $cfgData['bconsole']['cfg_path'] = $this->BconsoleConfigPath->Text;
104                 $cfgData['bconsole']['cfg_custom_path'] = $this->BconsoleConfigCustomPath->Text;
105                 $cfgData['bconsole']['use_sudo'] = (integer)($this->UseSudo->Checked === true);
106                 $cfgData['baculum']['login'] = $this->PanelLogin->Text;
107                 $cfgData['baculum']['password'] = $this->PanelPassword->Text;
108                 $cfgData['baculum']['debug'] = isset($this->applicationConfig['baculum']['debug']) ? $this->applicationConfig['baculum']['debug'] : "0";
109                 $cfgData['baculum']['lang'] = $_SESSION['language'];
110                 $ret = $this->getModule('configuration')->setApplicationConfig($cfgData);
111                 if($ret === true) {
112                         if($this->getModule('configuration')->isUsersConfig() === true) { // version with users config file, so next is try to auto-login
113                                 $previousUser = ($this->firstRun === false) ? $this->applicationConfig['baculum']['login'] : null;
114                                 $this->getModule('configuration')->setUsersConfig($cfgData['baculum']['login'], $cfgData['baculum']['password'], $this->firstRun, $previousUser);
115                                 // Automatic login after finish wizard.
116                                 $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
117                                 $urlPrefix = $this->Application->getModule('friendly-url')->getUrlPrefix();
118                                 $location = sprintf("%s://%s:%s@%s:%d%s", $http_protocol, $cfgData['baculum']['login'], $cfgData['baculum']['password'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $urlPrefix);
119                                 header("Location: $location");
120                                 exit();
121                         } else { // standard version (user defined auth method)
122                                 $this->goToDefaultPage();
123                         }
124                 }
125         }
126
127         public function setDBType($sender, $param) {
128                 $db = $this->DBType->SelectedValue;
129                 $this->setLogin($db);
130                 $this->setPassword($db);
131                 $this->setIP($db);
132                 $this->setDefaultPort($db);
133                 $this->setDBPath($db);
134         }
135
136         public function setLogin($db) {
137                 $this->Login->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
138         }
139
140         public function setPassword($db) {
141                 $this->Password->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
142         }
143
144         public function setIP($db) {
145                 $this->IP->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
146         }
147
148         public function setDefaultPort($db) {
149                 $configuration = $this->Application->getModule('configuration');
150                 $port = null;
151                 if($configuration->isPostgreSQLType($db) === true) {
152                         $port = $configuration::PGSQL_PORT;
153                 } elseif($configuration->isMySQLType($db) === true) {
154                         $port = $configuration::MYSQL_PORT;
155                 } elseif($configuration->isSQLiteType($db) === true) {
156                         $port = $configuration::SQLITE_PORT;
157                 }
158
159                 $prevPort = $this->Port->getViewState('port');
160
161                 if(is_null($port)) {
162                         $this->Port->Text = '';
163                         $this->Port->Enabled = false;
164                 } else {
165                         $this->Port->Enabled = true;
166                         $this->Port->Text = (empty($prevPort)) ? $port : $prevPort;
167                 }
168                 $this->Port->setViewState('port', '');
169         }
170
171         public function setDBPath($db) {
172                 if($this->getModule('configuration')->isSQLiteType($db) === true) {
173                         $this->DBPath->Enabled = true;
174                         $this->DBPathField->Display = 'Fixed';
175                 } else {
176                         $this->DBPath->Enabled = false;
177                         $this->DBPathField->Display = 'Hidden';
178                 }
179         }
180
181         public function setLang($sender, $param) {
182                 $_SESSION['language'] = $sender->SelectedValue;
183                 $this->goToPage('ConfigurationWizard');
184         }
185
186         public function validateAdministratorPassword($sender, $param) {
187                 $sender->Display = ($this->RetypePasswordRequireValidator->IsValid === true && $this->RetypePasswordRegexpValidator->IsValid === true) ? 'Dynamic' : 'None';
188                 $param->IsValid = ($param->Value === $this->PanelPassword->Text);
189         }
190
191          public function renderPanel($sender, $param) {
192                 $this->LoginValidator->Display = ($this->Login->Enabled === true) ? 'Dynamic' : 'None';
193                 $this->PortValidator->Display = ($this->Port->Enabled === true) ? 'Dynamic' : 'None';
194                 $this->IPValidator->Display = ($this->IP->Enabled === true) ? 'Dynamic' : 'None';
195                 $this->DBPathValidator->Display = ($this->DBPath->Enabled === true) ? 'Dynamic' : 'None';
196                 $this->DbTestResultOk->Display = 'None';
197                 $this->DbTestResultErr->Display = 'None';
198                 $this->Step2Content->render($param->NewWriter);
199         }
200         
201         public function connectionDBTest($sender, $param) {
202                 $validation = false;
203                 $configuration = $this->getModule('configuration');
204                 $dbParams = array();
205                 $dbParams['type'] = $this->DBType->SelectedValue;
206                 if($configuration->isMySQLType($dbParams['type']) === true || $configuration->isPostgreSQLType($dbParams['type']) === true) {
207                         $dbParams['name'] = $this->DBName->Text;
208                         $dbParams['login'] = $this->Login->Text;
209                         $dbParams['password'] = $this->Password->Text;
210                         $dbParams['host'] = $this->IP->Text;
211                         $dbParams['port'] = $this->Port->Text;
212                         $validation = true;
213                 } elseif($configuration->isSQLiteType($dbParams['type']) === true && !empty($this->DBPath->Text)) {
214                         $dbParams['path'] = $this->DBPath->Text;
215                         $validation = true;
216                 }
217                 
218                 $isValidate = ($validation === true) ? $this->getModule('db')->testDbConnection($dbParams) : false;
219                 $this->DbTestResultOk->Display = ($isValidate === true) ? 'Dynamic' : 'None';
220                 $this->DbTestResultErr->Display = ($isValidate === false) ? 'Dynamic' : 'None';
221                 $this->Step2Content->render($param->NewWriter);
222
223         }
224
225         public function connectionBconsoleTest($sender, $param) {
226                 $result = $this->getModule('bconsole')->testBconsoleCommand(array('version'), $this->BconsolePath->Text, $this->BconsoleConfigPath->Text, $this->UseSudo->Checked)->exitcode;
227                 $isValidate = ($result === 0);
228                 $this->BconsoleTestResultOk->Display = ($isValidate === true) ? 'Dynamic' : 'None';
229                 $this->BconsoleTestResultErr->Display = ($isValidate === false) ? 'Dynamic' : 'None';
230                 $this->Step4Content->render($param->NewWriter);
231         }
232 }
233 ?>