Added reset-adminpassword

This commit is contained in:
root 2024-03-13 16:29:29 +00:00
parent 8bcaa40153
commit f99f43b02f
2 changed files with 52 additions and 0 deletions

37
bin/reset-adminpassword Normal file
View File

@ -0,0 +1,37 @@
#!/bin/bash
#
# Resets the LDAP admin@domain.com password
. /etc/federated
. /federated/lib/functions.sh
usage() {
cat << EOF
Reset the LDAP admin@domain.com password
Usage: $0 password
Arguments:
password - the password to set the admin@domain.com account to
EOF
exit 2;
}
[ $# -ne 1 ] && usage
PASSWORD=$1
get_ldapdomain
[ ! -d "/federated/apps/ldap" ] && echo "* ldap is not installed." && exit 2
LDAP_BIND_PASSWORD=$(cat /federated/apps/ldap/.ldap.secret)
if [[ $LDAP_DOMIAN_MIDDLE ]]; then
echo -ne "* Resetting the LDAP admin@$LDAP_DOMAIN_FIRST.$LDAP_DOMAIN_MIDDLE.$LDAP_DOMAIN_LAST password.."
docker exec ldap ldappasswd -H ldap://localhost -D "cn=admin,dc=$LDAP_DOMAIN_FIRST,dc=$LDAP_DOMAIN_MIDDLE,dc=$LDAP_DOMAIN_LAST" -x -w $LDAP_BIND_PASSWORD -s $PASSWORD uid=admin,ou=people,dc=$LDAP_DOMAIN_FIRST,dc=$LDAP_DOMAIN_MIDDLE,dc=$LDAP_DOMAIN_LAST -Z
[ $? -ne 0 ] && failcheck "* Couldn't run ldappasswd inside ldap container"
echo -ne "done.\n"
else
echo -ne "* Resetting the LDAP admin@$LDAP_DOMAIN_FIRST.$LDAP_DOMAIN_LAST password.."
docker exec ldap ldappasswd -H ldap://localhost -D "cn=admin,dc=$LDAP_DOMAIN_FIRST,dc=$LDAP_DOMAIN_LAST" -x -w $LDAP_BIND_PASSWORD -s $PASSWORD uid=admin,ou=people,dc=$LDAP_DOMAIN_FIRST,dc=$LDAP_DOMAIN_LAST -Z
[ $? -ne 0 ] && failcheck "* Couldn't run ldappasswd inside ldap container"
echo -ne "done.\n"
fi

View File

@ -1412,3 +1412,18 @@ get_appvars_old() {
# Set SMTP user based on if fcore exists
[[ $(docker exec ldap slapcat | grep fcore) ]] && SMTPUSER="fcore" || SMTPUSER="admin"
}
get_ldapdomain() {
# Get LDAP DOMAIN from ldap its self and setup variables for each part
LDAP_DOMAIN=$(docker exec ldap slapcat | grep "dn:" | head -1 | awk -F: '{ print $2 }')
# Setup LDAP_DOMAIN variable for domain or subdomain
LDAP_DOMAIN_ARRAY=(${LDAP_DOMAIN//,/ })
if [ "${#LDAP_DOMAIN_ARRAY[@]}" -eq "2" ]; then
LDAP_DOMAIN_FIRST=$(echo "${LDAP_DOMAIN_ARRAY[0]}" | awk -F= '{ print $2 }')
LDAP_DOMAIN_LAST=$(echo "${LDAP_DOMAIN_ARRAY[1]}" | awk -F= '{ print $2 }')
elif [ "${#LDAP_DOMAIN_ARRAY[@]}" -eq "3" ]; then
LDAP_DOMAIN_FIRST=$(echo "${LDAP_DOMAIN_ARRAY[0]}" | awk -F= '{ print $2 }')
LDAP_DOMAIN_MIDDLE=$(echo "${LDAP_DOMAIN_ARRAY[1]}" | awk -F= '{ print $2 }')
LDAP_DOMAIN_LAST=$(echo "${LDAP_DOMAIN_ARRAY[2]}" | awk -F= '{ print $2 }')
fi
}