Clean up and make work adding and deleting records. Handles reverse and multiple records also
This commit is contained in:
parent
5c453e9a8d
commit
5bc7f923ad
|
@ -58,20 +58,20 @@ def add_forward_record(form_data, zone_keyring):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def add_reverse_record(form_data, zone_keyring):
|
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_fqdn = str(dns.reversename.from_address(form_data["data"]))
|
||||||
reverse_ip = re.search(r"([0-9]+).(.*).$", reverse_ip_fqdn).group(1)
|
reverse_ip = re.search(r"([0-9]+).(.*).$", reverse_ip_fqdn).group(1)
|
||||||
reverse_domain = re.search(r"([0-9]+).(.*).$", reverse_ip_fqdn).group(2)
|
reverse_domain = re.search(r"([0-9]+).(.*).$", reverse_ip_fqdn).group(2)
|
||||||
|
|
||||||
dns_update = dns.update.Update(reverse_domain, keyring = zone_keyring)
|
dns_update = dns.update.Update(reverse_domain, keyring = zone_keyring)
|
||||||
dns_update.replace(reverse_ip, int(form_data["ttl"]), "PTR", str(form_data["name"]) + ".")
|
dns_update.replace(reverse_ip, int(form_data["ttl"]), "PTR", str(form_data["name"]) + ".")
|
||||||
|
|
||||||
output = dns.query.tcp(dns_update, form_data["dns_server"])
|
output = dns.query.tcp(dns_update, form_data["dns_server"])
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def add_record(form_data):
|
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 a reverse PTR record is requested, this will be added too."""
|
||||||
|
|
||||||
if form_data["key_name"]:
|
if form_data["key_name"]:
|
||||||
|
|
|
@ -90,7 +90,8 @@ def view_add_record_result(request):
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
return render_to_response('bcommon/add_record_result.htm',
|
return render_to_response('bcommon/add_record_result.htm',
|
||||||
{ 'response' : add_record_response },
|
{ 'response' : add_record_response,
|
||||||
|
'rr_data' : cd },
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,23 +2,29 @@
|
||||||
|
|
||||||
|
|
||||||
{% block pageheader %}
|
{% block pageheader %}
|
||||||
|
Add Record Result
|
||||||
{% endblock pageheader %}
|
{% endblock pageheader %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
<table class="table">
|
||||||
{% if response.forward_response %}
|
{% if response.forward_response %}
|
||||||
Forward Record Creation Output
|
<tr>
|
||||||
<pre>
|
<th>Record: {{ response.name }}</th>
|
||||||
{{ response.forward_response }}
|
<th>Add Result</th>
|
||||||
</pre>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Forward: {{ rr_data.name }}</td>
|
||||||
|
<td><pre>{{ response.forward_response }}</pre></td>
|
||||||
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<p>
|
|
||||||
{% if response.reverse_response %}
|
{% if response.reverse_response %}
|
||||||
Reverse Record Creation Output
|
<tr>
|
||||||
<pre>
|
<td>Reverse: {{ rr_data.data }}</td>
|
||||||
{{ response.reverse_response }}
|
<td><pre>{{ response.reverse_response }}</pre></td>
|
||||||
</pre>
|
</tr>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</table>
|
||||||
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
|
@ -1,24 +1,43 @@
|
||||||
{% extends "base.htm" %}
|
{% extends "base.htm" %}
|
||||||
|
|
||||||
|
{% block pageheader %}
|
||||||
|
Delete record(s) in {{ zone_name }}
|
||||||
|
{% endblock pageheader %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
<form action="/delete_record/result/" method="POST">{% csrf_token %}
|
<form action="/delete_record/result/" method="POST">{% csrf_token %}
|
||||||
<input type="hidden" name="dns_server" value="{{ dns_server }}">
|
<input type="hidden" name="dns_server" value="{{ dns_server }}">
|
||||||
<input type="hidden" name="zone_name" value="{{ zone_name }}">
|
<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?
|
|
||||||
<ul>
|
<tr>
|
||||||
<li>Server: {{ dns_server }}</li>
|
<th colspan="2">Do you really want to delete the following records?</th>
|
||||||
<li>Domain: {{ zone_name }}</li>
|
</tr>
|
||||||
<li>Records: {% for current_rr in rr_array %} {{ current_rr}} {% endfor %}</li>
|
<tr>
|
||||||
<li>Key: <select name="key_name">
|
<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 %}
|
{% for current_key in tsig_keys %}
|
||||||
<option value="{{current_key}}">{{current_key}}</option>
|
<option value="{{current_key}}">{{current_key}}</option>
|
||||||
{% endfor %}
|
{% endfor %}</td>
|
||||||
</select> </li>
|
</tr>
|
||||||
</ul>
|
</select>
|
||||||
|
</table>
|
||||||
|
|
||||||
<input type="submit" value="Yes, I really want to delete them."/>
|
<input type="submit" value="Yes, I really want to delete them."/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
|
@ -2,16 +2,22 @@
|
||||||
|
|
||||||
|
|
||||||
{% block pageheader %}
|
{% block pageheader %}
|
||||||
|
Delete Record(s) Result
|
||||||
{% endblock pageheader %}
|
{% endblock pageheader %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
{% for current_response in delete_result %}
|
{% for current_response in delete_result %}
|
||||||
Record: {{ current_response.rr_item }}
|
<tr>
|
||||||
<pre>
|
<th>Record</th>
|
||||||
{{ current_response.output }}
|
<th>Delete Result</th>
|
||||||
</pre>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ current_response.rr_item }}</td>
|
||||||
|
<td><pre>{{ current_response.output }}</pre></td>
|
||||||
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
Loading…
Reference in New Issue