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('System.Security.IUserManager');
24 Prado::using('Application.Class.BaculumUser');
26 class BaculumUsersManager extends TModule implements IUserManager {
31 public function init($config) {
32 $this->configMod = $this->Application->getModule('configuration');
33 $this->config = $this->configMod->isApplicationConfig() ? $this->configMod->getApplicationConfig() : null;
36 public function getGuestName() {
40 public function validateUser($username, $password) {
42 if(!empty($username) && !empty($password)) {
43 $users = $this->configMod->getAllUsers();
44 $valid = (array_key_exists($username, $users) && $password === $users[$username]);
49 public function getUser($username = null) {
50 $user = new BaculumUser($this);
51 $user->setIsGuest(false);
54 $user->setName($username);
55 if (!is_null($username)) {
56 $users = $this->configMod->getAllUsers();
57 $user->setPwd($users[$username]);
59 if(is_null($this->config) || $this->config['baculum']['login'] === $username) {
60 $user->setRoles('admin');
62 $user->setRoles('user');
67 public function getUserFromCookie($cookie) {
68 $data = $cookie->Value;
70 $data = $this->Application->SecurityManager->validateData($data);
72 $data = unserialize($data);
73 if (is_array($data) && count($data) === 3) {
74 list($username, $address, $token) = $data;
75 return $this->getUser($username);
81 public function saveUserToCookie($cookie) {
82 $address = $this->Application->Request->UserHostAddress;
83 $username = $this->User->getName();
84 $token = $this->User->getID();
85 $data = array($username, $address, $token);
86 $data = serialize($data);
87 $data = $this->Application->SecurityManager->hashData($data);
88 $cookie->setValue($data);
91 public function loginUser($user = null, $pwd = null) {
92 if (is_null($user) && is_null($pwd) && isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
93 $user = $_SERVER['PHP_AUTH_USER'];
94 $pwd = $this->Application->getModule('configuration')->getCryptedPassword($_SERVER['PHP_AUTH_PW']);
96 $logged = $this->Application->getModule('auth')->login($user, $pwd, 86400);