cf.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- https://icanhazip.com);
  6. echo "Checking VPS"
  7. apt install jq curl -y
  8. DOMAIN=kayyo.online
  9. sub=$(</dev/urandom tr -dc a-z0-9 | head -c4)
  10. SUB_DOMAIN=${sub}.kayyo.online
  11. WILDCARD=*.${sub}.kayyo.online
  12. CF_ID=5faktadunia@gmail.com
  13. CF_KEY=b2185bbc8fc43ebbf4132daf1eee48a32b5d3
  14. set -euo pipefail
  15. IP=$(wget -qO- https://icanhazip.com);
  16. echo "Updating DNS for ${SUB_DOMAIN}..."
  17. ZONE=$(curl -sLX GET "https://api.cloudflare.com/client/v4/zones?name=${DOMAIN}&status=active" \
  18. -H "X-Auth-Email: ${CF_ID}" \
  19. -H "X-Auth-Key: ${CF_KEY}" \
  20. -H "Content-Type: application/json" | jq -r .result[0].id)
  21. RECORD=$(curl -sLX GET "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records?name=${SUB_DOMAIN}" \
  22. -H "X-Auth-Email: ${CF_ID}" \
  23. -H "X-Auth-Key: ${CF_KEY}" \
  24. -H "Content-Type: application/json" | jq -r .result[0].id)
  25. if [[ "${#RECORD}" -le 10 ]]; then
  26. RECORD=$(curl -sLX POST "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records" \
  27. -H "X-Auth-Email: ${CF_ID}" \
  28. -H "X-Auth-Key: ${CF_KEY}" \
  29. -H "Content-Type: application/json" \
  30. --data '{"type":"A","name":"'${SUB_DOMAIN}'","content":"'${IP}'","ttl":120,"proxied":false}' | jq -r .result.id)
  31. fi
  32. RESULT=$(curl -sLX PUT "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}" \
  33. -H "X-Auth-Email: ${CF_ID}" \
  34. -H "X-Auth-Key: ${CF_KEY}" \
  35. -H "Content-Type: application/json" \
  36. --data '{"type":"A","name":"'${SUB_DOMAIN}'","content":"'${IP}'","ttl":120,"proxied":false}')
  37. echo "Host : $SUB_DOMAIN"
  38. echo $SUB_DOMAIN > /root/domain
  39. sleep 5
  40. echo "Updating DNS for ${WILDCARD}..."
  41. ZONE=$(curl -sLX GET "https://api.cloudflare.com/client/v4/zones?name=${DOMAIN}&status=active" \
  42. -H "X-Auth-Email: ${CF_ID}" \
  43. -H "X-Auth-Key: ${CF_KEY}" \
  44. -H "Content-Type: application/json" | jq -r .result[0].id)
  45. RECORD=$(curl -sLX GET "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records?name=${WILDCARD}" \
  46. -H "X-Auth-Email: ${CF_ID}" \
  47. -H "X-Auth-Key: ${CF_KEY}" \
  48. -H "Content-Type: application/json" | jq -r .result[0].id)
  49. if [[ "${#RECORD}" -le 10 ]]; then
  50. RECORD=$(curl -sLX POST "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records" \
  51. -H "X-Auth-Email: ${CF_ID}" \
  52. -H "X-Auth-Key: ${CF_KEY}" \
  53. -H "Content-Type: application/json" \
  54. --data '{"type":"A","name":"'${WILDCARD}'","content":"'${IP}'","ttl":120,"proxied":false}' | jq -r .result.id)
  55. fi
  56. RESULT=$(curl -sLX PUT "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}" \
  57. -H "X-Auth-Email: ${CF_ID}" \
  58. -H "X-Auth-Key: ${CF_KEY}" \
  59. -H "Content-Type: application/json" \
  60. --data '{"type":"A","name":"'${WILDCARD}'","content":"'${IP}'","ttl":120,"proxied":false}')
  61. echo "Host : $WILDCARD"
  62. echo $WILDCARD > /home/wildcard
  63. rm -f /root/cf.sh