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.

139 lines
5.1 KiB

6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #!/usr/bin/env sh
  2. # -*- mode: sh; tab-width: 2; indent-tabs-mode: s; coding: utf-8 -*-
  3. # one.com ui wrapper for acme.sh
  4. # Author: github: @diseq
  5. # Created: 2019-02-17
  6. #
  7. # export ONECOM_User="username"
  8. # export ONECOM_Password="password"
  9. #
  10. # Usage:
  11. # acme.sh --issue --dns dns_one -d example.com
  12. #
  13. # only single domain supported atm
  14. dns_one_add() {
  15. mysubdomain=$(printf -- "%s" "$1" | rev | cut -d"." -f3- | rev)
  16. mydomain=$(printf -- "%s" "$1" | rev | cut -d"." -f1-2 | rev)
  17. txtvalue=$2
  18. # get credentials
  19. ONECOM_User="${ONECOM_User:-$(_readaccountconf_mutable ONECOM_User)}"
  20. ONECOM_Password="${ONECOM_Password:-$(_readaccountconf_mutable ONECOM_Password)}"
  21. if [ -z "$ONECOM_User" ] || [ -z "$ONECOM_Password" ]; then
  22. ONECOM_User=""
  23. ONECOM_Password=""
  24. _err "You didn't specify a one.com username and password yet."
  25. _err "Please create the key and try again."
  26. return 1
  27. fi
  28. #save the api key and email to the account conf file.
  29. _saveaccountconf_mutable ONECOM_User "$ONECOM_User"
  30. _saveaccountconf_mutable ONECOM_Password "$ONECOM_Password"
  31. # Login with user and password
  32. postdata="loginDomain=true"
  33. postdata="$postdata&displayUsername=$ONECOM_User"
  34. postdata="$postdata&username=$ONECOM_User"
  35. postdata="$postdata&targetDomain=$mydomain"
  36. postdata="$postdata&password1=$ONECOM_Password"
  37. postdata="$postdata&loginTarget="
  38. #_debug postdata "$postdata"
  39. response="$(_post "$postdata" "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded")"
  40. #_debug response "$response"
  41. JSESSIONID="$(grep "JSESSIONID" "$HTTP_HEADER" | grep "^[Ss]et-[Cc]ookie:" | _tail_n 1 | _egrep_o 'JSESSIONID=[^;]*;' | tr -d ';')"
  42. _debug jsessionid "$JSESSIONID"
  43. export _H1="Cookie: ${JSESSIONID}"
  44. # get entries
  45. response="$(_get "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records")"
  46. _debug response "$response"
  47. CSRF_G_TOKEN="$(grep "CSRF_G_TOKEN=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'CSRF_G_TOKEN=[^;]*;' | tr -d ';')"
  48. export _H2="Cookie: ${CSRF_G_TOKEN}"
  49. # Update the IP address for domain entry
  50. postdata="{\"type\":\"dns_custom_records\",\"attributes\":{\"priority\":0,\"ttl\":600,\"type\":\"TXT\",\"prefix\":\"$mysubdomain\",\"content\":\"$txtvalue\"}}"
  51. _debug postdata "$postdata"
  52. response="$(_post "$postdata" "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records" "" "POST" "application/json")"
  53. response="$(echo "$response" | _normalizeJson)"
  54. _debug response "$response"
  55. id=$(echo "$response" | sed -n "s/{\"result\":{\"data\":{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$mysubdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}}},\"metadata\":null}/\1/p")
  56. if [ -z "$id" ]; then
  57. _err "Add txt record error."
  58. return 1
  59. else
  60. _info "Added, OK ($id)"
  61. return 0
  62. fi
  63. }
  64. dns_one_rm() {
  65. mysubdomain=$(printf -- "%s" "$1" | rev | cut -d"." -f3- | rev)
  66. mydomain=$(printf -- "%s" "$1" | rev | cut -d"." -f1-2 | rev)
  67. txtvalue=$2
  68. # get credentials
  69. ONECOM_User="${ONECOM_User:-$(_readaccountconf_mutable ONECOM_User)}"
  70. ONECOM_Password="${ONECOM_Password:-$(_readaccountconf_mutable ONECOM_Password)}"
  71. if [ -z "$ONECOM_User" ] || [ -z "$ONECOM_Password" ]; then
  72. ONECOM_User=""
  73. ONECOM_Password=""
  74. _err "You didn't specify a one.com username and password yet."
  75. _err "Please create the key and try again."
  76. return 1
  77. fi
  78. # Login with user and password
  79. postdata="loginDomain=true"
  80. postdata="$postdata&displayUsername=$ONECOM_User"
  81. postdata="$postdata&username=$ONECOM_User"
  82. postdata="$postdata&targetDomain=$mydomain"
  83. postdata="$postdata&password1=$ONECOM_Password"
  84. postdata="$postdata&loginTarget="
  85. response="$(_post "$postdata" "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded")"
  86. #_debug response "$response"
  87. JSESSIONID="$(grep "JSESSIONID" "$HTTP_HEADER" | grep "^[Ss]et-[Cc]ookie:" | _tail_n 1 | _egrep_o 'JSESSIONID=[^;]*;' | tr -d ';')"
  88. _debug jsessionid "$JSESSIONID"
  89. export _H1="Cookie: ${JSESSIONID}"
  90. # get entries
  91. response="$(_get "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records")"
  92. response="$(echo "$response" | _normalizeJson)"
  93. _debug response "$response"
  94. CSRF_G_TOKEN="$(grep "CSRF_G_TOKEN=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'CSRF_G_TOKEN=[^;]*;' | tr -d ';')"
  95. export _H2="Cookie: ${CSRF_G_TOKEN}"
  96. id=$(printf -- "%s" "$response" | sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$mysubdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}.*/\1/p")
  97. if [ -z "$id" ]; then
  98. _err "Txt record not found."
  99. return 1
  100. fi
  101. # delete entry
  102. response="$(_post "$postdata" "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records/$id" "" "DELETE" "application/json")"
  103. response="$(echo "$response" | _normalizeJson)"
  104. _debug response "$response"
  105. if [ "$response" = '{"result":null,"metadata":null}' ]; then
  106. _info "Removed, OK"
  107. return 0
  108. else
  109. _err "Removing txt record error."
  110. return 1
  111. fi
  112. }