Add notify_change to log and Date header to email notifications

This commit is contained in:
2026-01-23 01:29:16 +01:00
parent 5744408c92
commit 4bf325ef27
2 changed files with 9 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ import smtplib
from . import datetime_str from . import datetime_str
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.utils import formatdate
from jinja2 import Environment, BaseLoader from jinja2 import Environment, BaseLoader
@@ -70,6 +71,7 @@ class EmailService:
msg["Subject"] = subject msg["Subject"] = subject
msg["From"] = self.config["from_address"] msg["From"] = self.config["from_address"]
msg["To"] = to msg["To"] = to
msg["Date"] = formatdate(localtime=True)
smtp_host = self.config["smtp_host"] smtp_host = self.config["smtp_host"]
smtp_port = self.config["smtp_port"] smtp_port = self.config["smtp_port"]

View File

@@ -364,6 +364,10 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
# Update database # Update database
hostname.save() hostname.save()
notify_change_val = extract_param(params, endpoint["params"]["notify_change"])
notify_change = notify_change_val.lower() not in ["0", "n", "no", "off"] \
if notify_change_val else False
changed_addrs = "" changed_addrs = ""
if ipv4_changed: if ipv4_changed:
changed_addrs += f" ipv4={ipv4}" changed_addrs += f" ipv4={ipv4}"
@@ -373,7 +377,7 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
if not ipv4_changed and not ipv6_changed: if not ipv4_changed and not ipv6_changed:
logging.info( logging.info(
f"No change: client={client_ip} hostname={hostname.hostname} " f"No change: client={client_ip} hostname={hostname.hostname} "
f"zone={hostname.zone}{changed_addrs}" f"zone={hostname.zone}{changed_addrs} notify_change={notify_change}"
) )
return ( return (
200, "nochg", 200, "nochg",
@@ -382,11 +386,10 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
logging.info( logging.info(
f"Updated: client={client_ip} hostname={hostname.hostname} " f"Updated: client={client_ip} hostname={hostname.hostname} "
f"zone={hostname.zone}{changed_addrs}" f"zone={hostname.zone}{changed_addrs} notify_change={notify_change}"
) )
notify_change = extract_param(params, endpoint["params"]["notify_change"]) if notify_change:
if notify_change and notify_change.lower() not in ["0", "no", "off"]:
try: try:
self.app.email_service.send_change_notification( self.app.email_service.send_change_notification(
hostname.user.email, hostname.user.email,