Add most of the framework for adding a cname record. templates, views, helper code.

Still need to cleanup helpers, figure out why delete is failing
This commit is contained in:
Jeffrey Forman 2012-10-26 17:09:05 -04:00
parent 9bb4b88b6b
commit 00b22acba7
7 changed files with 157 additions and 6 deletions

View File

@ -17,3 +17,12 @@ class FormAddRecord(forms.Form):
create_reverse = forms.BooleanField(label="Create Reverse Record (PTR)?", required=False) create_reverse = forms.BooleanField(label="Create Reverse Record (PTR)?", required=False)
data = forms.CharField(max_length=256, label="Record Data (IP/Hostname)") data = forms.CharField(max_length=256, label="Record Data (IP/Hostname)")
key_name = forms.ModelChoiceField(queryset=Key.objects.all(), empty_label=None, label="TSIG Key", required=False) key_name = forms.ModelChoiceField(queryset=Key.objects.all(), empty_label=None, label="TSIG Key", required=False)
class FormAddCnameRecord(forms.Form):
dns_server = forms.CharField(max_length=100)
originating_record = forms.CharField(max_length=100)
cname = forms.RegexField(max_length=100, regex="^[a-zA-Z0-9-_]+$")
zone_name = forms.CharField(max_length=256)
ttl = forms.ChoiceField(choices=TTL_CHOICES)
key_name = forms.ModelChoiceField(queryset=Key.objects.all(), empty_label=None, required=False)

View File

@ -3,9 +3,9 @@
from bcommon.models import BindServer, Key from bcommon.models import BindServer, Key
from django.template import Context from django.template import Context
from django.shortcuts import render_to_response, redirect from django.shortcuts import render_to_response, redirect
from bcommon.helpers import add_record, delete_record from bcommon.helpers import add_record, delete_record, add_cname_record
from bcommon.forms import FormAddRecord from bcommon.forms import FormAddRecord, FormAddCnameRecord
from django.template import RequestContext from django.template import RequestContext
from bcommon.keyutils import create_keyring from bcommon.keyutils import create_keyring
@ -95,6 +95,47 @@ def view_add_record_result(request):
context_instance=RequestContext(request)) context_instance=RequestContext(request))
def view_add_cname_record(request, dns_server, zone_name, record_name):
""" Process given input to add a CNAME pointer."""
return render_to_response("bcommon/add_cname_record_form.htm",
{ "dns_server" : dns_server,
"zone_name" : zone_name,
"record_name" : record_name,
"tsig_keys" : Key.objects.all() },
context_instance=RequestContext(request))
def view_add_cname_result(request):
if request.method == "GET":
# Return home. You shouldn't trying to directly access
# the url for deleting records.
return redirect('/')
form = FormAddCnameRecord(request.POST)
if form.is_valid():
cd = form.cleaned_data
else:
return "bad form" # TODO: Send back the form pre-populated with the error
try:
add_cname_response = add_cname_record(str(cd["dns_server"]),
str(cd["zone_name"]),
str(cd["originating_record"]),
str(cd["cname"]),
str(cd["ttl"]),
str(cd["key_name"]))
except Exception, err:
return render_to_response('bcommon/add_cname_result.htm',
{ 'errors' : err,
'rr_data' : cd },)
return render_to_response('bcommon/add_cname_result.htm',
{ 'response' : add_cname_response,
'rr_data' : cd },
context_instance=RequestContext(request))
def view_delete_record(request): def view_delete_record(request):
if request.method == "GET": if request.method == "GET":
# Return home. You shouldn't trying to directly acces # Return home. You shouldn't trying to directly acces

View File

@ -35,17 +35,17 @@
</div> </div>
</div> </div>
{% block errors %} {% block errors %}
{% if errors %} {% if errors %}
<div class="alert alert-error">
Errors were encountered: Errors were encountered:
<br> <br>
{{ errors }} {{ errors }}
{% if error_context %} {% if error_context %}
{{ error_context }} {{ error_context }}
{% endif %} {% endif %}
</div>
{% endif %} {% endif %}
{% endblock errors %} {% endblock errors %}

View File

@ -0,0 +1,63 @@
{% extends "base.htm" %}
{% block pageheader %}
Add cname record for {{record_name}}.{{zone_name}}
{% endblock pageheader %}
{% block body %}
<form class="form-horizontal" action="/add_cname_record/result/" method="post">{% csrf_token %}
<legend>Create CNAME record</legend>
<div class="control-group">
<label class="control-label">DNS Server: </label>
<div class="controls">
<span class="input-xlarge uneditable-input">{{dns_server}}</span>
<input type="hidden" name="dns_server" value="{{dns_server}}"/>
</div>
</div>
<div class="control-group">
<label class="control-label">Originating Record: </label>
<div class="controls">
<span class="input-xlarge uneditable-input">{{record_name}}.{{zone_name}}</span>
<input type="hidden" name="originating_record" value="{{record_name}}.{{zone_name}}"/>
</div>
</div>
<div class="control-group">
<label class="control-label">CNAME: </label>
<div class="controls">
<div class="input-append">
<input class="span2" size="100" name="cname" type="text"><span class="add-on">.{{zone_name}}</span>
<input type="hidden" name="zone_name" value="{{zone_name}}"/>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">TTL: </label>
<div class="controls">
<select name="ttl">
<!-- {% for key in tsig_keys %} -->
<!-- <option value="{{key}}">{{key}}</option> -->
<!-- {% endfor %} -->
<option value="86400">86400 (1 day)</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">TSIG Key: </label>
<div class="controls">
<select name="key_name">
<option selected="selected" value=""></option>
{% for key in tsig_keys %}
<option value="{{key}}">{{key}}</option>
{% endfor %}
</select>
</div>
</div>
<button type="submit" class="btn">Save Changes</button>
</form>
{% endblock body %}

View File

@ -0,0 +1,20 @@
{% extends "base.htm" %}
{% block pageheader %}
Add CNAME Record Result
{% endblock pageheader %}
{% block body %}
<table class="table">
<tr>
<th>CNAME</th>
<th>Add CNAME Result</th>
</tr>
<tr>
<td>{{ rr_data.cname }}.{{rr_data.zone_name }} points to {{ rr_data.originating_record }}</td>
<td><pre>{{ response }}</pre></td>
</tr>
</table>
{% endblock body %}

View File

@ -9,12 +9,13 @@ Zone listing for {{ zone_name }}
{% if not errors %} {% if not errors %}
<table class="table"> <table class="table">
<tr> <tr>
<th></th> <th>Select</th>
<th>Name</th> <th>Name</th>
<th>TTL</th> <th>TTL</th>
<th>Class</th> <th>Class</th>
<th>Type</th> <th>Type</th>
<th>Data</th> <th>Data</th>
<th></th>
</tr> </tr>
<form action="/delete_record/" method="post">{% csrf_token %} <form action="/delete_record/" method="post">{% csrf_token %}
@ -28,6 +29,19 @@ Zone listing for {{ zone_name }}
<td>{{ current_record.rr_class }}</td> <td>{{ current_record.rr_class }}</td>
<td>{{ current_record.rr_type }}</td> <td>{{ current_record.rr_type }}</td>
<td>{{ current_record.rr_data }}</td> <td>{{ current_record.rr_data }}</td>
<td>
<div class="btn-toolbar" style="margin: 0;">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">Record Actions <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Edit Record</a></li>
{% if current_record.rr_type == "A" %}
<li><a href="/add_cname/{{dns_server}}/{{zone_name}}/{{current_record.rr_name}}/">Add CNAME Pointer</a></li>
{% endif %}
</ul>
</div>
</div>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
<td colspan="6" align="right"><a href="/add_record/{{ dns_server }}/{{ zone_name }}/">Add Record</a></td> <td colspan="6" align="right"><a href="/add_record/{{ dns_server }}/{{ zone_name }}/">Add Record</a></td>

View File

@ -18,6 +18,10 @@ urlpatterns = patterns('',
(r'^delete_record/$', 'bcommon.views.view_delete_record'), (r'^delete_record/$', 'bcommon.views.view_delete_record'),
(r'^delete_record/result/$', 'bcommon.views.view_delete_result'), (r'^delete_record/result/$', 'bcommon.views.view_delete_result'),
(r'^add_cname/(?P<dns_server>[a-zA-Z0-9.-]+)/(?P<zone_name>[a-zA-Z0-9.-]+)/(?P<record_name>[a-zA-Z0-9-]+)/$', 'bcommon.views.view_add_cname_record'),
(r'^add_cname_record/result/$', 'bcommon.views.view_add_cname_result'),
) )
if settings.DEBUG: if settings.DEBUG: