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 __construct() {
32 parent::__construct();
33 $this->web_config = $this->getModule('web_config')->getConfig();
36 public function setUsers() {
37 if(!$_SESSION['admin']) {
40 $all_users = $this->getModule('basic_webuser')->getAllUsers();
41 $users = array_keys($all_users);
43 $users_list = array();
44 $users_feature = (array_key_exists('users', $this->web_config) && is_array($this->web_config['users']));
45 for ($i = 0; $i < count($users); $i++) {
47 if ($users_feature && array_key_exists($users[$i], $this->web_config['users'])) {
48 $host = $this->web_config['users'][$users[$i]];
50 $users_list[] = array(
53 'admin' => ($users[$i] === $this->web_config['baculum']['login'])
56 $this->UsersList->dataSource = $users_list;
57 $this->UsersList->dataBind();
60 public function initHosts($sender, $param) {
61 $api_hosts = array_keys($this->getModule('host_config')->getConfig());
62 $sender->DataSource = array_combine($api_hosts, $api_hosts);
66 public function userAction($sender, $param) {
67 if(!$_SESSION['admin']) {
70 list($action, $user, $value) = explode(';', $param->CallbackParameter, 3);
76 if ($user === $this->web_config['baculum']['login']) {
77 $this->web_config['baculum']['password'] = $value;
78 $valid = $this->getModule('web_config')->setConfig($this->web_config);
81 if ($valid === true) {
82 $this->getModule('basic_webuser')->setUsersConfig($user, $value);
84 if ($admin === true) {
85 // if admin password changed then try to auto-login by async request
86 $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
87 $this->switchToUser($user, $value);
90 // if normal user's password changed then update users grid
96 if ($user != $_SERVER['PHP_AUTH_USER']) {
97 $this->getModule('basic_webuser')->removeUser($user);
98 if (array_key_exists('users', $this->web_config) && array_key_exists($user, $this->web_config['users'])) {
99 unset($this->web_config['users'][$user]);
101 $this->getModule('web_config')->setConfig($this->web_config);
107 if (empty($value) && array_key_exists($user, $this->web_config['users'])) {
108 unset($this->web_config['users'][$user]);
110 $this->web_config['users'][$user] = $value;
112 $this->getModule('web_config')->setConfig($this->web_config);