Clean up and make work adding and deleting records. Handles reverse and multiple records also

This commit is contained in:
Jeffrey Forman 2012-10-22 20:39:07 -04:00
parent 5c453e9a8d
commit 5bc7f923ad
5 changed files with 61 additions and 29 deletions

View File

@ -58,20 +58,20 @@ def add_forward_record(form_data, zone_keyring):
return response
def add_reverse_record(form_data, zone_keyring):
""" Given a FormAddRecord dict and zone_keyring,
add/update a reverse PTR record."""
reverse_ip_fqdn = str(dns.reversename.from_address(form_data["data"]))
reverse_ip = re.search(r"([0-9]+).(.*).$", reverse_ip_fqdn).group(1)
reverse_domain = re.search(r"([0-9]+).(.*).$", reverse_ip_fqdn).group(2)
dns_update = dns.update.Update(reverse_domain, keyring = zone_keyring)
dns_update.replace(reverse_ip, int(form_data["ttl"]), "PTR", str(form_data["name"]) + ".")
output = dns.query.tcp(dns_update, form_data["dns_server"])
return output
def add_record(form_data):
"""Add a DNS record with data from a FormAddRecord object.
"""Add a DNS record with data from a FormAddRecord dict.
If a reverse PTR record is requested, this will be added too."""
if form_data["key_name"]:

View File

@ -90,7 +90,8 @@ def view_add_record_result(request):
context_instance=RequestContext(request))
return render_to_response('bcommon/add_record_result.htm',
{ 'response' : add_record_response },
{ 'response' : add_record_response,
'rr_data' : cd },
context_instance=RequestContext(request))

View File

@ -2,23 +2,29 @@
{% block pageheader %}
Add Record Result
{% endblock pageheader %}
{% block body %}
<table class="table">
{% if response.forward_response %}
Forward Record Creation Output
<pre>
{{ response.forward_response }}
</pre>
<tr>
<th>Record: {{ response.name }}</th>
<th>Add Result</th>
</tr>
<tr>
<td>Forward: {{ rr_data.name }}</td>
<td><pre>{{ response.forward_response }}</pre></td>
</tr>
{% endif %}
<p>
{% if response.reverse_response %}
Reverse Record Creation Output
<pre>
{{ response.reverse_response }}
</pre>
<tr>
<td>Reverse: {{ rr_data.data }}</td>
<td><pre>{{ response.reverse_response }}</pre></td>
</tr>
{% endif %}
</table>
{% endblock body %}

View File

@ -1,24 +1,43 @@
{% extends "base.htm" %}
{% block pageheader %}
Delete record(s) in {{ zone_name }}
{% endblock pageheader %}
{% block body %}
<table class="table">
<form action="/delete_record/result/" method="POST">{% csrf_token %}
<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: {{ 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">
<tr>
<th colspan="2">Do you really want to delete the following records?</th>
</tr>
<tr>
<td>Server</td>
<td>{{ dns_server }}</td>
</tr>
<tr>
<td>Domain</td>
<td> {{ zone_name }} </td>
</tr>
<tr>
<td>Records</td>
<td>{% for current_rr in rr_array %} {{ current_rr}} {% endfor %}</td>
</tr>
<tr>
<td>Key</td>
<td> <select name="key_name">
{% for current_key in tsig_keys %}
<option value="{{current_key}}">{{current_key}}</option>
{% endfor %}
</select> </li>
</ul>
{% endfor %}</td>
</tr>
</select>
</table>
<input type="submit" value="Yes, I really want to delete them."/>
</form>
{% endblock body %}

View File

@ -2,16 +2,22 @@
{% block pageheader %}
Delete Record(s) Result
{% endblock pageheader %}
{% block body %}
<table class="table">
{% for current_response in delete_result %}
Record: {{ current_response.rr_item }}
<pre>
{{ current_response.output }}
</pre>
<tr>
<th>Record</th>
<th>Delete Result</th>
</tr>
<tr>
<td>{{ current_response.rr_item }}</td>
<td><pre>{{ current_response.output }}</pre></td>
</tr>
{% endfor %}
</table>
{% endblock body %}