Merge branch 'hotfix/TXT' into 'main'

Hotfix for #2 : Errors when type is TXT

See merge request Neshura/cloudflare-dns-updater!2
This commit is contained in:
Neshura 2022-11-27 17:52:18 +00:00
commit fd19efd007
3 changed files with 24 additions and 6 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
venv/

View file

@ -31,7 +31,16 @@ def main():
for dnsrecord in dns_records:
if ipversion == 'skipping':
print(f"DNS Name: {dnsrecord['name']} | ID: {dnsrecord['id']} | Type : {dnsrecord['type']} | IP: {dnsrecord['content']}")
dns_names[dnsrecord['type']].append(dnsrecord["name"])
if dnsrecord['type'] in ['A', 'AAAA']:
dns_names[dnsrecord['type']].append(dnsrecord["name"])
else:
print(f"Cannot resolve record {dnsrecord['name']} because of type {dnsrecord['type']}")
print(f"------ Full DNS record ------\n"
f"{dnsrecord}"
f"\n---------------------------"
)
with open('cloudflare.json', 'r') as file:
values = json.load(file)
@ -55,8 +64,11 @@ def main():
if fullname in dns_names['A']:
new_dnsrecords = {"name": fullname, "type": "A", "content": ip_address_new}
print(f"Sending request {new_dnsrecords}")
r = cf.zones.dns_records.put(zone_id, dns_record_id, data=new_dnsrecords)
print(r)
try:
r = cf.zones.dns_records.patch(zone_id, dns_record_id, data=new_dnsrecords)
print(r)
except:
print("Error pushing entry")
case '6':
print("Updating IPv6")
@ -75,8 +87,11 @@ def main():
if fullname in dns_names['AAAA']:
new_dnsrecords = {"name": fullname, "type": "AAAA", "content": ip_address_new}
print(f"Sending request {new_dnsrecords}")
r = cf.zones.dns_records.put(zone_id, dns_record_id, data=new_dnsrecords)
print(r)
try:
r = cf.zones.dns_records.patch(zone_id, dns_record_id, data=new_dnsrecords)
print(r)
except:
print("Error pushing entry")
case 'skipping':
print("Done")
case other:

View file

@ -13,8 +13,9 @@ else
if [ ! -e cloudflare.json ] || [ ! -e config.ini ]; then
echo "Cloudflare config not found, is the script run in the correct directory?"
else
ipv4=$(curl -k -s https://am.i.mullvad.net/ip)
ipv4=$(curl -k -s https://am.i.mullvad.net/ip -4)
ipv6=$(curl -k -s https://ipv6.am.i.mullvad.net/)
source venv/bin/activate
python3 ./cloudflare_script.py 4 "$ipv4"
python3 ./cloudflare_script.py 6 "$ipv6"
fi