cf2.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. apt install jq curl -y
  6. DOMAIN=vpnku.cf
  7. sub=$(</dev/urandom tr -dc a-z0-9 | head -c4)
  8. SUB_DOMAIN=${sub}.vpnku.cf
  9. CF_ID=irwan@aidan.my
  10. CF_KEY=8861b44469da6162624ba9fd17066771
  11. set -euo pipefail
  12. IP=$(wget -qO- icanhazip.com);
  13. echo "Updating DNS for ${SUB_DOMAIN}..."
  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_DOMAIN}" \
  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_DOMAIN}'","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_DOMAIN}'","content":"'${IP}'","ttl":120,"proxied":false}')
  34. echo "Host : $SUB_DOMAIN"
  35. echo $SUB_DOMAIN > /root/domain
  36. rm -f /root/cf.sh