]> ToastFreeware Gitweb - toast/tdyndns.git/blobdiff - cgi-bin/dyndns.py
update docs after renames
[toast/tdyndns.git] / cgi-bin / dyndns.py
index 417c27a2c9981681117659a5ee8c214afaa52d63..5cbf1cee2d2ece5b71606fe3a94f0c478a111abf 100755 (executable)
@@ -13,7 +13,6 @@ import ipaddr
 
 # Configuration
 PASSWORD = 'hygCithOrs5'
-ZONE = '.dyn.colgarra.priv.at'
 DEBUG = False
 
 
@@ -72,6 +71,9 @@ class MyipInvalid(MyipError):
 class OfflineInvalid(DynDnsError):
        returncode = 'badparam' # not documented at dyn.com
 
+class NsupdateError(DynDnsError):
+       returncode = 'nohost'
+
 
 fields = cgi.FieldStorage()
 
@@ -134,8 +136,6 @@ try:
 
        # strip zone
        hostname = hostname.strip()
-       if hostname.endswith(ZONE):
-               hostname = hostname[:-len(ZONE)]
 
        # check offline
        if offline is None or offline.lower() == 'no':
@@ -155,22 +155,22 @@ try:
                                myip = os.environ.get('REMOTE_ADDR')
                                if not myip: # empty string if not present
                                        raise MyipMissing()
+       if not myip is None:
                try:
-                       ip = ipaddr.IPAddress(myip) # throws an exception if the IP address is not valid
+                       ipaddr.IPAddress(myip) # throws an exception if the IP address is not valid
                except ValueError:
                        raise MyipInvalid()
-               if isinstance(ip, ipaddr.IPv4Address):
-                       iptype = 'A'
-               elif isinstance(ip, ipaddr.IPv6Address):
-                       iptype = 'AAAA'
-               else:
-                       raise MyipInvalid() # should never happen
 
        # update bind
+       call_params = ['sudo', 'nsupdate_dyndns']
        if offline:
-               call(['sudo', '/usr/local/bin/nsupdate_dyndns', '--delete', hostname])
-       else:
-               call(['sudo', '/usr/local/bin/nsupdate_dyndns', '--ip', myip, hostname])
+               call_params.append('--delete')
+       if myip is not None:
+               call_params.extend(['--ip', myip])
+       call_params.append(hostname)
+       retcode = call(call_params)
+       if retcode != 0:
+               raise NsupdateError()
 
        # return success
        print "Content-Type: text/html"