diff --git a/nsupdate/api/views.py b/nsupdate/api/views.py index 59bcac0..2ea1d70 100644 --- a/nsupdate/api/views.py +++ b/nsupdate/api/views.py @@ -198,6 +198,14 @@ def AuthorizedNicUpdateView(request): def _update(hostname, ipaddr): ipaddr = str(ipaddr) # XXX bug in dnspython: crashes if ipaddr is unicode, wants a str! + hosts = Host.filter_by_fqdn(hostname) + num_hosts = len(hosts) + if num_hosts == 0: + return False + if num_hosts > 1: + logging.error("fqdn %s has multiple entries" % hostname) + return False + hosts[0].poke() try: update(hostname, ipaddr) logger.info('%s - received good update -> ip: %s' % (hostname, ipaddr, )) diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index fde541b..25e80b9 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -7,6 +7,7 @@ from django.db.models.signals import post_delete from django.contrib.auth.hashers import make_password from main import dnstools import dns.resolver +from datetime import datetime import re @@ -83,14 +84,18 @@ class Host(models.Model): def getIPv4(self): try: return dnstools.query_ns(self.get_fqdn(), 'A') - except dns.resolver.NXDOMAIN: - return '' + except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): + return '-' def getIPv6(self): try: return dnstools.query_ns(self.get_fqdn(), 'AAAA') - except dns.resolver.NXDOMAIN: - return '' + except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): + return '-' + + def poke(self): + self.last_api_update = datetime.now() + self.save() def generate_secret(self): # note: we use a quick hasher for the update_secret as expensive