Code cleanup, standardize on dns_server and zone_name

Added bootstrap CSS framework
Added error handling around deleting with a bad key.
This commit is contained in:
Jeffrey Forman 2011-11-26 13:03:00 -05:00
parent 380657d5f5
commit a03f49c158
10 changed files with 2515 additions and 56 deletions

View File

@ -7,19 +7,19 @@ import dns.update
re_IPADDRESS = re.compile(r"\d+.\d+.\d+.\d+")
def list_zone_records(dns_hostname, zone_name):
def list_zone_records(dns_server, zone_name):
"""Take a DNS server and a zone name,
and return an array of its records."""
# Need to move most of this logic into a helper method.
try:
zone = dns.zone.from_xfr(dns.query.xfr(dns_hostname, zone_name))
zone = dns.zone.from_xfr(dns.query.xfr(dns_server, zone_name))
except dns.exception.FormError:
# There was an error querying the server for the specific zone.
# Example: a zone that does not exist on the server.
return { 'errors' : 'Encountered a FormError when querying %s on %s' % (zone_name, dns_hostname) }
return { 'errors' : 'Encountered a FormError when querying %s on %s' % (zone_name, dns_server) }
except socket.gaierror, err:
# TODO: Need to better handle errors here.
return { 'errors' : "Problems querying DNS server %s: %s" % (dns_hostname, err) }
return { 'errors' : "Problems querying DNS server %s: %s" % (dns_server, err) }
names = zone.nodes.keys()
names.sort()
@ -46,13 +46,10 @@ def add_forward_record(form_data, zone_keyring):
dns_update.replace(hostname, int(form_data["ttl"]), str(form_data["record_type"]), str(form_data["data"]))
try:
print "in try in add_forward_record"
response = dns.query.tcp(dns_update, form_data["dns_server"])
except dns.tsig.BadPeerKey:
print "in except dns.tsig.badpeerkey"
raise Exception("There was a problem adding your forward record due to a TSIG key issue.")
print "add forward record response: %s" % response
return response
def add_reverse_record(form_data, zone_keyring):
@ -88,8 +85,12 @@ def add_record(form_data):
return response
def delete_record(form_data, rr_items):
keyring = create_keyring(form_data["key_name"])
dns_server = form_data["rr_server"]
try:
keyring = create_keyring(form_data["key_name"])
except Exception, err:
raise Exception("Error creating keyring in delete_record: %s" % err)
dns_server = form_data["dns_server"]
delete_response = []
for current_rr_item in rr_items:
re_record = re.search(r"(\w+)\.(.*)$", current_rr_item)

View File

@ -23,14 +23,14 @@ def view_server_list(request):
{ "server_list" : server_list},
context_instance=RequestContext(request))
def view_server_zones(request, dns_hostname):
def view_server_zones(request, dns_server):
""" Display the list of DNS zones a particular DNS host provides. """
try:
this_server = BindServer.objects.get(hostname=dns_hostname)
this_server = BindServer.objects.get(hostname=dns_server)
zone_array = this_server.list_zones()
except BindServer.DoesNotExist, err:
return render_to_response('bcommon/list_server_zones.htm',
{ 'errors' : "The server %s does not exist in this Binder instance." % dns_hostname },
{ 'errors' : "The server %s does not exist in this Binder instance." % dns_server },
context_instance=RequestContext(request))
if 'errors' in zone_array:
@ -40,13 +40,13 @@ def view_server_zones(request, dns_hostname):
return render_to_response('bcommon/list_server_zones.htm',
{ 'zone_array' : zone_array,
'dns_hostname' : dns_hostname },
'dns_server' : dns_server },
context_instance=RequestContext(request))
def view_zone_records(request, dns_hostname, zone_name):
def view_zone_records(request, dns_server, zone_name):
""" Display the list of records for a a particular zone."""
try:
this_server = BindServer.objects.get(hostname=dns_hostname)
this_server = BindServer.objects.get(hostname=dns_server)
zone_array = this_server.list_zone_records(zone_name)
except Exception, err:
return render_to_response('bcommon/list_zone.htm',
@ -55,8 +55,8 @@ def view_zone_records(request, dns_hostname, zone_name):
return render_to_response('bcommon/list_zone.htm',
{ 'zone_array' : zone_array,
'dns_hostname' : dns_hostname,
'rr_domain' : zone_name},
'dns_server' : dns_server,
'zone_name' : zone_name},
context_instance=RequestContext(request))
def view_add_record(request, dns_server, zone):
@ -100,13 +100,13 @@ def view_delete_record(request):
# the url for deleting records.
return redirect('/')
rr_server = request.POST['rr_server']
rr_domain = request.POST['rr_domain']
dns_server = request.POST['dns_server']
zone_name = request.POST['zone_name']
rr_array = request.POST.getlist('rr_array')
return render_to_response('bcommon/delete_record_initial.htm',
{ 'rr_server' : rr_server,
'rr_domain' : rr_domain,
{ 'dns_server' : dns_server,
'zone_name' : zone_name,
'rr_array' : rr_array,
'tsig_keys' : Key.objects.all() },
context_instance=RequestContext(request))
@ -123,7 +123,13 @@ def view_delete_result(request):
rr_unicode_array = request.POST.getlist('rr_array')[0]
rr_items = RE_UNICODEARRAY.findall(rr_unicode_array)
delete_result = delete_record(request.POST, rr_items)
try:
delete_result = delete_record(request.POST, rr_items)
except Exception, err:
return render_to_response('bcommon/delete_record_result.htm',
{ "errors" : err },
context_instance=RequestContext(request))
return render_to_response('bcommon/delete_record_result.htm',
{ 'delete_result' : delete_result },

2467
binder/files/static/bootstrap.css vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -46,12 +46,12 @@ USE_L10N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''
MEDIA_ROOT = os.path.join(SITE_ROOT, "files")
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''
MEDIA_URL = "/files/"
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
@ -65,7 +65,6 @@ SECRET_KEY = 'iuo-zka8nnv0o+b*7#_*fcep$@f^35=)c#7_20z6i8g0oc&r!g'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
@ -79,10 +78,7 @@ MIDDLEWARE_CLASSES = (
ROOT_URLCONF = 'binder.urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(SITE_ROOT, 'templates')
os.path.join(SITE_ROOT, "templates")
)
INSTALLED_APPS = (
@ -91,9 +87,6 @@ INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'bcommon',
)

View File

@ -1,8 +0,0 @@
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}

View File

@ -2,7 +2,7 @@
{% block header %}
<head>
<title>Binder DNS Admin</title>
<link rel="stylesheet" type="text/css" href="/static/style.css" />
<link rel="stylesheet" type="text/css" href="/files/static/bootstrap.css" />
</head>
{% endblock header %}

View File

@ -3,14 +3,14 @@
{% block body %}
<form action="/delete_record/result/" method="POST">{% csrf_token %}
<input type="hidden" name="rr_server" value="{{ rr_server }}">
<input type="hidden" name="rr_domain" value="{{ rr_domain }}">
<input type="hidden" name="dns_server" value="{{ dns_server }}">
<input type="hidden" name="zone_name" value="{{ zone_name }}">
<input type="hidden" name="rr_array" value="{{ rr_array }}">
<!-- <input type="hidden" name="delete_step" value="finalize"> -->
Do you really want to delete the following records?
<ul>
<li>Server: {{ rr_server }}</li>
<li>Domain: {{ rr_domain }}</li>
<li>Server: {{ dns_server }}</li>
<li>Domain: {{ zone_name }}</li>
<li>Records: {% for current_rr in rr_array %} {{ current_rr}} {% endfor %}</li>
<li>Key: <select name="key_name">
{% for current_key in tsig_keys %}

View File

@ -2,11 +2,11 @@
{% block body %}
{% if not errors %}
DNS Server Zone List for {{ dns_hostname }}:
DNS Server Zone List for {{ dns_server }}:
<ul>
{% for current_zone in zone_array %}
<li> <a href="/info/{{ dns_hostname }}/{{ current_zone }}/"> {{ current_zone }} </li>
<li> <a href="/info/{{ dns_server }}/{{ current_zone }}/"> {{ current_zone }} </li>
{% endfor %}
</ul>
{% endif %}

View File

@ -14,11 +14,11 @@
</tr>
<form action="/delete_record/" method="post">{% csrf_token %}
<input type="hidden" name="dns_server" value="{{ rr_server }}">
<input type="hidden" name="zone_name" value="{{ rr_domain }}">
<input type="hidden" name="dns_server" value="{{ dns_server }}">
<input type="hidden" name="zone_name" value="{{ zone_name }}">
{% for current_record in zone_array %}
<tr>
<td><input type="checkbox" name="rr_array" value="{{ current_record.rr_name }}.{{ rr_domain }}"></td>
<td><input type="checkbox" name="rr_array" value="{{ current_record.rr_name }}.{{ zone_name }}"></td>
<td>{{ current_record.rr_name }}</td>
<td>{{ current_record.rr_ttl }}</td>
<td>{{ current_record.rr_class }}</td>
@ -26,7 +26,7 @@
<td>{{ current_record.rr_data }}</td>
</tr>
{% endfor %}
<td colspan="6" align="right"><a href="/add_record/{{ rr_server }}/{{ rr_domain }}/">Add Record</a></td>
<td colspan="6" align="right"><a href="/add_record/{{ dns_server }}/{{ zone_name }}/">Add Record</a></td>
</table>
<input type="submit" value="Delete Selected"/>
</form>

View File

@ -10,8 +10,8 @@ urlpatterns = patterns('',
(r'^$', 'bcommon.views.home_index'),
(r'^info/$', 'bcommon.views.view_server_list'),
(r'^info/(?P<dns_hostname>[a-zA-Z0-9.-]+)/$', 'bcommon.views.view_server_zones'),
(r'^info/(?P<dns_hostname>[a-zA-Z0-9.-]+)/(?P<zone_name>[a-zA-Z0-9.-]+)/$', 'bcommon.views.view_zone_records'),
(r'^info/(?P<dns_server>[a-zA-Z0-9.-]+)/$', 'bcommon.views.view_server_zones'),
(r'^info/(?P<dns_server>[a-zA-Z0-9.-]+)/(?P<zone_name>[a-zA-Z0-9.-]+)/$', 'bcommon.views.view_zone_records'),
(r'^add_record/(?P<dns_server>[a-zA-Z0-9.-]+)/(?P<zone>[a-zA-Z0-9.-]+)/$', 'bcommon.views.view_add_record'),
(r'^add_record/result/$', 'bcommon.views.view_add_record_result'),
@ -22,6 +22,6 @@ urlpatterns = patterns('',
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root' : os.path.join(settings.SITE_ROOT, 'static')}),
)
(r'^files/(?P<path>.*)$', 'django.views.static.serve',
{'document_root' : settings.MEDIA_ROOT}
))