From 3d98c9285f800d5094dbeda3009ecb478b299df1 Mon Sep 17 00:00:00 2001 From: Gianluca Giacometti <52405+gianlucagiacometti@users.noreply.github.com> Date: Fri, 27 Dec 2024 17:58:53 +0100 Subject: [PATCH 1/7] Create dns_fmdns.sh --- dnsapi/dns_fmdns.sh | 129 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 dnsapi/dns_fmdns.sh diff --git a/dnsapi/dns_fmdns.sh b/dnsapi/dns_fmdns.sh new file mode 100644 index 0000000000..674072297b --- /dev/null +++ b/dnsapi/dns_fmdns.sh @@ -0,0 +1,129 @@ +#!/usr/bin/env sh + +# +# facileManager (https://github.com/WillyXJ/facileManager) hook script for acme.sh +# +# Author: Gianluca Giacometti +# Git repo and usage: https://github.com/gianlucagiacometti/proxmox-acme-facilemanager +# + +# Values to export: +# export FMDNS_API_ENDPOINT='https://my.fmdnsapi.endpoint' +# export FMDNS_API_TOKEN='xxxxx' +# export FMDNS_API_DOMAIN_ID='xxxxx' + +# IMPORTANT NOTE: set the validation delay at 360s since facileManager updates dns zones usually every 300s + +######## Public functions ##################### + +dns_fmdns_add() { + fulldomain="${1}" + txtvalue="${2}" + + FMDNS_API_TOKEN="${FMDNS_API_TOKEN:-$(_readaccountconf_mutable FMDNS_API_TOKEN)}" + # Check if API token exists + if [ -z "$FMDNS_API_TOKEN" ]; then + FMDNS_API_TOKEN="" + _err "You did not specify facileManager API token." + _err "Please export FMDNS_API_TOKEN and try again." + return 1 + fi + + FMDNS_API_ENDPOINT="${FMDNS_API_ENDPOINT:-$(_readaccountconf_mutable FMDNS_API_ENDPOINT)}" + # Check if API endpoint exists + if [ -z "$FMDNS_API_ENDPOINT" ]; then + FMDNS_API_ENDPOINT="" + _err "You did not specify facileManager API endpoint." + _err "Please export FMDNS_API_ENDPOINT and try again." + return 1 + fi + + FMDNS_API_DOMAIN_ID="${FMDNS_API_DOMAIN_ID:-$(_readaccountconf_mutable FMDNS_API_DOMAIN_ID)}" + # Check if API domain id exists + if [ -z "$FMDNS_API_DOMAIN_ID" ]; then + FMDNS_API_DOMAIN_ID="" + _err "You did not specify facileManager API domain id." + _err "Please export FMDNS_API_DOMAIN_ID and try again." + return 1 + fi + + _debug "Calling: _fmDnsApi_addRecord() '${fulldomain}' '${txtvalue}'" + _fmDnsApi_addRecord + return $? +} + +dns_fmdns_rm() { + fulldomain="${1}" + txtvalue="${2}" + + FMDNS_API_TOKEN="${FMDNS_API_TOKEN:-$(_readaccountconf_mutable FMDNS_API_TOKEN)}" + # Check if API token exists + if [ -z "$FMDNS_API_TOKEN" ]; then + FMDNS_API_TOKEN="" + _err "You did not specify facileManager API token." + _err "Please export FMDNS_API_TOKEN and try again." + return 1 + fi + + FMDNS_API_ENDPOINT="${FMDNS_API_ENDPOINT:-$(_readaccountconf_mutable FMDNS_API_ENDPOINT)}" + # Check if API endpoint exists + if [ -z "$FMDNS_API_ENDPOINT" ]; then + FMDNS_API_ENDPOINT="" + _err "You did not specify facileManager API endpoint." + _err "Please export FMDNS_API_ENDPOINT and try again." + return 1 + fi + + FMDNS_API_DOMAIN_ID="${FMDNS_API_DOMAIN_ID:-$(_readaccountconf_mutable FMDNS_API_DOMAIN_ID)}" + # Check if API domain id exists + if [ -z "$FMDNS_API_DOMAIN_ID" ]; then + FMDNS_API_DOMAIN_ID="" + _err "You did not specify facileManager API domain id." + _err "Please export FMDNS_API_DOMAIN_ID and try again." + return 1 + fi + + _debug "Calling: _fmDnsApi_removeRecord() '${fulldomain}' '${txtvalue}'" + _fmDnsApi_removeRecord + return $? +} + +#################### Private functions below ################################## + +_fmDnsApi_addRecord() { + _info "Connecting to ${FMDNS_API_ENDPOINT}" + _info "Adding record to zone" + curData="{\"fmAuthToken\":\"${FMDNS_API_TOKEN}\",\"id\":\"${FMDNS_API_DOMAIN_ID}\",\"action\":\"add\",\"name\":\"${fulldomain}\",\"value\":\"${txtvalue}\",\"type\":\"TXT\",\"ttl\":\"5\",\"autoupdate\":\"yes\"}" + curResult="$(_post "${curData}" "${FMDNS_API_ENDPOINT}")" + _info "API result: "${curResult}"" + _debug "Calling facileManager API: '${curData}' '${FMDNS_API_ENDPOINT}'" + _debug "Result of zone add: '$curResult'" + if [ "${curResult}" != "Success" ]; then + if [ -z "${curResult}" ]; then + _err "Empty response" + else + _err "${curResult}" + fi + return 1 + fi + return 0 +} + +_fmDnsApi_removeRecord() { + _info "Connecting to ${FMDNS_API_ENDPOINT}" + _info "Removing record from zone" + curData="{\"fmAuthToken\":\"${FMDNS_API_TOKEN}\",\"id\":\"${FMDNS_API_DOMAIN_ID}\",\"action\":\"delete\",\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"ttl\":\"5\",\"autoupdate\":\"yes\"}" + curResult="$(_post "${curData}" "${FMDNS_API_ENDPOINT}")" + _info "API result: "${curResult}"" + _debug "Calling facileManager API: '${curData}' '${FMDNS_API_ENDPOINT}'" + _debug "Result of zone delete: '$curResult'" + if [ "${curResult}" != "Success" ]; then + if [ -z "${curResult}" ]; then + _err "Empty response" + else + _err "${curResult}" + fi + return 1 + fi + return 0 +} From dbb46669db84fcecafd499f7bd91bb14c8d9a1b4 Mon Sep 17 00:00:00 2001 From: Gianluca Giacometti <52405+gianlucagiacometti@users.noreply.github.com> Date: Fri, 27 Dec 2024 18:21:18 +0100 Subject: [PATCH 2/7] Update dns_fmdns.sh --- dnsapi/dns_fmdns.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_fmdns.sh b/dnsapi/dns_fmdns.sh index 674072297b..076146b5c1 100644 --- a/dnsapi/dns_fmdns.sh +++ b/dnsapi/dns_fmdns.sh @@ -12,7 +12,7 @@ # export FMDNS_API_TOKEN='xxxxx' # export FMDNS_API_DOMAIN_ID='xxxxx' -# IMPORTANT NOTE: set the validation delay at 360s since facileManager updates dns zones usually every 300s +# IMPORTANT NOTE: set the validation delay at at least 360s since facileManager updates dns zones usually every 300s ######## Public functions ##################### From 15af878694af39672c24c5e695a92467e285d673 Mon Sep 17 00:00:00 2001 From: Gianluca Giacometti <52405+gianlucagiacometti@users.noreply.github.com> Date: Fri, 27 Dec 2024 18:26:31 +0100 Subject: [PATCH 3/7] Update dns_fmdns.sh --- dnsapi/dns_fmdns.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_fmdns.sh b/dnsapi/dns_fmdns.sh index 076146b5c1..71dba83f45 100644 --- a/dnsapi/dns_fmdns.sh +++ b/dnsapi/dns_fmdns.sh @@ -12,7 +12,7 @@ # export FMDNS_API_TOKEN='xxxxx' # export FMDNS_API_DOMAIN_ID='xxxxx' -# IMPORTANT NOTE: set the validation delay at at least 360s since facileManager updates dns zones usually every 300s +# IMPORTANT NOTE: set the validation delay at a minimum value of 360s, since facileManager usually updates dns zones every 300s ######## Public functions ##################### From 12fc118f5d5fc551e496708aa9e76cdaebd9ce5a Mon Sep 17 00:00:00 2001 From: Gianluca Giacometti <52405+gianlucagiacometti@users.noreply.github.com> Date: Fri, 27 Dec 2024 19:58:57 +0100 Subject: [PATCH 4/7] Update dns_fmdns.sh --- dnsapi/dns_fmdns.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dnsapi/dns_fmdns.sh b/dnsapi/dns_fmdns.sh index 71dba83f45..9c8f16f303 100644 --- a/dnsapi/dns_fmdns.sh +++ b/dnsapi/dns_fmdns.sh @@ -14,7 +14,7 @@ # IMPORTANT NOTE: set the validation delay at a minimum value of 360s, since facileManager usually updates dns zones every 300s -######## Public functions ##################### +##################### Public functions ##################### dns_fmdns_add() { fulldomain="${1}" @@ -88,7 +88,7 @@ dns_fmdns_rm() { return $? } -#################### Private functions below ################################## +##################### Private functions ##################### _fmDnsApi_addRecord() { _info "Connecting to ${FMDNS_API_ENDPOINT}" From 891daeffe02b51e43e43040b758316e7bcce5f6d Mon Sep 17 00:00:00 2001 From: Gianluca Giacometti <52405+gianlucagiacometti@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:23:40 +0100 Subject: [PATCH 5/7] Update dns_fmdns.sh --- dnsapi/dns_fmdns.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/dnsapi/dns_fmdns.sh b/dnsapi/dns_fmdns.sh index 9c8f16f303..017ef4f15a 100644 --- a/dnsapi/dns_fmdns.sh +++ b/dnsapi/dns_fmdns.sh @@ -1,18 +1,18 @@ #!/usr/bin/env sh -# -# facileManager (https://github.com/WillyXJ/facileManager) hook script for acme.sh -# -# Author: Gianluca Giacometti -# Git repo and usage: https://github.com/gianlucagiacometti/proxmox-acme-facilemanager -# - -# Values to export: -# export FMDNS_API_ENDPOINT='https://my.fmdnsapi.endpoint' -# export FMDNS_API_TOKEN='xxxxx' -# export FMDNS_API_DOMAIN_ID='xxxxx' - -# IMPORTANT NOTE: set the validation delay at a minimum value of 360s, since facileManager usually updates dns zones every 300s +# shellcheck disable=SC2034 +dns_fmdns_info='facileManager DNS API + API for self-hosted facileManager DNS. +Domains: github.com/WillyXJ/facileManager +Site: github.com/gianlucagiacometti/proxmox-acme-facilemanager +Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_fmdns +Options: + FMDNS_API_ENDPOINT API Endpoint. Web address of the API endpoint. + FMDNS_API_TOKEN API Token. + FMDNS_API_DOMAIN_ID Domain ID. Domain ID in your facileManager database. +Issues: github.com/gianlucagiacometti/proxmox-acme-facilemanager +Author: Gianluca Giacometti +' ##################### Public functions ##################### From 38aa8696e77cf86a7401a9c831dfdafd2d90e77c Mon Sep 17 00:00:00 2001 From: Gianluca Giacometti <52405+gianlucagiacometti@users.noreply.github.com> Date: Sat, 28 Dec 2024 20:44:18 +0100 Subject: [PATCH 6/7] Update dns_fmdns.sh --- dnsapi/dns_fmdns.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dnsapi/dns_fmdns.sh b/dnsapi/dns_fmdns.sh index 017ef4f15a..f452b0424b 100644 --- a/dnsapi/dns_fmdns.sh +++ b/dnsapi/dns_fmdns.sh @@ -95,7 +95,7 @@ _fmDnsApi_addRecord() { _info "Adding record to zone" curData="{\"fmAuthToken\":\"${FMDNS_API_TOKEN}\",\"id\":\"${FMDNS_API_DOMAIN_ID}\",\"action\":\"add\",\"name\":\"${fulldomain}\",\"value\":\"${txtvalue}\",\"type\":\"TXT\",\"ttl\":\"5\",\"autoupdate\":\"yes\"}" curResult="$(_post "${curData}" "${FMDNS_API_ENDPOINT}")" - _info "API result: "${curResult}"" + _info "API result: '${curResult}'" _debug "Calling facileManager API: '${curData}' '${FMDNS_API_ENDPOINT}'" _debug "Result of zone add: '$curResult'" if [ "${curResult}" != "Success" ]; then @@ -114,7 +114,7 @@ _fmDnsApi_removeRecord() { _info "Removing record from zone" curData="{\"fmAuthToken\":\"${FMDNS_API_TOKEN}\",\"id\":\"${FMDNS_API_DOMAIN_ID}\",\"action\":\"delete\",\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"ttl\":\"5\",\"autoupdate\":\"yes\"}" curResult="$(_post "${curData}" "${FMDNS_API_ENDPOINT}")" - _info "API result: "${curResult}"" + _info "API result: '${curResult}'" _debug "Calling facileManager API: '${curData}' '${FMDNS_API_ENDPOINT}'" _debug "Result of zone delete: '$curResult'" if [ "${curResult}" != "Success" ]; then From b629e26203c98d582c39e775fb72a5a10593da21 Mon Sep 17 00:00:00 2001 From: Gianluca Giacometti <52405+gianlucagiacometti@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:49:36 +0100 Subject: [PATCH 7/7] Fix info --- dnsapi/dns_fmdns.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dnsapi/dns_fmdns.sh b/dnsapi/dns_fmdns.sh index f452b0424b..78a4db5912 100644 --- a/dnsapi/dns_fmdns.sh +++ b/dnsapi/dns_fmdns.sh @@ -2,8 +2,7 @@ # shellcheck disable=SC2034 dns_fmdns_info='facileManager DNS API - API for self-hosted facileManager DNS. -Domains: github.com/WillyXJ/facileManager + API for self-hosted facileManager DNS github.com/WillyXJ/facileManager Site: github.com/gianlucagiacometti/proxmox-acme-facilemanager Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_fmdns Options: