dns_efficientip.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_efficientip_info='efficientip.com
  4. Site: https://efficientip.com/
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_efficientip
  6. Options:
  7. EfficientIP_Creds HTTP Basic Authentication credentials. E.g. "username:password"
  8. EfficientIP_Server EfficientIP SOLIDserver Management IP address or FQDN.
  9. EfficientIP_DNS_Name Name of the DNS smart or server hosting the zone. Optional.
  10. EfficientIP_View Name of the DNS view hosting the zone. Optional.
  11. OptionsAlt:
  12. EfficientIP_Token_Key Alternative API token key, prefered over basic authentication.
  13. EfficientIP_Token_Secret Alternative API token secret, required when using a token key.
  14. EfficientIP_Server EfficientIP SOLIDserver Management IP address or FQDN.
  15. EfficientIP_DNS_Name Name of the DNS smart or server hosting the zone. Optional.
  16. EfficientIP_View Name of the DNS view hosting the zone. Optional.
  17. Issues: github.com/acmesh-official/acme.sh/issues/6325
  18. Author: EfficientIP-Labs <[email protected]>
  19. '
  20. dns_efficientip_add() {
  21. fulldomain=$1
  22. txtvalue=$2
  23. _info "Using EfficientIP API"
  24. _debug fulldomain "$fulldomain"
  25. _debug txtvalue "$txtvalue"
  26. if { [ -z "${EfficientIP_Creds}" ] && { [ -z "${EfficientIP_Token_Key}" ] || [ -z "${EfficientIP_Token_Secret}" ]; }; } || [ -z "${EfficientIP_Server}" ]; then
  27. EfficientIP_Creds=""
  28. EfficientIP_Token_Key=""
  29. EfficientIP_Token_Secret=""
  30. EfficientIP_Server=""
  31. _err "You didn't specify any EfficientIP credentials or token or server (EfficientIP_Creds; EfficientIP_Token_Key; EfficientIP_Token_Secret; EfficientIP_Server)."
  32. _err "Please set them via EXPORT EfficientIP_Creds=username:password or EXPORT EfficientIP_server=ip/hostname"
  33. _err "or if you want to use Token instead EXPORT EfficientIP_Token_Key=yourkey"
  34. _err "and EXPORT EfficientIP_Token_Secret=yoursecret"
  35. _err "then try again."
  36. return 1
  37. fi
  38. if [ -z "${EfficientIP_DNS_Name}" ]; then
  39. EfficientIP_DNS_Name=""
  40. fi
  41. EfficientIP_DNSNameEncoded=$(printf "%b" "${EfficientIP_DNS_Name}" | _url_encode)
  42. if [ -z "${EfficientIP_View}" ]; then
  43. EfficientIP_View=""
  44. fi
  45. EfficientIP_ViewEncoded=$(printf "%b" "${EfficientIP_View}" | _url_encode)
  46. _saveaccountconf EfficientIP_Creds "${EfficientIP_Creds}"
  47. _saveaccountconf EfficientIP_Token_Key "${EfficientIP_Token_Key}"
  48. _saveaccountconf EfficientIP_Token_Secret "${EfficientIP_Token_Secret}"
  49. _saveaccountconf EfficientIP_Server "${EfficientIP_Server}"
  50. _saveaccountconf EfficientIP_DNS_Name "${EfficientIP_DNS_Name}"
  51. _saveaccountconf EfficientIP_View "${EfficientIP_View}"
  52. export _H1="Accept-Language:en-US"
  53. baseurlnObject="https://${EfficientIP_Server}/rest/dns_rr_add?rr_type=TXT&rr_ttl=300&rr_name=${fulldomain}&rr_value1=${txtvalue}"
  54. if [ "${EfficientIP_DNSNameEncoded}" != "" ]; then
  55. baseurlnObject="${baseurlnObject}&dns_name=${EfficientIP_DNSNameEncoded}"
  56. fi
  57. if [ "${EfficientIP_ViewEncoded}" != "" ]; then
  58. baseurlnObject="${baseurlnObject}&dnsview_name=${EfficientIP_ViewEncoded}"
  59. fi
  60. if [ -z "${EfficientIP_Token_Secret}" ] || [ -z "${EfficientIP_Token_Key}" ]; then
  61. EfficientIP_CredsEncoded=$(printf "%b" "${EfficientIP_Creds}" | _base64)
  62. export _H2="Authorization: Basic ${EfficientIP_CredsEncoded}"
  63. else
  64. TS=$(date +%s)
  65. Sig=$(printf "%b\n$TS\nPOST\n$baseurlnObject" "${EfficientIP_Token_Secret}" | _digest sha3-256 hex)
  66. EfficientIP_CredsEncoded=$(printf "%b:%b" "${EfficientIP_Token_Key}" "$Sig")
  67. export _H2="Authorization: SDS ${EfficientIP_CredsEncoded}"
  68. export _H3="X-SDS-TS: ${TS}"
  69. fi
  70. result="$(_post "" "${baseurlnObject}" "" "POST")"
  71. if [ "$(echo "${result}" | _egrep_o "ret_oid")" ]; then
  72. _info "DNS record successfully created"
  73. return 0
  74. else
  75. _err "Error creating DNS record"
  76. _err "${result}"
  77. return 1
  78. fi
  79. }
  80. dns_efficientip_rm() {
  81. fulldomain=$1
  82. txtvalue=$2
  83. _info "Using EfficientIP API"
  84. _debug fulldomain "${fulldomain}"
  85. _debug txtvalue "${txtvalue}"
  86. EfficientIP_ViewEncoded=$(printf "%b" "${EfficientIP_View}" | _url_encode)
  87. EfficientIP_DNSNameEncoded=$(printf "%b" "${EfficientIP_DNS_Name}" | _url_encode)
  88. EfficientIP_CredsEncoded=$(printf "%b" "${EfficientIP_Creds}" | _base64)
  89. export _H1="Accept-Language:en-US"
  90. baseurlnObject="https://${EfficientIP_Server}/rest/dns_rr_delete?rr_type=TXT&rr_name=$fulldomain&rr_value1=$txtvalue"
  91. if [ "${EfficientIP_DNSNameEncoded}" != "" ]; then
  92. baseurlnObject="${baseurlnObject}&dns_name=${EfficientIP_DNSNameEncoded}"
  93. fi
  94. if [ "${EfficientIP_ViewEncoded}" != "" ]; then
  95. baseurlnObject="${baseurlnObject}&dnsview_name=${EfficientIP_ViewEncoded}"
  96. fi
  97. if [ -z "$EfficientIP_Token_Secret" ] || [ -z "$EfficientIP_Token_Key" ]; then
  98. EfficientIP_CredsEncoded=$(printf "%b" "${EfficientIP_Creds}" | _base64)
  99. export _H2="Authorization: Basic $EfficientIP_CredsEncoded"
  100. else
  101. TS=$(date +%s)
  102. Sig=$(printf "%b\n$TS\nDELETE\n${baseurlnObject}" "${EfficientIP_Token_Secret}" | _digest sha3-256 hex)
  103. EfficientIP_CredsEncoded=$(printf "%b:%b" "${EfficientIP_Token_Key}" "$Sig")
  104. export _H2="Authorization: SDS ${EfficientIP_CredsEncoded}"
  105. export _H3="X-SDS-TS: $TS"
  106. fi
  107. result="$(_post "" "${baseurlnObject}" "" "DELETE")"
  108. if [ "$(echo "${result}" | _egrep_o "ret_oid")" ]; then
  109. _info "DNS Record successfully deleted"
  110. return 0
  111. else
  112. _err "Error deleting DNS record"
  113. _err "${result}"
  114. return 1
  115. fi
  116. }