Added files

This commit is contained in:
Phil 2024-06-22 21:58:00 +01:00
parent d3d3c0f5f0
commit abd07f8a4d
3 changed files with 70 additions and 0 deletions

17
Cloudflare/README.md Normal file
View File

@ -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
```

9
Cloudflare/config.conf Normal file
View File

@ -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

View File

@ -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