From: Philipp Spitzer Date: Wed, 5 Mar 2014 22:59:47 +0000 (+0100) Subject: Implemented offline parameter. X-Git-Tag: 0.0.2~27 X-Git-Url: https://git.toastfreeware.priv.at/toast/tdyndns.git/commitdiff_plain/e4b8753c82ea18479ced869ba96d17e44c84da46 Implemented offline parameter. --- diff --git a/cgi-bin/dyndns.py b/cgi-bin/dyndns.py index 8291ac2..95fcfda 100755 --- a/cgi-bin/dyndns.py +++ b/cgi-bin/dyndns.py @@ -66,15 +66,18 @@ class HostnameMissing(HostnameError): class PasswordWrong(HostnameError): pass -class IpError(DynDnsError): +class MyipError(DynDnsError): returncode = 'badip' # not documented at dyn.com -class IpMissing(IpError): +class MyipMissing(MyipError): pass -class IpInvalid(IpError): +class MyipInvalid(MyipError): pass +class OfflineInvalid(DynDnsError): + returncode = 'badparam' # not documented at dyn.com + try: # check username if username is None: @@ -103,24 +106,39 @@ try: if hostname.endswith(ZONE): hostname = hostname[:-len(ZONE)] + # check offline + if offline is None or offline.lower() == 'no': + offline = False + elif offline.lower() == 'yes': + offline = True + else: + raise OfflineInvalid() + # check IP address - if myip is None: - raise IpMissing() - try: - ip = ipaddr.IPAddress(myip) # throws an exception if the IP address is not valid - except ValueError: - raise IpInvalid() - if isinstance(ip, ipaddr.IPv4Address): - iptype = 'A' - elif isinstance(ip, ipaddr.IPv6Address): - iptype = 'AAAA' + if not offline: + if myip is None: + raise MyipMissing() + try: + ip = 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 + if offline: + call(['sudo', '/usr/local/bin/nsupdate_dyndns_del', hostname, 'A']) + call(['sudo', '/usr/local/bin/nsupdate_dyndns_del', hostname, 'AAAA']) else: - raise IpInvalid() # should never happen + call(['sudo', '/usr/local/bin/nsupdate_dyndns', hostname, myip, iptype]) - # access granted + # return success print "Content-Type: text/html" print - call(['sudo', '/usr/local/bin/nsupdate_dyndns', hostname, myip, iptype]) print "good" # Note: we should return 'nochg' in case the IP has not changed, however we don't know yet.