Commit fe9ba118 authored by Pierre-Elliott Bécue's avatar Pierre-Elliott Bécue

[cranspasswords] On envoit les notifs via la commande sendmail

parent 492d9f66
......@@ -10,9 +10,9 @@ import os
import pwd
import sys
import json
import smtplib
import datetime
import socket
import subprocess
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
......@@ -241,25 +241,25 @@ def backup(corps, fname, old):
back.write((u'* %s: %s\n' % (str(datetime.datetime.now()), corps)).encode("utf-8"))
back.close()
# TODO monter plus haut
def notification(subject, corps, fname, old):
"""Envoie par mail une notification de changement de fichier"""
conn = smtplib.SMTP('localhost')
frommail = serverconfig.CRANSP_MAIL
tomail = serverconfig.DEST_MAIL
msg = MIMEMultipart(_charset="utf-8")
msg['Subject'] = subject
msg['X-Mailer'] = serverconfig.cmd_name.decode()
msg['From'] = serverconfig.CRANSP_MAIL
msg['To'] = serverconfig.DEST_MAIL
msg['From'] = frommail
msg['To'] = tomail
msg.preamble = u"%s report" % (serverconfig.cmd_name.decode(),)
info = MIMEText(corps +
u"\nLa version précédente a été sauvegardée." +
u"\n\nModification effectuée sur %s." % socket.gethostname() +
u"\n\n-- \nCranspasswords.py", _charset="utf-8")
msg.attach(info)
conn.sendmail(frommail, tomail, msg.as_string())
conn.quit()
mailProcess = subprocess.Popen([serverconfig.sendmail_cmd, "-t"], stdin=subprocess.PIPE)
mailProcess.communicate(msg.as_string())
if __name__ == "__main__":
argv = sys.argv[0:]
......
......@@ -13,6 +13,9 @@ Dans le futur, pourra être remplacé par une connexion ldap.
#: Pour override le nom si vous voulez renommer la commande
cmd_name = 'cranspasswords'
#: Chemin vers la commande sendmail
sendmail_cmd = '/usr/lib/sendmail'
#: Répertoire de stockage des mots de passe
STORE = '/var/lib/%s/db/' % (cmd_name,)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment