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.

227 lines
7.1 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_world4you_info='World4You.com
  4. Site: World4You.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_world4you
  6. Options:
  7. WORLD4YOU_USERNAME Username
  8. WORLD4YOU_PASSWORD Password
  9. Issues: github.com/acmesh-official/acme.sh/issues/3269
  10. Author: Lorenz Stechauner <https://www.github.com/NerLOR>
  11. '
  12. WORLD4YOU_API="https://my.world4you.com/en"
  13. PAKETNR=''
  14. TLD=''
  15. RECORD=''
  16. ################ Public functions ################
  17. # Usage: dns_world4you_add <fqdn> <value>
  18. dns_world4you_add() {
  19. fqdn=$(echo "$1" | _lower_case)
  20. value="$2"
  21. _info "Using world4you to add record"
  22. _debug fulldomain "$fqdn"
  23. _debug txtvalue "$value"
  24. _login
  25. if [ "$?" != 0 ]; then
  26. return 1
  27. fi
  28. export _H1="Cookie: W4YSESSID=$sessid"
  29. form=$(_get "$WORLD4YOU_API/")
  30. _get_paketnr "$fqdn" "$form"
  31. paketnr="$PAKETNR"
  32. if [ -z "$paketnr" ]; then
  33. _err "Unable to parse paketnr"
  34. return 3
  35. fi
  36. _debug paketnr "$paketnr"
  37. export _H1="Cookie: W4YSESSID=$sessid"
  38. form=$(_get "$WORLD4YOU_API/$paketnr/dns")
  39. formiddp=$(echo "$form" | grep 'AddDnsRecordForm\[uniqueFormIdDP\]' | sed 's/^.*name="AddDnsRecordForm\[uniqueFormIdDP\]" value="\([^"]*\)".*$/\1/')
  40. form_token=$(echo "$form" | grep 'AddDnsRecordForm\[_token\]' | sed 's/^.*name="AddDnsRecordForm\[_token\]" value="\([^"]*\)".*$/\1/')
  41. if [ -z "$formiddp" ]; then
  42. _err "Unable to parse form"
  43. return 3
  44. fi
  45. _resethttp
  46. export ACME_HTTP_NO_REDIRECTS=1
  47. body="AddDnsRecordForm[name]=$RECORD&AddDnsRecordForm[dnsType][type]=TXT&AddDnsRecordForm[value]=$value&AddDnsRecordForm[uniqueFormIdDP]=$formiddp&AddDnsRecordForm[_token]=$form_token"
  48. _info "Adding record..."
  49. ret=$(_post "$body" "$WORLD4YOU_API/$paketnr/dns" '' POST 'application/x-www-form-urlencoded')
  50. _resethttp
  51. if _contains "$(_head_n 1 <"$HTTP_HEADER")" '302'; then
  52. res=$(_get "$WORLD4YOU_API/$paketnr/dns")
  53. if _contains "$res" "successfully"; then
  54. return 0
  55. else
  56. msg=$(echo "$res" | grep -A 15 'data-type="danger"' | grep "<h3[^>]*>[^<]" | sed 's/<[^>]*>//g' | sed 's/^\s*//g')
  57. if [ "$msg" = '' ]; then
  58. _err "Unable to add record: Unknown error"
  59. echo "$ret" >'error-01.html'
  60. echo "$res" >'error-02.html'
  61. _err "View error-01.html and error-02.html for debugging"
  62. else
  63. _err "Unable to add record: my.world4you.com: $msg"
  64. fi
  65. return 1
  66. fi
  67. else
  68. msg=$(echo "$ret" | grep '"form-error-message"' | sed 's/^.*<div class="form-error-message">\([^<]*\)<\/div>.*$/\1/')
  69. _err "Unable to add record: my.world4you.com: $msg"
  70. return 1
  71. fi
  72. }
  73. # Usage: dns_world4you_rm <fqdn> <value>
  74. dns_world4you_rm() {
  75. fqdn=$(echo "$1" | _lower_case)
  76. value="$2"
  77. _info "Using world4you to remove record"
  78. _debug fulldomain "$fqdn"
  79. _debug txtvalue "$value"
  80. _login
  81. if [ "$?" != 0 ]; then
  82. return 1
  83. fi
  84. export _H1="Cookie: W4YSESSID=$sessid"
  85. form=$(_get "$WORLD4YOU_API/")
  86. _get_paketnr "$fqdn" "$form"
  87. paketnr="$PAKETNR"
  88. if [ -z "$paketnr" ]; then
  89. _err "Unable to parse paketnr"
  90. return 3
  91. fi
  92. _debug paketnr "$paketnr"
  93. form=$(_get "$WORLD4YOU_API/$paketnr/dns")
  94. formiddp=$(echo "$form" | grep 'DeleteDnsRecordForm\[uniqueFormIdDP\]' | sed 's/^.*name="DeleteDnsRecordForm\[uniqueFormIdDP\]" value="\([^"]*\)".*$/\1/')
  95. form_token=$(echo "$form" | grep 'DeleteDnsRecordForm\[_token\]' | sed 's/^.*name="DeleteDnsRecordForm\[_token\]" value="\([^"]*\)".*$/\1/')
  96. if [ -z "$formiddp" ]; then
  97. _err "Unable to parse form"
  98. return 3
  99. fi
  100. recordid=$(printf "TXT:%s.:\"%s\"" "$fqdn" "$value" | _base64)
  101. _debug recordid "$recordid"
  102. _resethttp
  103. export ACME_HTTP_NO_REDIRECTS=1
  104. body="DeleteDnsRecordForm[recordId]=$recordid&DeleteDnsRecordForm[uniqueFormIdDP]=$formiddp&DeleteDnsRecordForm[_token]=$form_token"
  105. _info "Removing record..."
  106. ret=$(_post "$body" "$WORLD4YOU_API/$paketnr/dns/record/delete" '' POST 'application/x-www-form-urlencoded')
  107. _resethttp
  108. if _contains "$(_head_n 1 <"$HTTP_HEADER")" '302'; then
  109. res=$(_get "$WORLD4YOU_API/$paketnr/dns")
  110. if _contains "$res" "successfully"; then
  111. return 0
  112. else
  113. msg=$(echo "$res" | grep -A 15 'data-type="danger"' | grep "<h3[^>]*>[^<]" | sed 's/<[^>]*>//g' | sed 's/^\s*//g')
  114. if [ "$msg" = '' ]; then
  115. _err "Unable to remove record: Unknown error"
  116. echo "$ret" >'error-01.html'
  117. echo "$res" >'error-02.html'
  118. _err "View error-01.html and error-02.html for debugging"
  119. else
  120. _err "Unable to remove record: my.world4you.com: $msg"
  121. fi
  122. return 1
  123. fi
  124. else
  125. msg=$(echo "$ret" | grep "form-error-message" | sed 's/^.*<div class="form-error-message">\([^<]*\)<\/div>.*$/\1/')
  126. _err "Unable to remove record: my.world4you.com: $msg"
  127. return 1
  128. fi
  129. }
  130. ################ Private functions ################
  131. # Usage: _login
  132. _login() {
  133. WORLD4YOU_USERNAME="${WORLD4YOU_USERNAME:-$(_readaccountconf_mutable WORLD4YOU_USERNAME)}"
  134. WORLD4YOU_PASSWORD="${WORLD4YOU_PASSWORD:-$(_readaccountconf_mutable WORLD4YOU_PASSWORD)}"
  135. if [ -z "$WORLD4YOU_USERNAME" ] || [ -z "$WORLD4YOU_PASSWORD" ]; then
  136. WORLD4YOU_USERNAME=""
  137. WORLD4YOU_PASSWORD=""
  138. _err "You didn't specify world4you username and password yet."
  139. _err "Usage: export WORLD4YOU_USERNAME=<name>"
  140. _err "Usage: export WORLD4YOU_PASSWORD=<password>"
  141. return 1
  142. fi
  143. _saveaccountconf_mutable WORLD4YOU_USERNAME "$WORLD4YOU_USERNAME"
  144. _saveaccountconf_mutable WORLD4YOU_PASSWORD "$WORLD4YOU_PASSWORD"
  145. _resethttp
  146. export ACME_HTTP_NO_REDIRECTS=1
  147. page=$(_get "$WORLD4YOU_API/login")
  148. _resethttp
  149. if _contains "$(_head_n 1 <"$HTTP_HEADER")" '302'; then
  150. _info "Already logged in"
  151. _parse_sessid
  152. return 0
  153. fi
  154. _info "Logging in..."
  155. username="$WORLD4YOU_USERNAME"
  156. password="$WORLD4YOU_PASSWORD"
  157. csrf_token=$(echo "$page" | grep '_csrf_token' | sed 's/^.*<input[^>]*value=\"\([^"]*\)\".*$/\1/')
  158. _parse_sessid
  159. export _H1="Cookie: W4YSESSID=$sessid"
  160. export _H2="X-Requested-With: XMLHttpRequest"
  161. body="_username=$username&_password=$password&_csrf_token=$csrf_token"
  162. ret=$(_post "$body" "$WORLD4YOU_API/login" '' POST 'application/x-www-form-urlencoded')
  163. unset _H2
  164. _debug ret "$ret"
  165. if _contains "$ret" "\"success\":true"; then
  166. _info "Successfully logged in"
  167. _parse_sessid
  168. else
  169. msg=$(echo "$ret" | sed 's/^.*"message":"\([^\"]*\)".*$/\1/')
  170. _err "Unable to log in: my.world4you.com: $msg"
  171. return 1
  172. fi
  173. }
  174. # Usage: _get_paketnr <fqdn> <form>
  175. _get_paketnr() {
  176. fqdn="$1"
  177. form="$2"
  178. domains=$(echo "$form" | grep '<ul class="nav header-paket-list">' | sed 's/<li/\n<li/g' | sed 's/<[^>]*>/ /g' | sed 's/^.*>\([^>]*\)$/\1/')
  179. domain=''
  180. for domain in $domains; do
  181. if _contains "$fqdn" "$domain\$"; then
  182. break
  183. fi
  184. domain=''
  185. done
  186. if [ -z "$domain" ]; then
  187. return 1
  188. fi
  189. TLD="$domain"
  190. _debug domain "$domain"
  191. RECORD=$(echo "$fqdn" | cut -c"1-$((${#fqdn} - ${#TLD} - 1))")
  192. PAKETNR=$(echo "$domains" | grep "$domain" | sed 's/^[^,]*, *\([0-9]*\).*$/\1/')
  193. return 0
  194. }
  195. # Usage: _parse_sessid
  196. _parse_sessid() {
  197. sessid=$(grep 'W4YSESSID' <"$HTTP_HEADER" | _tail_n 1 | sed 's/^.*W4YSESSID=\([^;]*\);.*$/\1/')
  198. }