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.2 KiB

  1. #!/usr/bin/env sh
  2. #
  3. # facileManager (https://github.com/WillyXJ/facileManager) hook script for acme.sh
  4. #
  5. # Author: Gianluca Giacometti
  6. # Git repo and usage: https://github.com/gianlucagiacometti/proxmox-acme-facilemanager
  7. #
  8. # Values to export:
  9. # export FMDNS_API_ENDPOINT='https://my.fmdnsapi.endpoint'
  10. # export FMDNS_API_TOKEN='xxxxx'
  11. # export FMDNS_API_DOMAIN_ID='xxxxx'
  12. # IMPORTANT NOTE: set the validation delay at 360s since facileManager updates dns zones usually every 300s
  13. ######## Public functions #####################
  14. dns_fmdns_add() {
  15. fulldomain="${1}"
  16. txtvalue="${2}"
  17. FMDNS_API_TOKEN="${FMDNS_API_TOKEN:-$(_readaccountconf_mutable FMDNS_API_TOKEN)}"
  18. # Check if API token exists
  19. if [ -z "$FMDNS_API_TOKEN" ]; then
  20. FMDNS_API_TOKEN=""
  21. _err "You did not specify facileManager API token."
  22. _err "Please export FMDNS_API_TOKEN and try again."
  23. return 1
  24. fi
  25. FMDNS_API_ENDPOINT="${FMDNS_API_ENDPOINT:-$(_readaccountconf_mutable FMDNS_API_ENDPOINT)}"
  26. # Check if API endpoint exists
  27. if [ -z "$FMDNS_API_ENDPOINT" ]; then
  28. FMDNS_API_ENDPOINT=""
  29. _err "You did not specify facileManager API endpoint."
  30. _err "Please export FMDNS_API_ENDPOINT and try again."
  31. return 1
  32. fi
  33. FMDNS_API_DOMAIN_ID="${FMDNS_API_DOMAIN_ID:-$(_readaccountconf_mutable FMDNS_API_DOMAIN_ID)}"
  34. # Check if API domain id exists
  35. if [ -z "$FMDNS_API_DOMAIN_ID" ]; then
  36. FMDNS_API_DOMAIN_ID=""
  37. _err "You did not specify facileManager API domain id."
  38. _err "Please export FMDNS_API_DOMAIN_ID and try again."
  39. return 1
  40. fi
  41. _debug "Calling: _fmDnsApi_addRecord() '${fulldomain}' '${txtvalue}'"
  42. _fmDnsApi_addRecord
  43. return $?
  44. }
  45. dns_fmdns_rm() {
  46. fulldomain="${1}"
  47. txtvalue="${2}"
  48. FMDNS_API_TOKEN="${FMDNS_API_TOKEN:-$(_readaccountconf_mutable FMDNS_API_TOKEN)}"
  49. # Check if API token exists
  50. if [ -z "$FMDNS_API_TOKEN" ]; then
  51. FMDNS_API_TOKEN=""
  52. _err "You did not specify facileManager API token."
  53. _err "Please export FMDNS_API_TOKEN and try again."
  54. return 1
  55. fi
  56. FMDNS_API_ENDPOINT="${FMDNS_API_ENDPOINT:-$(_readaccountconf_mutable FMDNS_API_ENDPOINT)}"
  57. # Check if API endpoint exists
  58. if [ -z "$FMDNS_API_ENDPOINT" ]; then
  59. FMDNS_API_ENDPOINT=""
  60. _err "You did not specify facileManager API endpoint."
  61. _err "Please export FMDNS_API_ENDPOINT and try again."
  62. return 1
  63. fi
  64. FMDNS_API_DOMAIN_ID="${FMDNS_API_DOMAIN_ID:-$(_readaccountconf_mutable FMDNS_API_DOMAIN_ID)}"
  65. # Check if API domain id exists
  66. if [ -z "$FMDNS_API_DOMAIN_ID" ]; then
  67. FMDNS_API_DOMAIN_ID=""
  68. _err "You did not specify facileManager API domain id."
  69. _err "Please export FMDNS_API_DOMAIN_ID and try again."
  70. return 1
  71. fi
  72. _debug "Calling: _fmDnsApi_removeRecord() '${fulldomain}' '${txtvalue}'"
  73. _fmDnsApi_removeRecord
  74. return $?
  75. }
  76. #################### Private functions below ##################################
  77. _fmDnsApi_addRecord() {
  78. _info "Connecting to ${FMDNS_API_ENDPOINT}"
  79. _info "Adding record to zone"
  80. curData="{\"fmAuthToken\":\"${FMDNS_API_TOKEN}\",\"id\":\"${FMDNS_API_DOMAIN_ID}\",\"action\":\"add\",\"name\":\"${fulldomain}\",\"value\":\"${txtvalue}\",\"type\":\"TXT\",\"ttl\":\"5\",\"autoupdate\":\"yes\"}"
  81. curResult="$(_post "${curData}" "${FMDNS_API_ENDPOINT}")"
  82. _info "API result: "${curResult}""
  83. _debug "Calling facileManager API: '${curData}' '${FMDNS_API_ENDPOINT}'"
  84. _debug "Result of zone add: '$curResult'"
  85. if [ "${curResult}" != "Success" ]; then
  86. if [ -z "${curResult}" ]; then
  87. _err "Empty response"
  88. else
  89. _err "${curResult}"
  90. fi
  91. return 1
  92. fi
  93. return 0
  94. }
  95. _fmDnsApi_removeRecord() {
  96. _info "Connecting to ${FMDNS_API_ENDPOINT}"
  97. _info "Removing record from zone"
  98. curData="{\"fmAuthToken\":\"${FMDNS_API_TOKEN}\",\"id\":\"${FMDNS_API_DOMAIN_ID}\",\"action\":\"delete\",\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"ttl\":\"5\",\"autoupdate\":\"yes\"}"
  99. curResult="$(_post "${curData}" "${FMDNS_API_ENDPOINT}")"
  100. _info "API result: "${curResult}""
  101. _debug "Calling facileManager API: '${curData}' '${FMDNS_API_ENDPOINT}'"
  102. _debug "Result of zone delete: '$curResult'"
  103. if [ "${curResult}" != "Success" ]; then
  104. if [ -z "${curResult}" ]; then
  105. _err "Empty response"
  106. else
  107. _err "${curResult}"
  108. fi
  109. return 1
  110. fi
  111. return 0
  112. }