add support to add CNAME in zone, loosen restrictions on record data input
This commit is contained in:
parent
54c3bc18cc
commit
7fdcfab8a0
|
@ -3,6 +3,8 @@
|
|||
# 3rd Party
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.core import validators
|
||||
from django.forms import ValidationError
|
||||
|
||||
# App Imports
|
||||
|
@ -55,7 +57,7 @@ class FormAddForwardRecord(forms.Form):
|
|||
record_type = forms.ChoiceField(choices=settings.RECORD_TYPE_CHOICES,
|
||||
widget=forms.RadioSelect)
|
||||
zone_name = forms.CharField(max_length=100)
|
||||
record_data = forms.GenericIPAddressField()
|
||||
record_data = forms.CharField(max_length=100)
|
||||
ttl = forms.ChoiceField(choices=settings.TTL_CHOICES,
|
||||
widget=forms.RadioSelect)
|
||||
create_reverse = forms.BooleanField(required=False)
|
||||
|
@ -65,6 +67,16 @@ class FormAddForwardRecord(forms.Form):
|
|||
empty_label=None)
|
||||
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(FormAddForwardRecord, self).clean()
|
||||
record_type = cleaned_data.get("record_type")
|
||||
record_data = cleaned_data.get("record_data")
|
||||
if record_type in ("A", "AAAA"):
|
||||
try:
|
||||
validators.validate_ipv46_address(record_data)
|
||||
except:
|
||||
raise ValidationError("Invalid IP Address.")
|
||||
|
||||
class FormAddReverseRecord(forms.Form):
|
||||
|
||||
"""Form used to add a Reverse (PTR) DNS record."""
|
||||
|
|
|
@ -137,7 +137,8 @@ TTL_CHOICES = ((300, "5 minutes"),
|
|||
(86400, "1 day"))
|
||||
|
||||
RECORD_TYPE_CHOICES = (("A", "A"),
|
||||
("AAAA", "AAAA"))
|
||||
("AAAA", "AAAA"),
|
||||
("CNAME", "CNAME"))
|
||||
|
||||
LOGIN_REDIRECT_URL = '/'
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ def view_zone_records(request, dns_server, zone_name):
|
|||
|
||||
|
||||
def view_add_record(request, dns_server, zone_name):
|
||||
"""View to allow to add A records."""
|
||||
"""View to add an RR record to DNS zone."""
|
||||
this_server = get_object_or_404(models.BindServer, hostname=dns_server)
|
||||
|
||||
if request.method == 'POST':
|
||||
|
@ -89,6 +89,8 @@ def view_add_record(request, dns_server, zone_name):
|
|||
return redirect('zone_list',
|
||||
dns_server=dns_server,
|
||||
zone_name=zone_name)
|
||||
else:
|
||||
messages.error(request, "Form data was invalid. Check all inputs.")
|
||||
else:
|
||||
form = forms.FormAddForwardRecord(initial={'zone_name': zone_name})
|
||||
|
||||
|
|
Loading…
Reference in New Issue