Beispiel #1
0
    def gen_domain( self, domain, dname ):
        self.cur.execute("SELECT * FROM `zone_mx` WHERE `domain`='%s' ORDER BY `name`;" % (domain))
        bad_dnames = ['', '.', '_']
        cdomain = None
        if dname not in bad_dnames:
            # Other baddies
            if dname.find('in-addr.arpa') >= 0:
                return None
            else:
                # IT's a good domain. First see if it exists already. Else create it.
                cdomain = Domain( name = dname )
                try:
                    cdomain.save()
                except ValidationError, e:
                    arecs = AddressRecord.objects.filter(fqdn=dname)
                    ip_strs = []
                    mxs = MX.objects.filter(fqdn=dname)
                    mx_data = []
                    for arec in arecs:
                        ip_strs.append(arec.ip_str)
                        print "Re-Adding A record {0} to domain {1}".format(arec, dname)
                        arec.delete()

                    for mx in mxs:
                        print "Re-Adding MX record {0} to domain {1}".format(mx, dname)
                        mx_data.append((mx.server, mx.priority, mx.ttl))
                        mx.delete()

                    cdomain.save()
                    for ip_str in ip_strs:
                        AddressRecord(label="", domain=cdomain, ip_str=ip_str, ip_type='4').save()
                    for server, prio, ttl in mx_data:
                        mx = MX(label="", domain=cdomain, server=server, priority=prio, ttl=ttl)
                        mx.save()
                        print "Adding: {0} MX {1}".format(mx.fqdn, mx.server)
Beispiel #2
0
 def do_generic_add(self, data):
     mx = MX(**data)
     mx.__repr__()
     mx.save()
     self.assertTrue(mx.details())
     self.assertTrue(mx.get_detail_url())
     self.assertTrue(mx.get_update_url())
     self.assertTrue(mx.get_delete_url())
     rmx = MX.objects.filter(**data)
     self.assertTrue(len(rmx) == 1)
     return mx
Beispiel #3
0
    def test_add_mx_with_cname(self):
        label = "cnamederp1"
        domain = self.c_g
        data = "foo.com"

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

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

        self.assertRaises(ValidationError, cn.full_clean)
Beispiel #4
0
    def gen_forward_pointers(self):
        print "Migrating Forward Pointers in pointer table."
        sql = "SELECT * FROM `pointer` WHERE `type`='forward' ORDER BY hostname"
        self.cur.execute(sql)
        records = self.cur.fetchall()
        # We have abosulte names in the pointer table so print a root origin.
        for record in records:
            # Start Cyder
            domain = Domain.objects.filter( name = record[2] ) #This is a TLD record
            if domain:
                name = ''
                cdomain = domain[0]
            else:
                name = record[2].split('.')[0] # Get the front label
                dname = '.'.join(record[2].split('.')[1:])
                cdomain = Domain.objects.filter( name = dname )
                if not cdomain:
                    split = dname.split('.')
                    for i in list(reversed(range(len(split)))):
                        name = '.'.join(split[i:])
                        try:
                            cdomain, created = Domain.objects.get_or_create( name = name )
                            cdomain.save()
                        except ValidationError, e:
                            arecs = AddressRecord.objects.filter(fqdn=dname)
                            ip_strs = []
                            mxs = MX.objects.filter(fqdn=dname)
                            mx_data = []
                            for arec in arecs:
                                ip_strs.append(arec.ip_str)
                                print "Re-Adding A record {0} to domain {1}".format(arec, dname)
                                arec.delete()

                            for mx in mxs:
                                print "Re-Adding MX record {0} to domain {1}".format(mx, dname)
                                mx_data.append((mx.server, mx.priority, mx.ttl))
                                mx.delete()

                            cdomain.save()

                            for ip_str in ip_strs:
                                AddressRecord(label="", domain=cdomain,
                                        ip_str=ip_str, ip_type='4').save()
                            for server, prio, ttl in mx_data:
                                mx = MX(label="", domain=cdomain, server=server, priority=prio, ttl=ttl)
                                mx.save()
                                print "Adding: {0} MX {1}".format(mx.fqdn, mx.server)


                else:
                    cdomain = cdomain[0]
Beispiel #5
0
 def do_generic_add(self, data ):
     mx = MX( **data )
     mx.__repr__()
     mx.save()
     self.assertTrue(mx.details())
     self.assertTrue(mx.get_absolute_url())
     self.assertTrue(mx.get_edit_url())
     self.assertTrue(mx.get_delete_url())
     rmx = MX.objects.filter( **data )
     self.assertTrue( len(rmx) == 1 )
     return mx
Beispiel #6
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)
Beispiel #7
0
    def test_cleanup_mx(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)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.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"))
Beispiel #8
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()
Beispiel #9
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)
Beispiel #10
0
 def do_generic_add(self, data):
     mx = MX(**data)
     mx.__repr__()
     mx.save()
     self.assertTrue(mx.details())
     rmx = MX.objects.filter(**data)
     self.assertTrue(len(rmx) == 1)
     return mx
Beispiel #11
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 #12
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()
Beispiel #13
0
    def test_mx_cname_exists(self):
        # Duplicate test?
        label = "testyfoo"
        data = "wat"
        dom, _ = Domain.objects.get_or_create(name="cd")
        dom, _ = Domain.objects.get_or_create(name="what.cd")

        cn, _ = CNAME.objects.get_or_create(label=label,
                                            domain=dom,
                                            target=data)
        cn.full_clean()
        cn.save()

        rec = MX(label=label,
                 domain=dom,
                 server="asdf1",
                 priority=123,
                 ttl=123)

        self.assertRaises(ValidationError, rec.save)
Beispiel #14
0
    def test_cleanup_mx(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)
        mx = MX(label=label, domain=the_domain, server="foo", priority=4)
        mx.save()
        self.assertFalse(prune_tree(the_domain))
        mx.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"))
Beispiel #15
0
def ensure_domain(name):
    parts = list(reversed(name.split('.')))
    domain_name = ''
    for i in range(len(parts)):
        domain_name = parts[i] + '.' + domain_name
        domain_name = domain_name.strip('.')
        clobber_objects = []  # Objects that have the same name as a domain
        # need to be deleted and then recreated
        try:
            mxs = MX.objects.filter(fqdn=domain_name)
            # It got here. It exists
            for mx in mxs:
                label = mx.label
                mxdomain = mx.domain
                server = mx.server
                prio = mx.priority
                ttl = mx.ttl
                mxviews = [view.name for view in mx.views.all()]
                mx.delete()
                mx = MX(label='', server=server, priority=prio, ttl=ttl)
                clobber_objects.append((mx, mxviews))
        except ObjectDoesNotExist, e:
            pass
        try:
            addrs = AddressRecord.objects.filter(fqdn=domain_name)
            for exists_a in addrs:
                # It got here. It exists
                need_to_recreate_a = True
                ip_str = exists_a.ip_str
                ip_type = exists_a.ip_type
                aviews = [view.name for view in exists_a.views.all()]
                exists_a.delete(check_cname=False)
                a = AddressRecord(label='', ip_str=ip_str, ip_type=ip_type)
                clobber_objects.append((a, aviews))
        except ObjectDoesNotExist, e:
            pass
Beispiel #16
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()
Beispiel #17
0
 class Meta:
     always_return_data = True
     queryset = MX.objects.all()
     fields = MX.get_api_fields() + ['domain', 'views']
     authorization = Authorization()
     allowed_methods = allowed_methods
Beispiel #18
0
 def test_mx_update(self):
     mx = MX(server="foo", priority=4, ctnr=self.ctnr)
     self.generic_check(mx)