cfh.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- ifconfig.me/ip);
  6. source /root/mail.conf
  7. DOMAIN=$domain
  8. CF_ID=$email
  9. CF_KEY=$key
  10. set -euo pipefail
  11. read -p "Masukan Subdomain Anda :" sub
  12. read -p "Masukan Ip BUG :" IP
  13. echo "Updating DNS for ${sub}..."
  14. ZONE=$(curl -sLX GET "https://api.cloudflare.com/client/v4/zones?name=${DOMAIN}&status=active" \
  15. -H "X-Auth-Email: ${CF_ID}" \
  16. -H "X-Auth-Key: ${CF_KEY}" \
  17. -H "Content-Type: application/json" | jq -r .result[0].id)
  18. RECORD=$(curl -sLX GET "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records?name=${sub}" \
  19. -H "X-Auth-Email: ${CF_ID}" \
  20. -H "X-Auth-Key: ${CF_KEY}" \
  21. -H "Content-Type: application/json" | jq -r .result[0].id)
  22. if [[ "${#RECORD}" -le 10 ]]; then
  23. RECORD=$(curl -sLX POST "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records" \
  24. -H "X-Auth-Email: ${CF_ID}" \
  25. -H "X-Auth-Key: ${CF_KEY}" \
  26. -H "Content-Type: application/json" \
  27. --data '{"type":"A","name":"'${sub}'","content":"'${IP}'","ttl":120,"proxied":false}' | jq -r .result.id)
  28. fi
  29. RESULT=$(curl -sLX PUT "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}" \
  30. -H "X-Auth-Email: ${CF_ID}" \
  31. -H "X-Auth-Key: ${CF_KEY}" \
  32. -H "Content-Type: application/json" \
  33. --data '{"type":"A","name":"'${sub}'","content":"'${IP}'","ttl":120,"proxied":false}')
  34. echo "DONE...!"