3 * Bacula® - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2014 Marcin Haba
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.
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 * Bacula® is a registered trademark of Kern Sibbald.
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');
28 class ConfigurationWizard extends BaculumPage
31 public $applicationConfig;
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';
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();
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;
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'];
74 public function NextStep($sender, $param) {
77 public function PreviousStep($sender, $param) {
80 public function wizardStop($sender, $param) {
81 $this->goToDefaultPage();
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);
101 $this->goToDefaultPage();
105 public function setDBType($sender, $param) {
106 $db = $this->DBType->SelectedValue;
107 $this->setLogin($db);
108 $this->setPassword($db);
110 $this->setDefaultPort($db);
111 $this->setDBPath($db);
114 public function setLogin($db) {
115 $this->Login->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
118 public function setPassword($db) {
119 $this->Password->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
122 public function setIP($db) {
123 $this->IP->Enabled = ($this->getModule('configuration')->isSQLiteType($db) === false);
126 public function setDefaultPort($db) {
127 $configuration = $this->Application->getModule('configuration');
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;
137 $prevPort = $this->Port->getViewState('port');
140 $this->Port->Text = '';
141 $this->Port->Enabled = false;
143 $this->Port->Enabled = true;
144 $this->Port->Text = (empty($prevPort)) ? $port : $prevPort;
146 $this->Port->setViewState('port', '');
149 public function setDBPath($db) {
150 if($this->getModule('configuration')->isSQLiteType($db) === true) {
151 $this->DBPath->Enabled = true;
152 $this->DBPathField->Display = 'Fixed';
154 $this->DBPath->Enabled = false;
155 $this->DBPathField->Display = 'Hidden';
159 public function setLang($sender, $param) {
160 $this->Session['language'] = $sender->SelectedValue;
161 $this->goToPage('ConfigurationWizard');
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);
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);
179 public function connectionDBTest($sender, $param) {
181 $configuration = $this->getModule('configuration');
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;
191 } elseif($configuration->isSQLiteType($dbParams['type']) === true && !empty($this->DBPath->Text)) {
192 $dbParams['path'] = $this->DBPath->Text;
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);
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);