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'
22 fields = cgi.FieldStorage()
24 username = fields.getvalue('username')
25 password = fields.getvalue('password')
26 hostname = fields.getvalue('hostname')
27 myip = fields.getvalue('myip')
30 hostname = re.sub('\.dyn\.colgarra\.priv\.at\s*$', '', hostname)
34 user_info = pwd.getpwnam(username) # returns a key error if the user does not exist
35 if user_info.pw_uid < 1000:
36 raise RuntimeError('Invalid user name')
39 if password != PASSWORD:
40 raise RuntimeError('Invalid password')
43 if re.match(r'[-0-9a-z]+(\.[-0-9a-z]+)*$', hostname) is None:
44 raise RuntimeError('Invalid host name')
47 ip = ipaddr.IPAddress(myip) # throws axception if the IP address is not valid
48 if isinstance(ip, ipaddr.IPv4Address):
50 elif isinstance(ip, ipaddr.IPv6Address):
53 raise RuntimeError('Unknown IP address type')
56 print "Content-Type: text/html"
58 call(['sudo', '/usr/local/bin/nsupdate_dyndns', hostname, myip, type])
64 print "Content-Type: text/html"
65 print "Status: 403 Forbidden"