mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Fix regex for IPAddress.dns_name (but see #3106)
This commit is contained in:
parent
06245f6422
commit
e1bca52d57
@ -14,6 +14,6 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='ipaddress',
|
model_name='ipaddress',
|
||||||
name='dns_name',
|
name='dns_name',
|
||||||
field=models.CharField(blank=True, max_length=255, validators=[django.core.validators.RegexValidator(code='invalid', message='Only alphanumeric characters, hyphens, and periods are allowed in DNS names', regex='^[0-9A-Za-z\\.-]+$')]),
|
field=models.CharField(blank=True, max_length=255, validators=[django.core.validators.RegexValidator(code='invalid', message='Only alphanumeric characters, hyphens, and periods are allowed in DNS names', regex='^[0-9A-Za-z.-]+$')]),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -368,11 +368,15 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if self.prefix:
|
|
||||||
|
if isinstance(self.prefix, netaddr.IPNetwork):
|
||||||
|
|
||||||
# Clear host bits from prefix
|
# Clear host bits from prefix
|
||||||
self.prefix = self.prefix.cidr
|
self.prefix = self.prefix.cidr
|
||||||
# Infer address family from IPNetwork object
|
|
||||||
|
# Record address family
|
||||||
self.family = self.prefix.version
|
self.family = self.prefix.version
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def to_csv(self):
|
def to_csv(self):
|
||||||
@ -579,7 +583,7 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
validators=[DNSValidator],
|
validators=[DNSValidator],
|
||||||
verbose_name='DNS Name',
|
verbose_name='DNS Name',
|
||||||
help_text='Hostname or FQDN'
|
help_text='Hostname or FQDN (not case-sensitive)'
|
||||||
)
|
)
|
||||||
description = models.CharField(
|
description = models.CharField(
|
||||||
max_length=100,
|
max_length=100,
|
||||||
@ -633,9 +637,14 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if self.address:
|
|
||||||
# Infer address family from IPAddress object
|
# Record address family
|
||||||
|
if isinstance(self.address, netaddr.IPNetwork):
|
||||||
self.family = self.address.version
|
self.family = self.address.version
|
||||||
|
|
||||||
|
# Force dns_name to lowercase
|
||||||
|
self.dns_name = self.dns_name.lower()
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def log_change(self, user, request_id, action):
|
def log_change(self, user, request_id, action):
|
||||||
|
@ -2,7 +2,7 @@ from django.core.validators import RegexValidator
|
|||||||
|
|
||||||
|
|
||||||
DNSValidator = RegexValidator(
|
DNSValidator = RegexValidator(
|
||||||
regex='^[a-z]+$',
|
regex='^[0-9A-Za-z.-]+$',
|
||||||
message='Only alphanumeric characters, hyphens, and periods are allowed in DNS names',
|
message='Only alphanumeric characters, hyphens, and periods are allowed in DNS names',
|
||||||
code='invalid'
|
code='invalid'
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user