Created
March 1, 2017 06:43
-
-
Save clonemeagain/1f6f1639151858496266828a22c54fc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import json | |
import urllib2 | |
''' | |
Loads as many settings as makes sense for every domain in your account | |
Then stores those settings in a json file named for the domain. | |
''' | |
api_prefix = 'https://api.cloudflare.com/client/v4/zones/' | |
headers = { | |
"X-Auth-Email":"YOUR_EMAIL", | |
"X-Auth-Key":"YOUR_KEY", | |
"Content-Type":"application/json" | |
} | |
zone_endpoints = { | |
'/settings', | |
'/dns_records', | |
# '/railguns', | |
'/pagerules', | |
'/rate_limits', | |
'/firewall/access_rules/rules', | |
'/firewall/waf/packages' | |
} | |
def pd(value): | |
return json.dumps(value, sort_keys=True, indent=4, separators=(',',': ')) | |
# Retrieve all zones, will need changing if you have more than 50 zones.. | |
req = urllib2.Request(api_prefix, headers=headers) | |
zone_details = json.load(urllib2.urlopen(req)) | |
for zone in zone_details["result"]: | |
domain = zone['name'] | |
key = zone['id'] | |
all_settings = { | |
'domain_name' : domain, | |
'main_settings' : zone | |
} | |
for endpoint in zone_endpoints: | |
url = api_prefix + key + endpoint | |
#print ("Loading data from " + url) | |
req = urllib2.Request(url, headers=headers) | |
all_settings[endpoint] = json.load(urllib2.urlopen(req)) | |
#print("Domain " + domain + " settings:\n" + pd(all_settings)) | |
with open(domain + '.json','w') as outfile: | |
outfile.write(pd(all_settings)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you export your Cloudflare configs? With this simplish python script, that's how.