Add URL parameter to enable notification of IP changes
This commit is contained in:
@@ -317,7 +317,8 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
|
||||
now = utc_now()
|
||||
|
||||
changed = False
|
||||
ipv4_changed = False
|
||||
ipv6_changed = False
|
||||
if ipv4:
|
||||
hostname.last_ipv4_update = now
|
||||
if ipv4 != hostname.last_ipv4:
|
||||
@@ -330,7 +331,7 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
hostname.dns_ttl
|
||||
)
|
||||
hostname.last_ipv4 = ipv4
|
||||
changed = True
|
||||
ipv4_changed = True
|
||||
except Exception as e:
|
||||
hostname.save()
|
||||
logging.error(
|
||||
@@ -351,7 +352,7 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
hostname.dns_ttl
|
||||
)
|
||||
hostname.last_ipv6 = ipv6
|
||||
changed = True
|
||||
ipv6_changed = True
|
||||
except Exception as e:
|
||||
hostname.save()
|
||||
logging.error(
|
||||
@@ -364,15 +365,15 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
hostname.save()
|
||||
|
||||
changed_addrs = ""
|
||||
if ipv4:
|
||||
changed_addrs += f"ipv4={ipv4}"
|
||||
if ipv6:
|
||||
if ipv4_changed:
|
||||
changed_addrs += f" ipv4={ipv4}"
|
||||
if ipv6_changed:
|
||||
changed_addrs += f" ipv6={ipv6}"
|
||||
|
||||
if not changed:
|
||||
if not ipv4_changed and not ipv6_changed:
|
||||
logging.info(
|
||||
f"No change: client={client_ip} hostname={hostname.hostname} "
|
||||
f"zone={hostname.zone} {changed_addrs}"
|
||||
f"zone={hostname.zone}{changed_addrs}"
|
||||
)
|
||||
return (
|
||||
200, "nochg",
|
||||
@@ -381,8 +382,21 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
|
||||
logging.info(
|
||||
f"Updated: client={client_ip} hostname={hostname.hostname} "
|
||||
f"zone={hostname.zone} {changed_addrs}"
|
||||
f"zone={hostname.zone}{changed_addrs}"
|
||||
)
|
||||
|
||||
notify_change = extract_param(params, endpoint["params"]["notify_change"])
|
||||
if notify_change and notify_change.lower() not in ["0", "no", "off"]:
|
||||
try:
|
||||
self.app.email_service.send_change_notification(
|
||||
hostname.user.email,
|
||||
hostname,
|
||||
ipv4_changed,
|
||||
ipv6_changed
|
||||
)
|
||||
except Exception as e:
|
||||
logging.error(f"Sending change notification error: {e}")
|
||||
|
||||
return (
|
||||
200, "good",
|
||||
{"ipv4": hostname.last_ipv4, "ipv6": hostname.last_ipv6}
|
||||
|
||||
Reference in New Issue
Block a user