From abd07f8a4d52f7097a35470f2568e63aea9b8cc1 Mon Sep 17 00:00:00 2001 From: Phil Date: Sat, 22 Jun 2024 21:58:00 +0100 Subject: [PATCH] Added files --- Cloudflare/README.md | 17 +++++++++++ Cloudflare/config.conf | 9 ++++++ Cloudflare/export_dns_cloudflare.sh | 44 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 Cloudflare/README.md create mode 100644 Cloudflare/config.conf create mode 100644 Cloudflare/export_dns_cloudflare.sh diff --git a/Cloudflare/README.md b/Cloudflare/README.md new file mode 100644 index 0000000..a97c7fe --- /dev/null +++ b/Cloudflare/README.md @@ -0,0 +1,17 @@ +# Export_DNS +## Cloudflare + +Add your Cloudflare API key here. The key need to be able to read any DNS zones that you list below +``` +API_KEY=your_single_api_key +``` + +Add the Zone ID to the zone_id_value section and set the site_name_value to the name of the domain. This will be the name of the file that is created with the DNS infomation. +``` +ZONE_ID_1=zone_id_value_1 +SITE_NAME_1=site_name_value_1 + +ZONE_ID_2=zone_id_value_2 +SITE_NAME_2=site_name_value_2 +``` + diff --git a/Cloudflare/config.conf b/Cloudflare/config.conf new file mode 100644 index 0000000..7fc44e4 --- /dev/null +++ b/Cloudflare/config.conf @@ -0,0 +1,9 @@ +API_KEY=your_single_api_key + +ZONE_ID_1=zone_id_value_1 +SITE_NAME_1=site_name_value_1 + +ZONE_ID_2=zone_id_value_2 +SITE_NAME_2=site_name_value_2 + +# Add more entries as needed diff --git a/Cloudflare/export_dns_cloudflare.sh b/Cloudflare/export_dns_cloudflare.sh new file mode 100644 index 0000000..b70b361 --- /dev/null +++ b/Cloudflare/export_dns_cloudflare.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Source the configuration file +source config.conf + +# Create the export folder if it doesn't exist +EXPORT_FOLDER="export" +mkdir -p "$EXPORT_FOLDER" + +# Function to export DNS records +export_dns_records() { + local ZONE_ID=$1 + local SITE_NAME=$2 + + # Get current date and time + TIMESTAMP=$(date +"%Y%m%d_%H%M%S") + + # Define the output filename with timestamp + OUTPUT_FILE="$EXPORT_FOLDER/${SITE_NAME}_$TIMESTAMP" + + # Perform the curl request and save the output + curl -X GET --url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/export \ + -H "Authorization: Bearer $API_KEY" \ + -H "Content-Type: application/json" | tee "$OUTPUT_FILE" +} + +# Loop through the configuration entries +i=1 +while true; do + eval "ZONE_ID=\${ZONE_ID_$i}" + eval "SITE_NAME=\${SITE_NAME_$i}" + + # Break the loop if no more entries + if [ -z "$ZONE_ID" ] || [ -z "$SITE_NAME" ]; then + break + fi + + # Export DNS records for the current entry + export_dns_records "$ZONE_ID" "$SITE_NAME" + + # Increment the counter + ((i++)) +done +