]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/Portlets/Users.php
fca312f78b00afe9fb0b81daa525599e0cda86b4
[bacula/bacula] / gui / baculum / protected / Web / Portlets / Users.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2017 Kern Sibbald
7  *
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.
11  *
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.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23
24 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
25 Prado::using('Application.Web.Portlets.Portlets');
26
27 class Users extends Portlets {
28
29         public $web_config;
30
31         public function onInit($param) {
32                 parent::onInit($param);
33                 $this->web_config = $this->getModule('web_config')->getConfig();
34                 $this->setUsers();
35         }
36
37         public function setUsers() {
38                 if(!$_SESSION['admin']) {
39                         return;
40                 }
41                 $all_users = $this->getModule('basic_webuser')->getAllUsers();
42                 $users = array_keys($all_users);
43                 sort($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++) {
47                         $host = null;
48                         if ($users_feature && array_key_exists($users[$i], $this->web_config['users'])) {
49                                 $host = $this->web_config['users'][$users[$i]];
50                         }
51                         $users_list[] = array(
52                                 'user' => $users[$i],
53                                 'host' => $host,
54                                 'admin' => ($users[$i] === $this->web_config['baculum']['login'])
55                         );
56                 }
57                 $this->UsersList->dataSource = $users_list;
58                 $this->UsersList->dataBind();
59         }
60
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);
64                 $sender->dataBind();
65         }
66
67         public function userAction($sender, $param) {
68                 if(!$_SESSION['admin']) {
69                         return;
70                 }
71                 list($action, $user, $value) = explode(';', $param->CallbackParameter, 3);
72                 switch($action) {
73                         case 'newuser':
74                         case 'chpwd': {
75                                         $admin = false;
76                                         $valid = true;
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);
80                                                 $admin = true;
81                                         }
82                                         if ($valid === true) {
83                                                 $this->getModule('basic_webuser')->setUsersConfig($user, $value);
84                                         }
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);
89                                                 exit();
90                                         } else {
91                                                 // if normal user's password changed then update users grid
92                                                 $this->setUsers();
93                                         }
94                                 }
95                                 break;
96                         case 'rmuser': {
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]);
101                                                 }
102                                                 $this->getModule('web_config')->setConfig($this->web_config);
103                                                 $this->setUsers();
104                                         }
105                                 break;
106                                 }
107                         case 'set_host': {
108                                         if (empty($value) && array_key_exists($user, $this->web_config['users'])) {
109                                                 unset($this->web_config['users'][$user]);
110                                         } else {
111                                                 $this->web_config['users'][$user] = $value;
112                                         }
113                                         $this->getModule('web_config')->setConfig($this->web_config);
114                                 break;
115                                 }
116                 }
117         }
118 }