diff --git a/binder/forms.py b/binder/forms.py index 775a122..c752926 100644 --- a/binder/forms.py +++ b/binder/forms.py @@ -21,22 +21,45 @@ class CustomUnicodeListField(forms.CharField): return string_list +class CustomStringPeriodSuffix(forms.CharField): + """ Convert unicode to string and make sure period is last character. """ + ### This seems very unclean. Need a better to way to complete the fqdn + ### depending on if it ends in a period. + ### TODO(jforman): Add Regex check in here for valid rr data + ### http://www.zytrax.com/books/dns/apa/names.html + def clean(self, value): + try: + new_string = str(value) + if new_string[-1] != ".": + new_string += "." + except: + raise ValidationError("Unable to stick a period on the end of your input: %r" % value) + + return new_string ### Form Models -class FormAddRecord(forms.Form): - """ Form used to add a DNS record. - TODO: Right now this form only supports forward zone creation. - It wont accept values if you try to manually add a PTR. - """ +class FormAddForwardRecord(forms.Form): + """ Form used to add a Forward DNS record. """ dns_server = forms.CharField(max_length=100) record_name = forms.RegexField(max_length=100, regex="^[a-zA-Z0-9-_]+$", required=False) record_type = forms.ChoiceField(choices=local_settings.RECORD_TYPE_CHOICES) zone_name = forms.CharField(max_length=100) - record_data = forms.GenericIPAddressField() # TODO: Change to this a non-empty valid-data regex field. + record_data = forms.GenericIPAddressField() ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES) create_reverse = forms.BooleanField(required=False) key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False) +class FormAddReverseRecord(forms.Form): + """ Form used to add a Reverse (PTR) DNS record. """ + dns_server = forms.CharField(max_length=100) + record_name = forms.IntegerField(min_value=0, max_value=255) + record_type = forms.RegexField(regex=r"^PTR$",error_messages={"invalid" : "The only valid choice here is PTR."}) + zone_name = forms.CharField(max_length=100) + record_data = CustomStringPeriodSuffix(required=True) + ttl = forms.ChoiceField(choices=local_settings.TTL_CHOICES) + key_name = forms.ModelChoiceField(queryset=Key.objects.all(), required=False) + create_reverse = forms.BooleanField(required=False) + class FormAddCnameRecord(forms.Form): """ Form used to add a CNAME record. """ dns_server = forms.CharField(max_length=100) diff --git a/binder/templates/bcommon/add_record_form.htm b/binder/templates/bcommon/add_record_form.htm index e68c2e3..fbe7d6b 100644 --- a/binder/templates/bcommon/add_record_form.htm +++ b/binder/templates/bcommon/add_record_form.htm @@ -36,7 +36,7 @@ Add record in {{ zone_name }}