3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 Kern Sibbald
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('Application.Common.Class.ConfigFileModule');
26 * Manage webGUI configuration.
27 * Module is responsible for get/set webGUI config data.
29 * @author Marcin Haba <marcin.haba@bacula.pl>
31 class WebConfig extends ConfigFileModule {
34 * Web config file path
36 const CONFIG_FILE_PATH = 'Application.Web.Config.settings';
39 * Web config file format
41 const CONFIG_FILE_FORMAT = 'ini';
44 * Default application language
46 const DEFAULT_LANGUAGE = 'en';
49 * These options are obligatory for web config.
51 private $required_options = array(
52 'baculum' => array('login', 'password', 'debug', 'lang')
56 * Get (read) web config.
59 * @param string $section config section name
60 * @return array config
62 public function getConfig($section = null) {
63 $config = $this->readConfig(self::CONFIG_FILE_PATH, self::CONFIG_FILE_FORMAT);
64 if ($this->validateConfig($config) === true) {
65 if (!is_null($section)) {
66 $config = array_key_exists($section, $this->required_options) ? $config[$section] : array();
75 * Set (save) web config.
78 * @param array $config config
79 * @return boolean true if config saved successfully, otherwise false
81 public function setConfig(array $config) {
83 if ($this->validateConfig($config) === true) {
84 $result = $this->writeConfig($config, self::CONFIG_FILE_PATH, self::CONFIG_FILE_FORMAT);
90 * Validate web config.
91 * Config validation should be used as early as config data is available.
92 * Validation is done in read/write config methods.
95 * @param array $config config
96 * @return boolean true if config valid, otherwise false
98 private function validateConfig(array $config = array()) {
99 $is_valid = $this->isConfigValid($this->required_options, $config, self::CONFIG_FILE_FORMAT, self::CONFIG_FILE_PATH);
104 * Get web administrator name.
105 * Web interface supports one admin and many normal users.
107 * @return string web admin name
109 public function getWebAdmin() {
110 $config = $this->getConfig();
111 $web_admin = $config['baculum']['login'];
116 * Get application language short name.
117 * If no language set then returned is default language.
120 * @return string lanuage short name
122 public function getLanguage() {
124 $config = $this->getConfig();
125 if (array_key_exists('baculum', $config) && array_key_exists('lang', $config['baculum'])) {
126 $language = $config['baculum']['lang'];
128 if (is_null($language)) {
129 $language = self::DEFAULT_LANGUAGE;