🔒 Sécurisation via .env + refactorisation Monitor et MQTT

This commit is contained in:
2025-04-22 10:48:58 +02:00
parent 4991b6354c
commit 4dd230f77b
6 changed files with 80 additions and 50 deletions

View File

@@ -5,32 +5,38 @@ import time
import smtplib
from email.mime.text import MIMEText
import pandas as pd
from dotenv import load_dotenv
import os
# Charger les variables d'environnement
load_dotenv()
# --- Config MySQL ---
config = {
"host": "54.36.188.119",
"user": "michel",
"password": "#SO2&1nf%mZ@jfh",
"database": "Sondes"
"host": os.getenv("DB_HOST"),
"user": os.getenv("DB_USER"),
"password": os.getenv("DB_PASSWORD"),
"database": os.getenv("DB_NAME")
}
# --- Destinataires email ---
destinataires = ['services@domo91.fr']
destinataires = os.getenv("EMAIL_DEST").split(",")
# --- Fonction d'envoi de mail ---
def envoyer_mail(sujet, message, destinataires):
msg = MIMEText(message)
msg['Subject'] = sujet
msg['From'] = 'alertes_saclay@domo91.fr'
msg['From'] = os.getenv("EMAIL_FROM")
msg['To'] = ', '.join(destinataires)
try:
with smtplib.SMTP_SSL('smtp.mail.ovh.net', 465) as server:
server.login('alertes_saclay@domo91.fr', 'Kdpke674y23Feq^H')
with smtplib.SMTP_SSL(os.getenv("SMTP_HOST"), int(os.getenv("SMTP_PORT"))) as server:
server.login(os.getenv("SMTP_USER"), os.getenv("SMTP_PASSWORD"))
server.sendmail(msg['From'], destinataires, msg.as_string())
print(f"📧 Mail envoyé à {destinataires}", flush=True)
except Exception as e:
print(f"Erreur envoi mail : {e}", flush=True)
# --- Fonction de surveillance ---
def surveiller():
log_entries = []