aboutsummaryrefslogtreecommitdiffstats
path: root/ddns/frontend/dyn_com.py
diff options
context:
space:
mode:
Diffstat (limited to 'ddns/frontend/dyn_com.py')
-rw-r--r--ddns/frontend/dyn_com.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/ddns/frontend/dyn_com.py b/ddns/frontend/dyn_com.py
new file mode 100644
index 0000000..bbd61e5
--- /dev/null
+++ b/ddns/frontend/dyn_com.py
@@ -0,0 +1,47 @@
+from flask import request, Response
+import ddns.backend.dnsupdate
+from IPy import IP
+import ddns.auth
+import ddns.cfg_parser
+
+@ddns.auth.require_auth
+def dyn_com():
+ if request.method != 'GET':
+ return "badagent"
+
+ if not request.args.has_key('hostname'):
+ return "nohost"
+
+ if len(request.args.getlist('hostname')) > 1:
+ return "numhost"
+
+ if not request.args.has_key('myip'):
+ return "nohost"
+
+ hostname = request.args.get('hostname')
+ if not '.' in hostname:
+ return "notfqdn"
+
+ zone_name = hostname[hostname.find('.')+1:]
+ if zone_name[-1] != '.':
+ zone_name += '.'
+
+ hostname = hostname[0:hostname.find('.')]
+
+ try:
+ ip = IP(request.args.get('myip'))
+ except ValueError:
+ return "nohost"
+
+ for zone in ddns.cfg_parser.cfg['zones']:
+ if zone_name == zone['name']:
+ for domain in zone['domains']:
+ if domain['domain'] == hostname:
+ for user in domain['users']:
+ if request.authorization.username == user['username']:
+ ddns.backend.dnsupdate.update_dns(zone_name, hostname, ip)
+ # We should probably check something here...
+ return "good"
+ return auth.authenticate("!yours")
+ return "nohost"
+ return "nohost"