Exemplo n.º 1
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
Exemplo n.º 2
0
 def setUp(self):
     self.export = ExportTinydnsData()
     Record.save = None
     Record.create = None
     Record.delete = None