No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. from django.db import models
  2. from django.urls import reverse
  3. from whoisdb.models import MntdObject, WhoisObject, Contact, InetNum
  4. import ipaddress
  5. # generally allow domains for .dn to be created
  6. # allow owners of a subnet to create reverse dns record?
  7. class Nameserver(MntdObject):
  8. handleSuffix = "NS"
  9. # dns name
  10. # ip address, if glue
  11. # ipv4/ipv6 address?
  12. handle = None
  13. name = models.CharField(max_length=256)
  14. glueIPv4 = models.GenericIPAddressField(protocol='IPv4', blank=True, null=True)
  15. glueIPv6 = models.GenericIPAddressField(protocol='IPv6', blank=True, null=True)
  16. admin_c = models.ManyToManyField(Contact)
  17. def getPK(self):
  18. return self.pk
  19. def get_absolute_url(self):
  20. return reverse("domains:nameserver-show", args=(self.pk,))
  21. def __str__(self):
  22. return self.name
  23. def getAppName(self):
  24. return "domains"
  25. def getNoDeleteReasons(self):
  26. # nameservers can always be deleted
  27. return []
  28. class Domain(MntdObject):
  29. handle = None
  30. handleSuffix = "DOM"
  31. name = models.CharField(max_length=67, unique=True, db_index=True)
  32. nameservers = models.ManyToManyField(Nameserver, blank=True)
  33. admin_c = models.ManyToManyField(Contact)
  34. def getPK(self):
  35. return self.name
  36. def get_absolute_url(self):
  37. return reverse("domains:domain-show", args=(self.name,))
  38. def __str__(self):
  39. return self.name
  40. def getAppName(self):
  41. return "domains"
  42. def getNoDeleteReasons(self):
  43. reasons = []
  44. nameservers = Nameserver.objects.filter(name__endswith="." + self.name)
  45. for ns in nameservers:
  46. # FIXME: check if the nameserver has a glue record.... and also if it is maintained by us
  47. reasons.append("Nameserver %s depends on this domain" % ns.name)
  48. return reasons
  49. @classmethod
  50. def fixName(clazz, name):
  51. if not name.endswith("."):
  52. name += "."
  53. return name.lower()
  54. class ReverseZone(WhoisObject):
  55. handle = None
  56. parentNet = models.ForeignKey(InetNum)
  57. address = models.GenericIPAddressField(db_index=True)
  58. netmask = models.PositiveIntegerField()
  59. nameservers = models.ManyToManyField(Nameserver)
  60. def getPK(self):
  61. return self.pk
  62. def prefix(self):
  63. """ Helper function, mainly used in templates """
  64. return "%s/%s" % (self.address, self.netmask)
  65. def getNetwork(self):
  66. return ipaddress.ip_network(self.prefix())
  67. def get_absolute_url(self):
  68. return reverse("domains:reversezone-show", args=(self.pk,))
  69. def getAppName(self):
  70. return "domains"
  71. def __str__(self):
  72. return "%s @ %s" % (self.prefix(), self.parentNet)
  73. def getNoDeleteReasons(self):
  74. return []
  75. def canEdit(self, user):
  76. if self.parentNet:
  77. return self.parentNet.canEdit(user)
  78. else:
  79. return False