Merge pull request #139 from gtrig/feature/wildcard_dns

Adds wildcard DNS entry support
This commit is contained in:
Eduardo Silva
2026-02-10 10:06:00 -03:00
committed by GitHub
2 changed files with 13 additions and 5 deletions

View File

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

View File

@@ -124,7 +124,12 @@ bind-interfaces
if static_hosts: if static_hosts:
dnsmasq_config += '\n' dnsmasq_config += '\n'
for static_host in static_hosts: for static_host in static_hosts:
dnsmasq_config += f'address=/{static_host.hostname}/{static_host.ip_address}\n' # dnsmasq uses /.example.com/ for wildcards (matches *.example.com and example.com)
if static_host.hostname.startswith('*.'):
dnsmasq_domain = '.' + static_host.hostname[2:]
else:
dnsmasq_domain = static_host.hostname
dnsmasq_config += f'address=/{dnsmasq_domain}/{static_host.ip_address}\n'
if dns_lists: if dns_lists:
dnsmasq_config += '\n' dnsmasq_config += '\n'