3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2017 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.
24 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
25 Prado::using('Application.Web.Portlets.Portlets');
27 class Users extends Portlets {
31 public function onInit($param) {
32 parent::onInit($param);
33 $this->web_config = $this->getModule('web_config')->getConfig();
37 public function setUsers() {
38 if(!$_SESSION['admin']) {
41 $all_users = $this->getModule('basic_webuser')->getAllUsers();
42 $users = array_keys($all_users);
44 $users_list = array();
45 $users_feature = (array_key_exists('users', $this->web_config) && is_array($this->web_config['users']));
46 for ($i = 0; $i < count($users); $i++) {
48 if ($users_feature && array_key_exists($users[$i], $this->web_config['users'])) {
49 $host = $this->web_config['users'][$users[$i]];
51 $users_list[] = array(
54 'admin' => ($users[$i] === $this->web_config['baculum']['login'])
57 $this->UsersList->dataSource = $users_list;
58 $this->UsersList->dataBind();
61 public function initHosts($sender, $param) {
62 $api_hosts = array_keys($this->getModule('host_config')->getConfig());
63 $sender->DataSource = array_combine($api_hosts, $api_hosts);
67 public function userAction($sender, $param) {
68 if(!$_SESSION['admin']) {
71 list($action, $user, $value) = explode(';', $param->CallbackParameter, 3);
77 if ($user === $this->web_config['baculum']['login']) {
78 $this->web_config['baculum']['password'] = $value;
79 $valid = $this->getModule('web_config')->setConfig($this->web_config);
82 if ($valid === true) {
83 $this->getModule('basic_webuser')->setUsersConfig($user, $value);
85 if ($admin === true) {
86 // if admin password changed then try to auto-login by async request
87 $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
88 $this->switchToUser($user, $value);
91 // if normal user's password changed then update users grid
97 if ($user != $_SERVER['PHP_AUTH_USER']) {
98 $this->getModule('basic_webuser')->removeUser($user);
99 if (array_key_exists('users', $this->web_config) && array_key_exists($user, $this->web_config['users'])) {
100 unset($this->web_config['users'][$user]);
102 $this->getModule('web_config')->setConfig($this->web_config);
108 if (empty($value) && array_key_exists($user, $this->web_config['users'])) {
109 unset($this->web_config['users'][$user]);
111 $this->web_config['users'][$user] = $value;
113 $this->getModule('web_config')->setConfig($this->web_config);