[reverseDNS] add basic logic

This commit is contained in:
Nico Schottelius 2020-10-25 22:43:34 +01:00
commit ecc9e6f734
4 changed files with 53 additions and 5 deletions

View file

@ -4,8 +4,9 @@ import ipaddress
from django.db import models
from django.contrib.auth import get_user_model
from django.core.validators import MinValueValidator, MaxValueValidator
from django.core.exceptions import FieldError
from django.core.exceptions import FieldError, ValidationError
from uncloud_pay.models import Order
class MACAdress(models.Model):
default_prefix = 0x420000000000
@ -194,3 +195,30 @@ class ReverseDNSEntry(models.Model):
ip_address = models.GenericIPAddressField(null=False, unique=True)
name = models.CharField(max_length=253, null=False)
def save(self, *args, **kwargs):
# Product.objects.filter(config__parameters__contains='reverse_dns_network')
# FIXME: check if order is still active / not replaced
allowed = False
for order in Order.objects.filter(config__parameters__reverse_dns_network__isnull=False,
owner=self.owner):
network = order.config['parameters']['reverse_dns_network']
net = ipaddress.ip_network(network)
addr = ipaddress.ip_address(self.ip_address)
if addr in net:
allowed = True
break
if not allowed:
raise ValidationError(f"User {self.owner} does not have the right to create reverse DNS entry for {self.ip_address}")
super().save(*args, **kwargs)
def __str__(self):
return f"{self.ip_address} - {self.name}"