From 7135a48d64e8218450c29dec57414954bef1e2ab Mon Sep 17 00:00:00 2001 From: Jeffrey Forman Date: Thu, 14 Apr 2011 15:29:58 -0400 Subject: [PATCH] Rudimentary first listing of zones from an NS works. --- binder/bcommon/views.py | 23 +++++++++++++++++++++++ binder/templates/bcommon/list_zone.htm | 10 ++++++++++ binder/urls.py | 3 ++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 binder/templates/bcommon/list_zone.htm diff --git a/binder/bcommon/views.py b/binder/bcommon/views.py index 884234d..3f3d9f9 100644 --- a/binder/bcommon/views.py +++ b/binder/bcommon/views.py @@ -8,6 +8,10 @@ import urllib2 from BeautifulSoup import BeautifulStoneSoup as BS import re +import dns.query +import dns.zone +import socket + def list_servers(request): server_list = BindServer.objects.all().order_by('hostname') return render_to_response('bcommon/list_servers.htm', @@ -34,3 +38,22 @@ def list_server_zones(request, dns_hostname): return render_to_response('bcommon/list_server_zones.htm', { 'zone_array' : zone_array, 'dns_hostname' : dns_hostname }) + +def list_zone(request, dns_hostname, zone_name): + try: + z = dns.zone.from_xfr(dns.query.xfr(dns_hostname, zone_name)) + except socket.gaierror, e: + print "Problems querying DNS server %s: %s\n" % (options.dns_server, e) + return # Need to handle this situation when it can't query the NS. + + names = z.nodes.keys() + names.sort() # Sort the array alphabetically + record_array = [] + for n in names: + current_record = z[n].to_text(n) + for split_record in current_record.split("\n"): # Split the records on the newline + record_array.append([split_record]) # Add each record to our array + + return render_to_response('bcommon/list_zone.htm', + { 'record_array' : record_array, + 'dns_hostname' : dns_hostname }) diff --git a/binder/templates/bcommon/list_zone.htm b/binder/templates/bcommon/list_zone.htm new file mode 100644 index 0000000..87e3339 --- /dev/null +++ b/binder/templates/bcommon/list_zone.htm @@ -0,0 +1,10 @@ +{% extends "base.htm" %} + +{% block body %} + +