Various bugfixes and changes
1: Script had AAAA hardcoded, this would've changed all records to AAAA. 2: Script was not saving the DNS Records ids, only their names this would've made it impossible to actually edit the DNS Record 3: Lowered the amount of printing going on, removed irrelevant information such as zoneid from the print statements, also removed most printing during the update phase
This commit is contained in:
parent
26fcc3859f
commit
27bb82767b
1 changed files with 19 additions and 18 deletions
|
@ -46,15 +46,19 @@ class DNSUpdater:
|
||||||
print(f"Zone ID: {zone['id']} | Zone Name: {zone['name']}")
|
print(f"Zone ID: {zone['id']} | Zone Name: {zone['name']}")
|
||||||
|
|
||||||
def get_dns_records(self, log=False):
|
def get_dns_records(self, log=False):
|
||||||
dns_records = self._cloudflare.zones.dns_records.get(self.zone_id)
|
dns_records_all = self._cloudflare.zones.dns_records.get(self.zone_id)
|
||||||
|
|
||||||
dns_names = {'A' : [], 'AAAA' : []}
|
dns_records_to_update = {'A' : [], 'AAAA' : []}
|
||||||
for dnsrecord in dns_records:
|
for dnsrecord in dns_records_all:
|
||||||
if log:
|
if dnsrecord['type'] in ['A', 'AAAA']:
|
||||||
print(f"DNS Name: {dnsrecord['name']} | ID: {dnsrecord['id']} | Type : {dnsrecord['type']} | IP: {dnsrecord['content']}")
|
if log:
|
||||||
dns_names[dnsrecord['type']].append(dnsrecord["name"])
|
print(f"DNS Name: {dnsrecord['name']} | Type : {dnsrecord['type']} | IP: {dnsrecord['content']}")
|
||||||
|
dns_records_to_update[dnsrecord['type']].append(dnsrecord)
|
||||||
|
else:
|
||||||
|
if log:
|
||||||
|
print(f"| Unknow DNS | Type: {dnsrecord['type']} | Zone: {dnsrecord['name']}")
|
||||||
|
|
||||||
self.DNSNAMES = copy.deepcopy(dns_names)
|
self.DNSRECORDS = copy.deepcopy(dns_records_to_update)
|
||||||
|
|
||||||
def update_records(self):
|
def update_records(self):
|
||||||
if self.IPVER == 'skip':
|
if self.IPVER == 'skip':
|
||||||
|
@ -76,18 +80,15 @@ class DNSUpdater:
|
||||||
print(names_replace)
|
print(names_replace)
|
||||||
for name in names_replace:
|
for name in names_replace:
|
||||||
fullname = f"{name}.{self.HOSTNAME}"
|
fullname = f"{name}.{self.HOSTNAME}"
|
||||||
print(fullname)
|
|
||||||
|
|
||||||
for x in self.DNSNAMES:
|
for record in self.DNSRECORDS[dnstype]:
|
||||||
if x['name'] == fullname:
|
if record['name'] == fullname:
|
||||||
dns_record_id = x['id']
|
new_dnsrecord = {"name": fullname, "type": dnstype, "content": self.IPNEW}
|
||||||
print(dns_record_id)
|
print(f"Sending request {new_dnsrecord}")
|
||||||
|
res = self._cloudflare.zones.dns_records.patch(self.zone_id, record['id'], data=new_dnsrecord)
|
||||||
|
if res['content'] != new_dnsrecord['content']:
|
||||||
|
print(res)
|
||||||
|
|
||||||
if fullname in self.DNSNAMES[dnstype]:
|
|
||||||
new_dnsrecord = {"name": fullname, "type": "AAAA", "content": self.IPNEW}
|
|
||||||
print(f"Sending request {new_dnsrecord}")
|
|
||||||
r = self._cloudflare.zones.dns_records.patch(self.zone_id, dns_record_id, data=new_dnsrecord)
|
|
||||||
print(r)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue