Fixes #3: validation error in reverse zone
This commit is contained in:
parent
adfa056939
commit
e83a3aa6ee
|
@ -1,4 +1,4 @@
|
||||||
VERSION = '1.0.2'
|
VERSION = '1.0.3'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from extras.plugins import PluginConfig
|
from extras.plugins import PluginConfig
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import logging
|
|
||||||
import socket
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
import dns.tsigkeyring
|
import dns.tsigkeyring
|
||||||
import dns.update
|
import dns.update
|
||||||
|
import logging
|
||||||
|
import socket
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.functions import Length
|
from django.db.models.functions import Length
|
||||||
|
@ -11,7 +9,8 @@ from django.utils.html import format_html
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from dns import rcode
|
from dns import rcode
|
||||||
from dns.tsig import HMAC_MD5, HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, HMAC_SHA512
|
from dns.tsig import HMAC_MD5, HMAC_SHA1, HMAC_SHA224, HMAC_SHA256, HMAC_SHA384, HMAC_SHA512
|
||||||
from netaddr import ip
|
from netaddr import IPNetwork, ip
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from ipam.fields import IPNetworkField
|
from ipam.fields import IPNetworkField
|
||||||
from ipam.models import IPAddress
|
from ipam.models import IPAddress
|
||||||
|
@ -210,7 +209,7 @@ class ReverseZone(models.Model):
|
||||||
|
|
||||||
def record_name(self, address: ip.IPAddress):
|
def record_name(self, address: ip.IPAddress):
|
||||||
record_name = self.name
|
record_name = self.name
|
||||||
if self.prefix.version == 4:
|
if IPNetwork(self.prefix).version == 4:
|
||||||
for pos, octet in enumerate(address.words):
|
for pos, octet in enumerate(address.words):
|
||||||
if (pos + 1) * 8 <= self.prefix.prefixlen:
|
if (pos + 1) * 8 <= self.prefix.prefixlen:
|
||||||
continue
|
continue
|
||||||
|
@ -227,7 +226,7 @@ class ReverseZone(models.Model):
|
||||||
return record_name
|
return record_name
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.prefix.version == 4:
|
if isinstance(self.prefix, IPNetwork) and self.prefix.version == 4:
|
||||||
if self.prefix.prefixlen not in [0, 8, 16, 24] and not self.name:
|
if self.prefix.prefixlen not in [0, 8, 16, 24] and not self.name:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'name': _('Required when prefix length is not 0, 8, 16 or 24'),
|
'name': _('Required when prefix length is not 0, 8, 16 or 24'),
|
||||||
|
@ -240,7 +239,8 @@ class ReverseZone(models.Model):
|
||||||
break
|
break
|
||||||
|
|
||||||
self.name = f'{octet}.{self.name}'
|
self.name = f'{octet}.{self.name}'
|
||||||
else:
|
|
||||||
|
elif isinstance(self.prefix, IPNetwork) and self.prefix.version == 6:
|
||||||
if self.prefix.prefixlen % 4 != 0 and not self.name:
|
if self.prefix.prefixlen % 4 != 0 and not self.name:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'name': _('Required when prefix length is not a nibble boundary'),
|
'name': _('Required when prefix length is not a nibble boundary'),
|
||||||
|
|
Loading…
Reference in a new issue