Пример #1
0
    def clean(self, *args, **kwargs):
        super(Domain, self).clean(*args, **kwargs)

        is_new = self.pk is None

        if self.name.endswith('arpa'):
            self.is_reverse = True
        self.master_domain = name_to_master_domain(self.name)

        if self.master_domain and self.master_domain.delegated:
            raise ValidationError(
                '{} is delegated, so it cannot have subdomains.'.format(
                    self.master_domain.name))

        self.set_soa()

        if self.delegated and not self.soa:
            raise ValidationError(
                '{} is delegated, so it must be in a zone.'.format(self.name))

        # If the domain is new, its pk is None, so self.domain_set will contain
        # the top-level domains rather than an empty queryset.
        if not is_new and self.domain_set.filter(soa=self.soa).exclude(
                root_of_soa=None).exists():
            raise ValidationError("The root of this domain's zone is below "
                                  "it.")

        if is_new:
            # The object doesn't exist in the db yet. Make sure we don't
            # conflict with existing objects. We may want to move to a more
            # automatic solution where the creation of a new domain will
            # automatically move objects around (see the ensure_domain
            # function).
            qset = smart_fqdn_exists(self.name)
            if qset:
                objects = qset.all()
                raise ValidationError("Objects with this name already "
                                      "exist: {0}".format(
                    ', '.join(unicode(object) for object in objects))
                )
        else:
            db_self = Domain.objects.get(pk=self.pk)

            if db_self.name != self.name and self.domain_set.exists():
                raise ValidationError("Child domains rely on this domain's "
                                      "name remaining the same.")

            # Raise an exception...
            # If our soa is different AND it's non-null AND we have records in
            # this domain AND the new soa has a record domain with no
            # nameservers.
            if db_self.soa != self.soa and self.soa and self.has_record_set():
                if not self.soa.root_domain.nameserver_set.exists():
                    raise ValidationError("By changing this domain's SOA you "
                                          "are attempting to create a zone "
                                          "whose root domain has no NS "
                                          "record.")
Пример #2
0
    def clean(self, *args, **kwargs):
        super(Domain, self).clean(*args, **kwargs)

        is_new = self.pk is None

        if self.name.endswith('arpa'):
            self.is_reverse = True
        self.master_domain = name_to_master_domain(self.name)

        if self.master_domain and self.master_domain.delegated:
            raise ValidationError(
                '{} is delegated, so it cannot have subdomains.'.format(
                    self.master_domain.name))

        self.set_soa()

        if self.delegated and not self.soa:
            raise ValidationError(
                '{} is delegated, so it must be in a zone.'.format(self.name))

        # If the domain is new, its pk is None, so self.domain_set will contain
        # the top-level domains rather than an empty queryset.
        if not is_new and self.domain_set.filter(soa=self.soa).exclude(
                root_of_soa=None).exists():
            raise ValidationError("The root of this domain's zone is below "
                                  "it.")

        if is_new:
            # The object doesn't exist in the db yet. Make sure we don't
            # conflict with existing objects. We may want to move to a more
            # automatic solution where the creation of a new domain will
            # automatically move objects around (see the ensure_domain
            # function).
            qset = smart_fqdn_exists(self.name)
            if qset:
                objects = qset.all()
                raise ValidationError("Objects with this name already "
                                      "exist: {0}".format(', '.join(
                                          unicode(object)
                                          for object in objects)))
        else:
            db_self = Domain.objects.get(pk=self.pk)

            if db_self.name != self.name and self.domain_set.exists():
                raise ValidationError("Child domains rely on this domain's "
                                      "name remaining the same.")

            # Raise an exception...
            # If our soa is different AND it's non-null AND we have records in
            # this domain AND the new soa has a record domain with no
            # nameservers.
            if db_self.soa != self.soa and self.soa and self.has_record_set():
                if not self.soa.root_domain.nameserver_set.exists():
                    raise ValidationError("By changing this domain's SOA you "
                                          "are attempting to create a zone "
                                          "whose root domain has no NS "
                                          "record.")
Пример #3
0
    def existing_node_check(self):
        """
        Make sure no other nodes exist at the level of this CNAME.

            "If a CNAME RR is present at a node, no other data should be
            present; this ensures that the data for
            a canonical name and its aliases cannot be different."

            -- `RFC 1034 <http://tools.ietf.org/html/rfc1034>`_

        For example, this would be bad::

            FOO.BAR.COM     CNAME       BEE.BAR.COM

            BEE.BAR.COM     A           128.193.1.1

            FOO.BAR.COM     TXT         "v=spf1 include:foo.com -all"

        If you queried the ``FOO.BAR.COM`` name, the class of the record
        that would be returned would be ambiguous.



        .. note::
            The following records classes are checked.
                * :class:`AddressRecord` (A and AAAA)
                * :class:`SRV`
                * :class:`TXT`
                * :class:`MX`
        """
        qset = smart_fqdn_exists(self.fqdn, cn=False)
        if qset:
            objects = qset.all()
            raise ValidationError(
                "Objects with this name already exist: {0}".format(
                    ', '.join(unicode(object) for object in objects))
            )

        MX = get_model('cyder', 'MX')
        if MX.objects.filter(server=self.fqdn):
            raise ValidationError(
                "RFC 2181 says you shouldn't point MX records at CNAMEs and "
                "an MX points to this name!"
            )

        PTR = get_model('cyder', 'PTR')
        if PTR.objects.filter(fqdn=self.fqdn):
            raise ValidationError("RFC 1034 says you shouldn't point PTR "
                                  "records at CNAMEs, and a PTR points to"
                                  " %s!" % self.fqdn)
Пример #4
0
    def existing_node_check(self):
        """
        Make sure no other nodes exist at the level of this CNAME.

            "If a CNAME RR is present at a node, no other data should be
            present; this ensures that the data for
            a canonical name and its aliases cannot be different."

            -- `RFC 1034 <http://tools.ietf.org/html/rfc1034>`_

        For example, this would be bad::

            FOO.BAR.COM     CNAME       BEE.BAR.COM

            BEE.BAR.COM     A           128.193.1.1

            FOO.BAR.COM     TXT         "v=spf1 include:foo.com -all"

        If you queried the ``FOO.BAR.COM`` name, the class of the record
        that would be returned would be ambiguous.



        .. note::
            The following records classes are checked.
                * :class:`AddressRecord` (A and AAAA)
                * :class:`SRV`
                * :class:`TXT`
                * :class:`MX`
        """
        qset = smart_fqdn_exists(self.fqdn, cn=False)
        if qset:
            objects = qset.all()
            raise ValidationError(
                "Objects with this name already exist: {0}".format(', '.join(
                    unicode(object) for object in objects)))

        MX = get_model('cyder', 'MX')
        if MX.objects.filter(server=self.fqdn):
            raise ValidationError(
                "RFC 2181 says you shouldn't point MX records at CNAMEs and "
                "an MX points to this name!")

        PTR = get_model('cyder', 'PTR')
        if PTR.objects.filter(fqdn=self.fqdn):
            raise ValidationError("RFC 1034 says you shouldn't point PTR "
                                  "records at CNAMEs, and a PTR points to"
                                  " %s!" % self.fqdn)
Пример #5
0
    def clean(self):
        if self.name.endswith('arpa'):
            self.is_reverse = True
        self.master_domain = name_to_master_domain(self.name)

        do_zone_validation(self)
        # TODO, can we remove this?
        if self.pk is None:
            # The object doesn't exist in the db yet. Make sure we don't
            # conflict with existing objects. We may want to move to a more
            # automatic solution where the creation of a new domain will
            # automatically move objects around (see the ensure_domain
            # function).
            qset = smart_fqdn_exists(self.name)
            if qset:
                objects = qset.all()
                raise ValidationError("Objects with this name already "
                                      "exist {0}".format(objects))
Пример #6
0
    def clean(self):
        if self.name.endswith('arpa'):
            self.is_reverse = True
        self.master_domain = name_to_master_domain(self.name)

        do_zone_validation(self)
        # TODO, can we remove this?
        if self.pk is None:
            # The object doesn't exist in the db yet. Make sure we don't
            # conflict with existing objects. We may want to move to a more
            # automatic solution where the creation of a new domain will
            # automatically move objects around (see the ensure_domain
            # function).
            qset = smart_fqdn_exists(self.name)
            if qset:
                objects = qset.all()
                raise ValidationError("Objects with this name already "
                                      "exist {0}".format(objects))