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.

128 lines
4.3 KiB

1 month ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_fmdns_info='facileManager DNS API
  4. API for self-hosted facileManager DNS github.com/WillyXJ/facileManager
  5. Site: github.com/gianlucagiacometti/proxmox-acme-facilemanager
  6. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_fmdns
  7. Options:
  8. FMDNS_API_ENDPOINT API Endpoint. Web address of the API endpoint.
  9. FMDNS_API_TOKEN API Token.
  10. FMDNS_API_DOMAIN_ID Domain ID. Domain ID in your facileManager database.
  11. Issues: github.com/gianlucagiacometti/proxmox-acme-facilemanager
  12. Author: Gianluca Giacometti <php@gianlucagiacometti.it>
  13. '
  14. ##################### Public functions #####################
  15. dns_fmdns_add() {
  16. fulldomain="${1}"
  17. txtvalue="${2}"
  18. FMDNS_API_TOKEN="${FMDNS_API_TOKEN:-$(_readaccountconf_mutable FMDNS_API_TOKEN)}"
  19. # Check if API token exists
  20. if [ -z "$FMDNS_API_TOKEN" ]; then
  21. FMDNS_API_TOKEN=""
  22. _err "You did not specify facileManager API token."
  23. _err "Please export FMDNS_API_TOKEN and try again."
  24. return 1
  25. fi
  26. FMDNS_API_ENDPOINT="${FMDNS_API_ENDPOINT:-$(_readaccountconf_mutable FMDNS_API_ENDPOINT)}"
  27. # Check if API endpoint exists
  28. if [ -z "$FMDNS_API_ENDPOINT" ]; then
  29. FMDNS_API_ENDPOINT=""
  30. _err "You did not specify facileManager API endpoint."
  31. _err "Please export FMDNS_API_ENDPOINT and try again."
  32. return 1
  33. fi
  34. FMDNS_API_DOMAIN_ID="${FMDNS_API_DOMAIN_ID:-$(_readaccountconf_mutable FMDNS_API_DOMAIN_ID)}"
  35. # Check if API domain id exists
  36. if [ -z "$FMDNS_API_DOMAIN_ID" ]; then
  37. FMDNS_API_DOMAIN_ID=""
  38. _err "You did not specify facileManager API domain id."
  39. _err "Please export FMDNS_API_DOMAIN_ID and try again."
  40. return 1
  41. fi
  42. _debug "Calling: _fmDnsApi_addRecord() '${fulldomain}' '${txtvalue}'"
  43. _fmDnsApi_addRecord
  44. return $?
  45. }
  46. dns_fmdns_rm() {
  47. fulldomain="${1}"
  48. txtvalue="${2}"
  49. FMDNS_API_TOKEN="${FMDNS_API_TOKEN:-$(_readaccountconf_mutable FMDNS_API_TOKEN)}"
  50. # Check if API token exists
  51. if [ -z "$FMDNS_API_TOKEN" ]; then
  52. FMDNS_API_TOKEN=""
  53. _err "You did not specify facileManager API token."
  54. _err "Please export FMDNS_API_TOKEN and try again."
  55. return 1
  56. fi
  57. FMDNS_API_ENDPOINT="${FMDNS_API_ENDPOINT:-$(_readaccountconf_mutable FMDNS_API_ENDPOINT)}"
  58. # Check if API endpoint exists
  59. if [ -z "$FMDNS_API_ENDPOINT" ]; then
  60. FMDNS_API_ENDPOINT=""
  61. _err "You did not specify facileManager API endpoint."
  62. _err "Please export FMDNS_API_ENDPOINT and try again."
  63. return 1
  64. fi
  65. FMDNS_API_DOMAIN_ID="${FMDNS_API_DOMAIN_ID:-$(_readaccountconf_mutable FMDNS_API_DOMAIN_ID)}"
  66. # Check if API domain id exists
  67. if [ -z "$FMDNS_API_DOMAIN_ID" ]; then
  68. FMDNS_API_DOMAIN_ID=""
  69. _err "You did not specify facileManager API domain id."
  70. _err "Please export FMDNS_API_DOMAIN_ID and try again."
  71. return 1
  72. fi
  73. _debug "Calling: _fmDnsApi_removeRecord() '${fulldomain}' '${txtvalue}'"
  74. _fmDnsApi_removeRecord
  75. return $?
  76. }
  77. ##################### Private functions #####################
  78. _fmDnsApi_addRecord() {
  79. _info "Connecting to ${FMDNS_API_ENDPOINT}"
  80. _info "Adding record to zone"
  81. curData="{\"fmAuthToken\":\"${FMDNS_API_TOKEN}\",\"id\":\"${FMDNS_API_DOMAIN_ID}\",\"action\":\"add\",\"name\":\"${fulldomain}\",\"value\":\"${txtvalue}\",\"type\":\"TXT\",\"ttl\":\"5\",\"reload\":\"yes\"}"
  82. curResult="$(_post "${curData}" "${FMDNS_API_ENDPOINT}")"
  83. _info "API result: '${curResult}'"
  84. _debug "Calling facileManager API: '${curData}' '${FMDNS_API_ENDPOINT}'"
  85. _debug "Result of zone add: '$curResult'"
  86. if [ "${curResult}" != "Success" ]; then
  87. if [ -z "${curResult}" ]; then
  88. _err "Empty response"
  89. else
  90. _err "${curResult}"
  91. fi
  92. return 1
  93. fi
  94. return 0
  95. }
  96. _fmDnsApi_removeRecord() {
  97. _info "Connecting to ${FMDNS_API_ENDPOINT}"
  98. _info "Removing record from zone"
  99. curData="{\"fmAuthToken\":\"${FMDNS_API_TOKEN}\",\"id\":\"${FMDNS_API_DOMAIN_ID}\",\"action\":\"delete\",\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"ttl\":\"5\",\"reload\":\"yes\"}"
  100. curResult="$(_post "${curData}" "${FMDNS_API_ENDPOINT}")"
  101. _info "API result: '${curResult}'"
  102. _debug "Calling facileManager API: '${curData}' '${FMDNS_API_ENDPOINT}'"
  103. _debug "Result of zone delete: '$curResult'"
  104. if [ "${curResult}" != "Success" ]; then
  105. if [ -z "${curResult}" ]; then
  106. _err "Empty response"
  107. else
  108. _err "${curResult}"
  109. fi
  110. return 1
  111. fi
  112. return 0
  113. }