diff --git a/binder/bcommon/forms.py b/binder/bcommon/forms.py index 703e1eb..82516ca 100644 --- a/binder/bcommon/forms.py +++ b/binder/bcommon/forms.py @@ -17,3 +17,12 @@ class FormAddRecord(forms.Form): create_reverse = forms.BooleanField(label="Create Reverse Record (PTR)?", required=False) 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) + + +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) diff --git a/binder/bcommon/views.py b/binder/bcommon/views.py index 88adb8a..001b151 100644 --- a/binder/bcommon/views.py +++ b/binder/bcommon/views.py @@ -3,9 +3,9 @@ from bcommon.models import BindServer, Key from django.template import Context 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 bcommon.keyutils import create_keyring @@ -95,6 +95,47 @@ def view_add_record_result(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): if request.method == "GET": # Return home. You shouldn't trying to directly acces diff --git a/binder/templates/base.htm b/binder/templates/base.htm index 172db0d..1d0b6ad 100644 --- a/binder/templates/base.htm +++ b/binder/templates/base.htm @@ -35,24 +35,24 @@ - {% block errors %} {% if errors %} +
Errors were encountered:
{{ errors }} - {% if error_context %} {{ error_context }} {% endif %} +
{% endif %} {% endblock errors %} {% block body %} {% endblock body %} - + diff --git a/binder/templates/bcommon/add_cname_record_form.htm b/binder/templates/bcommon/add_cname_record_form.htm new file mode 100644 index 0000000..4bf0a4c --- /dev/null +++ b/binder/templates/bcommon/add_cname_record_form.htm @@ -0,0 +1,63 @@ +{% extends "base.htm" %} + +{% block pageheader %} +Add cname record for {{record_name}}.{{zone_name}} +{% endblock pageheader %} + +{% block body %} +
{% csrf_token %} + Create CNAME record +
+ +
+ {{dns_server}} + +
+
+ +
+ +
+ {{record_name}}.{{zone_name}} + +
+
+ +
+ +
+
+ .{{zone_name}} + +
+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +{% endblock body %} diff --git a/binder/templates/bcommon/add_cname_result.htm b/binder/templates/bcommon/add_cname_result.htm new file mode 100644 index 0000000..494a46e --- /dev/null +++ b/binder/templates/bcommon/add_cname_result.htm @@ -0,0 +1,20 @@ +{% extends "base.htm" %} + + +{% block pageheader %} +Add CNAME Record Result +{% endblock pageheader %} + +{% block body %} + + + + + + + + + +
CNAMEAdd CNAME Result
{{ rr_data.cname }}.{{rr_data.zone_name }} points to {{ rr_data.originating_record }}
{{ response }}
+ +{% endblock body %} diff --git a/binder/templates/bcommon/list_zone.htm b/binder/templates/bcommon/list_zone.htm index 994a6ee..b6b4fa3 100644 --- a/binder/templates/bcommon/list_zone.htm +++ b/binder/templates/bcommon/list_zone.htm @@ -9,12 +9,13 @@ Zone listing for {{ zone_name }} {% if not errors %} - + + {% csrf_token %} @@ -28,6 +29,19 @@ Zone listing for {{ zone_name }} + {% endfor %} diff --git a/binder/urls.py b/binder/urls.py index 9916bf5..303d824 100644 --- a/binder/urls.py +++ b/binder/urls.py @@ -18,6 +18,10 @@ urlpatterns = patterns('', (r'^delete_record/$', 'bcommon.views.view_delete_record'), (r'^delete_record/result/$', 'bcommon.views.view_delete_result'), + + (r'^add_cname/(?P[a-zA-Z0-9.-]+)/(?P[a-zA-Z0-9.-]+)/(?P[a-zA-Z0-9-]+)/$', 'bcommon.views.view_add_cname_record'), + (r'^add_cname_record/result/$', 'bcommon.views.view_add_cname_result'), + ) if settings.DEBUG:
Select Name TTL Class Type Data
{{ current_record.rr_class }} {{ current_record.rr_type }} {{ current_record.rr_data }} +
+
+ + +
+
+
Add Record