Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
limit.php
1<?php
2
3namespace Bitrix\Ldap;
4
8
9Loc::loadMessages(__FILE__);
10
11final class Limit
12{
13 private static $userLimit = 1000;
14 private static $userLimitExceededTag = 'LDAP_USER_LIMIT_EXCEEDED';
15 private static $isUserLimitExceeded = false;
16
17 public static function isUserLimitExceeded(): bool
18 {
19 if(self::$isUserLimitExceeded !== true)
20 {
21 $isFeatureEnabled = \CBXFeatures::IsFeatureEnabled('LdapUnlimitedUsers');
22 $featuresList = \CBXFeatures::GetFeaturesList();
23
24 if($isFeatureEnabled && !empty($featuresList))
25 {
26 self::$isUserLimitExceeded = false;
27 }
28 else
29 {
30 self::$isUserLimitExceeded = self::countLdapUsers() >= self::$userLimit;
31
32 if(self::$isUserLimitExceeded)
33 {
34 self::notifyUserLimitExceeded();
35 }
36 }
37 }
38
39 return self::$isUserLimitExceeded;
40 }
41
42 public static function getUserLimitNotifyMessage(): string
43 {
44 return loc::getMessage(
45 'LDAP_LIMIT_USER_LIMIT_EXCEEDED',
46 ['#LIMIT#' => self::$userLimit]
47 );
48 }
49
50 private static function notifyUserLimitExceeded(): void
51 {
52 \CEventLog::Add([
53 "SEVERITY" => \CEventLog::SEVERITY_WARNING,
54 "AUDIT_TYPE_ID" => self::$userLimitExceededTag,
55 "MODULE_ID" => "ldap",
56 "DESCRIPTION" => self::getUserLimitNotifyMessage()
57 ]);
58
59 \CAdminNotify::Add([
60 'MODULE_ID' => 'ldap',
61 'TAG' => self::$userLimitExceededTag,
62 'ENABLE_CLOSE' => 'Y',
63 'NOTIFY_TYPE' => \CAdminNotify::TYPE_NORMAL,
64 'MESSAGE' => self::getUserLimitNotifyMessage()
65 ]);
66 }
67
68 private static function countLdapUsers(): int
69 {
70 $result = 0;
71
72 $res = UserTable::query()
73 ->addSelect(new ExpressionField('CNT', 'COUNT(1)'))
74 ->whereLike('EXTERNAL_AUTH_ID', 'LDAP#%')
75 ->exec();
76
77 if($row = $res->fetch())
78 {
79 $result = (int)$row['CNT'];
80 }
81
82 return $result;
83 }
84}
static getUserLimitNotifyMessage()
Definition limit.php:42
static isUserLimitExceeded()
Definition limit.php:17
static loadMessages($file)
Definition loc.php:64