Esempio n. 1
0
    def setUpClass(cls):
        TestCase.setUpClass()
        cls.domain = Domain.objects.get_or_create(name=cls.domain_name)[0]
        d = cls.domain.name

        # ok
        Record(domain=cls.domain, type='A', content=cls.ip,
               name='a.%s' % d).save()
        Record(domain=cls.domain,
               type='CNAME',
               content='a.%s' % d,
               name='b.%s' % d).save()
        Record(domain=cls.domain,
               type='CNAME',
               content='b.%s' % d,
               name='c.%s' % d).save()
        Record(domain=cls.domain,
               type='CNAME',
               content='c.%s' % d,
               name='d.%s' % d).save()
        Record(domain=cls.domain,
               type='CNAME',
               content='d.%s' % d,
               name='e.%s' % d).save()

        # loop
        Record(domain=cls.domain,
               type='CNAME',
               content='g.%s' % d,
               name='f.%s' % d).save()
        Record(domain=cls.domain,
               type='CNAME',
               content='h.%s' % d,
               name='g.%s' % d).save()
        Record(domain=cls.domain,
               type='CNAME',
               content='f.%s' % d,
               name='h.%s' % d).save()

        # no answer
        Record(domain=cls.domain,
               type='CNAME',
               content='j.%s' % d,
               name='i.%s' % d).save()
Esempio n. 2
0
def set_ssh_pub(request):
    try:
        fqdn = hostname_from_principal(request.user.username)
    except ValueError:
        return HttpResponse(
            status=401,
            content='Unable to register public SSH key: invalid username')
    if Host.objects.filter(fqdn=fqdn).count() == 0:
        return HttpResponse(status=404)
    fqdn = '%s.%s%s' % (fqdn.partition('.')[0], settings.PDNS_ADMIN_PREFIX,
                        settings.PENATES_DOMAIN)
    domain_name = '%s%s' % (settings.PDNS_ADMIN_PREFIX,
                            settings.PENATES_DOMAIN)
    pub_ssh_key = request.body
    matcher = re.match(r'([\w\-]+) ([\w\+=/]{1,5000})(|\s.*)$', pub_ssh_key)
    if not matcher:
        return HttpResponse(status=406, content='Invalid public SSH key')
    methods = {
        'ssh-rsa': 1,
        'ssh-dss': 2,
        'ecdsa-sha2-nistp256': 3,
        'ssh-ed25519': 4,
    }
    if matcher.group(1) not in methods:
        return HttpResponse(status=406,
                            content='Unknown SSH key type %s' %
                            matcher.group(1))
    sha1_hash = hashlib.sha1(base64.b64decode(matcher.group(2))).hexdigest()
    sha256_hash = hashlib.sha256(base64.b64decode(
        matcher.group(2))).hexdigest()
    algorithm_code = methods[matcher.group(1)]
    domain = Domain.objects.get(name=domain_name)
    sha1_value = '%s 1 %s' % (algorithm_code, sha1_hash)
    sha256_value = '%s 2 %s' % (algorithm_code, sha256_hash)
    for value in sha1_value, sha256_value:
        if Record.objects.filter(domain=domain,
                                 name=fqdn,
                                 type='SSHFP',
                                 content__startswith=value[:4]).count() == 0:
            Record(domain=domain,
                   name=fqdn,
                   type='SSHFP',
                   content=value,
                   ttl=86400).save()
        else:
            Record.objects.filter(domain=domain, name=fqdn, type='SSHFP', content__startswith=value[:4]) \
                .update(content=value)
    return HttpResponse(status=201)
Esempio n. 3
0
 def get_ip_list(scheme, protocol='udp'):
     values = list(Service.objects.filter(scheme=scheme, protocol=protocol))
     return [Record.local_resolve(x.fqdn) or x.hostname for x in values]
Esempio n. 4
0
 def get_ip_or_none(scheme):
     values = list(Service.objects.filter(scheme=scheme)[0:1])
     if not values:
         return None
     return Record.local_resolve(values[0].fqdn) or values[0].hostname
Esempio n. 5
0
 def get_ip_list(scheme, protocol='udp'):
     values = list(Service.objects.filter(scheme=scheme, protocol=protocol))
     return [Record.local_resolve(x.fqdn) or x.hostname for x in values]
Esempio n. 6
0
 def get_ip_or_none(scheme):
     values = list(Service.objects.filter(scheme=scheme)[0:1])
     if not values:
         return None
     return Record.local_resolve(values[0].fqdn) or values[0].hostname
Esempio n. 7
0
 def test_no_answer(self):
     self.assertIsNone(Record.local_resolve('i.%s' % self.domain_name))
Esempio n. 8
0
 def test_loop(self):
     self.assertIsNone(Record.local_resolve('f.%s' % self.domain_name))
     self.assertIsNone(Record.local_resolve('g.%s' % self.domain_name))
     self.assertIsNone(Record.local_resolve('h.%s' % self.domain_name))
Esempio n. 9
0
 def test_indirect_4(self):
     self.assertEqual(self.ip,
                      Record.local_resolve('e.%s' % self.domain_name))
Esempio n. 10
0
 def test_ip(self):
     self.assertEqual(self.ip, Record.local_resolve(self.ip))
Esempio n. 11
0
 def test_no_answer(self):
     self.assertIsNone(Record.local_resolve('i.%s' % self.domain_name))
Esempio n. 12
0
 def test_loop(self):
     self.assertIsNone(Record.local_resolve('f.%s' % self.domain_name))
     self.assertIsNone(Record.local_resolve('g.%s' % self.domain_name))
     self.assertIsNone(Record.local_resolve('h.%s' % self.domain_name))
Esempio n. 13
0
 def test_indirect_4(self):
     self.assertEqual(self.ip, Record.local_resolve('e.%s' % self.domain_name))
Esempio n. 14
0
 def test_ip(self):
     self.assertEqual(self.ip, Record.local_resolve(self.ip))