Beispiel #1
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)
Beispiel #2
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
Beispiel #3
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 )
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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)
Beispiel #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)
Beispiel #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)
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
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()
Beispiel #12
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()
Beispiel #13
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()
Beispiel #14
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()
Beispiel #15
0
        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]
        else:
Beispiel #16
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
Beispiel #17
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
Beispiel #18
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()
Beispiel #19
0
        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]
        else: