diff options
Diffstat (limited to 'ddns/main.py')
-rwxr-xr-x | ddns/main.py | 61 |
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) |