Revert "Merge pull request #4 from porkbundomains/mod-patch-1"
This reverts commit82c2bf65bc
, reversing changes made toe653987444
.
This commit is contained in:
parent
facb8e01a4
commit
7e263cd083
1 changed files with 7 additions and 19 deletions
|
@ -4,7 +4,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def getRecords(domain): #grab all the records so we know which ones to delete to make room for our record. Also checks to make sure we've got the right domain
|
def getRecords(domain): #grab all the records so we know which ones to delete to make room for our record. Also checks to make sure we've got the right domain
|
||||||
allRecords=json.loads(requests.post(apiConfig["endpoint"] + '/dns/retrieveByNameType/' + rootDomain + "/A/" + subDomain, data = json.dumps(apiConfig)).text)
|
allRecords=json.loads(requests.post(apiConfig["endpoint"] + '/dns/retrieve/' + domain, data = json.dumps(apiConfig)).text)
|
||||||
if allRecords["status"]=="ERROR":
|
if allRecords["status"]=="ERROR":
|
||||||
print('Error getting domain. Check to make sure you specified the correct domain, and that API access has been switched on for this domain.');
|
print('Error getting domain. Check to make sure you specified the correct domain, and that API access has been switched on for this domain.');
|
||||||
sys.exit();
|
sys.exit();
|
||||||
|
@ -16,25 +16,18 @@ def getMyIP():
|
||||||
|
|
||||||
def deleteRecord():
|
def deleteRecord():
|
||||||
for i in getRecords(rootDomain)["records"]:
|
for i in getRecords(rootDomain)["records"]:
|
||||||
if i["name"]==fqdn and (i["type"] == 'ALIAS' or i["type"] == 'CNAME'):
|
if i["name"]==fqdn and (i["type"] == 'A' or i["type"] == 'ALIAS' or i["type"] == 'CNAME'):
|
||||||
print("Deleting existing " + i["type"] + " Record")
|
print("Deleting existing " + i["type"] + " Record")
|
||||||
deleteRecord = json.loads(requests.post(apiConfig["endpoint"] + '/dns/delete/' + rootDomain + '/' + i["id"], data = json.dumps(apiConfig)).text)
|
deleteRecord = json.loads(requests.post(apiConfig["endpoint"] + '/dns/delete/' + rootDomain + '/' + i["id"], data = json.dumps(apiConfig)).text)
|
||||||
|
|
||||||
def createRecord():
|
def createRecord():
|
||||||
createObj=apiConfig.copy()
|
createObj=apiConfig.copy()
|
||||||
createObj.update({'name': subDomain, 'type': 'A', 'content': myIP, 'ttl': 600})
|
createObj.update({'name': subDomain, 'type': 'A', 'content': myIP, 'ttl': 300})
|
||||||
endpoint = apiConfig["endpoint"] + '/dns/create/' + rootDomain
|
endpoint = apiConfig["endpoint"] + '/dns/create/' + rootDomain
|
||||||
print("Creating record: " + fqdn + " with answer of " + myIP)
|
print("Creating record: " + fqdn + " with answer of " + myIP)
|
||||||
create = json.loads(requests.post(apiConfig["endpoint"] + '/dns/create/'+ rootDomain, data = json.dumps(createObj)).text)
|
create = json.loads(requests.post(apiConfig["endpoint"] + '/dns/create/'+ rootDomain, data = json.dumps(createObj)).text)
|
||||||
return(create)
|
return(create)
|
||||||
|
|
||||||
def modRecord():
|
|
||||||
createObj=apiConfig.copy()
|
|
||||||
createObj.update({'content': myIP, 'ttl': 600})
|
|
||||||
endpoint = apiConfig["endpoint"] + '/dns/editByNameType/' + rootDomain + '/A/'+ subDomain
|
|
||||||
mod = json.loads(requests.post(apiConfig["endpoint"] + '/dns/editByNameType/'+ rootDomain + '/A/'+ subDomain, data = json.dumps(createObj)).text)
|
|
||||||
return(mod)
|
|
||||||
|
|
||||||
if len(sys.argv)>2: #at least the config and root domain is specified
|
if len(sys.argv)>2: #at least the config and root domain is specified
|
||||||
apiConfig = json.load(open(sys.argv[1])) #load the config file into a variable
|
apiConfig = json.load(open(sys.argv[1])) #load the config file into a variable
|
||||||
rootDomain=sys.argv[2]
|
rootDomain=sys.argv[2]
|
||||||
|
@ -53,13 +46,8 @@ if len(sys.argv)>2: #at least the config and root domain is specified
|
||||||
else:
|
else:
|
||||||
myIP=getMyIP() #otherwise use the detected exterior IP address
|
myIP=getMyIP() #otherwise use the detected exterior IP address
|
||||||
|
|
||||||
deleteRecord()
|
deleteRecord()
|
||||||
|
print(createRecord()["status"])
|
||||||
if getRecords(fqdn)["status"]=="ERROR":
|
|
||||||
print(createRecord()["status"])
|
|
||||||
else:
|
|
||||||
modRecord()
|
|
||||||
print("Modifying record: " + fqdn + " with answer of " + myIP)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Porkbun Dynamic DNS client, Python Edition\n\nError: not enough arguments. Examples:\npython porkbun-ddns.py /path/to/config.json example.com\npython porkbun-ddns.py /path/to/config.json example.com www\npython porkbun-ddns.py /path/to/config.json example.com '*'\npython porkbun-ddns.py /path/to/config.json example.com -i 10.0.0.1\n")
|
print("Porkbun Dynamic DNS client, Python Edition\n\nError: not enough arguments. Examples:\npython porkbun-ddns.py /path/to/config.json example.com\npython porkbun-ddns.py /path/to/config.json example.com www\npython porkbun-ddns.py /path/to/config.json example.com '*'\npython porkbun-ddns.py /path/to/config.json example.com -i 10.0.0.1\n")
|
Reference in a new issue