nettoyage du code

This commit is contained in:
Didier committed 2026-11-01 17:03:33 +01:00
1 parent 4cd82fb5bf
commit f1a7b3e76c
1 file changed
+111 -112
+111 -112
View File
@@ -245,11 +245,11 @@ infoEmail() {
;;
A | a )
searchEmail alias
echo "------------------------------------------------"
echo "------------------------------------------------"
echo " Alias : ${CHOIX_MAIL} "
echo ""
for INFOALIAS in $(ldapsearch -H ldap://${LDAP_IP} -x -D "cn=${LDAP_ADMIN_USERNAME},${ldap_root}" \
-w "${LDAP_ADMIN_PASSWORD}" -b "${ldap_root}" "(&(objectclass=PostfixBookMailForward)(cn=*${CHOIX_MAIL}*))" mail \
-w "${LDAP_ADMIN_PASSWORD}" -b "${ldap_root}" "(&(objectclass=PostfixBookMailForward)(cn=*${CHOIX_MAIL}*))" mail \
| grep ^mail: | sed -e 's/^mail://')
do
echo -ne "=====> ${GREEN} "
@@ -298,120 +298,119 @@ searchDestroy() {
-b "${ldap_root}" "(&(objectclass=inetOrgPerson)(cn=*${DEL_MAIL}*))" | grep ^cn | sed -e 's/cn: //' )
[ "${REP_SEARCH_DESTROY}" = "" ] && exit 1
fi
while :
do
# Si on est en intarctif on affiche la demande de validation
while :
do
# Si on est en intarctif on affiche la demande de validation
if [ "${DEL_AUTO}" != "TRUE" ]
then
echo "----------------------------------------------------------------------"
printKazMsg "${GREEN}${ACTION_EN_COURS}${NC}"
echo "----------------------------------------------------------------------"
echo -e "${BLINK} TOUT RETOUR EN ARRIERE EST IMPOSSIBLE ${NC}"
read -p "ON CONTINUE ? [ o / n ]: " SEARCH_DESTROY_INPUT
if [ "$SEARCH_DESTROY_INPUT" = "n" ] || [ "$SEARCH_DESTROY_INPUT" = "N" ]
then
searchDestroy
fi
else
# sinon on force la réponse à oui
SEARCH_DESTROY_INPUT="o"
fi
if [ "$SEARCH_DESTROY_INPUT" = "o" ] || [ "$SEARCH_DESTROY_INPUT" = "O" ]
then
####################################################################################################################
# si le domaine en cours est Kaz alors on cherche dans mattermost, dans nextcloud et on supprime
# le mail dans sympa
####################################################################################################################
if [ "${DOMAINE_EN_COURS}" = "${domain}" ]
then
MM_USER_ID=$(searchMattermost $REP_SEARCH_DESTROY)
if [ ! -z ${MM_USER_ID} ]
then
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} suppression de ${REP_SEARCH_DESTROY} trouvé dans mattermost ${NC}"
status_del=$(curl -s --request DELETE \
--header 'Accept: application/json' \
-H "Authorization: Bearer ${mattermost_token}" \
"${URL_AGORA_API}/api/v4/users/${MM_USER_ID}")
if [ "$(echo ${status_del} | jq -r .status)" -eq "200" ]
then
printKazMsg "Suppresion ok"
else
printKazError -e "Erreur de suppression"
fi
echo " ----------------- "
else
[ "${DEL_AUTO}" != "TRUE" ] && echo "Rien a supprimer dans mattermost"
fi
echo -e "${NC}"
echo -e "Recherche de ${GREEN} ${REP_SEARCH_DESTROY} ${NC} dans nextcloud"
USER_NEXTCLOUD_SUPPR=$(curl -s -X GET -H 'OCS-APIRequest:true' $httpProto://admin:$NEXTCLOUD_ADMIN_PASSWORD@$URL_NC/ocs/v1.php/cloud/users?search=${REP_SEARCH_DESTROY} | grep element | sed -s 's/[ \<\>\/]//g' | sed 's/element//g')
if [ ! -z ${USER_NEXTCLOUD_SUPPR} ]
then
if [ "${DEL_AUTO}" != "TRUE" ]
then
[ "${DEL_AUTO}" != "TRUE" ] && printKazMsg "le user trouvé est : ${USER_NEXTCLOUD_SUPPR}"
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} Suppresion de ${USER_NEXTCLOUD_SUPPR}"
fi
curl -H 'OCS-APIREQUEST: true' -X DELETE $httpProto://admin:$NEXTCLOUD_ADMIN_PASSWORD@$URL_NC/ocs/v1.php/cloud/users/${USER_NEXTCLOUD_SUPPR} >/dev/null 2>&1
if [ "$?" -eq "0" ]
then
printKazMsg "Suppresion ok"
else
printKazError "Erreur de suppression"
fi
else
[ "${DEL_AUTO}" != "TRUE" ] && printKazMsg "Rien à supprimer dans Nextcloud"
fi
echo -e "${NC}"
echo ""
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} suppression de ${REP_SEARCH_DESTROY} et ${MAIL_SECOURS} dans la liste info de sympa"
echo -e "${NC}"
echo ""
docker exec -i sympaServ sympa test soap --trusted_application=${SOAP_USER} --trusted_application_password=${SOAP_PASSWORD} --proxy_vars=\"USER_EMAIL=${LISTMASTER}\" --service=del --service_parameters=\"${NL_LIST},${REP_SEARCH_DESTROY}\" ${httpProto}://${URL_LISTE}/sympasoap
docker exec -i sympaServ sympa test soap --trusted_application=${SOAP_USER} --trusted_application_password=${SOAP_PASSWORD} --proxy_vars=\"USER_EMAIL=${LISTMASTER}\" --service=del --service_parameters=\"${NL_LIST},${MAIL_SECOURS}\" ${httpProto}://${URL_LISTE}/sympasoap
echo -e "${NC}"
echo ""
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} suppression de ${REP_SEARCH_DESTROY} dans le serveur de mail"
echo -e "${NC}"
echo ""
fi
############################## - Fin du cas de Kaz ##########################################################################################
echo -e "${NC}"
echo ""
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} suppression de ${REP_SEARCH_DESTROY} dans le ldap"
echo -e "${NC}"
echo ""
ldapdelete -H ldap://${LDAP_IP} -D "cn=${LDAP_ADMIN_USERNAME},${ldap_root}" -x -w "${LDAP_ADMIN_PASSWORD}" "cn=${REP_SEARCH_DESTROY},ou=users,${ldap_root}"
if [ "$?" -eq "0" ]
then
[ "${DEL_AUTO}" != "TRUE" ] && printKazMsg "Suppresion ok"
cd ${DOCK_VOL}/postfix_mailData/_data/${DOMAINE_EN_COURS}
USER_DEL_MAIL=$(echo ${REP_SEARCH_DESTROY} | sed -e 's/@.*//')
[ "${DEL_AUTO}" != "TRUE" ] && echo "Suppression des données ${USER_DEL_MAIL}"
rm -rf ${USER_DEL_MAIL} 2>/dev/null
sleep 2
else
[ "${DEL_AUTO}" != "TRUE" ] && printKazError "Erreur de suppression"
fi
[ "${DEL_AUTO}" != "TRUE" ] && printKazMsg "Envoi d'un message dans mattermost pour la suppression du compte"
PostMattermost "Le compte ${REP_SEARCH_DESTROY} est supprimé , mail envoyé à ${MAIL_SECOURS}" "Creation-Comptes"
MAIL_SUPPR="Le compte ${REP_SEARCH_DESTROY} est supprimé"
OLDIFS=${IFS}
IFS=''
ExpMail ${MAIL_SECOURS} "Suppression de Compte" ${MAIL_SUPPR}
echo -e "${NC}"
IFS=${OLDIFS}
# si on est en interactif on affiche le message
if [ "${DEL_AUTO}" != "TRUE" ]
then
echo "----------------------------------------------------------------------"
printKazMsg "${GREEN}${ACTION_EN_COURS}${NC}"
echo "----------------------------------------------------------------------"
echo -e "${BLINK} TOUT RETOUR EN ARRIERE EST IMPOSSIBLE ${NC}"
read -p "ON CONTINUE ? [ o / n ]: " SEARCH_DESTROY_INPUT
if [ "$SEARCH_DESTROY_INPUT" = "n" ] || [ "$SEARCH_DESTROY_INPUT" = "N" ]
then
searchDestroy
fi
read -p " ---------------------- Appuyer sur une touche pour continuer -------------------------"
searchDestroy
else
# sinon on force la réponse à oui
SEARCH_DESTROY_INPUT="o"
exit 0
fi
if [ "$SEARCH_DESTROY_INPUT" = "o" ] || [ "$SEARCH_DESTROY_INPUT" = "O" ]
then
####################################################################################################################
# si le domaine en cours est Kaz alors on cherche dans mattermost, dans nextcloud et on supprime
# le mail dans sympa
####################################################################################################################
if [ "${DOMAINE_EN_COURS}" = "${domain}" ]
then
MM_USER_ID=$(searchMattermost $REP_SEARCH_DESTROY)
if [ ! -z ${MM_USER_ID} ]
then
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} suppression de ${REP_SEARCH_DESTROY} trouvé dans mattermost ${NC}"
status_del=$(curl -s --request DELETE \
--header 'Accept: application/json' \
-H "Authorization: Bearer ${mattermost_token}" \
"${URL_AGORA_API}/api/v4/users/${MM_USER_ID}")
if [ "$(echo ${status_del} | jq -r .status)" -eq "200" ]
then
printKazMsg "Suppresion ok"
else
printKazError -e "Erreur de suppression"
fi
echo " ----------------- "
else
[ "${DEL_AUTO}" != "TRUE" ] && echo "Rien a supprimer dans mattermost"
fi
echo -e "${NC}"
echo -e "Recherche de ${GREEN} ${REP_SEARCH_DESTROY} ${NC} dans nextcloud"
USER_NEXTCLOUD_SUPPR=$(curl -s -X GET -H 'OCS-APIRequest:true' $httpProto://admin:$NEXTCLOUD_ADMIN_PASSWORD@$URL_NC/ocs/v1.php/cloud/users?search=${REP_SEARCH_DESTROY} | grep element | sed -s 's/[ \<\>\/]//g' | sed 's/element//g')
if [ ! -z ${USER_NEXTCLOUD_SUPPR} ]
then
if [ "${DEL_AUTO}" != "TRUE" ]
then
[ "${DEL_AUTO}" != "TRUE" ] && printKazMsg "le user trouvé est : ${USER_NEXTCLOUD_SUPPR}"
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} Suppresion de ${USER_NEXTCLOUD_SUPPR}"
fi
curl -H 'OCS-APIREQUEST: true' -X DELETE $httpProto://admin:$NEXTCLOUD_ADMIN_PASSWORD@$URL_NC/ocs/v1.php/cloud/users/${USER_NEXTCLOUD_SUPPR} >/dev/null 2>&1
if [ "$?" -eq "0" ]
then
printKazMsg "Suppresion ok"
else
printKazError "Erreur de suppression"
fi
else
[ "${DEL_AUTO}" != "TRUE" ] && printKazMsg "Rien à supprimer dans Nextcloud"
fi
echo -e "${NC}"
echo ""
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} suppression de ${REP_SEARCH_DESTROY} et ${MAIL_SECOURS} dans la liste info de sympa"
echo -e "${NC}"
echo ""
docker exec -i sympaServ sympa test soap --trusted_application=${SOAP_USER} --trusted_application_password=${SOAP_PASSWORD} --proxy_vars=\"USER_EMAIL=${LISTMASTER}\" --service=del --service_parameters=\"${NL_LIST},${REP_SEARCH_DESTROY}\" ${httpProto}://${URL_LISTE}/sympasoap
docker exec -i sympaServ sympa test soap --trusted_application=${SOAP_USER} --trusted_application_password=${SOAP_PASSWORD} --proxy_vars=\"USER_EMAIL=${LISTMASTER}\" --service=del --service_parameters=\"${NL_LIST},${MAIL_SECOURS}\" ${httpProto}://${URL_LISTE}/sympasoap
echo -e "${NC}"
echo ""
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} suppression de ${REP_SEARCH_DESTROY} dans le serveur de mail"
echo -e "${NC}"
echo ""
fi
############################## - Fin du cas de Kaz ##########################################################################################
echo -e "${NC}"
echo ""
[ "${DEL_AUTO}" != "TRUE" ] && echo -e "${RED} suppression de ${REP_SEARCH_DESTROY} dans le ldap"
echo -e "${NC}"
echo ""
ldapdelete -H ldap://${LDAP_IP} -D "cn=${LDAP_ADMIN_USERNAME},${ldap_root}" -x -w "${LDAP_ADMIN_PASSWORD}" "cn=${REP_SEARCH_DESTROY},ou=users,${ldap_root}"
if [ "$?" -eq "0" ]
then
[ "${DEL_AUTO}" != "TRUE" ] && printKazMsg "Suppresion ok"
cd ${DOCK_VOL}/postfix_mailData/_data/${DOMAINE_EN_COURS}
USER_DEL_MAIL=$(echo ${REP_SEARCH_DESTROY} | sed -e 's/@.*//')
[ "${DEL_AUTO}" != "TRUE" ] && echo "Suppression des données ${USER_DEL_MAIL}"
rm -rf ${USER_DEL_MAIL} 2>/dev/null
sleep 2
else
[ "${DEL_AUTO}" != "TRUE" ] && printKazError "Erreur de suppression"
fi
[ "${DEL_AUTO}" != "TRUE" ] && printKazMsg "Envoi d'un message dans mattermost pour la suppression du compte"
PostMattermost "Le compte ${REP_SEARCH_DESTROY} est supprimé , mail envoyé à ${MAIL_SECOURS}" "Creation-Comptes"
MAIL_SUPPR="Le compte ${REP_SEARCH_DESTROY} est supprimé"
OLDIFS=${IFS}
IFS=''
ExpMail ${MAIL_SECOURS} "Suppression de Compte" ${MAIL_SUPPR}
echo -e "${NC}"
IFS=${OLDIFS}
# si on est en interactif on affiche le message
if [ "${DEL_AUTO}" != "TRUE" ]
then
read -p " ---------------------- Appuyer sur une touche pour continuer -------------------------"
searchDestroy
else
exit 0
fi
fi
done
fi
done
}
gestPassword() {