Compare commits
No commits in common. "3832ec270933932918b8f31650bf926942484747" and "2fe001a646398eba44eecdae95af8f87a833119e" have entirely different histories.
3832ec2709
...
2fe001a646
|
@ -36,7 +36,7 @@ run your own external IP provider:
|
||||||
+ <?php $ip = $_SERVER['REMOTE_ADDR']; ?>
|
+ <?php $ip = $_SERVER['REMOTE_ADDR']; ?>
|
||||||
<?php print $ip; ?>
|
<?php print $ip; ?>
|
||||||
e.g.
|
e.g.
|
||||||
+ https://ifconfig.co
|
+ https://ifconfig.co/ip
|
||||||
+ http://ifconfig.me/ip
|
+ http://ifconfig.me/ip
|
||||||
+ http://whatismyip.akamai.com/
|
+ http://whatismyip.akamai.com/
|
||||||
+ http://ipinfo.io/ip
|
+ http://ipinfo.io/ip
|
||||||
|
|
|
@ -9,7 +9,7 @@ https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
Created on 13 Aug 2017
|
Created on 13 Aug 2017
|
||||||
http://doc.livedns.gandi.net/
|
http://doc.livedns.gandi.net/
|
||||||
http://doc.livedns.gandi.net/#api-endpoint -> https://dns.gandi.net/api/v5/
|
http://doc.livedns.gandi.net/#api-endpoint -> https://dns.beta.gandi.net/api/v5/
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import requests, json
|
import requests, json
|
||||||
|
@ -22,8 +22,8 @@ def get_dynip(ifconfig_provider):
|
||||||
similar to curl ifconfig.me/ip, see example.config.py for details to ifconfig providers
|
similar to curl ifconfig.me/ip, see example.config.py for details to ifconfig providers
|
||||||
'''
|
'''
|
||||||
r = requests.get(ifconfig_provider)
|
r = requests.get(ifconfig_provider)
|
||||||
print('Checking dynamic IP: ' , r.text.strip('\n'))
|
print 'Checking dynamic IP: ' , r._content.strip('\n')
|
||||||
return r.text.strip('\n')
|
return r.content.strip('\n')
|
||||||
|
|
||||||
def get_uuid():
|
def get_uuid():
|
||||||
'''
|
'''
|
||||||
|
@ -38,8 +38,8 @@ def get_uuid():
|
||||||
if u.status_code == 200:
|
if u.status_code == 200:
|
||||||
return json_object['zone_uuid']
|
return json_object['zone_uuid']
|
||||||
else:
|
else:
|
||||||
print('Error: HTTP Status Code ', u.status_code, 'when trying to get Zone UUID')
|
print 'Error: HTTP Status Code ', u.status_code, 'when trying to get Zone UUID'
|
||||||
print(json_object['message'])
|
print json_object['message']
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def get_dnsip(uuid):
|
def get_dnsip(uuid):
|
||||||
|
@ -56,11 +56,11 @@ def get_dnsip(uuid):
|
||||||
u = requests.get(url, headers=headers)
|
u = requests.get(url, headers=headers)
|
||||||
if u.status_code == 200:
|
if u.status_code == 200:
|
||||||
json_object = json.loads(u._content)
|
json_object = json.loads(u._content)
|
||||||
print('Checking IP from DNS Record' , config.subdomains[0], ':', json_object['rrset_values'][0].encode('ascii','ignore').decode().strip('\n'))
|
print 'Checking IP from DNS Record' , config.subdomains[0], ':', json_object['rrset_values'][0].encode('ascii','ignore').strip('\n')
|
||||||
return json_object['rrset_values'][0].encode('ascii','ignore').decode().strip('\n')
|
return json_object['rrset_values'][0].encode('ascii','ignore').strip('\n')
|
||||||
else:
|
else:
|
||||||
print('Error: HTTP Status Code ', u.status_code, 'when trying to get IP from subdomain', config.subdomains[0])
|
print 'Error: HTTP Status Code ', u.status_code, 'when trying to get IP from subdomain', config.subdomains[0]
|
||||||
print (json_object['message'])
|
print json_object['message']
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def update_records(uuid, dynIP, subdomain):
|
def update_records(uuid, dynIP, subdomain):
|
||||||
|
@ -71,7 +71,7 @@ def update_records(uuid, dynIP, subdomain):
|
||||||
-H 'X-Api-Key: XXX' \
|
-H 'X-Api-Key: XXX' \
|
||||||
-d '{"rrset_ttl": 10800,
|
-d '{"rrset_ttl": 10800,
|
||||||
"rrset_values": ["<VALUE>"]}' \
|
"rrset_values": ["<VALUE>"]}' \
|
||||||
https://dns.gandi.net/api/v5/zones/<UUID>/records/<NAME>/<TYPE>
|
https://dns.beta.gandi.net/api/v5/zones/<UUID>/records/<NAME>/<TYPE>
|
||||||
'''
|
'''
|
||||||
url = config.api_endpoint+ '/zones/' + uuid + '/records/' + subdomain + '/A'
|
url = config.api_endpoint+ '/zones/' + uuid + '/records/' + subdomain + '/A'
|
||||||
payload = {"rrset_ttl": config.ttl, "rrset_values": [dynIP]}
|
payload = {"rrset_ttl": config.ttl, "rrset_values": [dynIP]}
|
||||||
|
@ -80,11 +80,11 @@ def update_records(uuid, dynIP, subdomain):
|
||||||
json_object = json.loads(u._content)
|
json_object = json.loads(u._content)
|
||||||
|
|
||||||
if u.status_code == 201:
|
if u.status_code == 201:
|
||||||
print('Status Code:', u.status_code, ',', json_object['message'], ', IP updated for', subdomain)
|
print 'Status Code:', u.status_code, ',', json_object['message'], ', IP updated for', subdomain
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print('Error: HTTP Status Code ', u.status_code, 'when trying to update IP from subdomain', subdomain)
|
print 'Error: HTTP Status Code ', u.status_code, 'when trying to update IP from subdomain', subdomain
|
||||||
print(json_object['message'])
|
print json_object['message']
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,30 +92,27 @@ def update_records(uuid, dynIP, subdomain):
|
||||||
def main(force_update, verbosity):
|
def main(force_update, verbosity):
|
||||||
|
|
||||||
if verbosity:
|
if verbosity:
|
||||||
print("verbosity turned on - not implemented by now")
|
print "verbosity turned on - not implemented by now"
|
||||||
|
|
||||||
for key, value in config.dnsentries.items():
|
|
||||||
config.domain = key
|
|
||||||
config.subdomains = value
|
|
||||||
|
|
||||||
#get zone ID from Account
|
#get zone ID from Account
|
||||||
uuid = get_uuid()
|
uuid = get_uuid()
|
||||||
|
|
||||||
#compare dynIP and DNS IP
|
#compare dynIP and DNS IP
|
||||||
dynIP = get_dynip(config.ifconfig)
|
dynIP = get_dynip(config.ifconfig)
|
||||||
dnsIP = get_dnsip(uuid)
|
dnsIP = get_dnsip(uuid)
|
||||||
|
|
||||||
if force_update:
|
if force_update:
|
||||||
print("Going to update/create the DNS Records for the subdomains")
|
print "Going to update/create the DNS Records for the subdomains"
|
||||||
|
for sub in config.subdomains:
|
||||||
|
update_records(uuid, dynIP, sub)
|
||||||
|
else:
|
||||||
|
if dynIP == dnsIP:
|
||||||
|
print "IP Address Match - no further action"
|
||||||
|
else:
|
||||||
|
print "IP Address Mismatch - going to update the DNS Records for the subdomains with new IP", dynIP
|
||||||
for sub in config.subdomains:
|
for sub in config.subdomains:
|
||||||
update_records(uuid, dynIP, sub)
|
update_records(uuid, dynIP, sub)
|
||||||
else:
|
|
||||||
if dynIP == dnsIP:
|
|
||||||
print("IP Address Match - no further action")
|
|
||||||
else:
|
|
||||||
print("IP Address Mismatch - going to update the DNS Records for the subdomains with new IP", dynIP)
|
|
||||||
for sub in config.subdomains:
|
|
||||||
update_records(uuid, dynIP, sub)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -123,4 +120,11 @@ if __name__ == "__main__":
|
||||||
parser.add_argument('-f', '--force', help="force an update/create", action="store_true")
|
parser.add_argument('-f', '--force', help="force an update/create", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
main(args.force, args.verbose)
|
main(args.force, args.verbose)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue