2 """Dynamic DNS script. Expects URLs from routers in the form
3 https://info.colgarra.priv.at/dyndns/dyndns.py?username=<username>&password=<pass>&hostname=<domain>&myip=<ipaddr>
9 from subprocess import call
14 PASSWORD = 'hygCithOrs5'
15 ZONE = '.dyn.colgarra.priv.at'
23 fields = cgi.FieldStorage()
25 # the following fields are supported by most dyndns providers
26 # if a parameter is not provided, the .getvalue method returns None
27 username = fields.getvalue('username')
28 password = fields.getvalue('password')
29 hostname = fields.getvalue('hostname')
30 myip = fields.getvalue('myip')
31 wildcard = fields.getvalue('wildcard')
32 mx = fields.getvalue('mx')
33 backmx = fields.getvalue('backmx')
34 offline = fields.getvalue('offline')
39 user_info = pwd.getpwnam(username) # returns a key error if the user does not exist
40 if user_info.pw_uid < 1000:
41 raise RuntimeError('Invalid user name')
44 if password != PASSWORD:
45 raise RuntimeError('Invalid password')
48 if re.match(r'[-0-9a-z]+(\.[-0-9a-z]+)*$', hostname) is None:
49 raise RuntimeError('Invalid host name')
52 hostname = hostname.strip()
53 if hostname.endswith(ZONE):
54 hostname = hostname[:-len(ZONE)]
57 ip = ipaddr.IPAddress(myip) # throws axception if the IP address is not valid
58 if isinstance(ip, ipaddr.IPv4Address):
60 elif isinstance(ip, ipaddr.IPv6Address):
63 raise RuntimeError('Unknown IP address type')
66 print "Content-Type: text/html"
68 call(['sudo', '/usr/local/bin/nsupdate_dyndns', hostname, myip, type])
74 print "Content-Type: text/html"
75 print "Status: 403 Forbidden"