mirror of
https://github.com/capricornxl/ad-password-self-service.git
synced 2025-08-11 15:46:13 +08:00
更新一些小功能
This commit is contained in:
@@ -136,6 +136,8 @@ class AdOps(object):
|
||||
self.__conn()
|
||||
return True, self.conn.search(BASE_DN, SEARCH_FILTER.format(username),
|
||||
attributes=['sAMAccountName'])
|
||||
except IndexError:
|
||||
return False, "AdOps Exception: Connect.search未能检索到任何信息,当前账号可能被排除在<SEARCH_FILTER>之外,请联系管理员处理。"
|
||||
except Exception as e:
|
||||
return False, "AdOps Exception: {}".format(e)
|
||||
|
||||
@@ -149,6 +151,8 @@ class AdOps(object):
|
||||
self.__conn()
|
||||
self.conn.search(BASE_DN, SEARCH_FILTER.format(username), attributes=['name'])
|
||||
return True, self.conn.entries[0]['name']
|
||||
except IndexError:
|
||||
return False, "AdOps Exception: Connect.search未能检索到任何信息,当前账号可能被排除在<SEARCH_FILTER>之外,请联系管理员处理。"
|
||||
except Exception as e:
|
||||
return False, "AdOps Exception: {}".format(e)
|
||||
|
||||
@@ -163,6 +167,8 @@ class AdOps(object):
|
||||
self.conn.search(BASE_DN, SEARCH_FILTER.format(username),
|
||||
attributes=['distinguishedName'])
|
||||
return True, str(self.conn.entries[0]['distinguishedName'])
|
||||
except IndexError:
|
||||
return False, "AdOps Exception: Connect.search未能检索到任何信息,当前账号可能被排除在<SEARCH_FILTER>之外,请联系管理员处理。"
|
||||
except Exception as e:
|
||||
return False, "AdOps Exception: {}".format(e)
|
||||
|
||||
@@ -177,6 +183,8 @@ class AdOps(object):
|
||||
self.conn.search(BASE_DN, SEARCH_FILTER.format(username),
|
||||
attributes=['userAccountControl'])
|
||||
return True, self.conn.entries[0]['userAccountControl']
|
||||
except IndexError:
|
||||
return False, "AdOps Exception: Connect.search未能检索到任何信息,当前账号可能被排除在<SEARCH_FILTER>之外,请联系管理员处理。"
|
||||
except Exception as e:
|
||||
return False, "AdOps Exception: {}".format(e)
|
||||
|
||||
@@ -190,6 +198,8 @@ class AdOps(object):
|
||||
if _status:
|
||||
try:
|
||||
return True, self.conn.extend.microsoft.unlock_account(user='%s' % user_dn)
|
||||
except IndexError:
|
||||
return False, "AdOps Exception: Connect.search未能检索到任何信息,当前账号可能被排除在<SEARCH_FILTER>之外,请联系管理员处理。"
|
||||
except Exception as e:
|
||||
return False, "AdOps Exception: {}".format(e)
|
||||
else:
|
||||
@@ -247,5 +257,7 @@ class AdOps(object):
|
||||
return True, 'unlocked'
|
||||
else:
|
||||
return False, locked_status
|
||||
except IndexError:
|
||||
return False, "AdOps Exception: Connect.search未能检索到任何信息,当前账号可能被排除在<SEARCH_FILTER>之外,请联系管理员处理。"
|
||||
except Exception as e:
|
||||
return False, "AdOps Exception: {}".format(e)
|
||||
|
42
utils/logger_filter.py
Normal file
42
utils/logger_filter.py
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
from functools import wraps
|
||||
from traceback import format_exc
|
||||
|
||||
|
||||
def decorator_request_logger(logger):
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
def wrapper(request, *args, **kwargs):
|
||||
try:
|
||||
rsp = func(request, *args, **kwargs)
|
||||
logger.info(
|
||||
f'Request Arguments: {args} {kwargs}')
|
||||
# logger.info(
|
||||
# f'Request: {request.META["REMOTE_ADDR"]} {request.method} "{request.META["PATH_INFO"]}'
|
||||
# f'{request.META["QUERY_STRING"]} {request.META["SERVER_PROTOCOL"]}" {rsp.status_code} {rsp.content}')
|
||||
logger.info(rsp)
|
||||
return rsp
|
||||
except Exception as e:
|
||||
logger.error(format_exc())
|
||||
raise e
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def decorator_default_logger(logger):
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
logger.info(f'{args}, {kwargs}')
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
logger.error(format_exc())
|
||||
raise e
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
Reference in New Issue
Block a user