3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2015 Marcin Haba
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.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');
31 class ConfigurationWizard extends BaculumPage
34 public $applicationConfig;
37 const DEFAULT_DB_NAME = 'bacula';
38 const DEFAULT_DB_LOGIN = 'bacula';
39 const DEFAULT_BCONSOLE_BIN = '/usr/sbin/bconsole';
40 const DEFAULT_BCONSOLE_CONF = '/etc/bacula/bconsole.conf';
41 const DEFAULT_BCONSOLE_CONF_CUSTOM = '/etc/bacula/bconsole-{user}.conf';
43 public function onInit($param) {
44 parent::onInit($param);
45 $this->Lang->SelectedValue = $_SESSION['language'];
46 $config = $this->getModule('configuration');
47 $this->firstRun = !$config->isApplicationConfig();
48 $this->applicationConfig = $config->getApplicationConfig();
49 $this->userPattern = $config->getUserPattern();
50 if($this->firstRun === false && $this->User->getIsAdmin() === false) {
51 die('Access denied.');
55 public function onLoad($param) {
56 parent::onLoad($param);
57 $this->Licence->Text = $this->getModule('misc')->getLicence();
58 $this->Port->setViewState('port', $this->Port->Text);
59 if(!$this->IsPostBack && !$this->IsCallBack) {
60 if($this->firstRun === true) {
61 $this->DBName->Text = self::DEFAULT_DB_NAME;
62 $this->Login->Text = self::DEFAULT_DB_LOGIN;
63 $this->BconsolePath->Text = self::DEFAULT_BCONSOLE_BIN;
64 $this->BconsoleConfigPath->Text = self::DEFAULT_BCONSOLE_CONF;
65 $this->BconsoleConfigCustomPath->Text = self::DEFAULT_BCONSOLE_CONF_CUSTOM;
67 $this->DBType->SelectedValue = $this->getPage()->applicationConfig['db']['type'];
68 $this->DBName->Text = $this->applicationConfig['db']['name'];
69 $this->Login->Text = $this->applicationConfig['db']['login'];
70 $this->Password->Text = $this->applicationConfig['db']['password'];
71 $this->IP->Text = $this->applicationConfig['db']['ip_addr'];
72 $this->Port->Text = $this->applicationConfig['db']['port'];
73 $this->Port->setViewState('port', $this->applicationConfig['db']['port']);
74 $this->DBPath->Text = $this->applicationConfig['db']['path'];
75 $this->BconsolePath->Text = $this->applicationConfig['bconsole']['bin_path'];
76 $this->BconsoleConfigPath->Text = $this->applicationConfig['bconsole']['cfg_path'];
77 $this->BconsoleConfigCustomPath->Text = array_key_exists('cfg_custom_path', $this->applicationConfig['bconsole']) ? $this->applicationConfig['bconsole']['cfg_custom_path'] : self::DEFAULT_BCONSOLE_CONF_CUSTOM;
78 $this->UseSudo->Checked = $this->getPage()->applicationConfig['bconsole']['use_sudo'] == 1;
79 $this->PanelLogin->Text = $this->applicationConfig['baculum']['login'];
80 $this->PanelPassword->Text = $this->applicationConfig['baculum']['password'];
81 $this->RetypePanelPassword->Text = $this->applicationConfig['baculum']['password'];
86 public function NextStep($sender, $param) {
89 public function PreviousStep($sender, $param) {
92 public function wizardStop($sender, $param) {
93 $this->goToDefaultPage();
96 public function wizardCompleted() {
97 $cfgData = array('db' => array(), 'bconsole' => array(), 'baculum' => array());
98 $cfgData['db']['type'] = $this->DBType->SelectedValue;
99 $cfgData['db']['name'] = $this->DBName->Text;
100 $cfgData['db']['login'] = $this->Login->Text;
101 $cfgData['db']['password'] = $this->Password->Text;
102 $cfgData['db']['ip_addr'] = $this->IP->Text;
103 $cfgData['db']['port'] = $this->Port->Text;
104 $cfgData['db']['path'] = $this->Application->getModule('configuration')->isSQLiteType($cfgData['db']['type']) ? $this->DBPath->Text : '';
105 $cfgData['bconsole']['bin_path'] = $this->BconsolePath->Text;
106 $cfgData['bconsole']['cfg_path'] = $this->BconsoleConfigPath->Text;
107 $cfgData['bconsole']['cfg_custom_path'] = $this->BconsoleConfigCustomPath->Text;
108 $cfgData['bconsole']['use_sudo'] = (integer)($this->UseSudo->Checked === true);
109 $cfgData['baculum']['login'] = $this->PanelLogin->Text;
110 $cfgData['baculum']['password'] = $this->PanelPassword->Text;
111 $cfgData['baculum']['debug'] = isset($this->applicationConfig['baculum']['debug']) ? $this->applicationConfig['baculum']['debug'] : "0";
112 $cfgData['baculum']['lang'] = $_SESSION['language'];
113 $ret = $this->getModule('configuration')->setApplicationConfig($cfgData);
115 if($this->getModule('configuration')->isUsersConfig() === true) { // version with users config file, so next is try to auto-login
116 $previousUser = ($this->firstRun === false) ? $this->applicationConfig['baculum']['login'] : null;
117 $this->getModule('configuration')->setUsersConfig($cfgData['baculum']['login'], $cfgData['baculum']['password'], $this->firstRun, $previousUser);
119 // Automatic login after finish wizard.
120 $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
121 $this->getModule('configuration')->switchToUser($http_protocol, $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $cfgData['baculum']['login'], $cfgData['baculum']['password']);
123 } else { // standard version (user defined auth method)
124 $this->goToDefaultPage();
129 public function setDBType($sender, $param) {
130 $db = $this->DBType->SelectedValue;
131 $this->setLogin($db);
132 $this->setPassword($db);
134 $this->setDefaultPort($db);
135 $this->setDBPath($db);
138 public function setLogin($db) {
139 $this->Login->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
142 public function setPassword($db) {
143 $this->Password->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
146 public function setIP($db) {
147 $this->IP->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
150 public function setDefaultPort($db) {
151 $configuration = $this->Application->getModule('configuration');
153 if($configuration->isPostgreSQLType($db) === true) {
154 $port = $configuration::PGSQL_PORT;
155 } elseif($configuration->isMySQLType($db) === true) {
156 $port = $configuration::MYSQL_PORT;
157 } elseif($configuration->isSQLiteType($db) === true) {
158 $port = $configuration::SQLITE_PORT;
161 $prevPort = $this->Port->getViewState('port');
164 $this->Port->Text = '';
165 $this->Port->Enabled = false;
167 $this->Port->Enabled = true;
168 $this->Port->Text = (empty($prevPort)) ? $port : $prevPort;
170 $this->Port->setViewState('port', '');
173 public function setDBPath($db) {
174 if($this->getModule('configuration')->isSQLiteType($db) === true) {
175 $this->DBPath->Enabled = true;
176 $this->DBPathField->Display = 'Fixed';
178 $this->DBPath->Enabled = false;
179 $this->DBPathField->Display = 'Hidden';
183 public function setLang($sender, $param) {
184 $_SESSION['language'] = $sender->SelectedValue;
185 $this->goToPage('ConfigurationWizard');
188 public function validateAdministratorPassword($sender, $param) {
189 $sender->Display = ($this->RetypePasswordRequireValidator->IsValid === true && $this->RetypePasswordRegexpValidator->IsValid === true) ? 'Dynamic' : 'None';
190 $param->IsValid = ($param->Value === $this->PanelPassword->Text);
193 public function renderPanel($sender, $param) {
194 $this->LoginValidator->Display = ($this->Login->Enabled === true) ? 'Dynamic' : 'None';
195 $this->PortValidator->Display = ($this->Port->Enabled === true) ? 'Dynamic' : 'None';
196 $this->IPValidator->Display = ($this->IP->Enabled === true) ? 'Dynamic' : 'None';
197 $this->DBPathValidator->Display = ($this->DBPath->Enabled === true) ? 'Dynamic' : 'None';
198 $this->DbTestResultOk->Display = 'None';
199 $this->DbTestResultErr->Display = 'None';
200 $this->Step2Content->render($param->NewWriter);
203 public function connectionDBTest($sender, $param) {
205 $configuration = $this->getModule('configuration');
207 $dbParams['type'] = $this->DBType->SelectedValue;
208 if($configuration->isMySQLType($dbParams['type']) === true || $configuration->isPostgreSQLType($dbParams['type']) === true) {
209 $dbParams['name'] = $this->DBName->Text;
210 $dbParams['login'] = $this->Login->Text;
211 $dbParams['password'] = $this->Password->Text;
212 $dbParams['host'] = $this->IP->Text;
213 $dbParams['port'] = $this->Port->Text;
215 } elseif($configuration->isSQLiteType($dbParams['type']) === true && !empty($this->DBPath->Text)) {
216 $dbParams['path'] = $this->DBPath->Text;
220 $isValidate = ($validation === true) ? $this->getModule('db')->testDbConnection($dbParams) : false;
221 $this->DbTestResultOk->Display = ($isValidate === true) ? 'Dynamic' : 'None';
222 $this->DbTestResultErr->Display = ($isValidate === false) ? 'Dynamic' : 'None';
223 $this->Step2Content->render($param->NewWriter);
227 public function connectionBconsoleTest($sender, $param) {
228 $result = $this->getModule('bconsole')->testBconsoleCommand(array('version'), $this->BconsolePath->Text, $this->BconsoleConfigPath->Text, $this->UseSudo->Checked)->exitcode;
229 $isValidate = ($result === 0);
230 $this->BconsoleTestResultOk->Display = ($isValidate === true) ? 'Dynamic' : 'None';
231 $this->BconsoleTestResultErr->Display = ($isValidate === false) ? 'Dynamic' : 'None';