代码拉取完成,页面将自动刷新
同步操作将从 现任明教教主-乾颐堂/VIP_LDAP3 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python3
# -*- coding=utf-8 -*-
# 本脚由亁颐堂现任明教教主编写,用于乾颐盾Python课程!
# 教主QQ:605658506
# 亁颐堂官网www.qytang.com
# 教主技术进化论拓展你的技术新边疆
# https://ke.qq.com/course/271956?tuin=24199d8a
from ldap3 import Connection
from vip_ldap3_0_login_info import server, ad_admin_username, ad_admin_password
def get_user_info(username):
# 返回用户属于的组与用户名
try:
# 连接服务器
c = Connection(server, auto_bind=True, user="qytang\\"+ad_admin_username, password=ad_admin_password)
# 提取域qytang.com, 用户的memberOf,sn和department信息
c.search(search_base='dc=qytang,dc=com', search_filter='(&(samAccountName=' + username + '))', attributes=['memberOf', 'sn', 'department', 'createTimeStamp', 'accountExpires', 'userAccountControl', 'objectClass', 'pwdLastSet'], paged_size=5)
# 返回获取的memberOf,sn和department信息
return {'dn': c.response[0]['dn'],
'memberOf': c.response[0]['attributes']['memberOf'],
'sn': c.response[0]['attributes']['sn'],
'department': c.response[0]['attributes']['department'],
'createTimeStamp': c.response[0]['attributes']['createTimeStamp'],
'accountExpires': c.response[0]['attributes']['accountExpires'],
'userAccountControl': c.response[0]['attributes']['userAccountControl'],
'objectClass': c.response[0]['attributes']['objectClass'],
'pwdLastSet': c.response[0]['attributes']['pwdLastSet'],}
except Exception:
return None
def get_user_self_info(username, password):
# 返回用户属于的组与用户名
try:
# 连接服务器
c = Connection(server, auto_bind=True, user="qytang\\"+username, password=password)
# 提取域qytang.com, 用户的memberOf,sn和department信息
c.search(search_base='dc=qytang,dc=com', search_filter='(&(samAccountName=' + username + '))', attributes=['memberOf', 'sn', 'department', 'createTimeStamp', 'accountExpires', 'userAccountControl', 'objectClass', 'pwdLastSet'], paged_size=5)
# 返回获取的memberOf,sn和department信息
return {'dn': c.response[0]['dn'],
'memberOf': c.response[0]['attributes']['memberOf'],
'sn': c.response[0]['attributes']['sn'],
'department': c.response[0]['attributes']['department'],
'createTimeStamp': c.response[0]['attributes']['createTimeStamp'],
'accountExpires': c.response[0]['attributes']['accountExpires'],
'userAccountControl': c.response[0]['attributes']['userAccountControl'],
'objectClass': c.response[0]['attributes']['objectClass'],
'pwdLastSet': c.response[0]['attributes']['pwdLastSet'],}
except Exception as e:
print(e)
return None
if __name__ == '__main__':
# 可以查詢用戶
print(get_user_info('vip-qinke'))
print(get_user_self_info('vip-qinke42', 'Cisc0123'))
# 可以查詢組
# print(get_user_info('vipgroup'))
# userAccountControl
# https://lesca.me/archives/common-useraccountcontrol-values.html
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。