- Integrated additional Zod validation schemas for improved input validation across various API routes. - Updated existing services to utilize the new validation middleware, ensuring better request integrity. - Improved error handling mechanisms in key services to provide clearer feedback on request failures. - Conducted code cleanup to enhance readability and maintainability of the API services.
125 lines
4.0 KiB
Bash
Executable File
125 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Cloudflare DNS Import Script
|
|
# Bulk imports DNS records for d-bis.org zone
|
|
#
|
|
# Prerequisites:
|
|
# - Cloudflare API token with DNS:Edit permissions
|
|
# - jq installed (https://stedolan.github.io/jq/)
|
|
# - curl installed
|
|
#
|
|
# Usage:
|
|
# export CLOUDFLARE_API_TOKEN="your-api-token"
|
|
# export CLOUDFLARE_ZONE_ID="your-zone-id"
|
|
# ./cloudflare-dns-import.sh
|
|
#
|
|
|
|
set -e
|
|
|
|
# Configuration
|
|
ZONE_NAME="d-bis.org"
|
|
API_BASE="https://api.cloudflare.com/client/v4"
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Check prerequisites
|
|
if [ -z "$CLOUDFLARE_API_TOKEN" ]; then
|
|
echo -e "${RED}Error: CLOUDFLARE_API_TOKEN environment variable not set${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$CLOUDFLARE_ZONE_ID" ]; then
|
|
echo -e "${YELLOW}Zone ID not set, fetching from Cloudflare...${NC}"
|
|
ZONE_ID=$(curl -s -X GET "${API_BASE}/zones?name=${ZONE_NAME}" \
|
|
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
|
|
-H "Content-Type: application/json" | jq -r '.result[0].id')
|
|
|
|
if [ "$ZONE_ID" == "null" ] || [ -z "$ZONE_ID" ]; then
|
|
echo -e "${RED}Error: Zone ${ZONE_NAME} not found${NC}"
|
|
exit 1
|
|
fi
|
|
echo -e "${GREEN}Found Zone ID: ${ZONE_ID}${NC}"
|
|
else
|
|
ZONE_ID="$CLOUDFLARE_ZONE_ID"
|
|
fi
|
|
|
|
# Function to add DNS record
|
|
add_dns_record() {
|
|
local type=$1
|
|
local name=$2
|
|
local content=$3
|
|
local ttl=${4:-1} # 1 = Auto
|
|
local proxied=${5:-true}
|
|
|
|
echo -n "Adding ${type} record for ${name}... "
|
|
|
|
response=$(curl -s -X POST "${API_BASE}/zones/${ZONE_ID}/dns_records" \
|
|
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
--data "{
|
|
\"type\": \"${type}\",
|
|
\"name\": \"${name}\",
|
|
\"content\": \"${content}\",
|
|
\"ttl\": ${ttl},
|
|
\"proxied\": ${proxied}
|
|
}")
|
|
|
|
success=$(echo "$response" | jq -r '.success')
|
|
|
|
if [ "$success" == "true" ]; then
|
|
echo -e "${GREEN}✓${NC}"
|
|
else
|
|
errors=$(echo "$response" | jq -r '.errors[]?.message' | tr '\n' ' ')
|
|
echo -e "${RED}✗${NC}"
|
|
echo -e " ${RED}Error: ${errors}${NC}"
|
|
fi
|
|
}
|
|
|
|
echo -e "${GREEN}=== Cloudflare DNS Import Script ===${NC}"
|
|
echo -e "Zone: ${ZONE_NAME}"
|
|
echo -e "Zone ID: ${ZONE_ID}"
|
|
echo ""
|
|
|
|
# Production A Records
|
|
echo -e "${YELLOW}--- Production A Records ---${NC}"
|
|
add_dns_record "A" "api" "192.0.2.1" 1 true
|
|
add_dns_record "A" "mappings.api" "192.0.2.2" 1 true
|
|
add_dns_record "A" "webhooks.api" "192.0.2.3" 1 true
|
|
add_dns_record "A" "orchestrator.api" "192.0.2.4" 1 true
|
|
add_dns_record "A" "packets.api" "192.0.2.5" 1 true
|
|
|
|
# Production AAAA Records
|
|
echo -e "${YELLOW}--- Production AAAA Records ---${NC}"
|
|
add_dns_record "AAAA" "api" "2001:db8::1" 1 true
|
|
add_dns_record "AAAA" "mappings.api" "2001:db8::2" 1 true
|
|
add_dns_record "AAAA" "webhooks.api" "2001:db8::3" 1 true
|
|
add_dns_record "AAAA" "orchestrator.api" "2001:db8::4" 1 true
|
|
add_dns_record "AAAA" "packets.api" "2001:db8::5" 1 true
|
|
|
|
# Staging A Records
|
|
echo -e "${YELLOW}--- Staging A Records ---${NC}"
|
|
add_dns_record "A" "api-staging" "192.0.2.10" 1 true
|
|
add_dns_record "A" "mappings.api-staging" "192.0.2.11" 1 true
|
|
add_dns_record "A" "webhooks.api-staging" "192.0.2.12" 1 true
|
|
add_dns_record "A" "orchestrator.api-staging" "192.0.2.13" 1 true
|
|
add_dns_record "A" "packets.api-staging" "192.0.2.14" 1 true
|
|
|
|
# Staging AAAA Records
|
|
echo -e "${YELLOW}--- Staging AAAA Records ---${NC}"
|
|
add_dns_record "AAAA" "api-staging" "2001:db8::10" 1 true
|
|
add_dns_record "AAAA" "mappings.api-staging" "2001:db8::11" 1 true
|
|
add_dns_record "AAAA" "webhooks.api-staging" "2001:db8::12" 1 true
|
|
add_dns_record "AAAA" "orchestrator.api-staging" "2001:db8::13" 1 true
|
|
add_dns_record "AAAA" "packets.api-staging" "2001:db8::14" 1 true
|
|
|
|
echo ""
|
|
echo -e "${GREEN}=== Import Complete ===${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}Note: Remember to update IP addresses with actual production IPs!${NC}"
|
|
echo -e "${YELLOW}Current IPs are placeholders (192.0.2.x and 2001:db8::x)${NC}"
|
|
|