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.

129 lines
4.3 KiB

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