mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2024-11-23 02:27:05 +00:00
Dynamic DNS: Allow overriding http method in request parameter
I own a DSL router that allows me to specify a custom url for dynamic dns updates, but which can only do GET requests. In order to be able to update addresses on a mailinabox server, I added the option to emulate the required request method bu specifying it in a request parameter.
This commit is contained in:
parent
dd7a2aa8a6
commit
893a7274d2
@ -277,13 +277,15 @@ def dns_set_record(qname, rtype="A"):
|
||||
|
||||
# Read the record value from the request BODY, which must be
|
||||
# ASCII-only. Not used with GET.
|
||||
value = request.stream.read().decode("ascii", "ignore").strip()
|
||||
value = request.args.get("override_value", request.stream.read().decode("ascii", "ignore").strip())
|
||||
|
||||
if request.method == "GET":
|
||||
method = request.args.get("override_method", request.method)
|
||||
|
||||
if method == "GET":
|
||||
# Get the existing records matching the qname and rtype.
|
||||
return dns_get_records(qname, rtype)
|
||||
|
||||
elif request.method in ("POST", "PUT"):
|
||||
elif method in ("POST", "PUT"):
|
||||
# There is a default value for A/AAAA records.
|
||||
if rtype in ("A", "AAAA") and value == "":
|
||||
value = request.environ.get("HTTP_X_FORWARDED_FOR") # normally REMOTE_ADDR but we're behind nginx as a reverse proxy
|
||||
@ -292,17 +294,17 @@ def dns_set_record(qname, rtype="A"):
|
||||
if value == '':
|
||||
return ("No value for the record provided.", 400)
|
||||
|
||||
if request.method == "POST":
|
||||
if method == "POST":
|
||||
# Add a new record (in addition to any existing records
|
||||
# for this qname-rtype pair).
|
||||
action = "add"
|
||||
elif request.method == "PUT":
|
||||
elif method == "PUT":
|
||||
# In REST, PUT is supposed to be idempotent, so we'll
|
||||
# make this action set (replace all records for this
|
||||
# qname-rtype pair) rather than add (add a new record).
|
||||
action = "set"
|
||||
|
||||
elif request.method == "DELETE":
|
||||
elif method == "DELETE":
|
||||
if value == '':
|
||||
# Delete all records for this qname-type pair.
|
||||
value = None
|
||||
|
Loading…
Reference in New Issue
Block a user