29 public function __construct (
string $dn,
string $objectDn,
string $userDn, DateTime $timestamp)
32 $this->objectDn = $objectDn;
33 $this->userDn = $userDn;
34 $this->timestamp = $timestamp;
47 public static function add ($object,
string $user = NULL)
56 if (is_array($object)) {
57 foreach ($object as $obj) {
58 static::add($obj, $user);
68 if (isset($_POST[
'open_readonly'])) {
69 $cache[
'READ_ONLY'][$object] = TRUE;
72 if (isset($cache[
'READ_ONLY'][$object])) {
73 unset($cache[
'READ_ONLY'][$object]);
77 if (empty($object) || empty($user)) {
82 $ldap = $config->get_ldap_link();
83 $ldap->cd(
get_ou(
'lockRDN').
get_ou(
'fusiondirectoryRDN').$config->current[
'BASE']);
84 $ldap->search(
'(&(objectClass=fdLockEntry)(fdUserDn='.ldap_escape_f($user).
')(fdObjectDn='.base64_encode($object).
'))',
86 if ($ldap->get_errno() == 32) {
88 $ldap->cd($config->current[
'BASE']);
90 $ldap->create_missing_trees(
get_ou(
'lockRDN').
get_ou(
'fusiondirectoryRDN').$config->current[
'BASE']);
94 $ldap->cd(
get_ou(
'lockRDN').
get_ou(
'fusiondirectoryRDN').$config->current[
'BASE']);
95 $ldap->search(
'(&(objectClass=fdLockEntry)(fdUserDn='.ldap_escape_f($user).
')(fdObjectDn='.base64_encode($object).
'))',
98 if (!$ldap->success()) {
101 htmlescape(_(
'Cannot create locking information in LDAP tree. Please contact your administrator!')).
102 '<br><br>'.
htmlescape(_(
'LDAP server returned: %s')),
103 '<br><br><i>'.
htmlescape($ldap->get_error()).
'</i>' 109 if ($ldap->count() == 0) {
111 $name = md5($object);
112 $dn =
'cn='.$name.
','.
get_ou(
'lockRDN').get_ou(
'fusiondirectoryRDN').$config->current[
'BASE'];
115 'objectClass' =>
'fdLockEntry',
118 'fdObjectDn' => base64_encode($object),
122 if (!$ldap->success()) {
139 if (is_array($object)) {
140 foreach ($object as $obj) {
141 static::deleteByObject($obj);
156 if (isset($cache[
'READ_ONLY'][$object])) {
157 unset($cache[
'READ_ONLY'][$object]);
163 $ldap = $config->get_ldap_link();
164 $dn =
get_ou(
'lockRDN').get_ou(
'fusiondirectoryRDN').$config->current[
'BASE'];
166 $ldap->search(
'(&(objectClass=fdLockEntry)(fdObjectDn='.base64_encode($object).
'))', [
'fdObjectDn']);
167 if (!$ldap->success()) {
169 } elseif ($attrs = $ldap->fetch()) {
170 $ldap->rmdir($attrs[
'dn']);
171 if (!$ldap->success()) {
190 $ldap = $config->get_ldap_link();
191 $ldap->cd(
get_ou(
'lockRDN').
get_ou(
'fusiondirectoryRDN').$config->current[
'BASE']);
194 $ldap->search(
'(&(objectClass=fdLockEntry)(fdUserDn='.ldap_escape_f($userdn).
'))', [
'fdUserDn']);
195 while ($attrs = $ldap->fetch()) {
196 $ldap->rmdir($attrs[
'dn']);
211 public static function get ($objects,
bool $allow_readonly = FALSE): array
215 if (is_array($objects) && (count($objects) == 1)) {
216 $objects = reset($objects);
218 if (is_array($objects)) {
219 if ($allow_readonly) {
222 $filter =
'(&(objectClass=fdLockEntry)(|';
223 foreach ($objects as $obj) {
224 $filter .=
'(fdObjectDn='.base64_encode($obj).
')';
228 if ($allow_readonly && isset($_POST[
'open_readonly'])) {
232 $filter =
'(&(objectClass=fdLockEntry)(fdObjectDn='.base64_encode($objects).
'))';
236 $ldap = $config->get_ldap_link();
237 $dn =
get_ou(
'lockRDN').get_ou(
'fusiondirectoryRDN').$config->current[
'BASE'];
239 $ldap->search($filter, [
'fdUserDn',
'fdObjectDn',
'fdLockTimestamp']);
240 if (!$ldap->success()) {
245 $sessionLifetime = $config->get_cfg_value(
'sessionLifetime', 1800);
246 if ($sessionLifetime > 0) {
247 $expirationDate = (
new DateTime())->sub(
new DateInterval(
'PT'.$sessionLifetime.
'S'));
249 while ($attrs = $ldap->fetch()) {
251 if (isset($expirationDate) && ($date < $expirationDate)) {
253 $ldap->rmdir($attrs[
'dn']);
257 base64_decode($attrs[
'fdObjectDn'][0]),
258 $attrs[
'fdUserDn'][0],
264 if (!is_array($objects) && (count($locks) > 1)) {
266 $warning =
new FusionDirectoryWarning(
htmlescape(_(
'Found multiple locks for object to be locked. This should not happen - cleaning up multiple references.')));
270 foreach ($locks as $lock) {
271 $ldap->rmdir($lock->dn);
294 public static function addOrFail ($object,
string $user = NULL,
int $retries = 10)
297 while (!empty($locks =
Lock::get($object))) {
331 public static function genLockedMessage (array $locks,
bool $allowReadonly = FALSE,
string $action = NULL): string
335 $LOCK_VARS_USED_GET = [];
336 $LOCK_VARS_USED_POST = [];
337 $LOCK_VARS_USED_REQUEST = [];
340 foreach ($LOCK_VARS_TO_USE as $name) {
345 foreach ($_POST as $Pname => $Pvalue) {
346 if (preg_match($name, $Pname)) {
347 $LOCK_VARS_USED_POST[$Pname] = $_POST[$Pname];
351 foreach ($_GET as $Pname => $Pvalue) {
352 if (preg_match($name, $Pname)) {
353 $LOCK_VARS_USED_GET[$Pname] = $_GET[$Pname];
357 foreach ($_REQUEST as $Pname => $Pvalue) {
358 if (preg_match($name, $Pname)) {
359 $LOCK_VARS_USED_REQUEST[$Pname] = $_REQUEST[$Pname];
364 session::set(
'LOCK_VARS_USED_GET', $LOCK_VARS_USED_GET);
365 session::set(
'LOCK_VARS_USED_POST', $LOCK_VARS_USED_POST);
366 session::set(
'LOCK_VARS_USED_REQUEST', $LOCK_VARS_USED_REQUEST);
371 $smarty->assign(
'allow_readonly', $allowReadonly);
372 $smarty->assign(
'action', ($action ?? _(
'Edit anyway')));
373 $smarty->assign(
'locks', $locks);
htmlescape(string $str)
Escape string for HTML output.
get_ou($name)
Get the OU of a certain RDN.
get_template_path($filename='', $plugin=FALSE, $path='')
Return themed path for specified base file.
static get($name)
Accessor of a session var.
static toString(DateTime $date, $setToUTC=TRUE)
Convert from DateTime object to LDAP GeneralizedTime formatted string.
static genLockedMessage(array $locks, bool $allowReadonly=FALSE, string $action=NULL)
Generate a lock message.
static get($objects, bool $allow_readonly=FALSE)
Get locks for objects.
static deleteByUser(string $userdn)
Remove all locks owned by a specific userdn.
static set($name, $value)
Set a value in a session.
Error returned by an LDAP operation called from FusionDirectory.
static & get_ref($name)
Accessor of a session var by reference.
static add($object, string $user=NULL)
Add a lock for object(s)
& get_smarty()
Get global smarty object.
static addOrFail($object, string $user=NULL, int $retries=10)
Add a lock for object(s) or fail.
Parent class for all exceptions thrown in FusionDirectory.
static deleteByObject($object)
Remove a lock for object(s)
static fromString($string, $useException=TRUE)
Convert from LDAP GeneralizedTime formatted string to DateTime object.
Parent class for all errors in FusionDirectory.
static is_set($name)
Check if the name of the session is set.