Initial files push for DDNS Updater
This commit is contained in:
51
daily_report.py
Executable file
51
daily_report.py
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
import re
|
||||
|
||||
# Gmail SMTP settings
|
||||
SMTP_SERVER = "smtp.gmail.com"
|
||||
SMTP_PORT = 587
|
||||
EMAIL_ADDRESS = "ddns.updates@gmail.com"
|
||||
EMAIL_PASSWORD = "tacssyofvkgqvbzo"
|
||||
TO_EMAIL = "rafjaniak@outlook.com"
|
||||
|
||||
|
||||
# Log file path
|
||||
LOG_FILE = "/var/log/ddns.log"
|
||||
|
||||
def send_email(subject, body):
|
||||
msg = MIMEText(body)
|
||||
msg["Subject"] = subject
|
||||
msg["From"] = EMAIL_ADDRESS
|
||||
msg["To"] = TO_EMAIL
|
||||
|
||||
try:
|
||||
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
|
||||
server.ehlo()
|
||||
server.starttls()
|
||||
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
|
||||
server.send_message(msg)
|
||||
print("✅ Email sent successfully")
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to send email: {e}")
|
||||
|
||||
def get_last_log_entries():
|
||||
last_entries = {}
|
||||
with open(LOG_FILE) as f:
|
||||
for line in f:
|
||||
# Match domain entries with status ✅ or ❌
|
||||
match = re.search(r"\] (✅|❌|🌍) (\S+)", line)
|
||||
if match:
|
||||
status, domain = match.groups()
|
||||
last_entries[domain] = line.strip()
|
||||
return last_entries
|
||||
|
||||
if __name__ == "__main__":
|
||||
entries = get_last_log_entries()
|
||||
if entries:
|
||||
body = "\n".join(entries.values())
|
||||
else:
|
||||
body = "No log entries found."
|
||||
|
||||
send_email("DDNS Daily Report", body)
|
||||
Reference in New Issue
Block a user