Skip to content

Commit 7227634

Browse files
committed
Accept hostnames as additional parameters
This requires writing a wrapper script to pass those parameters, as DSM doesn't allow to do that directly. Resolves #3
1 parent 4996c1a commit 7227634

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

livedns.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,31 @@ def set_gandi_ip(addr, domain, hostname):
4444

4545
if __name__ == '__main__':
4646

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

5151
username = sys.argv[1] # ignored
5252
api_key = sys.argv[2]
5353
fqdn = sys.argv[3]
5454
ip = sys.argv[4]
55+
hostnames = sys.argv[5:]
5556

56-
dot = fqdn.find('.')
57-
if dot == -1:
5857
print('notfqdn')
58+
segments = fqdn.split(".")
59+
if len(segments) == 1:
5960
exit()
60-
61-
# if this is a top domain (a-la kofemann.dev) then use '@' as a special placeholder for empty name
62-
if fqdn.find('.', dot + 1) == -1:
63-
hostname = '@'
64-
domain = fqdn
61+
elif len(segments) == 2 and not hostnames:
62+
# top domains (a-la kofemann.dev) require '@' as a special empty hostname
63+
hostnames = ["@"]
6564
else:
66-
hostname = fqdn[:dot]
67-
domain = fqdn[dot+1:]
65+
hostnames += segments.pop(0)
66+
domain = ".".join(segments)
6867

6968
try:
70-
set_gandi_ip(ip, domain, hostname)
71-
new_ip = get_gandi_ip(domain, hostname)
69+
for hostname in hostnames:
70+
set_gandi_ip(ip, domain, hostname)
71+
new_ip = get_gandi_ip(domain, hostname)
7272
print('good')
7373
except urllib.error.HTTPError as e:
7474
if e.code == 401:

0 commit comments

Comments
 (0)