99import tldextract
1010import CloudFlare
1111import logging as log # for verbose output
12- import socket # to get default hostname
12+ import socket # to get default hostname
1313from .__about__ import __version__
1414
15- def update (cf_username , cf_key , hostname , ip , proxied = True , ttl = 1 ):
15+
16+ def update (cf_username , cf_key , hostname , ip , proxied = True , ttl = 120 ):
1617
1718 log .info ("Updating {} to {}" .format (hostname , ip ))
1819
@@ -31,7 +32,7 @@ def update(cf_username, cf_key, hostname, ip, proxied=True, ttl=1):
3132 params = {'name' : zone_domain }
3233 zones = cf .zones .get (params = params )
3334 except CloudFlare .exceptions .CloudFlareAPIError as e :
34- log .error ('badauth' )
35+ log .error ('badauth - %s' % ( e ) )
3536 exit ()
3637 except Exception as e :
3738 exit ('/zones.get - %s - api call failed' % (e ))
@@ -41,13 +42,13 @@ def update(cf_username, cf_key, hostname, ip, proxied=True, ttl=1):
4142 exit ()
4243
4344 if len (zones ) != 1 :
44- exit ('/zones.get - %s - api call returned %d items' % (zone_name , len (zones )))
45+ exit ('/zones.get - %s - api call returned %d items' % (zone_domain , len (zones )))
4546
4647 zone_id = zones [0 ]['id' ]
4748 log .info ("Zone ID is {}" .format (zone_id ))
4849
4950 try :
50- params = {'name' :hostname , 'match' :'all' , 'type' :ip_address_type }
51+ params = {'name' : hostname , 'match' : 'all' , 'type' : ip_address_type }
5152 dns_records = cf .zones .dns_records .get (zone_id , params = params )
5253 except CloudFlare .exceptions .CloudFlareAPIError as e :
5354 exit ('/zones/dns_records %s - %d %s - api call failed' % (hostname , e , e ))
@@ -78,11 +79,11 @@ def update(cf_username, cf_key, hostname, ip, proxied=True, ttl=1):
7879
7980 dns_record_id = dns_record ['id' ]
8081 dns_record = {
81- 'name' :hostname ,
82- 'type' :ip_address_type ,
83- 'content' :ip ,
84- 'proxied' :proxied ,
85- 'ttl' :ttl
82+ 'name' : hostname ,
83+ 'type' : ip_address_type ,
84+ 'content' : ip ,
85+ 'proxied' : proxied ,
86+ 'ttl' : ttl
8687 }
8788 try :
8889 dns_record = cf .zones .dns_records .put (zone_id , dns_record_id , data = dns_record )
@@ -94,10 +95,10 @@ def update(cf_username, cf_key, hostname, ip, proxied=True, ttl=1):
9495 if not updated :
9596 # no exsiting dns record to update - so create dns record
9697 dns_record = {
97- 'name' :hostname ,
98- 'type' :ip_address_type ,
99- 'content' :ip ,
100- 'ttl' :ttl
98+ 'name' : hostname ,
99+ 'type' : ip_address_type ,
100+ 'content' : ip ,
101+ 'ttl' : ttl
101102 }
102103 try :
103104 dns_record = cf .zones .dns_records .post (zone_id , data = dns_record )
@@ -143,5 +144,6 @@ def main():
143144def syno ():
144145 update (sys .argv [1 ], sys .argv [2 ], sys .argv [3 ], sys .argv [4 ])
145146
147+
146148if __name__ == '__main__' :
147149 main ()
0 commit comments