Example #1
0
    def do_remove_AAAA_record(self, aname, domain, ip ):
        aret = AddressRecord( label = aname, domain=domain, ip_str=ip, ip_type='6')
        aret.save()
        self.assertTrue(aret)

        aret.delete()

        nret  = AddressRecord.objects.filter( label = aname, domain = domain, ip_str = ip)
        self.assertFalse(nret)
Example #2
0
 def test_delete_with_cname_pointing_to_a(self):
     label = 'foo100'
     a = AddressRecord(label=label, domain=self.o_e, ip_str=
                       '128.193.1.10', ip_type='4')
     a.clean()
     a.save()
     cn = CNAME(label="foomom", domain=self.o_e, target=label + "." +
                self.o_e.name)
     cn.clean()
     cn.save()
     self.assertRaises(ValidationError, a.delete)
     a.delete(check_cname=False)
Example #3
0
    def test_basic_add_remove5(self):
        # Make sure all record types block
        c = Domain(name='foo22')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo22')
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="foo",
                                         comment="foo.foo22")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)

        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label,
                             domain=the_domain,
                             ip_type='4',
                             ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        ns = Nameserver(domain=the_domain, server="asdfasffoo")
        ns.save()
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        srv = SRV(label='_' + label,
                  domain=the_domain,
                  target="foo",
                  priority=4,
                  weight=4,
                  port=34)
        srv.save()
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
Example #4
0
    def do_remove_AAAA_record(self, aname, domain, ip):
        aret = AddressRecord(label=aname,
                             domain=domain,
                             ip_str=ip,
                             ip_type='6')
        aret.save()
        self.assertTrue(aret)

        aret.delete()

        nret = AddressRecord.objects.filter(label=aname,
                                            domain=domain,
                                            ip_str=ip)
        self.assertFalse(nret)
Example #5
0
 def test_delete_with_cname_pointing_to_a(self):
     label = 'foo100'
     a = AddressRecord(label=label,
                       domain=self.o_e,
                       ip_str='128.193.1.10',
                       ip_type='4')
     a.clean()
     a.save()
     cn = CNAME(label="foomom",
                domain=self.o_e,
                target=label + "." + self.o_e.name)
     cn.clean()
     cn.save()
     self.assertRaises(ValidationError, a.delete)
     a.delete(check_cname=False)
Example #6
0
    def test_basic_add_remove5(self):
        # Make sure all record types block
        c = Domain(name='foo22')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo22')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         comment="foo.foo22")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)

        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label, domain=the_domain,
                             ip_type='4', ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        ns = Nameserver(domain=the_domain, server="asdfasffoo")
        ns.save()
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        srv = SRV(
            label='_' + label, domain=the_domain, target="foo", priority=4,
            weight=4, port=34)
        srv.save()
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
Example #7
0
    def test_cleanup_address(self):
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.poo"))
        self.assertTrue(Domain.objects.filter(name="foo.poo"))

        fqdn = "bar.x.y.z.foo.poo"
        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label, domain=the_domain,
                             ip_type='4', ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.poo"))
        self.assertTrue(Domain.objects.filter(name="foo.poo"))
Example #8
0
    def test_cleanup_address(self):
        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.poo"))
        self.assertTrue(Domain.objects.filter(name="foo.poo"))

        fqdn = "bar.x.y.z.foo.poo"
        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label,
                             domain=the_domain,
                             ip_type='4',
                             ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.poo"))
        self.assertFalse(Domain.objects.filter(name="z.foo.poo"))
        self.assertTrue(Domain.objects.filter(name="foo.poo"))
Example #9
0
    def test_basic_add_remove5(self):
        # Make sure all record types block
        f_c = create_fake_zone("foo.foo22", suffix="")
        self.assertFalse(f_c.purgeable)
        fqdn = "bar.x.y.z.foo.foo22"
        label, the_domain = ensure_label_domain(fqdn)

        txt = TXT(label=label, domain=the_domain, txt_data="Nthing")
        txt.save()
        self.assertFalse(prune_tree(the_domain))
        txt.delete()

        label, the_domain = ensure_label_domain(fqdn)
        addr = AddressRecord(label=label, domain=the_domain,
                             ip_type='4', ip_str="10.2.3.4")
        addr.save()
        self.assertFalse(prune_tree(the_domain))
        addr.delete()

        label, the_domain = ensure_label_domain(fqdn)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.delete()

        label, the_domain = ensure_label_domain(fqdn)
        ns = Nameserver(domain=the_domain, server="asdfasffoo")
        ns.save()
        self.assertFalse(prune_tree(the_domain))
        ns.delete()

        label, the_domain = ensure_label_domain(fqdn)
        srv = SRV(
            label='_' + label, domain=the_domain, target="foo", priority=4,
            weight=4, port=34)
        srv.save()
        self.assertFalse(prune_tree(the_domain))
        srv.delete()
Example #10
0
class NameserverForm(DNSForm, UsabilityFormMixin):
    glue_ip_str = forms.CharField(label="Glue's IP Address", required=False)
    glue_ctnr = forms.ModelChoiceField(queryset=Ctnr.objects.all(),
                                       required=False,
                                       label="Glue's Container")

    class Meta:
        model = Nameserver
        fields = ('domain', 'server', 'views', 'ttl', 'glue_ip_str',
                  'glue_ctnr', 'description')
        exclude = ('addr_glue', 'intr_glue')
        widgets = {'views': forms.CheckboxSelectMultiple}

    def __init__(self, *args, **kwargs):
        super(NameserverForm, self).__init__(*args, **kwargs)
        if not self.instance:
            return
        if not self.instance.glue:
            # If it doesn't have glue, it doesn't need it.
            return
        addr_glue = AddressRecord.objects.filter(
            label=self.instance.glue.label, domain=self.instance.glue.domain)
        intr_glue = StaticInterface.objects.filter(
            label=self.instance.glue.label, domain=self.instance.glue.domain)

        glue_choices = []
        for glue in addr_glue:
            glue_choices.append(("addr_{0}".format(glue.pk), str(glue)))
        for glue in intr_glue:
            glue_choices.append(("intr_{0}".format(glue.pk), str(glue)))

        if isinstance(self.instance.glue, AddressRecord):
            initial = "addr_{0}".format(self.instance.glue.pk)
        elif isinstance(self.instance.glue, StaticInterface):
            initial = "intr_{0}".format(self.instance.glue.pk)

        self.fields['glue'] = forms.ChoiceField(choices=glue_choices,
                                                initial=initial)

    def clean(self, *args, **kwargs):
        self.glue = None
        if self.instance.pk is None:
            domain = self.cleaned_data['domain']
            glue_ip_str, glue_ctnr = (self.cleaned_data['glue_ip_str'],
                                      self.cleaned_data['glue_ctnr'])
            server = self.cleaned_data['server'].strip('.')
            if '.' in server:
                if server.lower() != domain.name.lower():
                    glue_label, glue_domain = tuple(server.split('.', 1))
                    glue_domain = glue_domain.strip('.').lower()
                else:
                    glue_label, glue_domain = "", server.lower()
            else:
                raise ValidationError(
                    "Please provide a fully qualified server name.")

            if domain.delegated:
                if glue_domain and glue_domain != domain.name.lower():
                    if glue_ip_str or glue_ctnr:
                        raise ValidationError(
                            "This record does not need glue, so "
                            "please leave the glue fields blank.")
                else:
                    if not (glue_ip_str and glue_ctnr):
                        raise ValidationError(
                            "This zone is delegated, so "
                            "please provide information for glue.")
                    gluekwargs = {
                        'domain': domain,
                        'label': glue_label,
                        'ip_str': glue_ip_str,
                        'ctnr': glue_ctnr
                    }
                    try:
                        self.glue = AddressRecord.objects.get(**gluekwargs)
                    except AddressRecord.DoesNotExist:
                        self.glue = AddressRecord(**gluekwargs)
                    self.glue.set_is_glue()
                    self.glue.save()
                    for v in View.objects.all():
                        self.glue.views.add(v)
            elif not domain.delegated and (glue_ip_str or glue_ctnr):
                raise ValidationError("This zone is not delegated, so please "
                                      "leave the glue fields blank.")
        cleaned_data = super(NameserverForm, self).clean(*args, **kwargs)
        return cleaned_data

    def save(self, *args, **kwargs):
        try:
            super(NameserverForm, self).save(*args, **kwargs)
        except Exception, e:
            if self.glue and self.glue.pk is not None:
                self.glue.delete(validate_glue=False)
            raise ValidationError(e)
Example #11
0
class NameserverForm(DNSForm, UsabilityFormMixin):
    glue_ip_str = forms.CharField(label="Glue's IP Address", required=False)
    glue_ctnr = forms.ModelChoiceField(
        queryset=Ctnr.objects.all(),
        required=False,
        label="Glue's Container")

    class Meta:
        model = Nameserver
        fields = ('domain', 'server', 'views', 'ttl', 'glue_ip_str',
                  'glue_ctnr', 'description')
        exclude = ('addr_glue', 'intr_glue')
        widgets = {'views': forms.CheckboxSelectMultiple}

    def __init__(self, *args, **kwargs):
        super(NameserverForm, self).__init__(*args, **kwargs)
        if not self.instance:
            return
        if not self.instance.glue:
            # If it doesn't have glue, it doesn't need it.
            return
        addr_glue = AddressRecord.objects.filter(
            label=self.instance.glue.label,
            domain=self.instance.glue.domain)
        intr_glue = StaticInterface.objects.filter(
            label=self.instance.glue.label,
            domain=self.instance.glue.domain)

        glue_choices = []
        for glue in addr_glue:
            glue_choices.append(("addr_{0}".format(glue.pk), str(glue)))
        for glue in intr_glue:
            glue_choices.append(("intr_{0}".format(glue.pk), str(glue)))

        if isinstance(self.instance.glue, AddressRecord):
            initial = "addr_{0}".format(self.instance.glue.pk)
        elif isinstance(self.instance.glue, StaticInterface):
            initial = "intr_{0}".format(self.instance.glue.pk)

        self.fields['glue'] = forms.ChoiceField(choices=glue_choices,
                                                initial=initial)

    def clean(self, *args, **kwargs):
        self.glue = None
        if self.instance.pk is None:
            domain = self.cleaned_data['domain']
            glue_ip_str, glue_ctnr = (self.cleaned_data['glue_ip_str'],
                                      self.cleaned_data['glue_ctnr'])
            server = self.cleaned_data['server'].strip('.')
            if '.' in server:
                if server.lower() != domain.name.lower():
                    glue_label, glue_domain = tuple(server.split('.', 1))
                    glue_domain = glue_domain.strip('.').lower()
                else:
                    glue_label, glue_domain = "", server.lower()
            else:
                raise ValidationError(
                    "Please provide a fully qualified server name.")

            if domain.delegated:
                if glue_domain and glue_domain != domain.name.lower():
                    if glue_ip_str or glue_ctnr:
                        raise ValidationError(
                            "This record does not need glue, so "
                            "please leave the glue fields blank.")
                else:
                    if not (glue_ip_str and glue_ctnr):
                        raise ValidationError(
                            "This zone is delegated, so "
                            "please provide information for glue.")
                    gluekwargs = {'domain': domain, 'label': glue_label,
                                  'ip_str': glue_ip_str, 'ctnr': glue_ctnr}
                    try:
                        self.glue = AddressRecord.objects.get(**gluekwargs)
                    except AddressRecord.DoesNotExist:
                        self.glue = AddressRecord(**gluekwargs)
                    self.glue.set_is_glue()
                    self.glue.save()
                    for v in View.objects.all():
                        self.glue.views.add(v)
            elif not domain.delegated and (glue_ip_str or glue_ctnr):
                raise ValidationError("This zone is not delegated, so please "
                                      "leave the glue fields blank.")
        cleaned_data = super(NameserverForm, self).clean(*args, **kwargs)
        return cleaned_data

    def save(self, *args, **kwargs):
        try:
            super(NameserverForm, self).save(*args, **kwargs)
        except Exception, e:
            if self.glue and self.glue.pk is not None:
                self.glue.delete(validate_glue=False)
            raise ValidationError(e)