Commit ffbca15d authored by Daniel STAN's avatar Daniel STAN

Ajout de l'envoi de mail et d'une nounou

parent 14db7244
...@@ -10,11 +10,17 @@ import os ...@@ -10,11 +10,17 @@ import os
import pwd import pwd
import sys import sys
import json import json
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
MYUID = pwd.getpwuid(os.getuid())[0] MYUID = pwd.getpwuid(os.getuid())[0]
if MYUID == 'root': if MYUID == 'root':
MYUID = os.environ['SUDO_USER'] MYUID = os.environ['SUDO_USER']
CRANSP_MAIL = "root@crans.org"
DEST_MAIL = "dstan@crans.org"
KEYS = { KEYS = {
"aza-vallina": ("Damien.Aza-Vallina@crans.org", None), "aza-vallina": ("Damien.Aza-Vallina@crans.org", None),
"dandrimont": ("nicolas.dandrimont@crans.org", "66475AAF"), "dandrimont": ("nicolas.dandrimont@crans.org", "66475AAF"),
...@@ -31,6 +37,7 @@ KEYS = { ...@@ -31,6 +37,7 @@ KEYS = {
"becue": ("becue@crans.org", "194974E2"), "becue": ("becue@crans.org", "194974E2"),
"dstan": ("daniel.stan@crans.org", "6E1C820B"), "dstan": ("daniel.stan@crans.org", "6E1C820B"),
"samir": ("samir@crans.org", "41C2B76B"), "samir": ("samir@crans.org", "41C2B76B"),
"boilard": ("boilard@crans.org", "C39EB6F4"),
"cauderlier": ("cauderlier@crans.org",None), #Méchant pas beau "cauderlier": ("cauderlier@crans.org",None), #Méchant pas beau
"maioli": ("maioli@crans.org",None) #Bis (maybe 9E5026E8) "maioli": ("maioli@crans.org",None) #Bis (maybe 9E5026E8)
} }
...@@ -52,13 +59,15 @@ NOUNOUS=RTC+[ ...@@ -52,13 +59,15 @@ NOUNOUS=RTC+[
"parret-freaud", "parret-freaud",
"cauderlier", "cauderlier",
"maioli", "maioli",
"samir" "samir",
"boilard"
] ]
CA=["becue","dstan","boilard"]
ROLES = { ROLES = {
"bureau": [], "ca": CA,
"ca": [], "ca-w": CA,
"rtc": RTC,
"nounous": NOUNOUS, "nounous": NOUNOUS,
"nounous-w": NOUNOUS #Or maybe RTC ? "nounous-w": NOUNOUS #Or maybe RTC ?
} }
...@@ -132,29 +141,60 @@ def putfile(filename): ...@@ -132,29 +141,60 @@ def putfile(filename):
return False return False
try: try:
oldroles = getfile(filename)['roles'] old = getfile(filename)
oldroles = old['roles']
except TypeError: except TypeError:
old = "//Nouveau fichier"
pass pass
else: else:
if not validate(oldroles,'w'): if not validate(oldroles,'w'):
return False return False
notification("Modification de %s" % filename,\
"Le fichier %s a été modifié par %s." %\
(filename,MYUID),filename,str(old))
writefile(filepath, json.dumps({'roles': roles, 'contents': contents})) writefile(filepath, json.dumps({'roles': roles, 'contents': contents}))
return True return True
def rmfile(filename): def rmfile(filename):
"""Supprime le fichier filename après avoir vérifié les droits sur le fichier""" """Supprime le fichier filename après avoir vérifié les droits sur le fichier"""
try: try:
roles = getfile(filename)['roles'] old = getfile(filename)
roles = old['roles']
except TypeError: except TypeError:
return True return True
else: else:
if validate(roles,'w'): if validate(roles,'w'):
notification("Suppression de %s" % filename,\
"Le fichier %s a été supprimé par %s." %\
(filename,MYUID),filename,str(old))
os.remove(getpath(filename)) os.remove(getpath(filename))
else: else:
return False return False
return True return True
def notification(subject,corps,fname,old):
conn = smtplib.SMTP('localhost')
frommail = CRANSP_MAIL
tomail = DEST_MAIL
msg = MIMEMultipart(_charset="utf-8")
msg['Subject'] = subject
# me == the sender's email address
# family = the list of all recipients' email addresses
msg['From'] = "cranspasswords <%s>" % CRANSP_MAIL
msg['To'] = DEST_MAIL
msg.preamble = "cranspasswords report"
info = MIMEText(corps + #"\nCi-joint l'ancien fichier." +
"\n\n-- \nCranspasswords.py",_charset="utf-8")
msg.attach(info)
#old = MIMEText(old)
#old.add_header('Content-Disposition', 'attachment', filename=fname)
#msg.attach(old)
conn.sendmail(frommail,tomail,msg.as_string())
conn.quit()
if __name__ == "__main__": if __name__ == "__main__":
argv = sys.argv[1:] argv = sys.argv[1:]
if len(argv) not in [1, 2]: if len(argv) not in [1, 2]:
......
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