32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
import ldap3
|
|
import ldap3.abstract
|
|
import ldap3.abstract.entry
|
|
import config
|
|
|
|
class AD:
|
|
def __init__(self):
|
|
server = ldap3.Server(config.AD_SERVER)
|
|
try:
|
|
server = ldap3.Server(config.AD_SERVER)
|
|
self.__conn = ldap3.Connection(server, user=config.AD_USERNAME, password=config.AD_PASSWORD, auto_bind=True)
|
|
except:
|
|
raise "Ошибка подключения к LDAP"
|
|
|
|
def getUserInfo(self, searchValue: str, searchField: str, searchAttr: list) -> list:
|
|
search_filter = "(&(objectClass=User)("+ searchField +"="+ searchValue +"))"
|
|
self.__conn.search(config.AD_BASE_DN, search_filter, search_scope="LEVEL", attributes=searchAttr)
|
|
|
|
d = {}
|
|
l = []
|
|
for entry in self.__conn.entries:
|
|
l.append(entry.entry_attributes_as_dict)
|
|
return l
|
|
|
|
def isDisabled(self, searchValue: str, searchField: str) -> bool:
|
|
ldap_filder = "(&(objectClass=User)(" + searchField + "="+searchValue+")(userAccountControl:1.2.840.113556.1.4.803:=2))"
|
|
self.__conn.search(config.AD_BASE_DN, ldap_filder, "SUBTREE" )
|
|
return bool(len(self.__conn.entries))
|
|
|
|
def isEnabled(self, searchValue: str, searchField: str) -> bool:
|
|
return not self.isDisabled(searchValue, searchField)
|
|
|