mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-02-20 11:36:18 +00:00
Added ability to manage wildcard dns entries
This commit is contained in:
11
dns/forms.py
11
dns/forms.py
@@ -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):
|
||||||
|
|||||||
@@ -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'
|
||||||
|
|||||||
Reference in New Issue
Block a user