示例#1
0
    def clean(self, ignore_conflicts=False):
        if self.name.endswith('arpa'):
            self.is_reverse = True
        self.master_domain = name_to_master_domain(self.name)

        if not self.master_domain and self.name in ('reverse', 'config'):
            # Right now zone files get placed into invzones/ where directories
            # corresponding to TLDs are placed. There are also directories
            # invzones/config/ (where configs are stored) and invzones/reverse/
            # (where reverse zones are stored) -- we don't want to clobber
            # these directories with TLD directories.
            raise ValidationError(
                "{0} is a reserved TLD name".format(self.name)
            )

        do_zone_validation(self)
        # TODO, can we remove this?
        if self.pk is None and not ignore_conflicts:
            # 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))
        elif self.pk is not None:
            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.")
    def clean(self, ignore_conflicts=False):
        if self.name.endswith('arpa'):
            self.is_reverse = True
        self.master_domain = name_to_master_domain(self.name)

        if not self.master_domain and self.name in ('reverse', 'config'):
            # Right now zone files get placed into invzones/ where directories
            # corresponding to TLDs are placed. There are also directories
            # invzones/config/ (where configs are stored) and invzones/reverse/
            # (where reverse zones are stored) -- we don't want to clobber
            # these directories with TLD directories.
            raise ValidationError("{0} is a reserved TLD name".format(
                self.name))

        do_zone_validation(self)
        # TODO, can we remove this?
        if self.pk is None and not ignore_conflicts:
            # 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))
        elif self.pk is not None:
            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.")
示例#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(objects)
            )

        cname_qset = self.__class__.objects.filter(
            label=self.label, domain=self.domain
        )

        if self.pk:
            cname_qset = cname_qset.filter(~Q(pk=self.pk))

        if cname_qset.exists():
            raise ValidationError(
                "A CNAME with this fqdn already exist."
            )

        MX = mozdns.mx.models.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!"
            )
    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(objects))

        cname_qset = self.__class__.objects.filter(label=self.label,
                                                   domain=self.domain)

        if self.pk:
            cname_qset = cname_qset.filter(~Q(pk=self.pk))

        if cname_qset.exists():
            raise ValidationError("A CNAME with this fqdn already exist.")

        MX = mozdns.mx.models.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!")
    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))
        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.")