Added ability to manage wildcard dns entries

This commit is contained in:
Γιώργος Τριγωνάκης
2026-02-05 12:03:38 +02:00
parent c83e22c6f6
commit 86a1f947d1
2 changed files with 13 additions and 5 deletions

View File

@@ -63,6 +63,7 @@ class StaticHostForm(forms.ModelForm):
self.helper = FormHelper()
self.helper.form_method = 'post'
self.fields['hostname'].label = _('Hostname')
self.fields['hostname'].help_text = _('Hostname or wildcard domain (e.g. *.example.com)')
self.fields['ip_address'].label = _('IP Address')
back_label = _('Back')
delete_label = _('Delete')
@@ -90,10 +91,12 @@ class StaticHostForm(forms.ModelForm):
cleaned_data = super().clean()
hostname = cleaned_data.get('hostname')
if hostname:
regex = r'^[a-zA-Z][a-zA-Z0-9-\.]*[a-zA-Z0-9]$'
if not re.match(regex, hostname):
raise ValidationError('Invalid hostname')
return
# Allow plain hostname (e.g. example.com) or wildcard (e.g. *.example.com)
plain_regex = r'^[a-zA-Z0-9]([a-zA-Z0-9-\.]*[a-zA-Z0-9])?$'
wildcard_regex = r'^\*\.([a-zA-Z0-9]([a-zA-Z0-9-\.]*[a-zA-Z0-9])?)$'
if not (re.match(plain_regex, hostname) or re.match(wildcard_regex, hostname)):
raise ValidationError(_('Invalid hostname. Use a hostname (e.g. example.com) or wildcard (e.g. *.example.com).'))
return cleaned_data
class DNSFilterListForm(forms.ModelForm):