Skip to content

Commit

Permalink
Accept hostnames as additional parameters
Browse files Browse the repository at this point in the history
This requires writing a wrapper script to pass those parameters, as DSM
doesn't allow to do that directly.

Resolves kofemann#3
  • Loading branch information
cdlm committed Feb 20, 2022
1 parent 4996c1a commit 7227634
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions livedns.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ def set_gandi_ip(addr, domain, hostname):

if __name__ == '__main__':

if len(sys.argv) != 5:
print("Usage: livedns <username> <api key> <fqdn> <ip>")
if len(sys.argv) < 5:
print("Usage: livedns <username> <api key> <fqdn> <ip> [hostname...]")
sys.exit(1)

username = sys.argv[1] # ignored
api_key = sys.argv[2]
fqdn = sys.argv[3]
ip = sys.argv[4]
hostnames = sys.argv[5:]

dot = fqdn.find('.')
if dot == -1:
print('notfqdn')
segments = fqdn.split(".")
if len(segments) == 1:
exit()

# if this is a top domain (a-la kofemann.dev) then use '@' as a special placeholder for empty name
if fqdn.find('.', dot + 1) == -1:
hostname = '@'
domain = fqdn
elif len(segments) == 2 and not hostnames:
# top domains (a-la kofemann.dev) require '@' as a special empty hostname
hostnames = ["@"]
else:
hostname = fqdn[:dot]
domain = fqdn[dot+1:]
hostnames += segments.pop(0)
domain = ".".join(segments)

try:
set_gandi_ip(ip, domain, hostname)
new_ip = get_gandi_ip(domain, hostname)
for hostname in hostnames:
set_gandi_ip(ip, domain, hostname)
new_ip = get_gandi_ip(domain, hostname)
print('good')
except urllib.error.HTTPError as e:
if e.code == 401:
Expand Down

0 comments on commit 7227634

Please sign in to comment.