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;
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';
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.');
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;
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'];
83 public function NextStep($sender, $param) {
86 public function PreviousStep($sender, $param) {
89 public function wizardStop($sender, $param) {
90 $this->goToDefaultPage();
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);
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");
121 } else { // standard version (user defined auth method)
122 $this->goToDefaultPage();
127 public function setDBType($sender, $param) {
128 $db = $this->DBType->SelectedValue;
129 $this->setLogin($db);
130 $this->setPassword($db);
132 $this->setDefaultPort($db);
133 $this->setDBPath($db);
136 public function setLogin($db) {
137 $this->Login->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
140 public function setPassword($db) {
141 $this->Password->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
144 public function setIP($db) {
145 $this->IP->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
148 public function setDefaultPort($db) {
149 $configuration = $this->Application->getModule('configuration');
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;
159 $prevPort = $this->Port->getViewState('port');
162 $this->Port->Text = '';
163 $this->Port->Enabled = false;
165 $this->Port->Enabled = true;
166 $this->Port->Text = (empty($prevPort)) ? $port : $prevPort;
168 $this->Port->setViewState('port', '');
171 public function setDBPath($db) {
172 if($this->getModule('configuration')->isSQLiteType($db) === true) {
173 $this->DBPath->Enabled = true;
174 $this->DBPathField->Display = 'Fixed';
176 $this->DBPath->Enabled = false;
177 $this->DBPathField->Display = 'Hidden';
181 public function setLang($sender, $param) {
182 $_SESSION['language'] = $sender->SelectedValue;
183 $this->goToPage('ConfigurationWizard');
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);
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);
201 public function connectionDBTest($sender, $param) {
203 $configuration = $this->getModule('configuration');
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;
213 } elseif($configuration->isSQLiteType($dbParams['type']) === true && !empty($this->DBPath->Text)) {
214 $dbParams['path'] = $this->DBPath->Text;
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);
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);