diff --git a/nsupdate/api/views.py b/nsupdate/api/views.py index e28f35f..3203998 100644 --- a/nsupdate/api/views.py +++ b/nsupdate/api/views.py @@ -24,7 +24,8 @@ def DetectIpView(request): af = dns.inet.af_for_address(ipaddr) key = 'ipv4' if af == dns.inet.AF_INET else 'ipv6' request.session[key] = ipaddr - image_data = open(settings.STATIC_ROOT+"/1px.gif", "rb").read() + with open(os.path.join(settings.STATIC_ROOT, "1px.gif"), "rb") as f: + image_data = f.read() return HttpResponse(image_data, mimetype="image/png") diff --git a/nsupdate/main/dnstools.py b/nsupdate/main/dnstools.py index c7aeaac..eb11198 100644 --- a/nsupdate/main/dnstools.py +++ b/nsupdate/main/dnstools.py @@ -21,6 +21,15 @@ class SameIpError(ValueError): def update(fqdn, ipaddr, ttl=60): + """ + intelligent dns updater - first does a lookup on the master server to find + the current ip and only sends a dynamic update if we have a different ip. + + :param fqdn: fully qualified domain name (str) + :param ipaddr: new ip address + :param ttl: time to live, default 60s (int) + :raises: SameIpError if new and old IP is the same + """ af = dns.inet.af_for_address(ipaddr) rdtype = 'A' if af == dns.inet.AF_INET else 'AAAA' try: diff --git a/nsupdate/main/urls.py b/nsupdate/main/urls.py index 19ec1cf..0872af6 100644 --- a/nsupdate/main/urls.py +++ b/nsupdate/main/urls.py @@ -1,12 +1,9 @@ from django.conf.urls import patterns, include, url -from main.views import ( - HomeView, OverviewView, HostView, DeleteHostView, -) -from api.views import ( - MyIpView, DetectIpView, NicUpdateView -) +from main.views import HomeView, OverviewView, HostView, DeleteHostView +from api.views import MyIpView, DetectIpView, NicUpdateView -urlpatterns = patterns('', +urlpatterns = patterns( + '', url(r'^$', HomeView.as_view(), name="home"), url(r'^overview/$', OverviewView.as_view(), name='overview'), url(r'^host/(?P\d+)/$', HostView.as_view(), name='host_view'),