2020-10-12 19:57:59 +00:00
|
|
|
#!/bin/python3
|
|
|
|
# @Author skiqqy
|
|
|
|
import requests
|
|
|
|
import os
|
2020-10-12 20:41:25 +00:00
|
|
|
import time
|
2020-10-12 19:57:59 +00:00
|
|
|
|
|
|
|
f = open("secret/godaddy_key", "r")
|
|
|
|
|
|
|
|
secret = ""
|
|
|
|
key = ""
|
|
|
|
for line in f:
|
|
|
|
line = line.replace("\n","")
|
|
|
|
parse = line.split(":")
|
|
|
|
if parse[0] == "secret":
|
|
|
|
secret = parse[1]
|
|
|
|
elif parse[0] == "key":
|
|
|
|
key = parse[1]
|
|
|
|
|
|
|
|
if secret == "" or key == "":
|
|
|
|
print("No key or secret set")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
url="https://api.godaddy.com/"
|
|
|
|
|
|
|
|
header={
|
|
|
|
"content-type":"application/json",
|
|
|
|
"Authorization":"sso-key " + key + ":" + secret
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Domains and subdomains
|
|
|
|
domains = {
|
|
|
|
"skiqqy.xyz":[
|
|
|
|
{"name": "git", "type": "A"},
|
|
|
|
{"name": "irc", "type": "A"},
|
|
|
|
{"name": "proj", "type": "A"},
|
2020-10-13 18:23:24 +00:00
|
|
|
{"name": "blog", "type": "A"},
|
2020-10-12 19:57:59 +00:00
|
|
|
{"name": "pay", "type": "A"},
|
2020-10-14 12:05:19 +00:00
|
|
|
{"name": "wiki", "type": "A"},
|
2020-10-17 18:58:14 +00:00
|
|
|
{"name": "files", "type": "A"},
|
2020-10-12 19:57:59 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get current public ip
|
2020-10-12 20:41:25 +00:00
|
|
|
# Max 60s then give up (1s per try + 1s sleep = 2s per iter => 30*2 =60
|
|
|
|
for i in range(30):
|
|
|
|
ip = os.popen('curl ifconfig.me --max-time 1').read()
|
|
|
|
if ip == "":
|
|
|
|
# We timed out
|
|
|
|
time.sleep(1)
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
if ip == "":
|
|
|
|
exit(1) # We could not get our ip
|
2020-10-12 19:57:59 +00:00
|
|
|
|
|
|
|
# Construct the post data
|
|
|
|
for domain in domains:
|
|
|
|
post = [{}]
|
|
|
|
for sub in domains[domain]:
|
|
|
|
post[0]["type"] = sub["type"]
|
|
|
|
post[0]["name"] = sub["name"]
|
|
|
|
post[0]["data"] = ip
|
|
|
|
post[0]["ttl"] = 3600
|
|
|
|
|
|
|
|
# Do the put
|
|
|
|
req_url = url + "v1/domains/" + domain + "/records/" + sub["type"] + "/" + sub["name"]
|
|
|
|
r = requests.put(req_url, headers=header, json=post)
|
|
|
|
print(r)
|