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:
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.