예제 #1
0
class TestTinydnsExport(unittest.TestCase):
    def setUp(self):
        self.export = ExportTinydnsData()
        Record.save = None
        Record.create = None
        Record.delete = None

    def test_a_record(self):
        model = Record()

        model.type = 'A'
        model.host = 'foo.vegadns.ubuntu'
        model.val = '1.2.3.4'
        model.ttl = '3600'

        self.assertEquals(
            self.export.data_line_from_model(model),
            '+foo.vegadns.ubuntu:1.2.3.4:3600\n'
        )

    def test_mx_record(self):
        model = Record()

        model.type = 'M'
        model.host = 'vegadns.ubuntu'
        model.val = 'mail.vegadns.ubuntu'
        model.distance = 10
        model.ttl = '3600'

        self.assertEquals(
            self.export.data_line_from_model(model),
            '@vegadns.ubuntu::mail.vegadns.ubuntu:10:3600\n'
        )

    def test_mx_record(self):
        model = Record()

        model.type = 'P'
        model.host = '4.3.2.1.in-addr.arpa'
        model.val = 'www.vegadns.ubuntu'
        model.ttl = '3600'

        self.assertEquals(
            self.export.data_line_from_model(model),
            '^4.3.2.1.in-addr.arpa:www.vegadns.ubuntu:3600\n'
        )

    def test_ptr_record(self):
        model = Record()

        model.type = 'T'
        model.host = 'vegadns.ubuntu'
        model.val = 'v=spf1 mx a ip4:1.2.3.0/24'
        model.ttl = '3600'

        self.assertEquals(
            self.export.data_line_from_model(model),
            "'vegadns.ubuntu:v=spf1 mx a ip4" r"\072" + "1.2.3.0/24:3600\n"
        )

    def test_spf_record(self):
        model = Record()

        model.type = 'F'
        model.host = 'example.com'
        model.val = 'v=spf1 mx -all'
        model.ttl = '3600'

        self.assertEquals(
            self.export.data_line_from_model(model),
            ":example.com:99:" r"\016" "v=spf1 mx -all:3600\n"
        )

    def test_aaaa_record(self):
        model = Record()

        model.type = '3'
        model.host = 'example.com'
        model.val = '0000:0000:0000:0000:0000:ffff:169.254.123.231'
        model.ttl = '3600'

        expected = (
            ":example.com:28:"
            r"\000\000\000\000\000\000\000\000\000\000\377\377\251\376\173\347"
            ":3600\n"
        )

        self.assertEquals(
            self.export.data_line_from_model(model),
            expected
        )

    def test_aaaaptr_record(self):
        model = Record()

        model.type = '3'
        model.host = 'example.com'
        model.val = '0000:0000:0000:0000:0000:ffff:169.254.123.231'
        model.ttl = '3600'

        expected = (
            ":example.com:28:"
            r"\000\000\000\000\000\000\000\000\000\000\377\377\251\376\173\347"
            ":3600\n"
        )

        self.assertEquals(
            self.export.data_line_from_model(model),
            expected
        )

    def test_aaaaptr_record(self):
        model = Record()

        model.type = '6'
        model.host = 'example.com'
        model.val = '0000:0000:0000:0000:0000:ffff:169.254.123.231'
        model.ttl = '3600'

        expected = (
            ":example.com:28:"
            r"\000\000\000\000\000\000\000\000\000\000\377\377\251\376\173\347"
            ":3600\n"

            "^7.e.b.7.e.f.9.a.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0"
            ".ip6.arpa"
            ":example.com:3600\n"
        )

        self.assertEquals(
            self.export.data_line_from_model(model),
            expected
        )

    def test_soa_record(self):
        domain = Domain()
        domain.domain = 'example.com'
        model = Record()

        # joined domain on domain_id
        model.domain_id = domain
        model.type = 'S'
        model.host = 'hostmaster.example.com:ns1.example.com'
        model.val = '16384:2048:1048576:2560:'
        model.ttl = '86400'

        expected = (
            "Zexample.com"
            ":ns1.example.com"
            ":hostmaster.example.com"
            ":"
            ":16384"
            ":2048"
            ":1048576"
            ":2560"
            ":86400\n"
        )

        self.assertEquals(
            self.export.data_line_from_model(model),
            expected
        )

    def test_srv_record(self):
        model = Record()

        model.type = 'V'
        model.host = '_xmpp-client._tcp.example.com.'
        model.val = 'xmpp.example.com'
        model.ttl = '3600'
        model.distance = 0
        model.weight = 10
        model.port = 5222

        expected = (
            ":_xmpp-client._tcp.example.com."
            ":33"
            r":\000\000\000\012\024\146\004xmpp\007example\003com\000"
            ":3600\n"
        )

        self.assertEquals(
            self.export.data_line_from_model(model),
            expected
        )

    def test_ns_record(self):
        model = Record()

        model.type = 'N'
        model.host = 'example.com'
        model.val = 'ns1.example.com'
        model.ttl = 3600

        expected = "&example.com::ns1.example.com:3600\n"

        self.assertEquals(
            self.export.data_line_from_model(model),
            expected
        )
예제 #2
0
 def setUp(self):
     self.export = ExportTinydnsData()
     Record.save = None
     Record.create = None
     Record.delete = None
예제 #3
0
    def get(self, format):
        if format != 'tinydns':
            abort(400, message="invalid format: " + format)

        records = self.get_records()

        domains = {}

        for record in records:
            if record.domain_id.domain not in domains:
                domains[record.domain_id.domain] = []

            domains[record.domain_id.domain].append(record)

        organized = []
        for key, val in sorted(domains.items()):
            organized.append({'domain_name': key, 'records': val})

        locations = self.get_locations()
        prefixes = self.get_prefixes()
        locationdata = "# locations\n"

        # need to build this manually since peewee join results are limiting
        for location in locations:
            temp_list = []

            for prefix in prefixes:
                if prefix.location_id != location.location_id:
                    continue
                else:
                    if prefix.prefix_type == "ipv4":
                        temp_list.append(prefix.prefix)
                    else:
                        temp_list.append("s" +
                                         str(prefix.prefix).replace(":", ""))

            if len(temp_list) == 0:
                locationdata += "%" + location.location + "\n"
            else:
                for i in temp_list:
                    locationdata += "%" + location.location + ":" + i + "\n"

        datafile = locationdata + "\n"
        tinydns = ExportTinydnsData()
        datafile += tinydns.export_domains(organized, locations)

        generation_record_host = config.get('monitoring',
                                            'vegadns_generation_txt_record')
        if generation_record_host \
           and Validate().record_hostname(generation_record_host):

            timestamp = self.get_latest_log_timestamp()
            md5 = hashlib.md5(datafile + "\n").hexdigest()

            model = ModelRecord()
            model.type = RecordType().set('TXT')
            model.host = generation_record_host
            model.val = str(timestamp) + "-" + md5
            model.ttl = 3600

            generation_record_line = tinydns.data_line_from_model(model)

            datafile += "\n\n# VegaDNS Generation TXT Record\n"
            datafile += generation_record_line.rstrip("\n")

        response = make_response(datafile)
        response.headers['content-type'] = 'text/plain'

        return response
예제 #4
0
파일: export.py 프로젝트: shupp/VegaDNS-API
    def get(self, format):
        if format != 'tinydns':
            abort(400, message="invalid format: " + format)

        records = self.get_records()

        domains = {}

        for record in records:
            if record.domain_id.domain not in domains:
                domains[record.domain_id.domain] = []

            domains[record.domain_id.domain].append(record)

        organized = []
        for key, val in sorted(domains.items()):
            organized.append(
                {
                    'domain_name': key,
                    'records': val
                }
            )

        locations = self.get_locations()
        prefixes = self.get_prefixes()
        locationdata = "# locations\n"

        # need to build this manually since peewee join results are limiting
        for location in locations:
            temp_list = []

            for prefix in prefixes:
                if prefix.location_id != location.location_id:
                    continue
                else:
                    if prefix.prefix_type == "ipv4":
                        temp_list.append(prefix.prefix)
                    else:
                        temp_list.append(
                            "s" + str(prefix.prefix).replace(
                                ":", ""
                            )
                        )

            if len(temp_list) == 0:
                locationdata += "%" + location.location + "\n"
            else:
                for i in temp_list:
                    locationdata += "%" + location.location + ":" + i + "\n"

        datafile = locationdata + "\n"
        tinydns = ExportTinydnsData()
        datafile += tinydns.export_domains(organized, locations)

        generation_record_host = config.get(
            'monitoring',
            'vegadns_generation_txt_record'
        )
        if generation_record_host \
           and Validate().record_hostname(generation_record_host):

            timestamp = self.get_latest_log_timestamp()
            md5 = hashlib.md5(datafile + "\n").hexdigest()

            model = ModelRecord()
            model.type = RecordType().set('TXT')
            model.host = generation_record_host
            model.val = str(timestamp) + "-" + md5
            model.ttl = 3600

            generation_record_line = tinydns.data_line_from_model(model)

            datafile += "\n\n# VegaDNS Generation TXT Record\n"
            datafile += generation_record_line.rstrip("\n")

        response = make_response(datafile)
        response.headers['content-type'] = 'text/plain'

        return response
예제 #5
0
class TestTinydnsExport(unittest.TestCase):
    def setUp(self):
        self.export = ExportTinydnsData()
        Record.save = None
        Record.create = None
        Record.delete = None

    def test_a_record(self):
        model = Record()

        model.type = 'A'
        model.host = 'foo.vegadns.ubuntu'
        model.val = '1.2.3.4'
        model.ttl = '3600'

        self.assertEquals(self.export.data_line_from_model(model),
                          '+foo.vegadns.ubuntu:1.2.3.4:3600\n')

    def test_mx_record(self):
        model = Record()

        model.type = 'M'
        model.host = 'vegadns.ubuntu'
        model.val = 'mail.vegadns.ubuntu'
        model.distance = 10
        model.ttl = '3600'

        self.assertEquals(self.export.data_line_from_model(model),
                          '@vegadns.ubuntu::mail.vegadns.ubuntu:10:3600\n')

    def test_mx_record(self):
        model = Record()

        model.type = 'P'
        model.host = '4.3.2.1.in-addr.arpa'
        model.val = 'www.vegadns.ubuntu'
        model.ttl = '3600'

        self.assertEquals(self.export.data_line_from_model(model),
                          '^4.3.2.1.in-addr.arpa:www.vegadns.ubuntu:3600\n')

    def test_ptr_record(self):
        model = Record()

        model.type = 'T'
        model.host = 'vegadns.ubuntu'
        model.val = 'v=spf1 mx a ip4:1.2.3.0/24'
        model.ttl = '3600'

        self.assertEquals(
            self.export.data_line_from_model(model),
            "'vegadns.ubuntu:v=spf1 mx a ip4"
            r"\072" + "1.2.3.0/24:3600\n")

    def test_spf_record(self):
        model = Record()

        model.type = 'F'
        model.host = 'example.com'
        model.val = 'v=spf1 mx -all'
        model.ttl = '3600'

        self.assertEquals(self.export.data_line_from_model(model),
                          ":example.com:99:"
                          r"\016"
                          "v=spf1 mx -all:3600\n")

    def test_aaaa_record(self):
        model = Record()

        model.type = '3'
        model.host = 'example.com'
        model.val = '0000:0000:0000:0000:0000:ffff:169.254.123.231'
        model.ttl = '3600'

        expected = (
            ":example.com:28:"
            r"\000\000\000\000\000\000\000\000\000\000\377\377\251\376\173\347"
            ":3600\n")

        self.assertEquals(self.export.data_line_from_model(model), expected)

    def test_aaaaptr_record(self):
        model = Record()

        model.type = '3'
        model.host = 'example.com'
        model.val = '0000:0000:0000:0000:0000:ffff:169.254.123.231'
        model.ttl = '3600'

        expected = (
            ":example.com:28:"
            r"\000\000\000\000\000\000\000\000\000\000\377\377\251\376\173\347"
            ":3600\n")

        self.assertEquals(self.export.data_line_from_model(model), expected)

    def test_aaaaptr_record(self):
        model = Record()

        model.type = '6'
        model.host = 'example.com'
        model.val = '0000:0000:0000:0000:0000:ffff:169.254.123.231'
        model.ttl = '3600'

        expected = (
            ":example.com:28:"
            r"\000\000\000\000\000\000\000\000\000\000\377\377\251\376\173\347"
            ":3600\n"
            "^7.e.b.7.e.f.9.a.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0"
            ".ip6.arpa"
            ":example.com:3600\n")

        self.assertEquals(self.export.data_line_from_model(model), expected)

    def test_soa_record(self):
        domain = Domain()
        domain.domain = 'example.com'
        model = Record()

        # joined domain on domain_id
        model.domain_id = domain
        model.type = 'S'
        model.host = 'hostmaster.example.com:ns1.example.com'
        model.val = '16384:2048:1048576:2560:'
        model.ttl = '86400'

        expected = ("Zexample.com"
                    ":ns1.example.com"
                    ":hostmaster.example.com"
                    ":"
                    ":16384"
                    ":2048"
                    ":1048576"
                    ":2560"
                    ":86400\n")

        self.assertEquals(self.export.data_line_from_model(model), expected)

    def test_srv_record(self):
        model = Record()

        model.type = 'V'
        model.host = '_xmpp-client._tcp.example.com.'
        model.val = 'xmpp.example.com'
        model.ttl = '3600'
        model.distance = 0
        model.weight = 10
        model.port = 5222

        expected = (":_xmpp-client._tcp.example.com."
                    ":33"
                    r":\000\000\000\012\024\146\004xmpp\007example\003com\000"
                    ":3600\n")

        self.assertEquals(self.export.data_line_from_model(model), expected)

    def test_ns_record(self):
        model = Record()

        model.type = 'N'
        model.host = 'example.com'
        model.val = 'ns1.example.com'
        model.ttl = 3600

        expected = "&example.com::ns1.example.com:3600\n"

        self.assertEquals(self.export.data_line_from_model(model), expected)
예제 #6
0
 def setUp(self):
     self.export = ExportTinydnsData()
     Record.save = None
     Record.create = None
     Record.delete = None