diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e0905d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/tags* \ No newline at end of file diff --git a/controle_adhesion/main.py b/controle_adhesion/main.py index 1cb08ad..a76ce74 100755 --- a/controle_adhesion/main.py +++ b/controle_adhesion/main.py @@ -155,7 +155,7 @@ def new_registrations_worker(): reg_city, "FR", "", - "Adhesion "+numcode, + "Adhesion {}, {} par {}".format(numcode, reg_tarif, reg_payment), "") answer = gestion_adduser(request) if len(answer) > 0: @@ -332,10 +332,6 @@ def main(): print(line) if is_sendable: - try: - os.remove("temp.txt") - except: - pass sendmail(mailheaders, mailtext) ## Bootstrap diff --git a/controle_cotisation/mail_cotisation.txt b/controle_cotisation/mail_cotisation.txt deleted file mode 100644 index 5b1eda4..0000000 --- a/controle_cotisation/mail_cotisation.txt +++ /dev/null @@ -1,32 +0,0 @@ -Content-Language: fr -From: =?UTF-8?Q?Tr=c3=a9sorier_de_Libre_en_Communs?= -To: -Subject: =?UTF-8?Q?=5bTr=c3=a9sorerie=5d_Re=c3=a7u_pour_votre_cotisation_de_?= - =?UTF-8?Q?membre?= -Mime-Version: 1.0 -Content-Type: multipart/mixed; boundary="------------3yxkFgv0AINs5nd0i6BJrWaV" - -This is a multi-part message in MIME format. ---------------3yxkFgv0AINs5nd0i6BJrWaV -Content-Type: text/plain; charset=UTF-8; format=flowed -Content-Transfer-Encoding: 8bit - -Bonsoir, - -Veuillez trouver ci-joint votre reçu pour la cotisation annuelle pour l'année civile ANNEE-CIVILE. - -Librement, - --- -Adrien Bourmault -Trésorier de Libre en Communs -GPG: 0980e827cb47fbb9 -- -Association Libre en Communs ---------------3yxkFgv0AINs5nd0i6BJrWaV -Content-Type: application/pdf; name="Recu_cotisation_ANNEE-CIVILE.pdf" -Content-Disposition: attachment; filename="Recu_cotisation_ANNEE-CIVILE.pdf" -Content-Transfer-Encoding: base64 - - - diff --git a/controle_cotisation/mail_instructions_cotisation.txt b/controle_cotisation/mail_instructions.txt similarity index 74% rename from controle_cotisation/mail_instructions_cotisation.txt rename to controle_cotisation/mail_instructions.txt index 7ddc3e2..6fb7a82 100644 --- a/controle_cotisation/mail_instructions_cotisation.txt +++ b/controle_cotisation/mail_instructions.txt @@ -1,11 +1,3 @@ -Content-Language: fr -From: =?UTF-8?Q?Tr=c3=a9sorier_de_Libre_en_Communs?= -To: -Subject: =?UTF-8?Q?=5bTr=c3=a9sorerie=5d_-_modalit=c3=a9s_de_r=c3=a8glement_de_vo?= - =?UTF-8?Q?tre_cotisation_ANNEE_CIVILE?= -Content-Type: text/plain; charset=UTF-8; format=flowed -Content-Transfer-Encoding: 8bit - Bonjour NOM_COTISANT, Je reviens vers vous pour vous informer des modalités de règlement de votre @@ -36,12 +28,9 @@ Domiciliation: CCM DU PLATEAU BRIARD Vous remerciant encore de votre engagement, Librement, --- +-- Adrien Bourmault Trésorier de Libre en Communs GPG: 0980e827cb47fbb9 - -Association Libre en Communs - - - +Association Libre en Communs \ No newline at end of file diff --git a/controle_cotisation/mail_instructions_headers.txt b/controle_cotisation/mail_instructions_headers.txt new file mode 100644 index 0000000..3387c3d --- /dev/null +++ b/controle_cotisation/mail_instructions_headers.txt @@ -0,0 +1,7 @@ +Content-Language: fr +From: =?UTF-8?Q?Tr=c3=a9sorier_de_Libre_en_Communs?= +To: +Subject: =?UTF-8?Q?=5bTr=c3=a9sorerie=5d_-_modalit=c3=a9s_de_r=c3=a8glement_de_vo?= + =?UTF-8?Q?tre_cotisation_ANNEE_CIVILE?= +Content-Type: text/plain; charset=UTF-8; format=flowed +Content-Transfer-Encoding: 8bit \ No newline at end of file diff --git a/controle_cotisation/mail_recap_header.txt b/controle_cotisation/mail_recap_header.txt new file mode 100644 index 0000000..3ec6294 --- /dev/null +++ b/controle_cotisation/mail_recap_header.txt @@ -0,0 +1,6 @@ +From: tresorier@a-lec.org +To: tresorier@a-lec.org +Subject: Suivi automatique des cotisations +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit \ No newline at end of file diff --git a/controle_cotisation/mail_recu.txt b/controle_cotisation/mail_recu.txt new file mode 100644 index 0000000..6bcc2b0 --- /dev/null +++ b/controle_cotisation/mail_recu.txt @@ -0,0 +1,12 @@ +Bonsoir, + +Veuillez trouver ci-joint votre reçu pour la cotisation annuelle pour l'année civile ANNEE-CIVILE. + +Librement, + +-- +Adrien Bourmault +Trésorier de Libre en Communs +GPG: 0980e827cb47fbb9 +- +Association Libre en Communs \ No newline at end of file diff --git a/controle_cotisation/mail_recu_attachment.txt b/controle_cotisation/mail_recu_attachment.txt new file mode 100644 index 0000000..a29e298 --- /dev/null +++ b/controle_cotisation/mail_recu_attachment.txt @@ -0,0 +1,4 @@ +--------------3yxkFgv0AINs5nd0i6BJrWaV +Content-Type: application/pdf; name="Recu_cotisation_ANNEE-CIVILE.pdf" +Content-Disposition: attachment; filename="Recu_cotisation_ANNEE-CIVILE.pdf" +Content-Transfer-Encoding: base64 \ No newline at end of file diff --git a/controle_cotisation/mail_recu_headers.txt b/controle_cotisation/mail_recu_headers.txt new file mode 100644 index 0000000..9e3eba2 --- /dev/null +++ b/controle_cotisation/mail_recu_headers.txt @@ -0,0 +1,12 @@ +Content-Language: fr +From: =?UTF-8?Q?Tr=c3=a9sorier_de_Libre_en_Communs?= +To: +Subject: =?UTF-8?Q?=5bTr=c3=a9sorerie=5d_Re=c3=a7u_pour_votre_cotisation_de_?= + =?UTF-8?Q?membre?= +Mime-Version: 1.0 +Content-Type: multipart/mixed; boundary="------------3yxkFgv0AINs5nd0i6BJrWaV" + +This is a multi-part message in MIME format. +--------------3yxkFgv0AINs5nd0i6BJrWaV +Content-Type: text/plain; charset=UTF-8; format=flowed +Content-Transfer-Encoding: 8bit \ No newline at end of file diff --git a/controle_cotisation/main.py b/controle_cotisation/main.py new file mode 100644 index 0000000..611e839 --- /dev/null +++ b/controle_cotisation/main.py @@ -0,0 +1,129 @@ +#!/usr/bin/python3 + +# Libre en Communs's cotisation control program +# Copyright (C) 2022 Libre en Communs + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import os, requests, json, datetime, shutil, quopri, subprocess +from requests.auth import HTTPBasicAuth +from requests.auth import HTTPDigestAuth + + +VERSION="0.0.1" +GESTION_SECRET_FILE="/home/tresorier/.secret/gestion_api_password" +GIT_SECRET_FILE="/home/tresorier/.secret/git_api_password" +WORKDIR="/srv/validation_cotisation.d" +MODALITY_MAIL="mail_instructions.txt" +MODALITY_MAIL_HEADERS="mail_instructions_headers.txt" +RECEPT_MAIL="mail_recu.txt" +RECEPT_MAIL_HEADERS="mail_recu_headers.txt" +RECEPT_MAIL_ATTACHMENT="mail_recu_attachment.txt" +SUMMARY_MAIL="mail_recap_header.txt" +SENDMAIL_LOCATION = "/usr/sbin/sendmail" # sendmail location +BUF=[] + +# gestion_read("SELECT * FROM services_users su \ +# INNER JOIN membres m ON m.id = su.id_user \ +# INNER JOIN services_fees sf ON sf.id = su.id_fee \ +# LEFT JOIN acc_transactions_users tu ON tu.id_service_user = su.id \ +# LEFT JOIN acc_transactions_lines l ON l.id_transaction = tu.id_transaction \ +# WHERE m.id = 3 AND l.id_account = 481;") + +def gestion_get_secret(): + with open(GESTION_SECRET_FILE) as sfile: + return sfile.readline().replace("\n", "") + +def git_get_secret(): + with open(GIT_SECRET_FILE) as sfile: + return sfile.readline().replace("\n", "") + +def get_file_content(filename): + with open(filename) as sfile: + return sfile.readlines() + +def get_file_content_all(filename): + with open(filename) as sfile: + return sfile.read() + +def set_file_content(filename, lines): + with open(filename, "x") as sfile: + return sfile.writelines(lines) + +def gestion_read(req): + response = requests.post('https://gestion.a-lec.org/api/sql/', + auth = HTTPBasicAuth('api666', gestion_get_secret()), + data = req) + return response.json() + +def git_mail_ticket_create(req): + response = requests.post('https://git.a-lec.org/api/v4/projects/46/issues', + headers={'PRIVATE-TOKEN' : git_get_secret()}, + data = req) + return response.json() + +def git_xmpp_ticket_create(req): + response = requests.post('https://git.a-lec.org/api/v4/projects/44/issues', + headers={'PRIVATE-TOKEN' : git_get_secret()}, + data = req) + return response.json() + +def gestion_adduser(req): + response = requests.put('https://gestion.a-lec.org/api/user/import', + auth = HTTPBasicAuth('api666', gestion_get_secret()), + data = req) + return response.content + +def setup_workdir(): + if not os.path.isdir(WORKDIR): + os.mkdir(WORKDIR) + if not "impayé" in os.listdir(WORKDIR): + os.mkdir(WORKDIR+"/impayé") + if not "expiré" in os.listdir(WORKDIR): + os.mkdir(WORKDIR+"/expiré") + if not "validé" in os.listdir(WORKDIR): + os.mkdir(WORKDIR+"/validé") + +def sendmail(headers, data): + msg = bytes(headers + "\n", 'utf-8') + quopri.encodestring(bytes(data, 'utf-8')) + subprocess.run([SENDMAIL_LOCATION, "-t", "-oi"], input=msg) + +def sendmail_with_attachment(headers, data, attachment_header, attachment): + msg = bytes(headers + "\n", 'utf-8') \ + + quopri.encodestring(bytes(data, 'utf-8')) \ + + bytes(attachment_header + "\n", 'utf-8') + + bytes(attachment, 'base64') + subprocess.run([SENDMAIL_LOCATION, "-t", "-oi"], input=msg) + + +def main(): + setup_workdir() + + # End of work + # Launch summary mail + mailheaders = get_file_content_all(SUMMARY_MAIL) + "\n" + mailtext = "" + + is_sendable = False; + for line in BUF: + mailtext += line + "\n" + is_sendable = True; + print(line) + + if is_sendable: + sendmail(mailheaders, mailtext) + +## Bootstrap +if __name__ == '__main__': + main() diff --git a/controle_cotisation/recap_header.txt b/controle_cotisation/recap_header.txt deleted file mode 100644 index 13306a3..0000000 --- a/controle_cotisation/recap_header.txt +++ /dev/null @@ -1,6 +0,0 @@ -From: root@gestion.a-lec.org (Cron Daemon) -To: tresorier@a-lec.org -Subject: Gestion -- script cotisation -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit