blob: 5ee6eaa8b12434afb0368e91deffccb55c3470ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)
|