mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 17:40:31 +00:00
Merge branch 'master' into Develop
This commit is contained in:
commit
242866948f
@ -588,7 +588,7 @@ def edit_book(book_id):
|
|||||||
|
|
||||||
# create the function for sorting...
|
# create the function for sorting...
|
||||||
calibre_db.update_title_sort(config)
|
calibre_db.update_title_sort(config)
|
||||||
book = calibre_db.get_filtered_book(book_id)
|
book = calibre_db.get_filtered_book(book_id, allow_show_archived=True)
|
||||||
|
|
||||||
# Book not found
|
# Book not found
|
||||||
if not book:
|
if not book:
|
||||||
|
@ -52,7 +52,7 @@ from .services import SyncToken as SyncToken
|
|||||||
from .web import download_required
|
from .web import download_required
|
||||||
from .kobo_auth import requires_kobo_auth, get_auth_token
|
from .kobo_auth import requires_kobo_auth, get_auth_token
|
||||||
|
|
||||||
KOBO_FORMATS = {"KEPUB": ["KEPUB"], "EPUB": ["EPUB3", "EPUB"]}
|
KOBO_FORMATS = {"KEPUB": ["KEPUB", "EPUB3"], "EPUB": ["EPUB"]}
|
||||||
KOBO_STOREAPI_URL = "https://storeapi.kobo.com"
|
KOBO_STOREAPI_URL = "https://storeapi.kobo.com"
|
||||||
KOBO_IMAGEHOST_URL = "https://kbimages1-a.akamaihd.net"
|
KOBO_IMAGEHOST_URL = "https://kbimages1-a.akamaihd.net"
|
||||||
|
|
||||||
|
@ -85,8 +85,8 @@ def init_app(app, config):
|
|||||||
log.error(e)
|
log.error(e)
|
||||||
|
|
||||||
|
|
||||||
def get_object_details(user=None, group=None, query_filter=None, dn_only=False):
|
def get_object_details(user=None,query_filter=None):
|
||||||
return _ldap.get_object_details(user, group, query_filter, dn_only)
|
return _ldap.get_object_details(user, query_filter=query_filter)
|
||||||
|
|
||||||
|
|
||||||
def bind():
|
def bind():
|
||||||
|
@ -332,7 +332,7 @@
|
|||||||
<input type="text" class="form-control" id="config_ldap_group_members_field" name="config_ldap_group_members_field" value="{% if config.config_ldap_group_members_field != None %}{{ config.config_ldap_group_members_field }}{% endif %}" autocomplete="off">
|
<input type="text" class="form-control" id="config_ldap_group_members_field" name="config_ldap_group_members_field" value="{% if config.config_ldap_group_members_field != None %}{{ config.config_ldap_group_members_field }}{% endif %}" autocomplete="off">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="ldap_import_user_filter">{{_('LDAP Authentication')}}</label>
|
<label for="ldap_import_user_filter">{{_('LDAP Member User Filter Detection')}}</label>
|
||||||
<select name="ldap_import_user_filter" id="ldap_import_user_filter" class="form-control" data-control="ldap_member_user_object">
|
<select name="ldap_import_user_filter" id="ldap_import_user_filter" class="form-control" data-control="ldap_member_user_object">
|
||||||
<option value="0" {% if config.config_ldap_member_user_object == "" %}selected{% endif %}>{{ _('Autodetect') }}</option>
|
<option value="0" {% if config.config_ldap_member_user_object == "" %}selected{% endif %}>{{ _('Autodetect') }}</option>
|
||||||
<option value="1" {% if config.config_ldap_member_user_object %}selected{% endif %}>{{ _('Custom Filter') }}</option>
|
<option value="1" {% if config.config_ldap_member_user_object %}selected{% endif %}>{{ _('Custom Filter') }}</option>
|
||||||
|
65
cps/web.py
65
cps/web.py
@ -328,37 +328,51 @@ def import_ldap_users():
|
|||||||
user = username.decode('utf-8')
|
user = username.decode('utf-8')
|
||||||
if '=' in user:
|
if '=' in user:
|
||||||
# if member object field is empty take user object as filter
|
# if member object field is empty take user object as filter
|
||||||
|
if config.config_ldap_member_user_object:
|
||||||
|
query_filter = config.config_ldap_member_user_object
|
||||||
|
else:
|
||||||
|
query_filter = config.config_ldap_user_object
|
||||||
try:
|
try:
|
||||||
if config.config_ldap_member_user_object:
|
user_identifier = extract_user_identifier(user, query_filter)
|
||||||
user_identifier = extract_user_identifier(user, config.config_ldap_member_user_object)
|
|
||||||
else:
|
|
||||||
user_identifier = extract_user_identifier(user, config.config_ldap_user_object)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning(e)
|
log.warning(e)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
user_identifier = user
|
user_identifier = user
|
||||||
|
query_filter = None
|
||||||
if ub.session.query(ub.User).filter(ub.User.nickname == user_identifier.lower()).first():
|
try:
|
||||||
log.warning("LDAP User: %s Already in Database", user_identifier)
|
user_data = services.ldap.get_object_details(user=user_identifier, query_filter=query_filter)
|
||||||
|
except AttributeError as e:
|
||||||
|
log.exception(e)
|
||||||
continue
|
continue
|
||||||
user_data = services.ldap.get_object_details(user=user_identifier,
|
|
||||||
group=None,
|
|
||||||
query_filter=None,
|
|
||||||
dn_only=False)
|
|
||||||
if user_data:
|
if user_data:
|
||||||
content = ub.User()
|
user_login_field = extract_dynamic_field_from_filter(user, config.config_ldap_user_object)
|
||||||
# user_login_field = extract_dynamic_field_from_filter(user, config.config_ldap_user_object)
|
|
||||||
content.nickname = user_identifier # user_data[user_login_field][0].decode('utf-8')
|
username = user_data[user_login_field][0].decode('utf-8')
|
||||||
content.password = '' # dummy password which will be replaced by ldap one
|
# check for duplicate username
|
||||||
|
if ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == username.lower()).first():
|
||||||
|
# if ub.session.query(ub.User).filter(ub.User.nickname == username).first():
|
||||||
|
log.warning("LDAP User %s Already in Database", user_data)
|
||||||
|
continue
|
||||||
|
|
||||||
|
kindlemail = ''
|
||||||
if 'mail' in user_data:
|
if 'mail' in user_data:
|
||||||
content.email = user_data['mail'][0].decode('utf-8')
|
useremail = user_data['mail'][0].decode('utf-8')
|
||||||
if (len(user_data['mail']) > 1):
|
if (len(user_data['mail']) > 1):
|
||||||
content.kindle_mail = user_data['mail'][1].decode('utf-8')
|
kindlemail = user_data['mail'][1].decode('utf-8')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.debug('No Mail Field Found in LDAP Response')
|
log.debug('No Mail Field Found in LDAP Response')
|
||||||
content.email = user + '@email.com'
|
useremail = username + '@email.com'
|
||||||
|
# check for duplicate email
|
||||||
|
if ub.session.query(ub.User).filter(func.lower(ub.User.email) == useremail.lower()).first():
|
||||||
|
log.warning("LDAP Email %s Already in Database", user_data)
|
||||||
|
continue
|
||||||
|
content = ub.User()
|
||||||
|
content.nickname = username
|
||||||
|
content.password = '' # dummy password which will be replaced by ldap one
|
||||||
|
content.email = useremail
|
||||||
|
content.kindle_mail = kindlemail
|
||||||
content.role = config.config_default_role
|
content.role = config.config_default_role
|
||||||
content.sidebar_view = config.config_default_show
|
content.sidebar_view = config.config_default_show
|
||||||
content.allowed_tags = config.config_allowed_tags
|
content.allowed_tags = config.config_allowed_tags
|
||||||
@ -386,16 +400,17 @@ def extract_user_data_from_field(user, field):
|
|||||||
if match:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
else:
|
else:
|
||||||
raise Exception("Could Not Parse LDAP User: %s", user)
|
raise Exception("Could Not Parse LDAP User: {}".format(user))
|
||||||
|
|
||||||
# CN=Firstname LastName,OU=Laba,OU=...,DC=...,DC=...
|
def extract_dynamic_field_from_filter(user, filter):
|
||||||
# CN=user displayname,OU=ouname1,OU=ouname2,OU=ouname3,DC=domain,DC=domain
|
|
||||||
def extract_user_identifier(user, filter):
|
|
||||||
match = re.search("([a-zA-Z0-9-]+)=%s", filter, re.IGNORECASE | re.UNICODE)
|
match = re.search("([a-zA-Z0-9-]+)=%s", filter, re.IGNORECASE | re.UNICODE)
|
||||||
if match:
|
if match:
|
||||||
dynamic_field = match.group(1)
|
return match.group(1)
|
||||||
else:
|
else:
|
||||||
raise Exception("Could Not Parse LDAP User: %s", user)
|
raise Exception("Could Not Parse LDAP Userfield: {}", user)
|
||||||
|
|
||||||
|
def extract_user_identifier(user, filter):
|
||||||
|
dynamic_field = extract_dynamic_field_from_filter(user, filter)
|
||||||
return extract_user_data_from_field(user, dynamic_field)
|
return extract_user_data_from_field(user, dynamic_field)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user