[cranspasswords] On envoit les notifs via la commande sendmail
This commit is contained in:
parent
492d9f664a
commit
fe9ba118ed
2 changed files with 14 additions and 11 deletions
14
server.py
14
server.py
|
@ -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,)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue