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:
parent
380657d5f5
commit
a03f49c158
|
@ -7,19 +7,19 @@ import dns.update
|
||||||
|
|
||||||
re_IPADDRESS = re.compile(r"\d+.\d+.\d+.\d+")
|
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,
|
"""Take a DNS server and a zone name,
|
||||||
and return an array of its records."""
|
and return an array of its records."""
|
||||||
# Need to move most of this logic into a helper method.
|
# Need to move most of this logic into a helper method.
|
||||||
try:
|
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:
|
except dns.exception.FormError:
|
||||||
# There was an error querying the server for the specific zone.
|
# There was an error querying the server for the specific zone.
|
||||||
# Example: a zone that does not exist on the server.
|
# 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:
|
except socket.gaierror, err:
|
||||||
# TODO: Need to better handle errors here.
|
# 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 = zone.nodes.keys()
|
||||||
names.sort()
|
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"]))
|
dns_update.replace(hostname, int(form_data["ttl"]), str(form_data["record_type"]), str(form_data["data"]))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print "in try in add_forward_record"
|
|
||||||
response = dns.query.tcp(dns_update, form_data["dns_server"])
|
response = dns.query.tcp(dns_update, form_data["dns_server"])
|
||||||
except dns.tsig.BadPeerKey:
|
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.")
|
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
|
return response
|
||||||
|
|
||||||
def add_reverse_record(form_data, zone_keyring):
|
def add_reverse_record(form_data, zone_keyring):
|
||||||
|
@ -88,8 +85,12 @@ def add_record(form_data):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def delete_record(form_data, rr_items):
|
def delete_record(form_data, rr_items):
|
||||||
keyring = create_keyring(form_data["key_name"])
|
try:
|
||||||
dns_server = form_data["rr_server"]
|
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 = []
|
delete_response = []
|
||||||
for current_rr_item in rr_items:
|
for current_rr_item in rr_items:
|
||||||
re_record = re.search(r"(\w+)\.(.*)$", current_rr_item)
|
re_record = re.search(r"(\w+)\.(.*)$", current_rr_item)
|
||||||
|
|
|
@ -23,14 +23,14 @@ def view_server_list(request):
|
||||||
{ "server_list" : server_list},
|
{ "server_list" : server_list},
|
||||||
context_instance=RequestContext(request))
|
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. """
|
""" Display the list of DNS zones a particular DNS host provides. """
|
||||||
try:
|
try:
|
||||||
this_server = BindServer.objects.get(hostname=dns_hostname)
|
this_server = BindServer.objects.get(hostname=dns_server)
|
||||||
zone_array = this_server.list_zones()
|
zone_array = this_server.list_zones()
|
||||||
except BindServer.DoesNotExist, err:
|
except BindServer.DoesNotExist, err:
|
||||||
return render_to_response('bcommon/list_server_zones.htm',
|
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))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
if 'errors' in zone_array:
|
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',
|
return render_to_response('bcommon/list_server_zones.htm',
|
||||||
{ 'zone_array' : zone_array,
|
{ 'zone_array' : zone_array,
|
||||||
'dns_hostname' : dns_hostname },
|
'dns_server' : dns_server },
|
||||||
context_instance=RequestContext(request))
|
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."""
|
""" Display the list of records for a a particular zone."""
|
||||||
try:
|
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)
|
zone_array = this_server.list_zone_records(zone_name)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
return render_to_response('bcommon/list_zone.htm',
|
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',
|
return render_to_response('bcommon/list_zone.htm',
|
||||||
{ 'zone_array' : zone_array,
|
{ 'zone_array' : zone_array,
|
||||||
'dns_hostname' : dns_hostname,
|
'dns_server' : dns_server,
|
||||||
'rr_domain' : zone_name},
|
'zone_name' : zone_name},
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
def view_add_record(request, dns_server, zone):
|
def view_add_record(request, dns_server, zone):
|
||||||
|
@ -100,13 +100,13 @@ def view_delete_record(request):
|
||||||
# the url for deleting records.
|
# the url for deleting records.
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
|
||||||
rr_server = request.POST['rr_server']
|
dns_server = request.POST['dns_server']
|
||||||
rr_domain = request.POST['rr_domain']
|
zone_name = request.POST['zone_name']
|
||||||
rr_array = request.POST.getlist('rr_array')
|
rr_array = request.POST.getlist('rr_array')
|
||||||
|
|
||||||
return render_to_response('bcommon/delete_record_initial.htm',
|
return render_to_response('bcommon/delete_record_initial.htm',
|
||||||
{ 'rr_server' : rr_server,
|
{ 'dns_server' : dns_server,
|
||||||
'rr_domain' : rr_domain,
|
'zone_name' : zone_name,
|
||||||
'rr_array' : rr_array,
|
'rr_array' : rr_array,
|
||||||
'tsig_keys' : Key.objects.all() },
|
'tsig_keys' : Key.objects.all() },
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
@ -123,7 +123,13 @@ def view_delete_result(request):
|
||||||
rr_unicode_array = request.POST.getlist('rr_array')[0]
|
rr_unicode_array = request.POST.getlist('rr_array')[0]
|
||||||
rr_items = RE_UNICODEARRAY.findall(rr_unicode_array)
|
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',
|
return render_to_response('bcommon/delete_record_result.htm',
|
||||||
{ 'delete_result' : delete_result },
|
{ 'delete_result' : delete_result },
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -46,12 +46,12 @@ USE_L10N = True
|
||||||
|
|
||||||
# Absolute path to the directory that holds media.
|
# Absolute path to the directory that holds media.
|
||||||
# Example: "/home/media/media.lawrence.com/"
|
# 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
|
# 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).
|
# trailing slash if there is a path component (optional in other cases).
|
||||||
# Examples: "http://media.lawrence.com", "http://example.com/media/"
|
# 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
|
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
|
||||||
# trailing slash.
|
# trailing slash.
|
||||||
|
@ -65,7 +65,6 @@ SECRET_KEY = 'iuo-zka8nnv0o+b*7#_*fcep$@f^35=)c#7_20z6i8g0oc&r!g'
|
||||||
TEMPLATE_LOADERS = (
|
TEMPLATE_LOADERS = (
|
||||||
'django.template.loaders.filesystem.Loader',
|
'django.template.loaders.filesystem.Loader',
|
||||||
'django.template.loaders.app_directories.Loader',
|
'django.template.loaders.app_directories.Loader',
|
||||||
# 'django.template.loaders.eggs.Loader',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
MIDDLEWARE_CLASSES = (
|
MIDDLEWARE_CLASSES = (
|
||||||
|
@ -79,10 +78,7 @@ MIDDLEWARE_CLASSES = (
|
||||||
ROOT_URLCONF = 'binder.urls'
|
ROOT_URLCONF = 'binder.urls'
|
||||||
|
|
||||||
TEMPLATE_DIRS = (
|
TEMPLATE_DIRS = (
|
||||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
os.path.join(SITE_ROOT, "templates")
|
||||||
# Always use forward slashes, even on Windows.
|
|
||||||
# Don't forget to use absolute paths, not relative paths.
|
|
||||||
os.path.join(SITE_ROOT, 'templates')
|
|
||||||
)
|
)
|
||||||
|
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
|
@ -91,9 +87,6 @@ INSTALLED_APPS = (
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.sites',
|
'django.contrib.sites',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
# Uncomment the next line to enable the admin:
|
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
# Uncomment the next line to enable admin documentation:
|
|
||||||
# 'django.contrib.admindocs',
|
|
||||||
'bcommon',
|
'bcommon',
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
|
|
||||||
table, th, td {
|
|
||||||
border: 1px solid black;
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% block header %}
|
{% block header %}
|
||||||
<head>
|
<head>
|
||||||
<title>Binder DNS Admin</title>
|
<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>
|
</head>
|
||||||
{% endblock header %}
|
{% endblock header %}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
<form action="/delete_record/result/" method="POST">{% csrf_token %}
|
<form action="/delete_record/result/" method="POST">{% csrf_token %}
|
||||||
<input type="hidden" name="rr_server" value="{{ rr_server }}">
|
<input type="hidden" name="dns_server" value="{{ dns_server }}">
|
||||||
<input type="hidden" name="rr_domain" value="{{ rr_domain }}">
|
<input type="hidden" name="zone_name" value="{{ zone_name }}">
|
||||||
<input type="hidden" name="rr_array" value="{{ rr_array }}">
|
<input type="hidden" name="rr_array" value="{{ rr_array }}">
|
||||||
<!-- <input type="hidden" name="delete_step" value="finalize"> -->
|
<!-- <input type="hidden" name="delete_step" value="finalize"> -->
|
||||||
Do you really want to delete the following records?
|
Do you really want to delete the following records?
|
||||||
<ul>
|
<ul>
|
||||||
<li>Server: {{ rr_server }}</li>
|
<li>Server: {{ dns_server }}</li>
|
||||||
<li>Domain: {{ rr_domain }}</li>
|
<li>Domain: {{ zone_name }}</li>
|
||||||
<li>Records: {% for current_rr in rr_array %} {{ current_rr}} {% endfor %}</li>
|
<li>Records: {% for current_rr in rr_array %} {{ current_rr}} {% endfor %}</li>
|
||||||
<li>Key: <select name="key_name">
|
<li>Key: <select name="key_name">
|
||||||
{% for current_key in tsig_keys %}
|
{% for current_key in tsig_keys %}
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% if not errors %}
|
{% if not errors %}
|
||||||
DNS Server Zone List for {{ dns_hostname }}:
|
DNS Server Zone List for {{ dns_server }}:
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for current_zone in zone_array %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -14,11 +14,11 @@
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<form action="/delete_record/" method="post">{% csrf_token %}
|
<form action="/delete_record/" method="post">{% csrf_token %}
|
||||||
<input type="hidden" name="dns_server" value="{{ rr_server }}">
|
<input type="hidden" name="dns_server" value="{{ dns_server }}">
|
||||||
<input type="hidden" name="zone_name" value="{{ rr_domain }}">
|
<input type="hidden" name="zone_name" value="{{ zone_name }}">
|
||||||
{% for current_record in zone_array %}
|
{% for current_record in zone_array %}
|
||||||
<tr>
|
<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_name }}</td>
|
||||||
<td>{{ current_record.rr_ttl }}</td>
|
<td>{{ current_record.rr_ttl }}</td>
|
||||||
<td>{{ current_record.rr_class }}</td>
|
<td>{{ current_record.rr_class }}</td>
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
<td>{{ current_record.rr_data }}</td>
|
<td>{{ current_record.rr_data }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% 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>
|
</table>
|
||||||
<input type="submit" value="Delete Selected"/>
|
<input type="submit" value="Delete Selected"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -10,8 +10,8 @@ urlpatterns = patterns('',
|
||||||
(r'^$', 'bcommon.views.home_index'),
|
(r'^$', 'bcommon.views.home_index'),
|
||||||
(r'^info/$', 'bcommon.views.view_server_list'),
|
(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_server>[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.-]+)/(?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/(?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'),
|
(r'^add_record/result/$', 'bcommon.views.view_add_record_result'),
|
||||||
|
@ -22,6 +22,6 @@ urlpatterns = patterns('',
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
urlpatterns += patterns('',
|
urlpatterns += patterns('',
|
||||||
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
|
(r'^files/(?P<path>.*)$', 'django.views.static.serve',
|
||||||
{'document_root' : os.path.join(settings.SITE_ROOT, 'static')}),
|
{'document_root' : settings.MEDIA_ROOT}
|
||||||
)
|
))
|
||||||
|
|
Loading…
Reference in New Issue