Ejemplo n.º 1
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        s, _ = SOA.objects.get_or_create(primary="foo", contact="Foo",
                                         comment="dddfoo")
        f_c = Domain(name='foo.foo1')
        f_c.soa = s
        f_c.save()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
Ejemplo n.º 2
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = create_fake_zone('foo.foo1', suffix="")
        self.assertEqual(f_c.name, 'foo.foo1')

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
Ejemplo n.º 3
0
 def test_dirty_cname(self):
     self.soa.dirty = False
     self.dom.dirty = False
     c = CNAME(label="asfd", domain=self.dom, data="nerp")
     c.full_clean()
     c.save()
     self.assertTrue(self.dom.dirty)
     self.assertFalse(self.soa.dirty)
Ejemplo n.º 4
0
    def test_add_with_cname(self):
        label = "cnamederp"
        domain = self.o_e
        data = "foo.com"
        cn = CNAME( label = label, domain = domain, data = data )
        cn.full_clean()
        cn.save()

        data = { 'label':'' ,'domain':self.o_e ,'server':'cnamederp.oregonstate.org' ,'priority':2 ,'ttl':2222 }
        mx = MX( **data )
        self.assertRaises( ValidationError, mx.save )
Ejemplo n.º 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)
Ejemplo n.º 6
0
    def test_delegation(self):
        name = "boom"
        dom = Domain(name=name, delegated=True)
        dom.save()

        # Creating objects in the domain should be locked.
        arec = AddressRecord(label="ns1",
                             domain=dom,
                             ip_str="128.193.99.9",
                             ip_type='4')
        self.assertRaises(ValidationError, arec.save)

        ns = Nameserver(domain=dom, server="ns1." + dom.name)
        self.assertRaises(ValidationError, ns.save)

        cn = CNAME(label="999asdf", domain=dom, target="asdf.asdf")
        self.assertRaises(ValidationError, cn.full_clean)

        # Undelegate (unlock) the domain.
        dom.delegated = False
        dom.save()

        # Add glue and ns record.
        arec.save()
        ns.save()

        # Re delegate the domain.
        dom.delegated = True
        dom.save()

        # Creation should still be locked
        arec1 = AddressRecord(label="ns2",
                              domain=dom,
                              ip_str="128.193.99.9",
                              ip_type='4')
        self.assertRaises(ValidationError, arec1.save)

        cn1 = CNAME(label="1000asdf", domain=dom, target="asdf.asdf")
        self.assertRaises(ValidationError, cn1.full_clean)

        # Editing should be allowed.
        arec = AddressRecord.objects.get(pk=arec.pk)
        arec.ip_str = "129.193.88.2"
        arec.save()

        # Adding new A records that have the same name as an NS should
        # be allows.
        arec1 = AddressRecord(label="ns1",
                              domain=dom,
                              ip_str="128.193.100.10",
                              ip_type='4')
        arec1.save()
Ejemplo n.º 7
0
def gen_CNAME():
    """Migrates CNAME objects.

    .. note::
        Run this only after migrating other DNS objects for every zone.

    .. note::
        Because MAINTAIN is totally messed up, some hostnames in the CNAME
        table have ``.``'s in them, so the fully qualified domain name is
        created first, then the label is stripped off of the front of that.

    .. note::
        If the fully qualified domain name of the label + domain name already
        exists as a domain object, that object becomes the alias and the label
        prefix is set to the empty string. Otherwise, the alias is the
        label + domain name.

    :uniqueness: label, domain, target
    """
    print "Creating CNAMEs."
    cursor.execute("SELECT * FROM zone_cname")

    for _, server, name, domain_id, ttl, zone, enabled in cursor.fetchall():
        server, name = server.lower(), name.lower()
        cursor.execute("SELECT name FROM domain WHERE id = '%s'" % domain_id)
        dname, = cursor.fetchone()
        if not dname:
            continue
        dname = dname.lower()

        fqdn = ".".join([name, dname])
        name, dname = fqdn.split(".", 1)

        if Domain.objects.filter(name=fqdn).exists():
            domain = Domain.objects.get(name=fqdn)
            name = ""
        elif Domain.objects.filter(name=dname).exists():
            domain = Domain.objects.get(name=dname)
        else:
            continue

        if server == ".".join([name, domain.name]):
            # In maintain, at least one CNAME is a loop: biosys.bioe.orst.edu
            continue

        cn = CNAME(label=name, domain=domain, target=server)
        # CNAMEs need to be cleaned independently of saving (no get_or_create)
        cn.full_clean()
        cn.save()
        if enabled:
            cn.views.add(public)
Ejemplo n.º 8
0
    def test_existing_cname_new_domain(self):
        name = "bo"
        b_dom,_ = Domain.objects.get_or_create( name = name, delegated=False )

        name = "to.bo"
        t_dom,_ = Domain.objects.get_or_create( name = name, delegated=False )

        cn = CNAME(domain=t_dom, label="no", data="asdf")
        cn.full_clean()
        cn.save()

        name = "no.to.bo"
        n_dom = Domain( name = name, delegated=False )
        self.assertRaises(ValidationError, n_dom.save)
Ejemplo n.º 9
0
    def test_domain_records_perms(self):
        """
        Test common domain record perms (cname, mx, txt, srv, ns)
        """
        self.setup_request()

        perm_table = {
            'cyder_admin': ['all'],
            'admin': ['all'],
            'user': ['all'],
            'guest': [cy.ACTION_VIEW],
        }

        # Initialize objs into ctnrs.
        domain = Domain(id=None, name='foo')
        domain.save()
        self.ctnr_admin.domains.add(domain)
        self.ctnr_user.domains.add(domain)
        self.ctnr_guest.domains.add(domain)
        self.save_all_ctnrs()
        domain_records = []
        domain_records.append(AddressRecord(domain=domain))
        domain_records.append(CNAME(domain=domain))
        domain_records.append(MX(domain=domain))
        domain_records.append(SRV(domain=domain))
        domain_records.append(TXT(domain=domain))
        domain_records.append(Nameserver(domain=domain))

        for obj in domain_records:
            self.check_perms_each_user(obj, perm_table)
Ejemplo n.º 10
0
    def do_add(self, label, domain, data):
        cn = CNAME(label = label, domain = domain, data = data)
        cn.full_clean()
        cn.save()
        cn.save()
        self.assertTrue(cn.get_absolute_url())
        self.assertTrue(cn.get_edit_url())
        self.assertTrue(cn.get_delete_url())
        self.assertTrue(cn.details())

        cs = CNAME.objects.filter(label = label, domain = domain, data = data)
        self.assertEqual(len(cs), 1)
        return cn
Ejemplo n.º 11
0
    def test_cname_point_to_itself(self):
        label = "foopy"
        data = "foopy.what.cd"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        cn = CNAME(label=label, domain=dom, target=data)
        self.assertRaises(ValidationError, cn.clean)
Ejemplo n.º 12
0
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo1')
        s, _ = SOA.objects.get_or_create(primary="foo", contact="foo",
                                         comment="foo.foo1")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Ejemplo n.º 13
0
    def test_ns_exists(self):
        # Duplicate test?
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        rec = Nameserver(domain=dom, server="asdf1")
        rec.save()
        cn = CNAME(label='', domain=dom, target=data)
        self.assertRaises(ValidationError, cn.clean)
Ejemplo n.º 14
0
    def test_integration3_zone(self):
        root_domain = create_fake_zone("wee3.wee.mozilla.com", "")
        res, error = self.search("zone=:wee3.wee.mozilla.com")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 1)
        self.assertEqual(len(res['NS']), 1)
        cn = CNAME(label="host1", domain=root_domain, target="whop.whop")
        cn.save()
        res, error = self.search("zone=:wee3.wee.mozilla.com host1")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 0)
        self.assertEqual(len(res['NS']), 0)
        self.assertEqual(len(res['CNAME']), 1)

        res, error = self.search("zone=:wee3.wee.mozilla.com " "type=:CNAME")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 0)
        self.assertEqual(len(res['NS']), 0)
        self.assertEqual(len(res['CNAME']), 1)
Ejemplo n.º 15
0
    def test_integration3_zone(self):
        root_domain = create_fake_zone("wee3.wee.mozilla.com", "")
        res, error = self.search("zone=:wee3.wee.mozilla.com")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 1)
        self.assertEqual(len(res['NS']), 1)
        cn = CNAME(label="host1", domain=root_domain, target="whop.whop")
        cn.save()
        res, error = self.search("zone=:wee3.wee.mozilla.com host1")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 0)
        self.assertEqual(len(res['NS']), 0)
        self.assertEqual(len(res['CNAME']), 1)

        res, error = self.search("zone=:wee3.wee.mozilla.com "
                                       "type=:CNAME")
        self.assertFalse(error)
        self.assertEqual(len(res['SOA']), 0)
        self.assertEqual(len(res['NS']), 0)
        self.assertEqual(len(res['CNAME']), 1)
Ejemplo n.º 16
0
    def test_txt_exists(self):
        label = "testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        rec, _ = TXT.objects.get_or_create(label=label,
                                           domain=dom,
                                           txt_data="asdf")

        cn = CNAME(label=label, domain=dom, target=data)
        self.assertRaises(ValidationError, cn.full_clean)
Ejemplo n.º 17
0
    def test_ptr_exists(self):
        label = "testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        rec = PTR(ip_str="10.193.1.1", ip_type='4', name='testyfoo.what.cd')
        rec.full_clean()
        rec.save()

        cn = CNAME(label=label, domain=dom, target=data)
        self.assertRaises(ValidationError, cn.full_clean)
Ejemplo n.º 18
0
    def test_basic_add_remove8(self):
        # Make sure a record's label is changed to '' when a domain with the
        # same name as it's fqdn is created.
        f_c = create_fake_zone("foo.foo3", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "www.x.y.z.foo.foo3"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual('www', label)
        self.assertEqual('x.y.z.foo.foo3', the_domain.name)
        self.assertTrue(the_domain.pk)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        fqdn = "*.www.x.y.z.foo.foo3"
        label2, the_domain2 = ensure_label_domain(fqdn)
        cname = CNAME.objects.get(fqdn=cname.fqdn)
        self.assertEqual('', cname.label)
        self.assertEqual('www.x.y.z.foo.foo3', cname.domain.name)
        self.assertEqual('*', label2)
        self.assertEqual('www.x.y.z.foo.foo3', the_domain2.name)
Ejemplo n.º 19
0
    def do_add(self, label, domain, data):
        cn = CNAME(label=label, domain=domain, target=data)
        cn.full_clean()
        cn.save()
        cn.save()
        self.assertTrue(cn.details())

        cs = CNAME.objects.filter(label=label, domain=domain, target=data)
        self.assertEqual(len(cs), 1)
        return cn
Ejemplo n.º 20
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = create_fake_zone('foo.foo1', suffix="")
        self.assertEqual(f_c.name, 'foo.foo1')

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
Ejemplo n.º 21
0
    def test_cleanup_cname(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="Foo",
                                         comment="dddfoo")
        f_c = Domain(name='foo.foo1')
        f_c.soa = s
        f_c.save()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))

        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()

        self.assertFalse(Domain.objects.filter(name="x.y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="y.z.foo.foo1"))
        self.assertFalse(Domain.objects.filter(name="z.foo.foo1"))
        fqdn = "bar.x.y.z.foo.poo"
        self.assertTrue(Domain.objects.filter(name="foo.foo1"))
Ejemplo n.º 22
0
    def test_address_record_exists_upper_case(self):
        label = "testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        rec, _ = AddressRecord.objects.get_or_create(label=label,
                                                     domain=dom,
                                                     ip_type='4',
                                                     ip_str="128.193.1.1")

        cn = CNAME(label=label.title(), domain=dom, target=data)
        self.assertRaises(ValidationError, cn.full_clean)
Ejemplo n.º 23
0
    def test_delegation(self):
        boom = create_zone('boom')
        bleh = Domain.objects.create(name='bleh.boom', delegated=True)
        self.ctnr.domains.add(bleh)

        # Creating objects in the domain should be disallowed.
        arec = AddressRecord(
            label="ns1", ctnr=self.ctnr, domain=bleh, ip_str="128.193.99.9",
            ip_type='4')
        self.assertRaises(ValidationError, arec.save)

        ns = Nameserver(domain=bleh, server="ns1." + bleh.name)
        self.assertRaises(ValidationError, ns.save)

        cn = CNAME(label="999asdf", ctnr=self.ctnr, domain=bleh,
                   target="asdf.asdf")
        self.assertRaises(ValidationError, cn.save)

        # Undelegate the domain.
        bleh.delegated = False
        bleh.save()

        # Add glue and NS record.
        arec.save()
        ns.save()

        # Re-delegate the domain.
        bleh.delegated = True
        bleh.save()

        # Creation should still be disallowed.
        self.assertRaises(
            ValidationError, AddressRecord.objects.create,
            label="ns2", ctnr=self.ctnr, domain=bleh, ip_str="128.193.99.9",
            ip_type='4')

        self.assertRaises(
            ValidationError, CNAME.objects.create,
            label="1000asdf", ctnr=self.ctnr, domain=bleh,
            target="asdf.asdf")

        # Editing should be allowed.
        arec = AddressRecord.objects.get(pk=arec.pk)
        arec.ip_str = "129.193.88.2"
        arec.save()

        # Adding new A records that have the same name as an NS should
        # be allowed.
        AddressRecord.objects.create(
            label="ns1", ctnr=self.ctnr, domain=bleh, ip_str="128.193.100.10",
            ip_type='4')
Ejemplo n.º 24
0
    def test_mx_exists(self):
        label = "testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        rec, _ = MX.objects.get_or_create(label=label,
                                          domain=dom,
                                          server="asdf",
                                          priority=123,
                                          ttl=123)

        cn = CNAME(label=label, domain=dom, target=data)
        self.assertRaises(ValidationError, cn.full_clean)
Ejemplo n.º 25
0
    def test_srv_exists(self):
        label = "_testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        rec, _ = SRV.objects.get_or_create(label=label,
                                           domain=dom,
                                           target="asdf",
                                           port=2,
                                           priority=2,
                                           weight=4)

        cn = CNAME(label=label, domain=dom, target=data)
        self.assertRaises(ValidationError, cn.full_clean)
Ejemplo n.º 26
0
 def normal_CNAMES(self):
     self.cur.execute("SELECT id, server, name, domain, ttl, zone FROM `zone_cname` WHERE `name` NOT LIKE '%.%';")
     cnames = self.cur.fetchall()
     for cname in cnames:
         id_ = cname[0]
         server = cname[1]
         label = cname[2]
         domain_id = cname[3]
         ttl = cname[4]
         zone = cname[5]
         # Get it's domain
         self.cur.execute("SELECT name FROM domain where id='%s'" %
                 (domain_id))
         dname = self.cur.fetchone()
         if not dname:
             print "ERROR: CNAME with id ({0}) doens't have a valid domain".format(id_)
             continue
         dname = dname[0]
         domain = Domain.objects.filter(name=dname)
         domain = domain[0]
         possible = CNAME.objects.filter(label=label, domain=domain, data=server)
         if possible:
             continue
         cn = CNAME(label=label, domain=domain, data=server)
         print "server:{0} label:{1}".format(server, label)
         # server:www.orst.edu label:dev
         try:
             cn.full_clean()
         except ValidationError, e:
             fqdn = label+"."+dname
             dom = Domain.objects.filter(name=fqdn)
             if dom:
                 dom = dom[0]
                 cn, _ = CNAME.objects.get_or_create(label='', domain=dom, data=server)
                 cn.full_clean()
                 cn.save()
                 print "Re-Added CNAME ({0})".format(id_)
                 continue
             else:
                 print "Couldn't fix {0}".format(e)
         cn.save()
Ejemplo n.º 27
0
    def do_add(self, label, domain, data):
        cn = CNAME(label=label, domain=domain, target=data)
        cn.full_clean()
        cn.save()
        cn.save()
        self.assertTrue(cn.details())

        cs = CNAME.objects.filter(
            label=label, domain=domain, target=data)
        self.assertEqual(len(cs), 1)
        return cn
Ejemplo n.º 28
0
    def test_intr_exists(self):
        label = "tdfestyfoo"
        data = "waasdft"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        intr = StaticInterface(label=label,
                               domain=dom,
                               ip_str="10.0.0.1",
                               ip_type='4',
                               system=self.s,
                               mac="11:22:33:44:55:66")
        intr.clean()
        intr.save()

        cn = CNAME(label=label, domain=dom, target=data)
        self.assertRaises(ValidationError, cn.full_clean)
Ejemplo n.º 29
0
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        f_c = create_fake_zone("foo.foo1", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Ejemplo n.º 30
0
    def test_bad_nameserver_soa_state_case_1_0(self):
        # This is Case 1
        root_domain = create_fake_zone("asdf10")
        for ns in root_domain.nameserver_set.all():
            ns.delete()

        # At his point we should have a domain at the root of a zone with no
        # other records in it.

        # Adding a record shouldn't be allowed because there is no NS record on
        # the zone's root domain.
        a = AddressRecord(label='',
                          domain=root_domain,
                          ip_type="6",
                          ip_str="1::")
        self.assertRaises(ValidationError, a.save)
        cn = CNAME(label='', domain=root_domain, target="asdf")
        self.assertRaises(ValidationError, cn.save)
Ejemplo n.º 31
0
    def test_basic_add_remove7(self):
        # try a star record
        f_c = create_fake_zone("foo.foo2", suffix="")
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "*.x.y.z.foo.foo2"
        label, the_domain = ensure_label_domain(fqdn)
        self.assertEqual('*', label)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Ejemplo n.º 32
0
def gen_CNAME():
    """Migrates CNAME objects.

    .. note::
        Run this only after migrating other DNS objects for every zone.

    .. note::
        Because MAINTAIN is totally messed up, some hostnames in the CNAME
        table have ``.``'s in them, so the fully qualified domain name is
        created first, then the label is stripped off of the front of that.

    .. note::
        If the fully qualified domain name of the label + domain name already
        exists as a domain object, that object becomes the alias and the label
        prefix is set to the empty string. Otherwise, the alias is the
        label + domain name.

    :uniqueness: label, domain, target
    """
    print "Creating CNAMEs."
    cursor.execute("SELECT * FROM zone_cname")

    for _, server, name, domain_id, ttl, zone, enabled in cursor.fetchall():
        server, name = server.lower(), name.lower()
        cursor.execute("SELECT name FROM domain WHERE id = '%s'" % domain_id)
        dname, = cursor.fetchone()
        if not dname:
            continue
        dname = dname.lower()

        fqdn = ".".join([name, dname])
        name, dname = fqdn.split(".", 1)

        if Domain.objects.filter(name=fqdn).exists():
            domain = Domain.objects.get(name=fqdn)
            name = ""
        elif Domain.objects.filter(name=dname).exists():
            domain = Domain.objects.get(name=dname)
        else:
            continue

        if server == ".".join([name, domain.name]):
            # In maintain, at least one CNAME is a loop: biosys.bioe.orst.edu
            continue

        cn = CNAME(label=name, domain=domain, target=server)
        # CNAMEs need to be cleaned independently of saving (no get_or_create)
        cn.full_clean()
        cn.save()
        if enabled:
            cn.views.add(public)
Ejemplo n.º 33
0
    def test_add_mx_with_cname(self):
        label = "cnamederp1"
        domain = self.c_g
        data = "foo.com"

        fqdn = label + '.' + domain.name
        mx_data = {
            'label': '',
            'domain': self.c_g,
            'server': fqdn,
            'priority': 2,
            'ttl': 2222
        }
        mx = MX(**mx_data)
        mx.save()

        cn = CNAME(label=label, domain=domain, target=data)

        self.assertRaises(ValidationError, cn.full_clean)
Ejemplo n.º 34
0
    def test_existing_cname_new_domain(self):
        name = "bo"
        b_dom, _ = Domain.objects.get_or_create(name=name, delegated=False)

        name = "to.bo"
        t_dom, _ = Domain.objects.get_or_create(name=name, delegated=False)

        cn = CNAME(domain=t_dom, label="no", target="asdf")
        cn.full_clean()
        cn.save()

        name = "no.to.bo"
        n_dom = Domain(name=name, delegated=False)
        self.assertRaises(ValidationError, n_dom.save)
Ejemplo n.º 35
0
def migrate_CNAME(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('CNAME'):
        name = name.to_text().strip('.')
        print str(name) + " CNAME " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            domain_name = name.split('.')[1:]
            domain = ensure_domain('.'.join(domain_name), force=True)
        data = rdata.target.to_text().strip('.')

        if not CNAME.objects.filter(label=label, domain=domain,
                                    target=data).exists():
            cn = CNAME(label=label, domain=domain, target=data)
            cn.full_clean()
            cn.save()
            for view in views:
                cn.views.add(view)
                cn.save()
Ejemplo n.º 36
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)
Ejemplo n.º 37
0
    def test_add_with_cname(self):
        label = "cnamederp"
        domain = self.o_e
        data = "foo.com"
        cn = CNAME(label=label, domain=domain, target=data)
        cn.full_clean()
        cn.save()

        data = {
            'label': '',
            'domain': self.o_e,
            'server': 'cnamederp.oregonstate.org',
            'priority': 2,
            'ttl': 2222
        }
        mx = MX(**data)
        self.assertRaises(ValidationError, mx.save)
Ejemplo n.º 38
0
def migrate_CNAME(zone, root_domain, soa, views):
    for (name, ttl, rdata) in zone.iterate_rdatas('CNAME'):
        name = name.to_text().strip('.')
        print str(name) + " CNAME " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            domain_name = name.split('.')[1:]
            domain = ensure_domain('.'.join(domain_name), force=True)
        data = rdata.target.to_text().strip('.')

        if not CNAME.objects.filter(label=label, domain=domain,
                                    target=data).exists():
            cn = CNAME(label=label, domain=domain, target=data)
            cn.full_clean()
            cn.save()
            for view in views:
                cn.views.add(view)
                cn.save()
Ejemplo n.º 39
0
    def test_basic_add_remove6(self):
        # Make sure CNAME record block
        c = Domain(name='foo1')
        c.save()
        self.assertFalse(c.purgeable)
        f_c = Domain(name='foo.foo1')
        s, _ = SOA.objects.get_or_create(primary="foo",
                                         contact="foo",
                                         comment="foo.foo1")
        f_c.soa = s
        f_c.save()
        self.assertFalse(f_c.purgeable)
        fqdn = "cname.x.y.z.foo.foo1"
        label, the_domain = ensure_label_domain(fqdn)

        cname = CNAME(label=label, domain=the_domain, target="foo")
        cname.save()
        self.assertFalse(prune_tree(the_domain))
        cname.delete()
Ejemplo n.º 40
0
def gen_CNAME():
    """Migrates CNAME objects.

    .. note::
        Run this only after migrating other DNS objects for every zone.

    .. note::
        Because MAINTAIN is totally messed up, some hostnames in the CNAME
        table have ``.``'s in them, so the fully qualified domain name is
        created first, then the label is stripped off of the front of that.

    .. note::
        If the fully qualified domain name of the label + domain name already
        exists as a domain object, that object becomes the alias and the label
        prefix is set to the empty string. Otherwise, the alias is the
        label + domain name.

    :uniqueness: label, domain, target
    """
    print "Creating CNAMEs."
    sql = ("SELECT zone_cname.id, zone_cname.server, zone_cname.name, "
           "zone_cname.enabled, zone.name, domain.name FROM zone_cname "
           "JOIN zone ON zone_cname.zone = zone.id "
           "JOIN domain ON zone_cname.domain = domain.id")
    cursor.execute(sql)

    for pk, server, name, enabled, zone, dname in cursor.fetchall():
        server, name = server.lower(), name.lower()
        dname = dname.lower()

        fqdn = ".".join([name, dname])
        name, dname = fqdn.split(".", 1)

        if Domain.objects.filter(name=fqdn).exists():
            domain = Domain.objects.get(name=fqdn)
            name = ""
        elif Domain.objects.filter(name=dname).exists():
            domain = Domain.objects.get(name=dname)
        else:
            _, domain = get_label_domain_workaround(fqdn)

        if server == ".".join([name, domain.name]):
            # In maintain, at least one CNAME is a loop: biosys.bioe.orst.edu
            print "Ignoring CNAME %s: Is a loop." % server
            continue

        if CNAME.objects.filter(label=name, domain=domain).exists():
            c = CNAME.objects.get(label=name, domain=domain)
            if c.target != server:
                print ("ALERT: Conflicting CNAME with fqdn %s already exists."
                       % fqdn)
            continue

        ctnr = Zone.ctnr_from_zone_name(zone, 'CNAME')
        if ctnr is None:
            continue

        if ctnr not in domain.ctnr_set.all():
            print "CNAME %s has mismatching container for its domain." % pk
            continue

        cn = CNAME(label=name, domain=domain, target=server, ctnr=ctnr)
        cn.set_fqdn()
        dup_ptrs = PTR.objects.filter(fqdn=cn.fqdn)
        if dup_ptrs:
            print "Removing duplicate PTR for %s" % cn.fqdn
            dup_ptrs.delete(update_range_usage=False)

        # CNAMEs need to be cleaned independently of saving (no get_or_create)
        try:
            cn.full_clean()
            cn.save()
            if enabled:
                cn.views.add(public)
                cn.views.add(private)
        except ValidationError, e:
            print "Error:", e
Ejemplo n.º 41
0
Archivo: api.py Proyecto: Ziaunys/chili
 class Meta:
     always_return_data = True
     queryset = CNAME.objects.all()
     fields = CNAME.get_api_fields() + ['domain', 'views']
     authorization = Authorization()
     allowed_methods = allowed_methods
Ejemplo n.º 42
0
    for (name, ttl, rdata) in zone.iterate_rdatas('CNAME'):
        name = name.to_text().strip('.')
        print str(name) + " CNAME " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            domain_name = name.split('.')[1:]
            domain = ensure_domain('.'.join(domain_name))
        data = rdata.target.to_text().strip('.')

        if not CNAME.objects.filter(label=label, domain=domain,
                                    data=data).exists():
            cn = CNAME(label=label, domain=domain, data=data)
            cn.full_clean()
            cn.save()
            if views:
                for view in views:
                    cn.views.add(view)
                    cn.save()
    # TODO, records not done yet. TXT, SSHFP, AAAA
    # Create list
    for (name, ttl, rdata) in zone.iterate_rdatas('TXT'):
        name = name.to_text().strip('.')
        print str(name) + " TXT " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
Ejemplo n.º 43
0
    for (name, ttl, rdata) in zone.iterate_rdatas('CNAME'):
        name = name.to_text().strip('.')
        print str(name) + " CNAME " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
        else:
            label = name.split('.')[0]
            domain_name = name.split('.')[1:]
            domain = ensure_domain('.'.join(domain_name))
        data = rdata.target.to_text().strip('.')

        if not CNAME.objects.filter(label=label, domain=domain,
                                    data=data).exists():
            cn = CNAME(label=label, domain=domain,
                       data=data)
            cn.full_clean()
            cn.save()
            if views:
                for view in views:
                    cn.views.add(view)
                    cn.save()
    # TODO, records not done yet. TXT, SSHFP, AAAA
    # Create list
    for (name, ttl, rdata) in zone.iterate_rdatas('TXT'):
        name = name.to_text().strip('.')
        print str(name) + " TXT " + str(rdata)
        exists_domain = Domain.objects.filter(name=name)
        if exists_domain:
            label = ''
            domain = exists_domain[0]
Ejemplo n.º 44
0
def populate_forward_dns(svn_zones):
    for site, data in svn_zones.iteritems():
        zone, records = data
        print "-" * 15 + " " + site

        for (name, ttl, rdata) in zone.iterate_rdatas('SOA'):
            print str(name) + " SOA " + str(rdata)
            exists = SOA.objects.filter(
                minimum=rdata.minimum,
                contact=rdata.rname.to_text().strip('.'),
                primary=rdata.mname.to_text().strip('.'),
                comment="SOA for"
                " {0}.mozilla.com".format(site))
            if exists:
                soa = exists[0]
            else:
                soa = SOA(serial=rdata.serial,
                          minimum=rdata.minimum,
                          contact=rdata.rname.to_text().strip('.'),
                          primary=rdata.mname.to_text().strip('.'),
                          comment="SOA for"
                          " {0}.mozilla.com".format(site))
                soa.clean()
                soa.save()
            domain_split = list(reversed(name.to_text().strip('.').split('.')))
            for i in range(len(domain_split)):
                domain_name = domain_split[:i + 1]
                base_domain, created = Domain.objects.get_or_create(
                    name='.'.join(list(reversed(domain_name))))
            base_domain.soa = soa
            base_domain.save()
        """
            Algo for creating names and domains.
            Get all names.
            Sort by number of labels, longest first.
            For each name:
                if exists_domain(name):
                    label = ''
                    domain = name
                else:
                    label = name.split('.')[0]
                    domain_name = name.split('.')[1:]
                    if domain_name exists:
                        domain = domain_name
                    else:
                        domain = create(domain_name)
        """
        # Create list
        names = []
        for (name, ttl, rdata) in zone.iterate_rdatas('A'):
            names.append((name.to_text().strip('.'), rdata))
        sorted_names = list(
            sorted(names,
                   cmp=lambda n1, n2: -1
                   if len(n1[0].split('.')) > len(n2[0].split('.')) else 1))

        for name, rdata in sorted_names:
            print str(name) + " A " + str(rdata)
            exists_domain = Domain.objects.filter(name=name)
            if exists_domain:
                label = ''
                domain = exists_domain[0]
            else:
                label = name.split('.')[0]
                if label.find('unused') != -1:
                    continue
                parts = list(reversed(name.split('.')[1:]))
                domain_name = ''
                for i in range(len(parts)):
                    domain_name = parts[i] + '.' + domain_name
                    domain_name = domain_name.strip('.')
                    domain, created = Domain.objects.get_or_create(
                        name=domain_name)
                    if domain.master_domain and domain.master_domain.soa:
                        domain.soa = domain.master_domain.soa
            a, _ = AddressRecord.objects.get_or_create(label=label,
                                                       domain=domain,
                                                       ip_str=rdata.to_text(),
                                                       ip_type='4')

        for (name, ttl, rdata) in zone.iterate_rdatas('NS'):
            name = name.to_text().strip('.')
            print str(name) + " NS " + str(rdata)
            domain = ensure_domain(name)
            ns, _ = Nameserver.objects.get_or_create(
                domain=domain, server=rdata.target.to_text().strip('.'))
        for (name, ttl, rdata) in zone.iterate_rdatas('MX'):
            name = name.to_text().strip('.')
            print str(name) + " MX " + str(rdata)
            exists_domain = Domain.objects.filter(name=name)
            if exists_domain:
                label = ''
                domain = exists_domain[0]
            else:
                label = name.split('.')[0]
                domain_name = name.split('.')[1:]
                domain = ensure_domain(domain_name)
            priority = rdata.preference
            server = rdata.exchange.to_text().strip('.')
            mx, _ = MX.objects.get_or_create(label=label,
                                             domain=domain,
                                             server=server,
                                             priority=priority,
                                             ttl="3600")
        for (name, ttl, rdata) in zone.iterate_rdatas('CNAME'):
            name = name.to_text().strip('.')
            print str(name) + " CNAME " + str(rdata)
            exists_domain = Domain.objects.filter(name=name)
            if exists_domain:
                label = ''
                domain = exists_domain[0]
            else:
                label = name.split('.')[0]
                domain_name = name.split('.')[1:]
                domain = ensure_domain('.'.join(domain_name))
            data = rdata.target.to_text().strip('.')

            if not CNAME.objects.filter(label=label, domain=domain,
                                        data=data).exists():
                cn = CNAME(label=label, domain=domain, data=data)
                cn.full_clean()
                cn.save()
Ejemplo n.º 45
0
def populate_forward_dns(svn_zones):
    for site, data in svn_zones.iteritems():
        zone, records = data
        print "-" * 15 + " " + site

        for (name, ttl, rdata) in zone.iterate_rdatas('SOA'):
            print str(name) + " SOA " + str(rdata)
            exists = SOA.objects.filter(minimum=rdata.minimum,
                                        contact=rdata.rname.to_text(
                                        ).strip('.'),
                                        primary=rdata.mname.to_text().strip('.'), comment="SOA for"
                                        " {0}.mozilla.com".format(site))
            if exists:
                soa = exists[0]
            else:
                soa = SOA(serial=rdata.serial, minimum=rdata.minimum,
                          contact=rdata.rname.to_text().strip('.'),
                          primary=rdata.mname.to_text().strip('.'), comment="SOA for"
                          " {0}.mozilla.com".format(site))
                soa.clean()
                soa.save()
            domain_split = list(reversed(name.to_text().strip('.').split('.')))
            for i in range(len(domain_split)):
                domain_name = domain_split[:i + 1]
                base_domain, created = Domain.objects.get_or_create(name=
                                                                    '.'.join(list(reversed(domain_name))))
            base_domain.soa = soa
            base_domain.save()

        """
            Algo for creating names and domains.
            Get all names.
            Sort by number of labels, longest first.
            For each name:
                if exists_domain(name):
                    label = ''
                    domain = name
                else:
                    label = name.split('.')[0]
                    domain_name = name.split('.')[1:]
                    if domain_name exists:
                        domain = domain_name
                    else:
                        domain = create(domain_name)
        """
        # Create list
        names = []
        for (name, ttl, rdata) in zone.iterate_rdatas('A'):
            names.append((name.to_text().strip('.'), rdata))
        sorted_names = list(sorted(names, cmp=lambda n1, n2: -1 if
                                   len(n1[0].split('.')) > len(n2[0].split('.')) else 1))

        for name, rdata in sorted_names:
            print str(name) + " A " + str(rdata)
            exists_domain = Domain.objects.filter(name=name)
            if exists_domain:
                label = ''
                domain = exists_domain[0]
            else:
                label = name.split('.')[0]
                if label.find('unused') != -1:
                    continue
                parts = list(reversed(name.split('.')[1:]))
                domain_name = ''
                for i in range(len(parts)):
                    domain_name = parts[i] + '.' + domain_name
                    domain_name = domain_name.strip('.')
                    domain, created = Domain.objects.get_or_create(name=
                                                                   domain_name)
                    if domain.master_domain and domain.master_domain.soa:
                        domain.soa = domain.master_domain.soa
            a, _ = AddressRecord.objects.get_or_create(label=label,
                                                       domain=domain, ip_str=rdata.to_text(), ip_type='4')

        for (name, ttl, rdata) in zone.iterate_rdatas('NS'):
            name = name.to_text().strip('.')
            print str(name) + " NS " + str(rdata)
            domain = ensure_domain(name)
            ns, _ = Nameserver.objects.get_or_create(domain=domain,
                                                     server=rdata.target.to_text().strip('.'))
        for (name, ttl, rdata) in zone.iterate_rdatas('MX'):
            name = name.to_text().strip('.')
            print str(name) + " MX " + str(rdata)
            exists_domain = Domain.objects.filter(name=name)
            if exists_domain:
                label = ''
                domain = exists_domain[0]
            else:
                label = name.split('.')[0]
                domain_name = name.split('.')[1:]
                domain = ensure_domain(domain_name)
            priority = rdata.preference
            server = rdata.exchange.to_text().strip('.')
            mx, _ = MX.objects.get_or_create(label=label, domain=domain,
                                             server=server, priority=priority, ttl="3600")
        for (name, ttl, rdata) in zone.iterate_rdatas('CNAME'):
            name = name.to_text().strip('.')
            print str(name) + " CNAME " + str(rdata)
            exists_domain = Domain.objects.filter(name=name)
            if exists_domain:
                label = ''
                domain = exists_domain[0]
            else:
                label = name.split('.')[0]
                domain_name = name.split('.')[1:]
                domain = ensure_domain('.'.join(domain_name))
            data = rdata.target.to_text().strip('.')

            if not CNAME.objects.filter(label=label, domain=domain,
                                        data=data).exists():
                cn = CNAME(label=label, domain=domain,
                           data=data)
                cn.full_clean()
                cn.save()
Ejemplo n.º 46
0
 def test_cname_update(self):
     cname = CNAME(target="foo", ctnr=self.ctnr)
     self.generic_check(cname)