You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.2 KiB

  1. # inside url we need domain, username and password
  2. [ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'"
  3. [ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
  4. [ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
  5. local urlCp='http://cp.cnkuai.cn/'
  6. local urlLogin='http://cp.cnkuai.cn/userlogin.asp'
  7. local urlCaptcha='http://cp.cnkuai.cn/inc/image.asp'
  8. local urlDnsA='http://cp.cnkuai.cn/dns_a.asp'
  9. local urlDnsAAAA='http://cp.cnkuai.cn/dns_ipv6.asp'
  10. local urlDnsSave='http://cp.cnkuai.cn/dns_save.asp'
  11. getPixel(){
  12. local filename=$1
  13. local x=$(($2*3))
  14. local y=$(($3*3))
  15. local width=48
  16. hexdump -s "$((x+width*y))" -n 3 -e '3/1 "%02X"' "$filename"
  17. }
  18. captchaChar(){
  19. local filename=$1
  20. local xoffset=$2
  21. if [ "$(getPixel "$filename" $((xoffset+2)) 5)" = '000000' ]; then
  22. echo '1'
  23. elif [ "$(getPixel "$filename" $((xoffset+5)) 7)" = '000000' ]; then
  24. echo '2'
  25. elif [ "$(getPixel "$filename" $((xoffset+4)) 3)" = '000000' ]; then
  26. echo '4'
  27. elif [ "$(getPixel "$filename" $((xoffset+6)) 4)" = '000000' ]; then
  28. echo '7'
  29. elif [ "$(getPixel "$filename" $((xoffset+5)) 8)" = '000000' ]; then
  30. echo '8'
  31. elif [ "$(getPixel "$filename" $((xoffset+6)) 8)" = '000000' ]; then
  32. echo '9'
  33. elif [ "$(getPixel "$filename" $((xoffset+5)) 6)" = '000000' ]; then
  34. echo '3'
  35. elif [ "$(getPixel "$filename" $((xoffset+0)) 4)" = '000000' ]; then
  36. echo '5'
  37. elif [ "$(getPixel "$filename" $((xoffset+1)) 5)" = '000000' ]; then
  38. echo '6'
  39. else
  40. echo '0'
  41. fi
  42. }
  43. captcha(){
  44. local str
  45. str=$(captchaChar "$1" 9)
  46. str=$str$(captchaChar "$1" 18)
  47. str=$str$(captchaChar "$1" 26)
  48. str=$str$(captchaChar "$1" 35)
  49. echo "$str"
  50. }
  51. #clean
  52. rm /tmp/cnkuai.*
  53. #login to cnkuai dns cp
  54. curl -c '/tmp/cnkuai.cookiejar' "$urlCaptcha" | gif2rgb > /tmp/cnkuai.rgb || return 1
  55. yzm=$(captcha "/tmp/cnkuai.rgb")
  56. curl -b '/tmp/cnkuai.cookiejar' -c '/tmp/cnkuai.cookiejar' -H "Content-Type: application/x-www-form-urlencoded" -H "Referer: $urlCp" -d "userid=$URL_USER&password=$URL_PASS&yzm=$yzm&B1=%C8%B7%C8%CF%B5%C7%C2%BD&lx=0&userlx=3" -X POST "$urlLogin" > /dev/null || return 1
  57. if [ "$use_ipv6" -eq 0 ]; then
  58. curl -b '/tmp/cnkuai.cookiejar' -c '/tmp/cnkuai.cookiejar' "$urlDnsA" > /tmp/cnkuai.html || return 1
  59. else
  60. curl -b '/tmp/cnkuai.cookiejar' -c '/tmp/cnkuai.cookiejar' "$urlDnsAAAA" > /tmp/cnkuai.html || return 1
  61. fi
  62. local domainline
  63. domainline=$(awk "/<td>$domain<\/td>/{ print NR; exit }" /tmp/cnkuai.html)
  64. local domainid
  65. domainid=$(awk "NR==$((domainline+3))" /tmp/cnkuai.html | sed 's/^.*name=\x27domainid\x27 value="//g' | sed 's/".*$//g')
  66. local dnslistid
  67. dnslistid=$(awk "NR==$((domainline+3))" /tmp/cnkuai.html | sed 's/^.*name=\x27dnslistid\x27 value="//g' | sed 's/".*$//g')
  68. local data
  69. if [ "$use_ipv6" -eq 0 ]; then
  70. data="T2=$__IP&T3=120&act=dns_a_edit&domainid=$domainid&dnslistid=$dnslistid&B1=%D0%DE%B8%C4"
  71. else
  72. data="T2=$__IP&T3=120&act=dns_ipv6_edit&domainid=$domainid&dnslistid=$dnslistid&B1=%D0%DE%B8%C4"
  73. fi
  74. curl -b '/tmp/cnkuai.cookiejar' -c '/tmp/cnkuai.cookiejar' -H "Content-Type: application/x-www-form-urlencoded" -H "Referer: $urlDnsA" -d "$data" -X POST "$urlDnsSave" > /dev/null || return 1
  75. return 0