Added configurable TTL option, plus documentation

This commit is contained in:
Timothy Miller 2022-07-30 21:20:41 -04:00
parent 2b9ebdeab2
commit ef4e3a5787
3 changed files with 13 additions and 2 deletions

View File

@ -78,6 +78,7 @@ Some ISP provided modems only allow port forwarding over IPv4 or IPv6. In this c
"zone_id": "The ID of the zone that will get the records. From your dashboard click into the zone. Under the overview tab, scroll down and the zone ID is listed in the right rail", "zone_id": "The ID of the zone that will get the records. From your dashboard click into the zone. Under the overview tab, scroll down and the zone ID is listed in the right rail",
"subdomains": "Array of subdomains you want to update the A & where applicable, AAAA records. IMPORTANT! Only write subdomain name. Do not include the base domain name. (e.g. foo or an empty string to update the base domain)", "subdomains": "Array of subdomains you want to update the A & where applicable, AAAA records. IMPORTANT! Only write subdomain name. Do not include the base domain name. (e.g. foo or an empty string to update the base domain)",
"proxied": false (defaults to false. Make it true if you want CDN/SSL benefits from cloudflare. This usually disables SSH) "proxied": false (defaults to false. Make it true if you want CDN/SSL benefits from cloudflare. This usually disables SSH)
"ttl": "Defaults to 300 seconds. Longer TTLs speed up DNS lookups by increasing the chance of cached results, but a longer TTL also means that updates to your records take longer to go into effect. You can choose a TTL between 30 seconds and 1 day. For more information, see [Cloudflare's TTL documentation](https://developers.cloudflare.com/dns/manage-dns-records/reference/ttl/)",
``` ```
## 📠 Hosting multiple subdomains on the same IP? ## 📠 Hosting multiple subdomains on the same IP?

View File

@ -96,6 +96,7 @@ def getIPs():
def commitRecord(ip): def commitRecord(ip):
global ttl
for option in config["cloudflare"]: for option in config["cloudflare"]:
subdomains = option["subdomains"] subdomains = option["subdomains"]
response = cf_api("zones/" + option['zone_id'], "GET", option) response = cf_api("zones/" + option['zone_id'], "GET", option)
@ -103,7 +104,6 @@ def commitRecord(ip):
time.sleep(5) time.sleep(5)
return return
base_domain_name = response["result"]["name"] base_domain_name = response["result"]["name"]
ttl = 300 # default Cloudflare TTL
for subdomain in subdomains: for subdomain in subdomains:
name = subdomain["name"].lower().strip() name = subdomain["name"].lower().strip()
fqdn = base_domain_name fqdn = base_domain_name
@ -229,6 +229,15 @@ if __name__ == '__main__':
except: except:
purgeUnknownRecords = False purgeUnknownRecords = False
print("⚙️ No config detected for 'purgeUnknownRecords' - defaulting to False") print("⚙️ No config detected for 'purgeUnknownRecords' - defaulting to False")
try:
ttl = int(config["ttl"])
except:
ttl = 300
print(
"⚙️ No config detected for 'ttl' - defaulting to 300 seconds (5 minutes)")
if ttl < 30:
ttl = 30 # default Cloudflare TTL
print("⚙️ TTL is too low - defaulting to 60 seconds (1 minute)")
if(len(sys.argv) > 1): if(len(sys.argv) > 1):
if(sys.argv[1] == "--repeat"): if(sys.argv[1] == "--repeat"):
delay = 5*60 delay = 5*60

View File

@ -23,5 +23,6 @@
], ],
"a": true, "a": true,
"aaaa": true, "aaaa": true,
"purgeUnknownRecords": false "purgeUnknownRecords": false,
"ttl": 300
} }