aboutsummaryrefslogtreecommitdiffstats
path: root/ddns/main.py
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2014-03-17 04:16:49 +0100
committerMarius Halden <marius.h@lden.org>2014-03-17 04:16:49 +0100
commit7c575aaa8e98a6aa7eda8d69e2b14d014ee91b09 (patch)
tree7bd082fd216e1577440cf1ea599467993c2fef36 /ddns/main.py
downloadDDNS.py-7c575aaa8e98a6aa7eda8d69e2b14d014ee91b09.tar.gz
DDNS.py-7c575aaa8e98a6aa7eda8d69e2b14d014ee91b09.tar.bz2
DDNS.py-7c575aaa8e98a6aa7eda8d69e2b14d014ee91b09.tar.xz
Initial commit
Diffstat (limited to 'ddns/main.py')
-rwxr-xr-xddns/main.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/ddns/main.py b/ddns/main.py
new file mode 100755
index 0000000..5ee6eaa
--- /dev/null
+++ b/ddns/main.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+from flask import Flask, request, Response
+import ddns
+import cfg_parser
+import auth
+from IPy import IP
+
+cfg_file="/srv/http/lden.org/ddns/ddns/ddns.cfg"
+cfg = cfg_parser.read_config(cfg_file)
+
+auth.auth_cfg = cfg['users']
+ddns.zone_cfg = cfg['zones']
+ddns.gen_keyring(cfg['dnskeys'])
+
+app = Flask(__name__)
+
+@app.route("/nic/update")
+@auth.require_auth
+def dyndns():
+ 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 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.update_dns(zone_name, hostname, ip)
+ return "good"
+ return auth.authenticate("!yours")
+ return "nohost"
+ return "nohost"
+
+if __name__ == "__main__":
+ app.run(host="0.0.0.0", debug=True)