46 lines
864 B
Python
46 lines
864 B
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import yaml
|
|
import requests
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
TOKEN = os.getenv("CF_API_TOKEN")
|
|
ZONE = os.getenv("CF_ZONE_ID")
|
|
|
|
headers = {
|
|
"Authorization": f"Bearer {TOKEN}",
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
url = f"https://api.cloudflare.com/client/v4/zones/{ZONE}/dns_records"
|
|
|
|
records = requests.get(url, headers=headers).json()["result"]
|
|
|
|
data = {
|
|
"zone": "mrredportal.com",
|
|
"defaults": {
|
|
"ttl": 1,
|
|
"proxied": False,
|
|
},
|
|
"records": {},
|
|
}
|
|
|
|
for r in records:
|
|
name = r["name"].replace(".mrredportal.com", "")
|
|
|
|
data["records"][name] = {
|
|
"type": r["type"],
|
|
"content": r["content"],
|
|
"proxied": r["proxied"],
|
|
"ttl": r["ttl"],
|
|
}
|
|
|
|
with open("dns.yaml", "w") as f:
|
|
yaml.dump(data, f, sort_keys=True)
|
|
|
|
print("dns.yaml written.")
|
|
|