def ns_default_command(record_ns_key_default): try: data_record = model.read_by_id("record", record_ns_key_default) except Exception as e: raise e else: zone = model.read_by_id("zone", str(data_record['zone'])) ttl = model.read_by_id("ttl", str(data_record['ttl']))['value'] types = model.read_by_id("type", str(data_record['type']))['value'] data_content = model.content_by_record(data_record['key']) for i in data_content: json_command = { zone['value']: { "id_zone": zone['key'], "type": "general", "command": "zone", "general": { "sendblock": { "cmd": "zone-set", "zone": zone['value'], "owner": data_record['value'], "rtype": types, "ttl": ttl, "data": i['value'] }, "receive": { "type": "block" } } } } producer.send(json_command)
def get(self, key): try: data_zone = model.read_by_id("zone", key) except Exception as e: return response(401, message=str(e)) else: user_data = model.read_by_id("user", data_zone['user']) data = { "key": data_zone['key'], "value": data_zone['value'], "created_at": data_zone['created_at'], "user": user_data } return response(200, data=data)
def soa_default_command(soa_record_key): try: data_record = model.read_by_id("record", soa_record_key) except Exception as e: raise e try: zone = model.read_by_id("zone", data_record['zone']) except Exception as e: raise e try: data_type = model.read_by_id("type", data_record['type'])['value'] except Exception as e: raise e if data_type != "SOA": return False try: data_ttl = model.read_by_id("ttl", data_record['ttl'])['value'] except Exception as e: raise e try: data_content = model.content_by_record(data_record['key'])[0]['value'] except Exception as e: raise e json_command = { zone['value']: { "id_zone": zone['key'], "command": "zone", "type": "general", "general": { "sendblock": { "cmd": "zone-set", "zone": zone['value'], "owner": data_record['value'], "rtype": "SOA", "ttl": data_ttl, "data": data_content }, "receive": { "type": "block" } } } } producer.send(json_command)
def check_record_serial(key): try: record = model.read_by_id("record", key) except Exception as e: raise e else: return record['serial']
def get(self, project_id): results = list() user = dict() try: data_user = model.read_all("user") except Exception as e: return response(401, message=str(e)) else: for i in data_user: if i['project_id'] == project_id: user = i break try: data_zone = model.read_all("zone") except Exception as e: return response(401, message=str(e)) else: for i in data_zone: if i['user'] == user['key']: user = model.read_by_id("user", i['user']) record = model.record_by_zone(i['key']) data = { "key": i['key'], "value": i['value'], "created_at": i['created_at'], "user": user, "record": record } results.append(data) return response(200, data=results)
def get(self, key): try: data = model.read_by_id("ttl", key) except Exception as e: return response(401, message=str(e)) else: return response(200, data=data)
def get(self, key): zone_data = model.read_by_id("zone", key)['value'] command_data = command.config_zone(zone_data, key) try: test = producer.send(command_data) except Exception as e: return response(401, message=str(e)) else: data = {"send_status": test, "command": command_data} return response(200, data=data, message=test)
def get(self, key): try: data_content = model.read_by_id("content", key) except Exception as e: return response(401, message=str(e)) else: record = model.read_by_id("record", data_content['record']) types = model.read_by_id("type", record['type']) ttl = model.read_by_id("ttl", record['ttl']) zone = model.read_by_id("zone", record['zone']) data = { "key": data_content['key'], "value": data_content['value'], "created_at": data_content['created_at'], "record": record, "ttl": ttl, "type": types, "zone": zone } return response(200, data=data)
def content_validation(record, content): valid = False try: data_record = model.read_by_id("record", record) data_type = model.read_by_id("type", data_record['type']) except Exception: pass else: if data_type['value'] == 'A': valid = a_content_validation(content) elif data_type['value'] == "MX": valid = mx_content_validation(content) elif data_type['value'] == "CNAME": valid = cname_content_validation(content) elif data_type['value'] == "TXT": valid = txt_content_validation(content) else: valid = False return valid
def get(self, key): try: data_serial = model.read_by_id("serial", key) except Exception as e: return response(401, message=str(e)) else: record = model.read_by_id("record", data_serial["record"]) types = model.read_by_id("type", record['type']) ttl = model.read_by_id("ttl", record['ttl']) zone = model.read_by_id("zone", record['zone']) data = { "key": data_serial['key'], "name": data_serial['name'], "value": data_serial['value'], "record": record, "ttl": ttl, "type": types, "zone": zone } return response(200, data=data)
def record_mx_duplicate(record, types, zone): try: data_record = model.read_all("record") except Exception as e: pass else: result = False for i in data_record: type_data = model.read_by_id("type", types) if zone == i['zone']: if record == i['value'] and type_data['value'] == 'MX': result = True break return result
def get(self): result = list() try: data_serial = model.read_all("serial") except Exception as e: return response(401, message=str(e)) else: for i in data_serial: record = model.read_by_id("record", i["record"]) types = model.read_by_id("type", record['type']) ttl = model.read_by_id("ttl", record['ttl']) zone = model.read_by_id("zone", record['zone']) data = { "key": i['key'], "name": i['name'], "value": i['value'], "record": record, "ttl": ttl, "type": types, "zone": zone } result.append(data) return response(200, data=result)
def get(self): results = list() try: data_content = model.read_all("content") print(data_content) except Exception as e: return response(401, message=str(e)) else: for i in data_content: record = model.read_by_id("record", i['record']) types = model.read_by_id("type", record['type']) ttl = model.read_by_id("ttl", record['ttl']) zone = model.read_by_id("zone", record['zone']) data = { "key": i['key'], "value": i['value'], "created_at": i['created_at'], "record": record, "ttl": ttl, "type": types, "zone": zone } results.append(data) return response(200, data=results)
def get(self): results = list() try: data_zone = model.read_all("zone") except Exception as e: return response(401, message=str(e)) for i in data_zone: user_data = model.read_by_id("user", i['user']) data = { "key": i['key'], "value": i['value'], "created_at": i['created_at'], "user": user_data } results.append(data) return response(200, data=results)
def record_insert(key): try: data_record = model.read_by_id("record", key) except Exception as e: raise e zone = model.read_by_id("zone", str(data_record['zone'])) ttl = model.read_by_id("ttl", str(data_record['ttl']))['value'] types = model.read_by_id("type", str(data_record['type']))['value'] data_content = model.content_by_record(data_record['key'])[0]['value'] serial = "" if data_record['serial']: serial_data = model.serial_by_record(data_record['key']) for i in serial_data: if serial == "": serial = i['value'] else: serial = serial + " " + i['value'] json_command = { zone['value']: { "id_zone": zone['key'], "command": "zone", "type": "general", "general": { "sendblock": { "cmd": "zone-set", "zone": zone['value'], "owner": data_record['value'], "rtype": types, "ttl": ttl, "data": serial + " " + data_content }, "receive": { "type": "block" } } } } else: json_command = { zone['value']: { "id_zone": zone['key'], "type": "general", "command": "zone", "general": { "sendblock": { "cmd": "zone-set", "zone": zone['value'], "owner": data_record['value'], "rtype": types, "ttl": ttl, "data": data_content }, "receive": { "type": "block" } } } } return json_command