Add GET parameter to allow useres to change expiry TTL
This commit is contained in:
@@ -377,10 +377,77 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
else:
|
||||
ipv6 = ip
|
||||
|
||||
# Process expiry_ttl parameter
|
||||
expiry_ttl_param = extract_param(
|
||||
params, endpoint["params"]["expiry_ttl"])
|
||||
expiry_ttl = None
|
||||
if expiry_ttl_param:
|
||||
try:
|
||||
expiry_ttl = int(expiry_ttl_param)
|
||||
if expiry_ttl < 0:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
raise DDNSClientError(
|
||||
"Invalid expiry_ttl",
|
||||
400,
|
||||
STATUS_NOHOST,
|
||||
client=client_ip,
|
||||
username=username,
|
||||
hostname=hostname.hostname,
|
||||
zone=hostname.zone,
|
||||
expiry_ttl=expiry_ttl_param
|
||||
)
|
||||
|
||||
# Validate bounds
|
||||
defaults = self.app.config["defaults"]
|
||||
allow_zero = defaults.get("expiry_ttl_allow_zero", True)
|
||||
ttl_min = defaults.get("expiry_ttl_min")
|
||||
ttl_max = defaults.get("expiry_ttl_max")
|
||||
|
||||
if expiry_ttl == 0:
|
||||
if not allow_zero:
|
||||
raise DDNSClientError(
|
||||
"Zero expiry_ttl not allowed",
|
||||
400,
|
||||
STATUS_NOHOST,
|
||||
client=client_ip,
|
||||
username=username,
|
||||
hostname=hostname.hostname,
|
||||
zone=hostname.zone,
|
||||
expiry_ttl=expiry_ttl
|
||||
)
|
||||
else:
|
||||
if ttl_min is not None and expiry_ttl < ttl_min:
|
||||
raise DDNSClientError(
|
||||
"expiry_ttl below minimum",
|
||||
400,
|
||||
STATUS_NOHOST,
|
||||
client=client_ip,
|
||||
username=username,
|
||||
hostname=hostname.hostname,
|
||||
zone=hostname.zone,
|
||||
expiry_ttl=expiry_ttl,
|
||||
min=ttl_min
|
||||
)
|
||||
if ttl_max is not None and expiry_ttl > ttl_max:
|
||||
raise DDNSClientError(
|
||||
"expiry_ttl above maximum",
|
||||
400,
|
||||
STATUS_NOHOST,
|
||||
client=client_ip,
|
||||
username=username,
|
||||
hostname=hostname.hostname,
|
||||
zone=hostname.zone,
|
||||
expiry_ttl=expiry_ttl,
|
||||
max=ttl_max
|
||||
)
|
||||
|
||||
# Process notify_change parameter
|
||||
notify_change = extract_param(params, endpoint["params"]["notify_change"])
|
||||
notify_change = notify_change.lower() in ["1", "y", "yes", "on", "true"] \
|
||||
if notify_change else False
|
||||
notify_change = extract_param(
|
||||
params, endpoint["params"]["notify_change"])
|
||||
notify_change = (notify_change.lower() in
|
||||
["1", "y", "yes", "on", "true"]
|
||||
if notify_change else False)
|
||||
|
||||
# Good rate limit check
|
||||
if self.app.good_limiter:
|
||||
@@ -406,7 +473,8 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
hostname,
|
||||
ipv4,
|
||||
ipv6,
|
||||
notify_change
|
||||
notify_change,
|
||||
expiry_ttl
|
||||
)
|
||||
|
||||
def _authenticate(self, client_ip, username, password):
|
||||
@@ -466,7 +534,8 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
except Exception as e:
|
||||
logging.error(f"DNS rollback failed ({record_type}): {e}")
|
||||
|
||||
def _process_ip_update(self, client_ip, user, hostname, ipv4, ipv6, notify_change):
|
||||
def _process_ip_update(self, client_ip, user, hostname, ipv4, ipv6,
|
||||
notify_change, expiry_ttl):
|
||||
"""Process IP update for hostname."""
|
||||
now = now_utc()
|
||||
|
||||
@@ -475,6 +544,12 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
ipv4_changed = False
|
||||
ipv6_changed = False
|
||||
|
||||
# Apply expiry_ttl if provided
|
||||
expiry_ttl_changed = False
|
||||
if expiry_ttl is not None and expiry_ttl != hostname.expiry_ttl:
|
||||
hostname.expiry_ttl = expiry_ttl
|
||||
expiry_ttl_changed = True
|
||||
|
||||
if ipv4:
|
||||
hostname.last_ipv4_update = now
|
||||
if ipv4 != hostname.last_ipv4:
|
||||
@@ -546,28 +621,30 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
zone=hostname.zone
|
||||
)
|
||||
|
||||
changed_addrs = ""
|
||||
if ipv4_changed:
|
||||
changed_addrs += f" ipv4={ipv4}"
|
||||
if ipv6_changed:
|
||||
changed_addrs += f" ipv6={ipv6}"
|
||||
|
||||
if not ipv4_changed and not ipv6_changed:
|
||||
if not ipv4_changed and not ipv6_changed and not expiry_ttl_changed:
|
||||
logging.info(
|
||||
f"No change: client={client_ip} hostname={hostname.hostname} "
|
||||
f"zone={hostname.zone}{changed_addrs} notify_change={str(notify_change).lower()}"
|
||||
f"zone={hostname.zone} notify_change={str(notify_change).lower()}"
|
||||
)
|
||||
self.respond(
|
||||
200,
|
||||
STATUS_NOCHG,
|
||||
ipv4=hostname.last_ipv4,
|
||||
ipv6=hostname.last_ipv6
|
||||
ipv6=hostname.last_ipv6,
|
||||
expiry_ttl=hostname.expiry_ttl
|
||||
)
|
||||
return
|
||||
|
||||
changed_info = ""
|
||||
if ipv4_changed:
|
||||
changed_info += f" ipv4={ipv4}"
|
||||
if ipv6_changed:
|
||||
changed_info += f" ipv6={ipv6}"
|
||||
if expiry_ttl_changed:
|
||||
changed_info += f" expiry_ttl={hostname.expiry_ttl}"
|
||||
logging.info(
|
||||
f"Updated: client={client_ip} hostname={hostname.hostname} "
|
||||
f"zone={hostname.zone}{changed_addrs} notify_change={str(notify_change).lower()}"
|
||||
f"zone={hostname.zone}{changed_info} notify_change={str(notify_change).lower()}"
|
||||
)
|
||||
|
||||
if notify_change:
|
||||
@@ -585,7 +662,8 @@ class DDNSRequestHandler(BaseHTTPRequestHandler):
|
||||
200,
|
||||
STATUS_GOOD,
|
||||
ipv4=hostname.last_ipv4,
|
||||
ipv6=hostname.last_ipv6
|
||||
ipv6=hostname.last_ipv6,
|
||||
expiry_ttl=hostname.expiry_ttl
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user