Revert merge pull request #39
This commit is contained in:
parent
378c600084
commit
6b25c64846
@ -1,4 +1,4 @@
|
|||||||
import argparse, requests, json, sys, signal, os, time
|
import requests, json, sys, signal, os, time
|
||||||
|
|
||||||
PATH = os.getcwd() + "/"
|
PATH = os.getcwd() + "/"
|
||||||
version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
|
version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
|
||||||
@ -23,6 +23,9 @@ class GracefulExit:
|
|||||||
print("🛑 Stopping main thread...")
|
print("🛑 Stopping main thread...")
|
||||||
self.kill_now = True
|
self.kill_now = True
|
||||||
|
|
||||||
|
with open(PATH + "config.json") as config_file:
|
||||||
|
config = json.loads(config_file.read())
|
||||||
|
|
||||||
def deleteEntries(type):
|
def deleteEntries(type):
|
||||||
# Helper function for deleting A or AAAA records
|
# Helper function for deleting A or AAAA records
|
||||||
# in the case of no IPv4 or IPv6 connection, yet
|
# in the case of no IPv4 or IPv6 connection, yet
|
||||||
@ -75,7 +78,7 @@ def getIPs():
|
|||||||
})
|
})
|
||||||
return ips
|
return ips
|
||||||
|
|
||||||
def commitRecord(ip, config):
|
def commitRecord(ip):
|
||||||
for c in config["cloudflare"]:
|
for c in config["cloudflare"]:
|
||||||
subdomains = c["subdomains"]
|
subdomains = c["subdomains"]
|
||||||
response = cf_api("zones/" + c['zone_id'], "GET", c)
|
response = cf_api("zones/" + c['zone_id'], "GET", c)
|
||||||
@ -148,25 +151,22 @@ def cf_api(endpoint, method, config, headers={}, data=False):
|
|||||||
|
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def updateIPs(config):
|
def updateIPs():
|
||||||
for ip in getIPs():
|
for ip in getIPs():
|
||||||
commitRecord(ip, config)
|
commitRecord(ip)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
if(len(sys.argv) > 1):
|
||||||
parser.add_argument("--repeat", type=bool)
|
if(sys.argv[1] == "--repeat"):
|
||||||
parser.add_argument("--config-path", dest="config", type=open, default=os.path.join(PATH, "config.json"))
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
if args.repeat:
|
|
||||||
delay = 5*60
|
delay = 5*60
|
||||||
print("⏲️ Updating IPv4 (A) & IPv6 (AAAA) records every 5 minutes")
|
print("⏲️ Updating IPv4 (A) & IPv6 (AAAA) records every 5 minutes")
|
||||||
next_time = time.time()
|
next_time = time.time()
|
||||||
killer = GracefulExit()
|
killer = GracefulExit()
|
||||||
while not killer.kill_now:
|
while not killer.kill_now:
|
||||||
time.sleep(max(0, next_time - time.time()))
|
time.sleep(max(0, next_time - time.time()))
|
||||||
updateIPs(json.load(args.config))
|
updateIPs()
|
||||||
next_time += (time.time() - next_time) // delay * delay + delay
|
next_time += (time.time() - next_time) // delay * delay + delay
|
||||||
else:
|
else:
|
||||||
updateIPs(json.load(args.config))
|
print("😡 Unrecognized parameter '" + sys.argv[1] + "'. Stopping now.")
|
||||||
|
else:
|
||||||
|
updateIPs()
|
||||||
Reference in New Issue
Block a user