#!/bin/bash # setup LDAP authentication for nextcloud # this script must be run as www-data [[ ${LDAP_ENABLE,,} == "true" ]] || { echo Skipping LDAP setup exit 0 } PREV_DIR=${PWD} cd /var/www/html php occ app:enable user_ldap php occ ldap:show-config s01 | grep -q 'Invalid configID' && { # config does not yet exist, create it php occ ldap:create-empty-config } [[ -z ${LDAP_HOST} ]] || { php occ ldap:set-config s01 ldapHost ${LDAP_HOST} php occ ldap:set-config s01 ldapPort ${LDAP_PORT:-389} } [[ -z ${LDAP_BACKUP_HOST} ]] || { php occ ldap:set-config s01 ldapBackupHost ${LDAP_BACKUP_HOST} php occ ldap:set-config s01 ldapBackupPort ${LDAP_BACKUP_PORT:-389} } # credentials for accessing LDAP directory [[ -z ${LDAP_AGENT_NAME} ]] || { php occ ldap:set-config s01 ldapAgentName ${LDAP_AGENT_NAME} } [[ -z ${LDAP_AGENT_PASSWORD} ]] || { php occ ldap:set-config s01 ldapAgentPassword ${LDAP_AGENT_PASSWORD} } # search base [[ -z ${LDAP_BASE} ]] || { php occ ldap:set-config s01 ldapBase ${LDAP_BASE} php occ ldap:set-config s01 ldapBaseUsers ${LDAP_BASE_USERS:-ou=People,${LDAP_BASE}} php occ ldap:set-config s01 ldapBaseGroups ${LDAP_BASE_GROUPS:-ou=Group,${LDAP_BASE}} } LDAP_USER_FILTER_OBJECTCLASS=${LDAP_USER_FILTER_OBJECTCLASS:-inetOrgPerson} php occ ldap:set-config s01 ldapUserFilterObjectclass "$(echo ${LDAP_USER_FILTER_OBJECTCLASS} | tr ' ' '\n')" DEFAULT_FILTER="(|(objectclass=${LDAP_USER_FILTER_OBJECTCLASS// /)(objectclass=}))" LDAP_USER_FILTER="${LDAP_USER_FILTER:-${DEFAULT_FILTER}}" php occ ldap:set-config s01 ldapUserFilter "${LDAP_USER_FILTER}" # | ldapUserFilterGroups | | # | ldapUserFilterMode | 0 | DEFAULT_LOGIN_FILTER="(&${DEFAULT_FILTER}(uid=%uid))" php occ ldap:set-config s01 ldapLoginFilter "${LDAP_LOGIN_FILTER:-${DEFAULT_LOGIN_FILTER}}" # | ldapLoginFilterAttributes | | # | ldapLoginFilterEmail | 0 | # | ldapLoginFilterMode | 0 | # | ldapLoginFilterUsername | 1 | LDAP_GROUP_FILTER_OBJECTCLASS=${LDAP_GROUP_FILTER_OBJECTCLASS:-organizationalRole} php occ ldap:set-config s01 ldapGroupFilterObjectclass "$(echo ${LDAP_GROUP_FILTER_OBJECTCLASS} | tr ' ' '\n')" DEFAULT_GFILTER="(|(objectclass=${LDAP_GROUP_FILTER_OBJECTCLASS// /)(objectclass=}))" LDAP_GROUP_FILTER="${LDAP_GROUP_FILTER:-${DEFAULT_GFILTER}}" php occ ldap:set-config s01 ldapGroupFilter "${LDAP_GROUP_FILTER}" # | ldapGroupFilterGroups | | # | ldapGroupFilterMode | 0 | php occ ldap:set-config s01 ldapGidNumber "${LDAP_GID_NUMBER:-gidNumber}" php occ ldap:set-config s01 ldapUserDisplayName "${LDAP_USER_DISPLAY_NAME:-cn}" [[ -z ${LDAP_USER_DISPLAY_NAME_2} ]] || { php occ ldap:set-config s01 ldapUserDisplayName2 "${LDAP_USER_DISPLAY_NAME_2}" } php occ ldap:set-config s01 ldapGroupDisplayName "${LDAP_GROUP_DISPLAY_NAME:-cn}" # | ldapTLS | 0 | # | ldapQuotaAttribute | | # | ldapQuotaDefault | | php occ ldap:set-config s01 ldapEmailAttribute "${LDAP_EMAIL_ATTRIBUTE:-mail}" php occ ldap:set-config s01 ldapGroupMemberAssocAttr "${LDAP_GROUP_MEMBER_ASSOC_ATTR:-memberUid}" # | hasMemberOfFilterSupport | 0 | # | homeFolderNamingRule | | # | lastJpegPhotoLookup | 0 | # | ldapAttributesForGroupSearch | | # | ldapAttributesForUserSearch | | # | ldapCacheTTL | 600 | # | ldapDefaultPPolicyDN | | # | ldapDynamicGroupMemberURL | | # | ldapExperiencedAdmin | 0 | # | ldapExpertUUIDGroupAttr | | # | ldapExpertUUIDUserAttr | | # | ldapExpertUsernameAttr | | # | ldapExtStorageHomeAttribute | | # | ldapIgnoreNamingRules | | # | ldapNestedGroups | 0 | # | ldapOverrideMainServer | | # | ldapPagingSize | 500 | # | ldapUserAvatarRule | default | # | ldapUuidGroupAttribute | auto | # | ldapUuidUserAttribute | auto | # | turnOffCertCheck | 0 | # | turnOnPasswordChange | 0 | # | useMemberOfToDetectMembership | 1 | # set config as active php occ ldap:set-config s01 ldapConfigurationActive 1 cd ${PREV_DIR}