2014-08-21 19:59:13 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2014-08-21 19:59:13 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2014-08-21 19:59:13 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2014-08-21 19:59:13 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-08-21 19:59:13 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-08-21 19:59:13 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-08-21 19:59:13 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-05-12 12:25:50 +03:00
|
|
|
namespace OCA\User_LDAP\User;
|
2014-08-21 19:59:13 +04:00
|
|
|
|
2014-12-20 18:09:04 +03:00
|
|
|
use OCA\User_LDAP\Mapping\UserMapping;
|
2017-07-11 23:43:47 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDBConnection;
|
2020-10-26 16:44:15 +03:00
|
|
|
use OCP\Share\IManager;
|
|
|
|
use OCP\Share\IShare;
|
2014-08-21 19:59:13 +04:00
|
|
|
|
|
|
|
class OfflineUser {
|
|
|
|
/**
|
|
|
|
* @var string $ocName
|
|
|
|
*/
|
|
|
|
protected $ocName;
|
|
|
|
/**
|
|
|
|
* @var string $dn
|
|
|
|
*/
|
|
|
|
protected $dn;
|
|
|
|
/**
|
|
|
|
* @var string $uid the UID as provided by LDAP
|
|
|
|
*/
|
|
|
|
protected $uid;
|
|
|
|
/**
|
|
|
|
* @var string $displayName
|
|
|
|
*/
|
|
|
|
protected $displayName;
|
|
|
|
/**
|
|
|
|
* @var string $homePath
|
|
|
|
*/
|
|
|
|
protected $homePath;
|
|
|
|
/**
|
|
|
|
* @var string $lastLogin the timestamp of the last login
|
|
|
|
*/
|
|
|
|
protected $lastLogin;
|
2018-12-17 19:37:45 +03:00
|
|
|
/**
|
|
|
|
* @var string $foundDeleted the timestamp when the user was detected as unavailable
|
|
|
|
*/
|
|
|
|
protected $foundDeleted;
|
2014-08-21 19:59:13 +04:00
|
|
|
/**
|
|
|
|
* @var string $email
|
|
|
|
*/
|
|
|
|
protected $email;
|
|
|
|
/**
|
|
|
|
* @var bool $hasActiveShares
|
|
|
|
*/
|
|
|
|
protected $hasActiveShares;
|
|
|
|
/**
|
2017-07-11 23:43:47 +03:00
|
|
|
* @var IConfig $config
|
2014-08-21 19:59:13 +04:00
|
|
|
*/
|
2014-12-20 18:33:37 +03:00
|
|
|
protected $config;
|
2014-08-21 19:59:13 +04:00
|
|
|
/**
|
2017-07-11 23:43:47 +03:00
|
|
|
* @var IDBConnection $db
|
2014-08-21 19:59:13 +04:00
|
|
|
*/
|
|
|
|
protected $db;
|
|
|
|
/**
|
2015-01-07 15:28:56 +03:00
|
|
|
* @var \OCA\User_LDAP\Mapping\UserMapping
|
2014-08-21 19:59:13 +04:00
|
|
|
*/
|
2014-12-20 18:09:04 +03:00
|
|
|
protected $mapping;
|
2020-10-26 16:44:15 +03:00
|
|
|
/** @var IManager */
|
|
|
|
private $shareManager;
|
2014-08-21 19:59:13 +04:00
|
|
|
|
2020-10-26 16:44:15 +03:00
|
|
|
public function __construct(
|
|
|
|
$ocName,
|
|
|
|
IConfig $config,
|
|
|
|
UserMapping $mapping,
|
|
|
|
IManager $shareManager
|
|
|
|
) {
|
2014-08-21 19:59:13 +04:00
|
|
|
$this->ocName = $ocName;
|
2014-12-20 18:33:37 +03:00
|
|
|
$this->config = $config;
|
2014-12-20 18:09:04 +03:00
|
|
|
$this->mapping = $mapping;
|
2020-10-26 16:44:15 +03:00
|
|
|
$this->shareManager = $shareManager;
|
2014-08-21 19:59:13 +04:00
|
|
|
}
|
|
|
|
|
2015-10-30 21:20:42 +03:00
|
|
|
/**
|
|
|
|
* remove the Delete-flag from the user.
|
|
|
|
*/
|
|
|
|
public function unmark() {
|
2018-12-17 19:37:45 +03:00
|
|
|
$this->config->deleteUserValue($this->ocName, 'user_ldap', 'isDeleted');
|
|
|
|
$this->config->deleteUserValue($this->ocName, 'user_ldap', 'foundDeleted');
|
2015-10-30 21:20:42 +03:00
|
|
|
}
|
|
|
|
|
2014-08-21 19:59:13 +04:00
|
|
|
/**
|
|
|
|
* exports the user details in an assoc array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function export() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$data = [];
|
2014-08-21 19:59:13 +04:00
|
|
|
$data['ocName'] = $this->getOCName();
|
|
|
|
$data['dn'] = $this->getDN();
|
|
|
|
$data['uid'] = $this->getUID();
|
|
|
|
$data['displayName'] = $this->getDisplayName();
|
|
|
|
$data['homePath'] = $this->getHomePath();
|
|
|
|
$data['lastLogin'] = $this->getLastLogin();
|
|
|
|
$data['email'] = $this->getEmail();
|
|
|
|
$data['hasActiveShares'] = $this->getHasActiveShares();
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-12 07:16:27 +03:00
|
|
|
* getter for Nextcloud internal name
|
2014-08-21 19:59:13 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getOCName() {
|
|
|
|
return $this->ocName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getter for LDAP uid
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUID() {
|
2021-02-15 15:36:02 +03:00
|
|
|
if ($this->uid === null) {
|
2020-10-26 15:54:03 +03:00
|
|
|
$this->fetchDetails();
|
|
|
|
}
|
2014-08-21 19:59:13 +04:00
|
|
|
return $this->uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getter for LDAP DN
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDN() {
|
2021-02-15 15:36:02 +03:00
|
|
|
if ($this->dn === null) {
|
2020-10-26 15:54:03 +03:00
|
|
|
$this->fetchDetails();
|
|
|
|
}
|
2014-08-21 19:59:13 +04:00
|
|
|
return $this->dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getter for display name
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDisplayName() {
|
2021-02-15 15:36:02 +03:00
|
|
|
if ($this->displayName === null) {
|
2020-10-26 15:54:03 +03:00
|
|
|
$this->fetchDetails();
|
|
|
|
}
|
2014-08-21 19:59:13 +04:00
|
|
|
return $this->displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getter for email
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getEmail() {
|
2021-02-15 15:36:02 +03:00
|
|
|
if ($this->email === null) {
|
2020-10-26 15:54:03 +03:00
|
|
|
$this->fetchDetails();
|
|
|
|
}
|
2014-08-21 19:59:13 +04:00
|
|
|
return $this->email;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getter for home directory path
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHomePath() {
|
2021-02-15 15:36:02 +03:00
|
|
|
if ($this->homePath === null) {
|
2020-10-26 15:54:03 +03:00
|
|
|
$this->fetchDetails();
|
|
|
|
}
|
2014-08-21 19:59:13 +04:00
|
|
|
return $this->homePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getter for the last login timestamp
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getLastLogin() {
|
2021-02-15 15:36:02 +03:00
|
|
|
if ($this->lastLogin === null) {
|
2020-10-26 15:54:03 +03:00
|
|
|
$this->fetchDetails();
|
|
|
|
}
|
2018-01-26 01:06:53 +03:00
|
|
|
return (int)$this->lastLogin;
|
2014-08-21 19:59:13 +04:00
|
|
|
}
|
|
|
|
|
2018-12-17 19:37:45 +03:00
|
|
|
/**
|
|
|
|
* getter for the detection timestamp
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getDetectedOn() {
|
2021-02-15 15:36:02 +03:00
|
|
|
if ($this->foundDeleted === null) {
|
2020-10-26 15:54:03 +03:00
|
|
|
$this->fetchDetails();
|
|
|
|
}
|
2018-12-17 19:37:45 +03:00
|
|
|
return (int)$this->foundDeleted;
|
|
|
|
}
|
|
|
|
|
2014-08-21 19:59:13 +04:00
|
|
|
/**
|
|
|
|
* getter for having active shares
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getHasActiveShares() {
|
2021-02-15 15:36:02 +03:00
|
|
|
if ($this->hasActiveShares === null) {
|
2020-10-26 15:54:03 +03:00
|
|
|
$this->fetchDetails();
|
|
|
|
}
|
2014-08-21 19:59:13 +04:00
|
|
|
return $this->hasActiveShares;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* reads the user details
|
|
|
|
*/
|
|
|
|
protected function fetchDetails() {
|
2018-12-17 19:37:45 +03:00
|
|
|
$properties = [
|
2020-10-05 16:12:57 +03:00
|
|
|
'displayName' => 'user_ldap',
|
|
|
|
'uid' => 'user_ldap',
|
|
|
|
'homePath' => 'user_ldap',
|
2018-12-17 19:37:45 +03:00
|
|
|
'foundDeleted' => 'user_ldap',
|
2020-10-05 16:12:57 +03:00
|
|
|
'email' => 'settings',
|
|
|
|
'lastLogin' => 'login',
|
2018-12-17 19:37:45 +03:00
|
|
|
];
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($properties as $property => $app) {
|
2014-12-20 18:33:37 +03:00
|
|
|
$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
|
2014-08-21 19:59:13 +04:00
|
|
|
}
|
|
|
|
|
2014-12-20 18:09:04 +03:00
|
|
|
$dn = $this->mapping->getDNByName($this->ocName);
|
2014-08-21 19:59:13 +04:00
|
|
|
$this->dn = ($dn !== false) ? $dn : '';
|
|
|
|
|
|
|
|
$this->determineShares();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* finds out whether the user has active shares. The result is stored in
|
|
|
|
* $this->hasActiveShares
|
|
|
|
*/
|
|
|
|
protected function determineShares() {
|
2020-10-26 16:44:15 +03:00
|
|
|
$shareInterface = new \ReflectionClass(IShare::class);
|
|
|
|
$shareConstants = $shareInterface->getConstants();
|
|
|
|
|
|
|
|
foreach ($shareConstants as $constantName => $constantValue) {
|
|
|
|
if (strpos($constantName, 'TYPE_') !== 0
|
|
|
|
|| $constantValue === IShare::TYPE_USERGROUP
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$shares = $this->shareManager->getSharesBy(
|
|
|
|
$this->ocName,
|
|
|
|
$constantValue,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
1
|
|
|
|
);
|
|
|
|
if (!empty($shares)) {
|
|
|
|
$this->hasActiveShares = true;
|
|
|
|
return;
|
|
|
|
}
|
2014-08-21 19:59:13 +04:00
|
|
|
}
|
|
|
|
|
2020-10-26 16:44:15 +03:00
|
|
|
$this->hasActiveShares = false;
|
2014-08-21 19:59:13 +04:00
|
|
|
}
|
|
|
|
}
|