Merge pull request #57 from omeganot/master
Config option for purge/delete of "stale" records
This commit is contained in:
commit
def75e282d
@ -33,6 +33,7 @@ def getIPs():
|
|||||||
aaaa = None
|
aaaa = None
|
||||||
global ipv4_enabled
|
global ipv4_enabled
|
||||||
global ipv6_enabled
|
global ipv6_enabled
|
||||||
|
global purgeUnknownRecords
|
||||||
if ipv4_enabled:
|
if ipv4_enabled:
|
||||||
try:
|
try:
|
||||||
a = requests.get("https://1.1.1.1/cdn-cgi/trace").text.split("\n")
|
a = requests.get("https://1.1.1.1/cdn-cgi/trace").text.split("\n")
|
||||||
@ -43,6 +44,7 @@ def getIPs():
|
|||||||
if not shown_ipv4_warning:
|
if not shown_ipv4_warning:
|
||||||
shown_ipv4_warning = True
|
shown_ipv4_warning = True
|
||||||
print("🧩 IPv4 not detected")
|
print("🧩 IPv4 not detected")
|
||||||
|
if purgeUnknownRecords:
|
||||||
deleteEntries("A")
|
deleteEntries("A")
|
||||||
if ipv6_enabled:
|
if ipv6_enabled:
|
||||||
try:
|
try:
|
||||||
@ -54,6 +56,7 @@ def getIPs():
|
|||||||
if not shown_ipv6_warning:
|
if not shown_ipv6_warning:
|
||||||
shown_ipv6_warning = True
|
shown_ipv6_warning = True
|
||||||
print("🧩 IPv6 not detected")
|
print("🧩 IPv6 not detected")
|
||||||
|
if purgeUnknownRecords:
|
||||||
deleteEntries("AAAA")
|
deleteEntries("AAAA")
|
||||||
ips = {}
|
ips = {}
|
||||||
if(a is not None):
|
if(a is not None):
|
||||||
@ -118,6 +121,7 @@ def commitRecord(ip):
|
|||||||
print("➕ Adding new record " + str(record))
|
print("➕ Adding new record " + str(record))
|
||||||
response = cf_api(
|
response = cf_api(
|
||||||
"zones/" + option['zone_id'] + "/dns_records", "POST", option, {}, record)
|
"zones/" + option['zone_id'] + "/dns_records", "POST", option, {}, record)
|
||||||
|
if purgeUnknownRecords:
|
||||||
for identifier in duplicate_ids:
|
for identifier in duplicate_ids:
|
||||||
identifier = str(identifier)
|
identifier = str(identifier)
|
||||||
print("🗑️ Deleting stale record " + identifier)
|
print("🗑️ Deleting stale record " + identifier)
|
||||||
@ -165,6 +169,7 @@ if __name__ == '__main__':
|
|||||||
shown_ipv6_warning = False
|
shown_ipv6_warning = False
|
||||||
ipv4_enabled = True
|
ipv4_enabled = True
|
||||||
ipv6_enabled = True
|
ipv6_enabled = True
|
||||||
|
purgeUnknownRecords = False
|
||||||
|
|
||||||
if(version < 3.5):
|
if(version < 3.5):
|
||||||
raise Exception("🐍 This script requires Python 3.5+")
|
raise Exception("🐍 This script requires Python 3.5+")
|
||||||
@ -185,6 +190,11 @@ if __name__ == '__main__':
|
|||||||
ipv4_enabled = True
|
ipv4_enabled = True
|
||||||
ipv6_enabled = True
|
ipv6_enabled = True
|
||||||
print("⚙️ Individually disable IPv4 or IPv6 with new config.json options. Read more about it here: https://github.com/timothymiller/cloudflare-ddns/blob/master/README.md")
|
print("⚙️ Individually disable IPv4 or IPv6 with new config.json options. Read more about it here: https://github.com/timothymiller/cloudflare-ddns/blob/master/README.md")
|
||||||
|
try:
|
||||||
|
purgeUnknownRecords = config["purgeUnknownRecords"]
|
||||||
|
except:
|
||||||
|
purgeUnknownRecords = False
|
||||||
|
print("⚙️ No config detected for 'purgeUnknownRecords' - defaulting to False")
|
||||||
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
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"purgeUnknownRecords": false,
|
||||||
"cloudflare": [
|
"cloudflare": [
|
||||||
{
|
{
|
||||||
"authentication": {
|
"authentication": {
|
||||||
|
|||||||
Reference in New Issue
Block a user