mirror of
https://github.com/KevinMidboe/cloudflare-ddns.git
synced 2026-01-07 17:55:38 +00:00
Compare commits
3 Commits
7b5ddcec21
...
67e58fc8ee
| Author | SHA1 | Date | |
|---|---|---|---|
| 67e58fc8ee | |||
| f32267280a | |||
| 34e8ca8c95 |
@@ -15,6 +15,7 @@ import requests
|
||||
from logger import logger
|
||||
|
||||
API_KEY = ''
|
||||
DDNS_A_RECORD_NAME = 'addr'
|
||||
|
||||
|
||||
def setAPIKey(apiKey):
|
||||
@@ -64,9 +65,11 @@ def getZones():
|
||||
data = cloudflareRequest(url)
|
||||
|
||||
if 'success' not in data and 'errors' not in data:
|
||||
logger.info("Unexpected cloudflare error when getting zones, no response!")
|
||||
logger.info(
|
||||
"Unexpected cloudflare error when getting zones, no response!")
|
||||
logger.info("data:" + str(data))
|
||||
raise Exception('Unexpected Cloudflare error, missing response! Check logs.')
|
||||
raise Exception(
|
||||
'Unexpected Cloudflare error, missing response! Check logs.')
|
||||
|
||||
if data['success'] is False:
|
||||
logger.info('Request to cloudflare was unsuccessful, error:')
|
||||
@@ -87,9 +90,11 @@ def getRecordsForZone(zoneId):
|
||||
data = cloudflareRequest(url)
|
||||
|
||||
if 'success' not in data and 'errors' not in data:
|
||||
logger.info("Unexpected cloudflare error when getting records, no response!")
|
||||
logger.info(
|
||||
"Unexpected cloudflare error when getting records, no response!")
|
||||
logger.info("data:" + str(data))
|
||||
raise Exception('Unexpected Cloudflare error, missing response! Check logs.')
|
||||
raise Exception(
|
||||
'Unexpected Cloudflare error, missing response! Check logs.')
|
||||
|
||||
if data['success'] is False:
|
||||
logger.info('Request from cloudflare was unsuccessful, error:')
|
||||
@@ -106,13 +111,15 @@ def getRecordsForZone(zoneId):
|
||||
|
||||
def getDDNSAddresszoneId(ddnsZone):
|
||||
records = getRecordsForZone(ddnsZone)
|
||||
ddns_re = r"^{}\.".format(DDNS_A_RECORD_NAME)
|
||||
|
||||
for record in records:
|
||||
if not re.match(r"^addr\.", record['name']):
|
||||
if not re.match(ddns_re, record['name']):
|
||||
continue
|
||||
return record
|
||||
|
||||
raise Exception('No ddns record found for zone: {}'.format(ddnsZone))
|
||||
raise Exception('No \'{}\' DDNS record found for zone: {}'.format(
|
||||
DDNS_A_RECORD_NAME, ddnsZone))
|
||||
|
||||
|
||||
def updateRecord(zoneId, recordId, name, newIP, ttl, proxied):
|
||||
|
||||
@@ -12,7 +12,8 @@ DDNS_ZONE = os.getenv('DDNS_ZONE')
|
||||
|
||||
|
||||
def validIP(ipString):
|
||||
ipRegex = '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
|
||||
ipRegex = r'^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}' \
|
||||
r'([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
|
||||
return bool(re.search(ipRegex, str(ipString)))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user