From f99f43b02fee19c9196ff662173140d7b9bc6067 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 13 Mar 2024 16:29:29 +0000 Subject: [PATCH] Added reset-adminpassword --- bin/reset-adminpassword | 37 +++++++++++++++++++++++++++++++++++++ lib/functions.sh | 15 +++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 bin/reset-adminpassword diff --git a/bin/reset-adminpassword b/bin/reset-adminpassword new file mode 100644 index 0000000..acad5d5 --- /dev/null +++ b/bin/reset-adminpassword @@ -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 diff --git a/lib/functions.sh b/lib/functions.sh index 16fb077..a9404b2 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -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 +}