Parcourir la source

Check consistency between subnets and reverse DNS entries

Baptiste Jonglez il y a 11 ans
Parent
commit
de2d1c8446
1 fichiers modifiés avec 7 ajouts et 0 suppressions
  1. 7 0
      coin/resources/models.py

+ 7 - 0
coin/resources/models.py

@@ -83,11 +83,18 @@ class IPSubnet(models.Model):
         if conflicting:
         if conflicting:
             raise ValidationError('Subnet must not intersect with existing subnets.\nIntersected subnets: {}.'.format(conflicting))
             raise ValidationError('Subnet must not intersect with existing subnets.\nIntersected subnets: {}.'.format(conflicting))
 
 
+    def validate_reverse_dns(self):
+        """Check that reverse DNS entries, if any, are included in the subnet"""
+        incorrect = [str(rev.ip) for rev in self.reversednsentry_set.all() if not rev.ip in self.inet]
+        if incorrect:
+            raise ValidationError('Some reverse DNS entries are not in the subnet: {}.'.format(incorrect))
+
     def clean(self):
     def clean(self):
         if not self.inet:
         if not self.inet:
             self.allocate()
             self.allocate()
         else:
         else:
             self.validate_inclusion()
             self.validate_inclusion()
+        self.validate_reverse_dns()
 
 
     def __unicode__(self):
     def __unicode__(self):
         return str(self.inet)
         return str(self.inet)