support multiple domains in update script; get rid of usernames
[dyn-nsupdate.git] / client.py
index a4d41fa86ac646da3008a89fddc1b652927ba1ac..d32542b1e3e6b8ba579d52fabfbc0fbd4583cac5 100755 (executable)
--- a/client.py
+++ b/client.py
@@ -3,24 +3,32 @@ import urllib2, socket, urllib, sys
 
 # configuration variables
 server = 'ns.ralfj.de'
-user = 'yourusername'
+domains = ['your.domain.ralfj.de'] # list of domains to update
 password = 'yourpassword'
-domain = 'your.domain.ralfj.de'
 # END of configuration variables
 
-# check if the domain is already mapped to our current IP
-myip = urllib2.urlopen('https://'+server+'/checkip').read().strip()
-currip = socket.gethostbyname(domain)
-if myip == currip:
-       # nothing to do
-       sys.exit(0)
+def update_domain(domain):
+       '''Update the given domain, using the global server, user, password. Returns True on success, False on failure.'''
+       # check if the domain is already mapped to our current IP
+       myip = urllib2.urlopen('https://'+server+'/checkip').read().strip()
+       domainip = socket.gethostbyname(domain)
+       if myip == domainip:
+               # nothing to do
+               return True
 
-# we need to update the IP
-result = urllib2.urlopen('https://'+server+'/update?user='+urllib.quote(user)+'&password='+urllib.quote(password)+'&domain='+urllib.quote(domain)+'&ip='+urllib.quote(myip)).read().strip()
-if 'good '+myip == result: 
-       # nothing to do, all went all right
-       sys.exit(0)
+       # we need to update the IP
+       result = urllib2.urlopen('https://'+server+'/update?password='+urllib.quote(password)+'&domain='+urllib.quote(domain)+'&ip='+urllib.quote(myip)).read().strip()
+       if 'good '+myip == result: 
+               # all went all right
+               return True
+       else:
+               # Something went wrong
+               print "Unexpected answer from server",server,"while updating",domain,"to",myip
+               print result
+               return False
 
-# there was an error :(
-print result
-sys.exit(1)
+exitcode = 0
+for domain in domains:
+       if not update_domain(domain):
+               exitcode = 1
+sys.exit(exitcode)