diff --git a/bin/createUser.sh b/bin/createUser.sh index efd5ce6..cbcac8d 100755 --- a/bin/createUser.sh +++ b/bin/createUser.sh @@ -5,6 +5,8 @@ # ki : fab # test git du 02/10/2023 depuis snster +#maj by fab du 05/07/2026: remplacer les appels mmctl soit par l'api REST soit par un webhook entrant + # !!! need by htpasswd # apt-get install apache2-utils dos2unix @@ -42,6 +44,7 @@ cd "${KAZ_ROOT}" . $KAZ_KEY_DIR/env-ldapServ . $KAZ_KEY_DIR/env-sympaServ . $KAZ_KEY_DIR/env-paheko +. $KAZ_KEY_DIR/env-mattermostAdmin # DOCK_DIR="${KAZ_COMP_DIR}" # ??? @@ -218,15 +221,36 @@ FILE_LDIF=/home/sauve/ldap.ldif gunzip ${FILE_LDIF}.gz -f grep -aEiorh '([[:alnum:]]+([._-][[:alnum:]]+)*@[[:alnum:]]+([._-][[:alnum:]]+)*\.[[:alpha:]]{2,6})' ${FILE_LDIF} | sort -u > ${TFILE_EMAIL} -echo "récupération des login mattermost... " -docker exec -i mattermostServ bin/mmctl user list --all | grep ":.*(" | cut -d ':' -f 2 | cut -d ' ' -f 2 | sort > "${TFILE_MM}" +# remplacé par la l'API REST +# echo "récupération des login mattermost... " +# docker exec -i mattermostServ bin/mmctl user list --all | grep ":.*(" | cut -d ':' -f 2 | cut -d ' ' -f 2 | sort > "${TFILE_MM}" + +> "${TFILE_MM}" + +page=0 +while true; do + json=$(curl -s \ + -H "Authorization: Bearer ${mattermost_token}" \ + "https://${URL_AGORA}/api/v4/users?page=${page}&per_page=200") + + nb=$(echo "${json}" | jq 'length') + + if [ "${nb}" -eq 0 ]; then + break + fi + + echo "${json}" | jq -r '.[].username' >> "${TFILE_MM}" + page=$((page + 1)) +done +sort -o "${TFILE_MM}" "${TFILE_MM}" + dos2unix "${TFILE_MM}" -echo "done" +# remplacé par la l'API REST # se connecter à l'agora pour ensuite pouvoir passer toutes les commandes mmctl -. $KAZ_KEY_DIR/env-mattermostAdmin -echo "docker exec -i mattermostServ bin/mmctl auth login ${httpProto}://${URL_AGORA} --name local-server --username ${mattermost_user} --password ${mattermost_pass}" | tee -a "${CMD_INIT}" +# . $KAZ_KEY_DIR/env-mattermostAdmin +# echo "docker exec -i mattermostServ bin/mmctl auth login ${httpProto}://${URL_AGORA} --name local-server --username ${mattermost_user} --password ${mattermost_pass}" | tee -a "${CMD_INIT}" # vérif des emails regex="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$" @@ -593,23 +617,99 @@ userPassword: {CRYPT}${pass}\n\n' | ldapmodify -c -H ldap://${LDAP_IP} -D \"cn=$ if grep -q "^${IDENT_KAZ}$" "${TFILE_MM}" 2>/dev/null; then echo "${IDENT_KAZ} existe déjà sur mattermost" | tee -a "${LOG}" else + # on créé le compte mattermost - echo "docker exec -i mattermostServ bin/mmctl user create --email ${EMAIL_SOUHAITE} --username ${IDENT_KAZ} --password ${PASSWORD}" | tee -a "${CMD_LOGIN}" + #echo "docker exec -i mattermostServ bin/mmctl user create --email ${EMAIL_SOUHAITE} --username ${IDENT_KAZ} --password ${PASSWORD}" | tee -a "${CMD_LOGIN}" +#on remplace par l'api rest +cat <