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 username = fields.getvalue('username')
26 password = fields.getvalue('password')
27 hostname = fields.getvalue('hostname')
28 myip = fields.getvalue('myip')
31 hostname = hostname.strip()
32 if hostname.endswith(ZONE):
33 hostname = hostname[:-len(ZONE)]
37 user_info = pwd.getpwnam(username) # returns a key error if the user does not exist
38 if user_info.pw_uid < 1000:
39 raise RuntimeError('Invalid user name')
42 if password != PASSWORD:
43 raise RuntimeError('Invalid password')
46 if re.match(r'[-0-9a-z]+(\.[-0-9a-z]+)*$', hostname) is None:
47 raise RuntimeError('Invalid host name')
50 ip = ipaddr.IPAddress(myip) # throws axception if the IP address is not valid
51 if isinstance(ip, ipaddr.IPv4Address):
53 elif isinstance(ip, ipaddr.IPv6Address):
56 raise RuntimeError('Unknown IP address type')
59 print "Content-Type: text/html"
61 call(['sudo', '/usr/local/bin/nsupdate_dyndns', hostname, myip, type])
67 print "Content-Type: text/html"
68 print "Status: 403 Forbidden"