2017-03-14 20:18:57 +01:00
|
|
|
from django.db import models
|
|
|
|
from django.urls import reverse
|
|
|
|
|
2017-03-22 04:06:24 +01:00
|
|
|
from whoisdb.models import MntdObject, WhoisObject, Contact, InetNum
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2017-03-21 02:36:07 +01:00
|
|
|
import ipaddress
|
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
# generally allow domains for .dn to be created
|
|
|
|
# allow owners of a subnet to create reverse dns record?
|
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
class Nameserver(MntdObject):
|
|
|
|
handleSuffix = "NS"
|
|
|
|
# dns name
|
|
|
|
# ip address, if glue
|
|
|
|
# ipv4/ipv6 address?
|
|
|
|
handle = None
|
2017-03-22 19:11:19 +01:00
|
|
|
name = models.CharField(max_length=256)
|
2017-03-14 20:18:57 +01:00
|
|
|
glueIPv4 = models.GenericIPAddressField(protocol='IPv4', blank=True, null=True)
|
|
|
|
glueIPv6 = models.GenericIPAddressField(protocol='IPv6', blank=True, null=True)
|
|
|
|
|
|
|
|
admin_c = models.ManyToManyField(Contact)
|
|
|
|
|
2017-03-22 04:06:24 +01:00
|
|
|
def getPK(self):
|
2017-03-22 19:11:19 +01:00
|
|
|
return self.pk
|
2017-03-22 04:06:24 +01:00
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
def get_absolute_url(self):
|
2017-03-22 19:11:19 +01:00
|
|
|
return reverse("domains:nameserver-show", args=(self.pk,))
|
2017-03-14 20:18:57 +01:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2017-03-31 03:26:10 +02:00
|
|
|
def getAppName(self):
|
|
|
|
return "domains"
|
|
|
|
|
2017-03-22 19:11:19 +01:00
|
|
|
def getNoDeleteReasons(self):
|
|
|
|
# nameservers can always be deleted
|
|
|
|
return []
|
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
class Domain(MntdObject):
|
|
|
|
handle = None
|
|
|
|
handleSuffix = "DOM"
|
|
|
|
name = models.CharField(max_length=67, unique=True, db_index=True)
|
|
|
|
|
|
|
|
nameservers = models.ManyToManyField(Nameserver, blank=True)
|
|
|
|
admin_c = models.ManyToManyField(Contact)
|
|
|
|
|
2017-03-22 04:06:24 +01:00
|
|
|
def getPK(self):
|
|
|
|
return self.name
|
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse("domains:domain-show", args=(self.name,))
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2017-03-31 03:26:10 +02:00
|
|
|
def getAppName(self):
|
|
|
|
return "domains"
|
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
def getNoDeleteReasons(self):
|
|
|
|
reasons = []
|
|
|
|
|
|
|
|
nameservers = Nameserver.objects.filter(name__endswith="." + self.name)
|
|
|
|
for ns in nameservers:
|
2017-03-22 19:11:19 +01:00
|
|
|
# FIXME: check if the nameserver has a glue record.... and also if it is maintained by us
|
2017-03-15 02:22:08 +01:00
|
|
|
reasons.append("Nameserver %s depends on this domain" % ns.name)
|
|
|
|
|
|
|
|
return reasons
|
|
|
|
|
|
|
|
|
2017-03-22 04:06:24 +01:00
|
|
|
class ReverseZone(WhoisObject):
|
|
|
|
handle = None
|
|
|
|
|
2017-03-14 20:18:57 +01:00
|
|
|
parentNet = models.ForeignKey(InetNum)
|
|
|
|
address = models.GenericIPAddressField(db_index=True)
|
|
|
|
netmask = models.PositiveIntegerField()
|
|
|
|
|
2017-03-15 02:22:08 +01:00
|
|
|
nameservers = models.ManyToManyField(Nameserver)
|
|
|
|
|
2017-03-22 04:06:24 +01:00
|
|
|
def getPK(self):
|
|
|
|
return self.pk
|
|
|
|
|
2017-03-21 02:36:07 +01:00
|
|
|
def prefix(self):
|
|
|
|
""" Helper function, mainly used in templates """
|
|
|
|
return "%s/%s" % (self.address, self.netmask)
|
|
|
|
|
|
|
|
def getNetwork(self):
|
|
|
|
return ipaddress.ip_network(self.prefix())
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse("domains:reversezone-show", args=(self.pk,))
|
|
|
|
|
2017-03-31 03:26:10 +02:00
|
|
|
def getAppName(self):
|
|
|
|
return "domains"
|
|
|
|
|
2017-03-21 02:36:07 +01:00
|
|
|
def __str__(self):
|
|
|
|
return "%s @ %s" % (self.prefix(), self.parentNet)
|
2017-03-14 20:18:57 +01:00
|
|
|
|
2017-03-21 02:36:07 +01:00
|
|
|
def getNoDeleteReasons(self):
|
|
|
|
return []
|
2017-03-21 19:34:02 +01:00
|
|
|
|
|
|
|
def canEdit(self, user):
|
|
|
|
if self.parentNet:
|
|
|
|
return self.parentNet.canEdit(user)
|
|
|
|
else:
|
|
|
|
return False
|