Fixed IPv6 access inside Docker container
This commit is contained in:
parent
1e55144bf2
commit
5ac69b8274
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
@ -9,13 +9,14 @@
|
||||
".vscode": true,
|
||||
"LICENSE": true,
|
||||
"requirements.txt": true,
|
||||
"build-docker-image.sh": false,
|
||||
"build-docker-image.sh": true,
|
||||
".gitignore": true,
|
||||
"Dockerfile": false,
|
||||
"start-sync.sh": false,
|
||||
"Dockerfile": true,
|
||||
"start-sync.sh": true,
|
||||
"venv": true
|
||||
},
|
||||
"explorerExclude.backup": null,
|
||||
"python.linting.pylintEnabled": true,
|
||||
"python.linting.enabled": true
|
||||
"python.linting.enabled": true,
|
||||
"python.pythonPath": "venv/bin/python"
|
||||
}
|
||||
@ -11,7 +11,7 @@ RUN pip install -r requirements.txt
|
||||
#
|
||||
# ---- Release ----
|
||||
FROM dependencies AS release
|
||||
# copy project file(s)
|
||||
# copy project source file(s)
|
||||
WORKDIR /
|
||||
COPY cloudflare-ddns.py .
|
||||
CMD ["python", "/cloudflare-ddns.py", "--repeat"]
|
||||
CMD ["python", "-u", "/cloudflare-ddns.py", "--repeat"]
|
||||
@ -1,5 +1,5 @@
|
||||
import requests, json, sys, os
|
||||
import time, traceback
|
||||
import time
|
||||
|
||||
PATH = os.getcwd() + "/"
|
||||
version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
|
||||
@ -10,7 +10,6 @@ if(version < 3.5):
|
||||
with open(PATH + "config.json") as config_file:
|
||||
config = json.loads(config_file.read())
|
||||
|
||||
|
||||
def getIPs():
|
||||
a = requests.get("https://api.ipify.org?format=json").json().get("ip")
|
||||
aaaa = requests.get("https://api6.ipify.org?format=json").json().get("ip")
|
||||
@ -27,6 +26,8 @@ def getIPs():
|
||||
"type": "AAAA",
|
||||
"ip": aaaa
|
||||
})
|
||||
else:
|
||||
print("Warning: IPv6 not detected.")
|
||||
|
||||
return ips
|
||||
|
||||
@ -102,26 +103,21 @@ def cf_api(endpoint, method, config, headers={}, data=False):
|
||||
|
||||
return response.json()
|
||||
|
||||
def every(delay, task):
|
||||
next_time = time.time() + delay
|
||||
while True:
|
||||
time.sleep(max(0, next_time - time.time()))
|
||||
try:
|
||||
task()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
# in production code you might want to have this instead of course:
|
||||
# logger.exception("Problem while executing repetitive task.")
|
||||
# skip tasks if we are behind schedule:
|
||||
next_time += (time.time() - next_time) // delay * delay + delay
|
||||
|
||||
def updateIPs():
|
||||
for ip in getIPs():
|
||||
print("Checking " + ip["type"] + " records")
|
||||
commitRecord(ip)
|
||||
|
||||
if(len(sys.argv) > 1):
|
||||
if(sys.argv[1] == "--repeat"):
|
||||
import threading
|
||||
threading.Thread(target=lambda: every(60*15, updateIPs)).start()
|
||||
updateIPs()
|
||||
print("Updating A & AAAA records every 15 minutes")
|
||||
updateIPs()
|
||||
delay = 15*60 # 15 minutes
|
||||
next_time = time.time() + delay
|
||||
while True:
|
||||
time.sleep(max(0, next_time - time.time()))
|
||||
updateIPs()
|
||||
next_time += (time.time() - next_time) // delay * delay + delay
|
||||
else:
|
||||
print("Unrecognized parameter '" + sys.argv[1] + "'. Stopping now.")
|
||||
else:
|
||||
updateIPs()
|
||||
@ -3,14 +3,14 @@
|
||||
{
|
||||
"authentication": {
|
||||
"api_token": "api_token_here",
|
||||
"api_key": {
|
||||
"api_key": "api_key_here",
|
||||
"account_email": "your_email_here"
|
||||
}
|
||||
"api_key": {
|
||||
"api_key": "api_key_here",
|
||||
"account_email": "your_email_here"
|
||||
}
|
||||
},
|
||||
"zone_id": "your_zone_id_here",
|
||||
"subdomains": [
|
||||
"",
|
||||
"",
|
||||
"subdomain"
|
||||
],
|
||||
"proxied": false
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
cloudflare-ddns:
|
||||
image: timothymiller/cloudflare-ddns:latest
|
||||
image: timothyjmiller/cloudflare-ddns:latest
|
||||
container_name: cloudflare-ddns
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
network_mode: "host"
|
||||
environment:
|
||||
- PUID=1000
|
||||
- PGID=1000
|
||||
volumes:
|
||||
- /EDIT/YOUR/PATH/HERE/config.json:/config.json
|
||||
- /YOUR/PATH/HERE/config.json:/config.json
|
||||
restart: unless-stopped
|
||||
Reference in New Issue
Block a user