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 %} +