3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2015 Marcin Haba
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 {
32 public function init($config) {
33 $this->configMod = $this->Application->getModule('configuration');
34 $this->config = $this->configMod->isApplicationConfig() ? $this->configMod->getApplicationConfig() : null;
35 $this->users = $this->configMod->getAllUsers();
38 public function getGuestName() {
42 public function validateUser($username, $password) {
44 if(!empty($username) && !empty($password)) {
45 $users = $this->configMod->getAllUsers();
46 $valid = (array_key_exists($username, $users) && $password === $users[$username]);
51 public function getUser($username = null) {
52 $user = new BaculumUser($this);
53 $user->setIsGuest(false);
56 $user->setName($username);
57 if (!is_null($username)) {
58 $user->setPwd($this->users[$username]);
60 if(is_null($this->config) || $this->config['baculum']['login'] === $username) {
61 $user->setRoles('admin');
63 $user->setRoles('user');
68 public function getUserFromCookie($cookie) {
69 $data = $cookie->Value;
71 $data = $this->Application->SecurityManager->validateData($data);
73 $data = unserialize($data);
74 if (is_array($data) && count($data) === 3) {
75 list($username, $address, $token) = $data;
76 return $this->getUser($username);
82 public function saveUserToCookie($cookie) {
83 $address = $this->Application->Request->UserHostAddress;
84 $username = $this->User->getName();
85 $token = $this->User->getID();
86 $data = array($username, $address, $token);
87 $data = serialize($data);
88 $data = $this->Application->SecurityManager->hashData($data);
89 $cookie->setValue($data);
92 public function loginUser($user = null, $pwd = null) {
93 if (is_null($user) && is_null($pwd)) {
94 $user = $_SERVER['PHP_AUTH_USER'];
95 $pwd = $this->Application->getModule('configuration')->getCryptedPassword($_SERVER['PHP_AUTH_PW']);
97 $logged = $this->Application->getModule('auth')->login($user, $pwd, 86400);