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'
25 fields = cgi.FieldStorage()
27 # the following fields are supported by most dyndns providers
28 # if a parameter is not provided, the .getvalue method returns None
29 username = fields.getvalue('username')
30 password = fields.getvalue('password')
31 hostname = fields.getvalue('hostname')
32 myip = fields.getvalue('myip')
33 wildcard = fields.getvalue('wildcard')
34 mx = fields.getvalue('mx')
35 backmx = fields.getvalue('backmx')
36 offline = fields.getvalue('offline')
41 user_info = pwd.getpwnam(username) # returns a key error if the user does not exist
42 if user_info.pw_uid < 1000:
43 raise RuntimeError('Invalid user name')
46 if password != PASSWORD:
47 raise RuntimeError('Invalid password')
50 if re.match(r'[-0-9a-z]+(\.[-0-9a-z]+)*$', hostname) is None:
51 raise RuntimeError('Invalid host name')
54 hostname = hostname.strip()
55 if hostname.endswith(ZONE):
56 hostname = hostname[:-len(ZONE)]
59 ip = ipaddr.IPAddress(myip) # throws axception if the IP address is not valid
60 if isinstance(ip, ipaddr.IPv4Address):
62 elif isinstance(ip, ipaddr.IPv6Address):
65 raise RuntimeError('Unknown IP address type')
68 print "Content-Type: text/html"
70 call(['sudo', '/usr/local/bin/nsupdate_dyndns', hostname, myip, type])
76 print "Content-Type: text/html"
77 print "Status: 403 Forbidden"