blob: 9b803ec4f1acff6529ac73863b862bc1b209c9c1 (
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
|
from flask import request
from IPy import IP
import ddns.backend.dnsupdate
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"
if len(request.args.getlist('myip')) != 1:
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 "nohost2"
raise RuntimeError("ooops")
return "nohost1"
|