From a54f51e0dab51523efd26ba81011903d63a86e16 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 17:42:06 +0000 Subject: [PATCH 01/18] Create dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 182 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 dnsapi/dns_jamotech.sh diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh new file mode 100644 index 00000000..a6f691b1 --- /dev/null +++ b/dnsapi/dns_jamotech.sh @@ -0,0 +1,182 @@ +#!/usr/bin/env sh + +#Here is a sample custom api script. +#This file name is "dns_myapi.sh" +#So, here must be a method dns_myapi_add() +#Which will be called by acme.sh to add the txt record to your api system. +#returns 0 means success, otherwise error. +# +#Author: Neilpang +#Report Bugs here: https://github.com/acmesh-official/acme.sh +# +######## Public functions ##################### + +# Please Read this guide first: https://github.com/acmesh-official/acme.sh/wiki/DNS-API-Dev-Guide + +# API Calls to be made +# _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") +# _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=_acme-challenge.subdomain&target=ACMEKEY&type=TXT") +# _get("https://api.corp-jamo.tech/dns/v1/records/add.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") +# _get("https://api.corp-jamo.tech/dns/v1/records/add.php?access=accesskey&hostname=_acme-challenge.subdomain&target=ACMEKEY&type=TXT") +# _get("https://api.corp-jamo.tech/dns/v1/records/remove.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") +# _get("https://api.corp-jamo.tech/dns/v1/records/remove.php?access=accesskey&hostname=_acme-challenge.subdomain&target=ACMEKEY&type=TXT") + +#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" +dns_jamotech_add() { + fulldomain=$1 + txtvalue=$2 + JTECH_ENDIP="${JTECH_ENDIP:-$(_readaccountconf_mutable JTECH_ENDIP)}" + JTECH_KEY="${JTECH_KEY:-$(_readaccountconf_mutable JTECH_KEY)}" + + if [ "$JTECH_ENDIP" ]; then + _saveaccountconf_mutable JTECH_ENDIP "$JTECH_ENDIP" + else + _err "You need to specify an end IP by running 'export JTECH_ENDIP=IP'" + return 1 + fi + + if [ "$JTECH_KEY" ]; then + _saveaccountconf_mutable JTECH_KEY "$JTECH_KEY" + else + _err "You need to specify an API Key by running 'export JTECH_KEY=APIKEY'" + return 1 + fi + _info "Using jamotech-register to add the TXT record" + _get_root + _create_record + _debug fulldomain "$fulldomain" + _debug txtvalue "$txtvalue" + +} + + +#Usage: fulldomain txtvalue +#Remove the txt record after validation. +dns_jamotech_rm() { + fulldomain=$1 + txtvalue=$2 + + JTECH_ENDIP="${JTECH_ENDIP:-$(_readaccountconf_mutable JTECH_ENDIP)}" + JTECH_KEY="${JTECH_KEY:-$(_readaccountconf_mutable JTECH_KEY)}" + + if [ "$JTECH_ENDIP" ]; then + _saveaccountconf_mutable JTECH_ENDIP "$JTECH_ENDIP" + else + _err "You need to specify an end IP by running 'export JTECH_ENDIP=IP'" + return 1 + fi + + if [ "$JTECH_KEY" ]; then + _saveaccountconf_mutable JTECH_KEY "$JTECH_KEY" + else + _err "You need to specify an API Key by running 'export JTECH_KEY=APIKEY'" + return 1 + fi + + + _info "Using jamotech-clean to remove the TXT record" + _get_root + _remove_record + _debug fulldomain "$fulldomain" + _debug txtvalue "$txtvalue" + +} + + +#################### Private functions below ################################## +# _acme-challenge.www.domain.com +# returns +# _domain=domain.com +# _txtdomain=_acme-challenge.www +# _adomain=www + + +_get_root() { + domain=$fulldomain + txtdomain=${domain%.jamo.tech} + subdomain=$(echo "$txtdomain" | cut -d'.' -f2-) + _debug "txtdomain = $txtdomain" + _debug "subdomain = $subdomain" + _debug "Domain: $domain TXTDomain: $txtdomain Subdomain: $subdomain" + if [ -z "$domain" ] || [ -z "$txtdomain" ] || [ -z "$subdomain" ] ; then + _err "We weren't able to determine the records which need to be created." + return 1 + fi + _txthost="$txtdomain" + _subhost="$subdomain" + _err "$domain not found" + return 1 +} + + +_check_record() { + server_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$subdomain&target=$JTECH_ENDIP&type=A" + txt_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" + _debug "API ENDPOINTS $server_record $txt_record" + + response="$(_get "$server_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + if _contains "$response" '"exists":"true"}'; then + _err "Record already exists." + return 1 + fi + + response="$(_get "$txt_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + if _contains "$response" '"exists":"true"}'; then + _err "Record already exists." + return 1 + fi +} + + +_create_record() { + _check_record + server_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$subdomain&target=$JTECH_ENDIP&type=A" + txt_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" + _debug "API ENDPOINTS $server_record $txt_record" + + response="$(_get "$server_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + response="$(_get "$txt_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + return 0 +} + + + +_remove_record() { + server_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$subdomain&target=$JTECH_ENDIP&type=A" + txt_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" + _debug "API ENDPOINTS $server_record $txt_record" + + response="$(_get "$server_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + response="$(_get "$txt_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + return 0 +} From 71d949c8ef03c0f75420e433fe34c12fdad3b71b Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 17:55:22 +0000 Subject: [PATCH 02/18] Update comments Update comments to reflect actual outputs from private functions --- dnsapi/dns_jamotech.sh | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index a6f691b1..dc3efbf3 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -1,17 +1,12 @@ #!/usr/bin/env sh -#Here is a sample custom api script. -#This file name is "dns_myapi.sh" -#So, here must be a method dns_myapi_add() -#Which will be called by acme.sh to add the txt record to your api system. -#returns 0 means success, otherwise error. -# -#Author: Neilpang -#Report Bugs here: https://github.com/acmesh-official/acme.sh -# -######## Public functions ##################### +# acme.sh JamoTech helper script +# This is to be used on client systems and used by Ansible +# to deploy SSL certificates on the jamo.tech domain to +# customer servers for web panels and the likes to their +# customer jamo.tech subdomain. -# Please Read this guide first: https://github.com/acmesh-official/acme.sh/wiki/DNS-API-Dev-Guide +######## Public functions ##################### # API Calls to be made # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") @@ -84,11 +79,10 @@ dns_jamotech_rm() { #################### Private functions below ################################## -# _acme-challenge.www.domain.com +# _acme-challenge.client.jamo.tech # returns -# _domain=domain.com -# _txtdomain=_acme-challenge.www -# _adomain=www +# _txthost="_acme-challenge.client" +# _subhost="client" _get_root() { From aa18ac86662bb68bf756a0e052c28da626106c72 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 19:53:08 +0000 Subject: [PATCH 03/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index dc3efbf3..ba16d66c 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -5,6 +5,7 @@ # to deploy SSL certificates on the jamo.tech domain to # customer servers for web panels and the likes to their # customer jamo.tech subdomain. +# ######## Public functions ##################### From 7de8257ca2e9c15fa423ab773f6ccf67a9f3a13b Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 19:58:12 +0000 Subject: [PATCH 04/18] Force workflow run Force workflow run --- dnsapi/dns_jamotech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index ba16d66c..c12c61ac 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -5,7 +5,7 @@ # to deploy SSL certificates on the jamo.tech domain to # customer servers for web panels and the likes to their # customer jamo.tech subdomain. -# + ######## Public functions ##################### From d8b370224d3e9b9e76f68332868411f7f9a335e3 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 20:05:17 +0000 Subject: [PATCH 05/18] Force actions run Force actions run --- dnsapi/dns_jamotech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index c12c61ac..ba16d66c 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -5,7 +5,7 @@ # to deploy SSL certificates on the jamo.tech domain to # customer servers for web panels and the likes to their # customer jamo.tech subdomain. - +# ######## Public functions ##################### From 292a8726da388d82e68280f0c552070b3a9e4907 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 20:14:09 +0000 Subject: [PATCH 06/18] Force actions run Force actions run --- dnsapi/dns_jamotech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index ba16d66c..c12c61ac 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -5,7 +5,7 @@ # to deploy SSL certificates on the jamo.tech domain to # customer servers for web panels and the likes to their # customer jamo.tech subdomain. -# + ######## Public functions ##################### From 278378e26f510a73d0942ca0cf87d16b6b082b5e Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 20:20:15 +0000 Subject: [PATCH 07/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index c12c61ac..ba16d66c 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -5,7 +5,7 @@ # to deploy SSL certificates on the jamo.tech domain to # customer servers for web panels and the likes to their # customer jamo.tech subdomain. - +# ######## Public functions ##################### From b69e93e69ad15caa51f1701eb951bb4ca01484fb Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 20:50:26 +0000 Subject: [PATCH 08/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index ba16d66c..c12c61ac 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -5,7 +5,7 @@ # to deploy SSL certificates on the jamo.tech domain to # customer servers for web panels and the likes to their # customer jamo.tech subdomain. -# + ######## Public functions ##################### From 26ae489efa7922017e300d8f0addbc6f03c260e4 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 21:08:48 +0000 Subject: [PATCH 09/18] Update jamotech.sh to comply with shellcheck Update jamotech.sh to comply with shellcheck --- dnsapi/dns_jamotech.sh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index c12c61ac..000446be 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -1,14 +1,18 @@ #!/usr/bin/env sh -# acme.sh JamoTech helper script -# This is to be used on client systems and used by Ansible -# to deploy SSL certificates on the jamo.tech domain to -# customer servers for web panels and the likes to their -# customer jamo.tech subdomain. - - +#Here is a sample custom api script. +#This file name is "dns_myapi.sh" +#So, here must be a method dns_myapi_add() +#Which will be called by acme.sh to add the txt record to your api system. +#returns 0 means success, otherwise error. +# +#Author: Neilpang +#Report Bugs here: https://github.com/acmesh-official/acme.sh +# ######## Public functions ##################### +# Please Read this guide first: https://github.com/acmesh-official/acme.sh/wiki/DNS-API-Dev-Guide + # API Calls to be made # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=_acme-challenge.subdomain&target=ACMEKEY&type=TXT") @@ -80,10 +84,11 @@ dns_jamotech_rm() { #################### Private functions below ################################## -# _acme-challenge.client.jamo.tech +# _acme-challenge.www.domain.com # returns -# _txthost="_acme-challenge.client" -# _subhost="client" +# _domain=domain.com +# _txtdomain=_acme-challenge.www +# _adomain=www _get_root() { @@ -105,7 +110,7 @@ _get_root() { _check_record() { - server_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$subdomain&target=$JTECH_ENDIP&type=A" + server_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" txt_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" _debug "API ENDPOINTS $server_record $txt_record" @@ -135,7 +140,7 @@ _check_record() { _create_record() { _check_record - server_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$subdomain&target=$JTECH_ENDIP&type=A" + server_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" txt_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" _debug "API ENDPOINTS $server_record $txt_record" @@ -157,7 +162,7 @@ _create_record() { _remove_record() { - server_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$subdomain&target=$JTECH_ENDIP&type=A" + server_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" txt_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" _debug "API ENDPOINTS $server_record $txt_record" From 9e788f84079976de8ea356da8d776c93380d7914 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 21:10:36 +0000 Subject: [PATCH 10/18] Update for shellcheck compliance --- dnsapi/dns_jamotech.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index 000446be..22fe3c74 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -111,7 +111,7 @@ _get_root() { _check_record() { server_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" - txt_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" + txt_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" _debug "API ENDPOINTS $server_record $txt_record" response="$(_get "$server_record")" @@ -141,7 +141,7 @@ _check_record() { _create_record() { _check_record server_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" - txt_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" + txt_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" _debug "API ENDPOINTS $server_record $txt_record" response="$(_get "$server_record")" @@ -163,7 +163,7 @@ _create_record() { _remove_record() { server_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" - txt_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$txtdomain&target=$txtvalue&type=TXT" + txt_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" _debug "API ENDPOINTS $server_record $txt_record" response="$(_get "$server_record")" From b190e45b019af24d7dfc2f80fad59c141f7e432b Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 21:14:59 +0000 Subject: [PATCH 11/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 128 +++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 68 deletions(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index 22fe3c74..8b14d55e 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -49,7 +49,6 @@ dns_jamotech_add() { } - #Usage: fulldomain txtvalue #Remove the txt record after validation. dns_jamotech_rm() { @@ -73,7 +72,6 @@ dns_jamotech_rm() { return 1 fi - _info "Using jamotech-clean to remove the TXT record" _get_root _remove_record @@ -82,7 +80,6 @@ dns_jamotech_rm() { } - #################### Private functions below ################################## # _acme-challenge.www.domain.com # returns @@ -90,7 +87,6 @@ dns_jamotech_rm() { # _txtdomain=_acme-challenge.www # _adomain=www - _get_root() { domain=$fulldomain txtdomain=${domain%.jamo.tech} @@ -98,7 +94,7 @@ _get_root() { _debug "txtdomain = $txtdomain" _debug "subdomain = $subdomain" _debug "Domain: $domain TXTDomain: $txtdomain Subdomain: $subdomain" - if [ -z "$domain" ] || [ -z "$txtdomain" ] || [ -z "$subdomain" ] ; then + if [ -z "$domain" ] || [ -z "$txtdomain" ] || [ -z "$subdomain" ]; then _err "We weren't able to determine the records which need to be created." return 1 fi @@ -108,75 +104,71 @@ _get_root() { return 1 } - _check_record() { - server_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" - txt_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" - _debug "API ENDPOINTS $server_record $txt_record" - - response="$(_get "$server_record")" - if [ "$?" != "0" ]; then - _err "error" - return 1 - fi - - if _contains "$response" '"exists":"true"}'; then - _err "Record already exists." - return 1 - fi - - response="$(_get "$txt_record")" - if [ "$?" != "0" ]; then - _err "error" - return 1 - fi - - if _contains "$response" '"exists":"true"}'; then - _err "Record already exists." - return 1 - fi -} + server_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" + txt_record="https://api.corp-jamo.tech/dns/v1/records/exists.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" + _debug "API ENDPOINTS $server_record $txt_record" + + response="$(_get "$server_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + if _contains "$response" '"exists":"true"}'; then + _err "Record already exists." + return 1 + fi -_create_record() { - _check_record - server_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" - txt_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" - _debug "API ENDPOINTS $server_record $txt_record" - - response="$(_get "$server_record")" - if [ "$?" != "0" ]; then - _err "error" - return 1 - fi - - response="$(_get "$txt_record")" - if [ "$?" != "0" ]; then - _err "error" - return 1 - fi - - return 0 + response="$(_get "$txt_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + if _contains "$response" '"exists":"true"}'; then + _err "Record already exists." + return 1 + fi } +_create_record() { + _check_record + server_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" + txt_record="https://api.corp-jamo.tech/dns/v1/records/add.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" + _debug "API ENDPOINTS $server_record $txt_record" + + response="$(_get "$server_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + response="$(_get "$txt_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + return 0 +} _remove_record() { - server_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" - txt_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" - _debug "API ENDPOINTS $server_record $txt_record" - - response="$(_get "$server_record")" - if [ "$?" != "0" ]; then - _err "error" - return 1 - fi - - response="$(_get "$txt_record")" - if [ "$?" != "0" ]; then - _err "error" - return 1 - fi - - return 0 + server_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$_subhost&target=$JTECH_ENDIP&type=A" + txt_record="https://api.corp-jamo.tech/dns/v1/records/remove.php?access=$JTECH_KEY&hostname=$_txthost&target=$txtvalue&type=TXT" + _debug "API ENDPOINTS $server_record $txt_record" + + response="$(_get "$server_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + response="$(_get "$txt_record")" + if [ "$?" != "0" ]; then + _err "error" + return 1 + fi + + return 0 } From 863153da78ccb16c050a1c5433370df83da5b259 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 21:55:02 +0000 Subject: [PATCH 12/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index 8b14d55e..60b9b0d4 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -1,17 +1,14 @@ #!/usr/bin/env sh -#Here is a sample custom api script. -#This file name is "dns_myapi.sh" -#So, here must be a method dns_myapi_add() -#Which will be called by acme.sh to add the txt record to your api system. -#returns 0 means success, otherwise error. -# -#Author: Neilpang -#Report Bugs here: https://github.com/acmesh-official/acme.sh -# -######## Public functions ##################### - -# Please Read this guide first: https://github.com/acmesh-official/acme.sh/wiki/DNS-API-Dev-Guide +# JamoTech Customer Domain amce Helper +# This script is intended to be run via +# acme.sh on managed customer systems +# to allow customers to create and renew +# SSL certificates on their client +# subdomain e.g (client.jamo.tech) +# without the need for support staff +# to create TXT records. + # API Calls to be made # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") @@ -21,7 +18,6 @@ # _get("https://api.corp-jamo.tech/dns/v1/records/remove.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") # _get("https://api.corp-jamo.tech/dns/v1/records/remove.php?access=accesskey&hostname=_acme-challenge.subdomain&target=ACMEKEY&type=TXT") -#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" dns_jamotech_add() { fulldomain=$1 txtvalue=$2 @@ -49,8 +45,6 @@ dns_jamotech_add() { } -#Usage: fulldomain txtvalue -#Remove the txt record after validation. dns_jamotech_rm() { fulldomain=$1 txtvalue=$2 @@ -81,11 +75,6 @@ dns_jamotech_rm() { } #################### Private functions below ################################## -# _acme-challenge.www.domain.com -# returns -# _domain=domain.com -# _txtdomain=_acme-challenge.www -# _adomain=www _get_root() { domain=$fulldomain From 841f807dbea94d5f618ccb3a3d8dbdb7aab4fe27 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Mon, 29 Nov 2021 21:57:25 +0000 Subject: [PATCH 13/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index 60b9b0d4..4ae214af 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -9,7 +9,6 @@ # without the need for support staff # to create TXT records. - # API Calls to be made # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=_acme-challenge.subdomain&target=ACMEKEY&type=TXT") From b99f69ceb769598af59e838a1bc792b7a427b943 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Tue, 30 Nov 2021 19:06:33 +0000 Subject: [PATCH 14/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index 4ae214af..60b9b0d4 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -9,6 +9,7 @@ # without the need for support staff # to create TXT records. + # API Calls to be made # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=_acme-challenge.subdomain&target=ACMEKEY&type=TXT") From ca5af75d0064fbe2f859e14917d3158c6fafc1d8 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Tue, 30 Nov 2021 19:24:30 +0000 Subject: [PATCH 15/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index 60b9b0d4..694317f7 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -8,7 +8,7 @@ # subdomain e.g (client.jamo.tech) # without the need for support staff # to create TXT records. - +# # API Calls to be made # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") From 5b8aceea98c60cb5d8254e4533eb67fe135af6b9 Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Wed, 1 Dec 2021 16:49:20 +0000 Subject: [PATCH 17/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index 694317f7..60b9b0d4 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -8,7 +8,7 @@ # subdomain e.g (client.jamo.tech) # without the need for support staff # to create TXT records. -# + # API Calls to be made # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") From 5609e07a7f2e2b4fae8e25525665525c3564d74d Mon Sep 17 00:00:00 2001 From: Jamo <71354459+Jamo-Tech@users.noreply.github.com> Date: Sat, 4 Dec 2021 17:51:37 +0000 Subject: [PATCH 18/18] Update dns_jamotech.sh --- dnsapi/dns_jamotech.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/dnsapi/dns_jamotech.sh b/dnsapi/dns_jamotech.sh index 60b9b0d4..4ae214af 100644 --- a/dnsapi/dns_jamotech.sh +++ b/dnsapi/dns_jamotech.sh @@ -9,7 +9,6 @@ # without the need for support staff # to create TXT records. - # API Calls to be made # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=subdomain&target=10.8.0.1&type=A") # _get("https://api.corp-jamo.tech/dns/v1/records/exists.php?access=accesskey&hostname=_acme-challenge.subdomain&target=ACMEKEY&type=TXT")