forked from tbaldur/cyberpanel-mods
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloudflare_to_powerdns.sh
40 lines (31 loc) · 1.17 KB
/
cloudflare_to_powerdns.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# TODO: Add arguments option to api_key, domain and domain_names so you don't need to edit the file
api_key=qwerty1234567890asdfg
domain_names=( "domain1.com" "domain2.com")
for domain in "${domain_names[@]}"
do
#Get zone ID from domain
zone_id=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$domain&status=active" \
-H "X-Auth-Email: $email" \
-H "X-Auth-Key: $api_key" \
-H "Content-Type: application/json" | \
jq -r '.result[].id')
#Export dns zone
(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/export" \
-H "X-Auth-Email: $email" \
-H "X-Auth-Key: $api_key" \
-H "Content-Type: application/json")>"$domain".txt
#Get zone from txt into sql
(zone2sql --gmysql --zone="$domain".txt --zone-name="$domain")>"$domain".sql
#Erase first line that contains the domain from sql file
sed -i '1d' "$domain".sql
#Read mysql password
mysql_password=$(cat /etc/cyberpanel/mysqlPassword)
#Delete exiting records from domain
#Runs query to database
mysql -u root -p"$mysql_password" cyberpanel < "$domain".sql
#Cleans temporary files
rm -f "$domain".txt
rm -f "$domain".sql
done