#!/bin/bash # Check_don # Copyright 2022 Adrien Bourmault # Licence AGPL v3 PASSWORD=$(cat ~/.secret/gestion_api_password) TOKEN=$(cat ~/.secret/git_api_password) contains() { [[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]] } # RECUPERATION DONNEES requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d "SELECT * FROM services_users su INNER JOIN membres m ON m.id = su.id_user INNER JOIN services s ON s.id = su.id_service LEFT JOIN services_fees sf ON sf.id = su.id_fee INNER JOIN (SELECT id, MAX(date) FROM services_users GROUP BY id_user, id_service) AS su2 ON su2.id = su.id WHERE su.id_service = 1 AND m.id = $1;") # Note: su.id_service = 1 parceque la cotisation correspond au service 1 #requete=$(echo -e $requete | cut -d ":" -f 3 | tr -d "\"}]") requete=$(echo -e $requete | tr -d "{}\"[]" | cut -c 9-1000) IFS="," read -a results <<< $requete # VERIFICATION EXISTENCE if [ ${#results[@]} -eq $((0)) ] then echo " *** MEMBRE INEXISTANT ***" exit 1 fi statut=$(echo ${results[15]} | cut -d ":" -f 2) siren=$(echo ${results[16]}| cut -d ":" -f 2) nom=$(echo ${results[17]}| cut -d ":" -f 2) courriel=$(echo ${results[18]}| cut -d ":" -f 2) numero=$(echo ${results[13]}| cut -d ":" -f 2) montant=$(echo ${results[5]}| cut -d ":" -f 2) if [ "$montant" == "null" ] then montant=2000 fi montant=${montant::-2},${montant: -2:2} date=$(echo ${results[6]} | cut -d ":" -f 2) ANNEE_CIVILE=$(( $(echo ${results[7]} | cut -d ":" -f 2 | cut -d "-" -f 1) - 1)) # Vérifier que le courriel est opérationnel requete=$(curl -s --header "PRIVATE-TOKEN: $TOKEN" --request GET "https://git.a-lec.org/api/v4/projects/46/issues?not%5Blabels%5D=R%C3%A9solu&state=opened" | grep -e "Création de compte courriel membre n°${numero}") echo $requete if [ ! -z "$requete" ] then echo " COURRIEL NON FONCTIONNEL" exit 0 fi FILE=$(mktemp /tmp/temporary.XXXXXXXX) cat mail_instructions_cotisation.txt >> "$FILE" sed -i "s/ANNEE_CIVILE/$ANNEE_CIVILE/g" "$FILE" sed -i "s/NUMERO_MEMBRE/$numero/" "$FILE" sed -i "s/COURRIEL_COTISANT/$courriel/" "$FILE" sed -i "s/NOM_COTISANT/$nom/" "$FILE" sed -i "s/MONTANT_COTISATION/$montant/" "$FILE" # ENVOI ( cat "$FILE" ) | /usr/sbin/sendmail -i -- tresorier@a-lec.org "$courriel" #cat "$FILE" rm -f "$FILE"