mirror of
https://github.com/acmesh-official/acme.sh
synced 2025-11-06 07:00:41 +08:00
Compare commits
171 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b5c09da04 | ||
|
|
97741398fb | ||
|
|
f8b225e70e | ||
|
|
fc3a181779 | ||
|
|
9541ea6a9f | ||
|
|
f716f6060e | ||
|
|
dc0cca8c83 | ||
|
|
4f303de00c | ||
|
|
05aa26e619 | ||
|
|
2028e4c8ad | ||
|
|
5c7feba77b | ||
|
|
23f2677052 | ||
|
|
6b67511748 | ||
|
|
36e0feea43 | ||
|
|
69392f67e8 | ||
|
|
e7d130cc11 | ||
|
|
d4dad58b0d | ||
|
|
baff032e3b | ||
|
|
26309f51e3 | ||
|
|
f8f53a6bd9 | ||
|
|
ac3667c765 | ||
|
|
5aa0f547cf | ||
|
|
70fdb1042f | ||
|
|
8dea519235 | ||
|
|
0712e98904 | ||
|
|
c7ccddbcb9 | ||
|
|
efd3e8067b | ||
|
|
c6f7b7f35f | ||
|
|
f3dd1603db | ||
|
|
be7688a4df | ||
|
|
8e2f11389d | ||
|
|
346454c21b | ||
|
|
c822870cf8 | ||
|
|
9666cf680e | ||
|
|
a88622c1be | ||
|
|
c3fbc36ce7 | ||
|
|
f174d7dd39 | ||
|
|
b2ff9240ac | ||
|
|
7a3c61b744 | ||
|
|
b59b0f0386 | ||
|
|
f59f484c01 | ||
|
|
a44ea0ddf0 | ||
|
|
76d0ef0851 | ||
|
|
549ebbb462 | ||
|
|
341656ddb9 | ||
|
|
5a3c3b4876 | ||
|
|
375b8dceb7 | ||
|
|
f37546e173 | ||
|
|
ec7889dfa8 | ||
|
|
563d59526f | ||
|
|
0ffd5de6fc | ||
|
|
5014f83b86 | ||
|
|
84b0f29d87 | ||
|
|
b23e05dbc5 | ||
|
|
ef15e55947 | ||
|
|
c282dd086f | ||
|
|
aac9f089d9 | ||
|
|
adce8f52e8 | ||
|
|
20b64c8900 | ||
|
|
66d781a226 | ||
|
|
867ec010ab | ||
|
|
ce0c6da9fa | ||
|
|
f1f14040b8 | ||
|
|
51cfd996eb | ||
|
|
6d0e4bed4b | ||
|
|
05247dc4a4 | ||
|
|
43011f3bfa | ||
|
|
38854bd876 | ||
|
|
a9726bd52f | ||
|
|
4216c9e8f7 | ||
|
|
a8d670fc0d | ||
|
|
cbacc779fc | ||
|
|
896778cead | ||
|
|
04b0c62bf9 | ||
|
|
63a779baa8 | ||
|
|
2d1a776db7 | ||
|
|
3d2df3ba93 | ||
|
|
eb6238781d | ||
|
|
6140a3c26b | ||
|
|
6eaf2d67b7 | ||
|
|
35b34c43ed | ||
|
|
f67a9d2de1 | ||
|
|
05acf28e0d | ||
|
|
5698bec621 | ||
|
|
3ec495225f | ||
|
|
fee9baca89 | ||
|
|
bec26ce754 | ||
|
|
343d7df57c | ||
|
|
dca6a4bbd5 | ||
|
|
a32b95544b | ||
|
|
2422e0b481 | ||
|
|
3441bd0e7c | ||
|
|
05ced9fbc4 | ||
|
|
b7c3df455e | ||
|
|
d7affad059 | ||
|
|
34c3da9117 | ||
|
|
a22d3b2390 | ||
|
|
7c09bdc6e0 | ||
|
|
bc291141b1 | ||
|
|
c1b089d1c3 | ||
|
|
1271f97b66 | ||
|
|
582c77805c | ||
|
|
9eb5f65b8f | ||
|
|
00f01a9889 | ||
|
|
671edc33e1 | ||
|
|
1253357a39 | ||
|
|
6df31eb7f5 | ||
|
|
9299a83b17 | ||
|
|
a6614abd24 | ||
|
|
4c9d99040c | ||
|
|
6ef8adc863 | ||
|
|
a00300f88a | ||
|
|
274393ac64 | ||
|
|
1339b9422d | ||
|
|
ed9e196bf6 | ||
|
|
bba5376a36 | ||
|
|
df3575217a | ||
|
|
c504506455 | ||
|
|
2a28772312 | ||
|
|
d04c6dd3ac | ||
|
|
e48daffad9 | ||
|
|
58642286c9 | ||
|
|
6d62ae226a | ||
|
|
14f6f9ec94 | ||
|
|
e10f447b5b | ||
|
|
1d1f61613c | ||
|
|
18ad01533b | ||
|
|
288049dc95 | ||
|
|
573c8f3b13 | ||
|
|
e85d7a7be5 | ||
|
|
7015215f26 | ||
|
|
ffa5472b31 | ||
|
|
e00f0b4cf1 | ||
|
|
dc5c220e8f | ||
|
|
933d49b0b0 | ||
|
|
9af85f5a7e | ||
|
|
7ec52145e8 | ||
|
|
aa6112482d | ||
|
|
d035cdcff9 | ||
|
|
7ad3ddef2a | ||
|
|
38e08bb91f | ||
|
|
252a21e2ae | ||
|
|
ba7db3edda | ||
|
|
f64b061a28 | ||
|
|
f323ced4ca | ||
|
|
c06ec7c6ba | ||
|
|
835f9aad91 | ||
|
|
a4ec9f8b44 | ||
|
|
47c33d0344 | ||
|
|
f500c7abcb | ||
|
|
95dd7b5323 | ||
|
|
65c950e1a4 | ||
|
|
e484f32b1a | ||
|
|
bc396e7a90 | ||
|
|
ce182f43db | ||
|
|
9382d52d55 | ||
|
|
dd156d0689 | ||
|
|
ac9f6e3a41 | ||
|
|
1e7534b9d7 | ||
|
|
72d800ed10 | ||
|
|
54143ae6d4 | ||
|
|
f0d6d46766 | ||
|
|
4a81205e04 | ||
|
|
0ac37981cb | ||
|
|
400c31d031 | ||
|
|
54b38086e5 | ||
|
|
e0deca33d0 | ||
|
|
0b2b8b960b | ||
|
|
9826b8ae69 | ||
|
|
2ce9fb9760 | ||
|
|
ae66c6f0b4 |
2
.github/ISSUE_TEMPLATE.md
vendored
2
.github/ISSUE_TEMPLATE.md
vendored
@@ -5,7 +5,7 @@
|
||||
如何调试 https://github.com/Neilpang/acme.sh/wiki/How-to-debug-acme.sh
|
||||
|
||||
If it is a bug report:
|
||||
- make sure you are able to repro it on the latest released version.
|
||||
- make sure you are able to repro it on the latest released version.
|
||||
You can install the latest version by: `acme.sh --upgrade`
|
||||
|
||||
- Search the existing issues.
|
||||
|
||||
@@ -28,11 +28,11 @@ script:
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then shellcheck -V ; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then shellcheck -e SC2181 **/*.sh && echo "shellcheck OK" ; fi
|
||||
- cd ..
|
||||
- git clone https://github.com/Neilpang/acmetest.git && cp -r acme.sh acmetest/ && cd acmetest
|
||||
- git clone --depth 1 https://github.com/Neilpang/acmetest.git && cp -r acme.sh acmetest/ && cd acmetest
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$NGROK_TOKEN" ]; then sudo TEST_LOCAL="$TEST_LOCAL" NGROK_TOKEN="$NGROK_TOKEN" ./rundocker.sh testplat ubuntu:latest ; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "osx" -a "$NGROK_TOKEN" ]; then sudo TEST_LOCAL="$TEST_LOCAL" NGROK_TOKEN="$NGROK_TOKEN" ACME_OPENSSL_BIN="$ACME_OPENSSL_BIN" ./letest.sh ; fi
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ FROM alpine:3.10
|
||||
RUN apk update -f \
|
||||
&& apk --no-cache add -f \
|
||||
openssl \
|
||||
openssh-client \
|
||||
coreutils \
|
||||
bind-tools \
|
||||
curl \
|
||||
|
||||
206
acme.sh
206
acme.sh
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
VER=2.8.4
|
||||
VER=2.8.5
|
||||
|
||||
PROJECT_NAME="acme.sh"
|
||||
|
||||
@@ -153,7 +153,7 @@ fi
|
||||
|
||||
__green() {
|
||||
if [ "${__INTERACTIVE}${ACME_NO_COLOR:-0}" = "10" -o "${ACME_FORCE_COLOR}" = "1" ]; then
|
||||
printf '\033[1;31;32m%b\033[0m' "$1"
|
||||
printf '\33[1;32m%b\33[0m' "$1"
|
||||
return
|
||||
fi
|
||||
printf -- "%b" "$1"
|
||||
@@ -161,7 +161,7 @@ __green() {
|
||||
|
||||
__red() {
|
||||
if [ "${__INTERACTIVE}${ACME_NO_COLOR:-0}" = "10" -o "${ACME_FORCE_COLOR}" = "1" ]; then
|
||||
printf '\033[1;31;40m%b\033[0m' "$1"
|
||||
printf '\33[1;31m%b\33[0m' "$1"
|
||||
return
|
||||
fi
|
||||
printf -- "%b" "$1"
|
||||
@@ -178,7 +178,7 @@ _printargs() {
|
||||
printf -- "%s" "$1='$2'"
|
||||
fi
|
||||
printf "\n"
|
||||
# return the saved exit status
|
||||
# return the saved exit status
|
||||
return "$_exitstatus"
|
||||
}
|
||||
|
||||
@@ -265,6 +265,37 @@ _usage() {
|
||||
printf "\n" >&2
|
||||
}
|
||||
|
||||
__debug_bash_helper() {
|
||||
# At this point only do for --debug 3
|
||||
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -lt "$DEBUG_LEVEL_3" ]; then
|
||||
return
|
||||
fi
|
||||
# Return extra debug info when running with bash, otherwise return empty
|
||||
# string.
|
||||
if [ -z "${BASH_VERSION}" ]; then
|
||||
return
|
||||
fi
|
||||
# We are a bash shell at this point, return the filename, function name, and
|
||||
# line number as a string
|
||||
_dbh_saveIFS=$IFS
|
||||
IFS=" "
|
||||
# Must use eval or syntax error happens under dash. The eval should use
|
||||
# single quotes as older versions of busybox had a bug with double quotes and
|
||||
# eval.
|
||||
# Use 'caller 1' as we want one level up the stack as we should be called
|
||||
# by one of the _debug* functions
|
||||
eval '_dbh_called=($(caller 1))'
|
||||
IFS=$_dbh_saveIFS
|
||||
eval '_dbh_file=${_dbh_called[2]}'
|
||||
if [ -n "${_script_home}" ]; then
|
||||
# Trim off the _script_home directory name
|
||||
eval '_dbh_file=${_dbh_file#$_script_home/}'
|
||||
fi
|
||||
eval '_dbh_function=${_dbh_called[1]}'
|
||||
eval '_dbh_lineno=${_dbh_called[0]}'
|
||||
printf "%-40s " "$_dbh_file:${_dbh_function}:${_dbh_lineno}"
|
||||
}
|
||||
|
||||
_debug() {
|
||||
if [ "${LOG_LEVEL:-$DEFAULT_LOG_LEVEL}" -ge "$LOG_LEVEL_1" ]; then
|
||||
_log "$@"
|
||||
@@ -273,7 +304,8 @@ _debug() {
|
||||
_syslog "$SYSLOG_DEBUG" "$@"
|
||||
fi
|
||||
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_1" ]; then
|
||||
_printargs "$@" >&2
|
||||
_bash_debug=$(__debug_bash_helper)
|
||||
_printargs "${_bash_debug}$@" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -306,7 +338,8 @@ _debug2() {
|
||||
_syslog "$SYSLOG_DEBUG" "$@"
|
||||
fi
|
||||
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_2" ]; then
|
||||
_printargs "$@" >&2
|
||||
_bash_debug=$(__debug_bash_helper)
|
||||
_printargs "${_bash_debug}$@" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -338,7 +371,8 @@ _debug3() {
|
||||
_syslog "$SYSLOG_DEBUG" "$@"
|
||||
fi
|
||||
if [ "${DEBUG:-$DEBUG_LEVEL_NONE}" -ge "$DEBUG_LEVEL_3" ]; then
|
||||
_printargs "$@" >&2
|
||||
_bash_debug=$(__debug_bash_helper)
|
||||
_printargs "${_bash_debug}$@" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -461,6 +495,19 @@ _exists() {
|
||||
return $ret
|
||||
}
|
||||
|
||||
_findcommand() {
|
||||
_fcmd="$1"
|
||||
if command >/dev/null 2>&1; then
|
||||
command -v "$_fcmd"
|
||||
elif _exists which; then
|
||||
which "$_fcmd"
|
||||
elif eval type type >/dev/null 2>&1; then
|
||||
eval type $_fcmd | cut -d " " -f 3
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#a + b
|
||||
_math() {
|
||||
_m_opts="$@"
|
||||
@@ -1985,7 +2032,7 @@ _send_signed_request() {
|
||||
_debug code "$code"
|
||||
|
||||
_debug2 original "$response"
|
||||
if echo "$responseHeaders" | grep -i "Content-Type: application/json" >/dev/null 2>&1; then
|
||||
if echo "$responseHeaders" | grep -i "Content-Type: *application/json" >/dev/null 2>&1; then
|
||||
response="$(echo "$response" | _normalizeJson)"
|
||||
fi
|
||||
_debug2 response "$response"
|
||||
@@ -2006,8 +2053,10 @@ _send_signed_request() {
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
break
|
||||
return 0
|
||||
done
|
||||
_info "Giving up sending to CA server after $MAX_REQUEST_RETRY_TIMES retries."
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
@@ -2379,7 +2428,7 @@ __initHome() {
|
||||
if [ -z "$ACCOUNT_CONF_PATH" ]; then
|
||||
ACCOUNT_CONF_PATH="$_DEFAULT_ACCOUNT_CONF_PATH"
|
||||
fi
|
||||
|
||||
_debug3 ACCOUNT_CONF_PATH "$ACCOUNT_CONF_PATH"
|
||||
DEFAULT_LOG_FILE="$LE_CONFIG_HOME/$PROJECT_NAME.log"
|
||||
|
||||
DEFAULT_CA_HOME="$LE_CONFIG_HOME/ca"
|
||||
@@ -3331,7 +3380,7 @@ _on_issue_success() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if _hasfield "$Le_Webroot" "$W_DNS"; then
|
||||
if _hasfield "$Le_Webroot" "$W_DNS" && [ -z "$FORCE_DNS_MANUAL" ]; then
|
||||
_err "$_DNS_MANUAL_WARN"
|
||||
fi
|
||||
|
||||
@@ -3411,7 +3460,7 @@ _regAccount() {
|
||||
fi
|
||||
|
||||
_debug2 responseHeaders "$responseHeaders"
|
||||
_accUri="$(echo "$responseHeaders" | grep -i "^Location:" | _head_n 1 | cut -d ' ' -f 2 | tr -d "\r\n")"
|
||||
_accUri="$(echo "$responseHeaders" | grep -i "^Location:" | _head_n 1 | cut -d ':' -f 2- | tr -d "\r\n ")"
|
||||
_debug "_accUri" "$_accUri"
|
||||
if [ -z "$_accUri" ]; then
|
||||
_err "Can not find account id url."
|
||||
@@ -3678,7 +3727,7 @@ _ns_purge_cf() {
|
||||
|
||||
#checks if cf server is available
|
||||
_ns_is_available_cf() {
|
||||
if _get "https://cloudflare-dns.com"; then
|
||||
if _get "https://cloudflare-dns.com" >/dev/null 2>&1; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
@@ -3785,9 +3834,11 @@ _check_dns_entries() {
|
||||
_sleep 10
|
||||
else
|
||||
_info "All success, let's return"
|
||||
break
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
_info "Timed out waiting for DNS."
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
@@ -3968,7 +4019,7 @@ issue() {
|
||||
_on_issue_err "$_post_hook"
|
||||
return 1
|
||||
fi
|
||||
Le_LinkOrder="$(echo "$responseHeaders" | grep -i '^Location.*$' | _tail_n 1 | tr -d "\r\n" | cut -d " " -f 2)"
|
||||
Le_LinkOrder="$(echo "$responseHeaders" | grep -i '^Location.*$' | _tail_n 1 | tr -d "\r\n " | cut -d ":" -f 2-)"
|
||||
_debug Le_LinkOrder "$Le_LinkOrder"
|
||||
Le_OrderFinalize="$(echo "$response" | _egrep_o '"finalize" *: *"[^"]*"' | cut -d '"' -f 4)"
|
||||
_debug Le_OrderFinalize "$Le_OrderFinalize"
|
||||
@@ -4047,7 +4098,18 @@ $_authorizations_map"
|
||||
fi
|
||||
|
||||
if [ "$ACME_VERSION" = "2" ]; then
|
||||
response="$(echo "$_authorizations_map" | grep "^$(_idn "$d")," | sed "s/$d,//")"
|
||||
_idn_d="$(_idn "$d")"
|
||||
_candindates="$(echo "$_authorizations_map" | grep -i "^$_idn_d,")"
|
||||
_debug2 _candindates "$_candindates"
|
||||
if [ "$(echo "$_candindates" | wc -l)" -gt 1 ]; then
|
||||
for _can in $_candindates; do
|
||||
if _startswith "$(echo "$_can" | tr '.' '|')" "$(echo "$_idn_d" | tr '.' '|'),"; then
|
||||
_candindates="$_can"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
response="$(echo "$_candindates" | sed "s/$_idn_d,//")"
|
||||
_debug2 "response" "$response"
|
||||
if [ -z "$response" ]; then
|
||||
_err "get to authz error."
|
||||
@@ -4070,45 +4132,59 @@ $_authorizations_map"
|
||||
|
||||
entry="$(echo "$response" | _egrep_o '[^\{]*"type":"'$vtype'"[^\}]*')"
|
||||
_debug entry "$entry"
|
||||
keyauthorization=""
|
||||
if [ -z "$entry" ]; then
|
||||
_err "Error, can not get domain token entry $d"
|
||||
_supported_vtypes="$(echo "$response" | _egrep_o "\"challenges\":\[[^]]*]" | tr '{' "\n" | grep type | cut -d '"' -f 4 | tr "\n" ' ')"
|
||||
if [ "$_supported_vtypes" ]; then
|
||||
_err "The supported validation types are: $_supported_vtypes, but you specified: $vtype"
|
||||
if ! _startswith "$d" '*.'; then
|
||||
_debug "Not a wildcard domain, lets check whether the validation is already valid."
|
||||
if echo "$response" | grep '"status":"valid"' >/dev/null 2>&1; then
|
||||
_debug "$d is already valid."
|
||||
keyauthorization="$STATE_VERIFIED"
|
||||
_debug keyauthorization "$keyauthorization"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$keyauthorization" ]; then
|
||||
_err "Error, can not get domain token entry $d for $vtype"
|
||||
_supported_vtypes="$(echo "$response" | _egrep_o "\"challenges\":\[[^]]*]" | tr '{' "\n" | grep type | cut -d '"' -f 4 | tr "\n" ' ')"
|
||||
if [ "$_supported_vtypes" ]; then
|
||||
_err "The supported validation types are: $_supported_vtypes, but you specified: $vtype"
|
||||
fi
|
||||
_clearup
|
||||
_on_issue_err "$_post_hook"
|
||||
return 1
|
||||
fi
|
||||
_clearup
|
||||
_on_issue_err "$_post_hook"
|
||||
return 1
|
||||
fi
|
||||
token="$(echo "$entry" | _egrep_o '"token":"[^"]*' | cut -d : -f 2 | tr -d '"')"
|
||||
_debug token "$token"
|
||||
|
||||
if [ -z "$token" ]; then
|
||||
_err "Error, can not get domain token $entry"
|
||||
_clearup
|
||||
_on_issue_err "$_post_hook"
|
||||
return 1
|
||||
fi
|
||||
if [ "$ACME_VERSION" = "2" ]; then
|
||||
uri="$(echo "$entry" | _egrep_o '"url":"[^"]*' | cut -d '"' -f 4 | _head_n 1)"
|
||||
else
|
||||
uri="$(echo "$entry" | _egrep_o '"uri":"[^"]*' | cut -d '"' -f 4)"
|
||||
fi
|
||||
_debug uri "$uri"
|
||||
if [ -z "$keyauthorization" ]; then
|
||||
token="$(echo "$entry" | _egrep_o '"token":"[^"]*' | cut -d : -f 2 | tr -d '"')"
|
||||
_debug token "$token"
|
||||
|
||||
if [ -z "$uri" ]; then
|
||||
_err "Error, can not get domain uri. $entry"
|
||||
_clearup
|
||||
_on_issue_err "$_post_hook"
|
||||
return 1
|
||||
fi
|
||||
keyauthorization="$token.$thumbprint"
|
||||
_debug keyauthorization "$keyauthorization"
|
||||
if [ -z "$token" ]; then
|
||||
_err "Error, can not get domain token $entry"
|
||||
_clearup
|
||||
_on_issue_err "$_post_hook"
|
||||
return 1
|
||||
fi
|
||||
if [ "$ACME_VERSION" = "2" ]; then
|
||||
uri="$(echo "$entry" | _egrep_o '"url":"[^"]*' | cut -d '"' -f 4 | _head_n 1)"
|
||||
else
|
||||
uri="$(echo "$entry" | _egrep_o '"uri":"[^"]*' | cut -d '"' -f 4)"
|
||||
fi
|
||||
_debug uri "$uri"
|
||||
|
||||
if printf "%s" "$response" | grep '"status":"valid"' >/dev/null 2>&1; then
|
||||
_debug "$d is already verified."
|
||||
keyauthorization="$STATE_VERIFIED"
|
||||
if [ -z "$uri" ]; then
|
||||
_err "Error, can not get domain uri. $entry"
|
||||
_clearup
|
||||
_on_issue_err "$_post_hook"
|
||||
return 1
|
||||
fi
|
||||
keyauthorization="$token.$thumbprint"
|
||||
_debug keyauthorization "$keyauthorization"
|
||||
|
||||
if printf "%s" "$response" | grep '"status":"valid"' >/dev/null 2>&1; then
|
||||
_debug "$d is already verified."
|
||||
keyauthorization="$STATE_VERIFIED"
|
||||
_debug keyauthorization "$keyauthorization"
|
||||
fi
|
||||
fi
|
||||
|
||||
dvlist="$d$sep$keyauthorization$sep$uri$sep$vtype$sep$_currentRoot"
|
||||
@@ -4472,7 +4548,7 @@ $_authorizations_map"
|
||||
return 1
|
||||
fi
|
||||
if [ -z "$Le_LinkOrder" ]; then
|
||||
Le_LinkOrder="$(echo "$responseHeaders" | grep -i '^Location.*$' | _tail_n 1 | tr -d "\r\n" | cut -d " " -f 2)"
|
||||
Le_LinkOrder="$(echo "$responseHeaders" | grep -i '^Location.*$' | _tail_n 1 | tr -d "\r\n" | cut -d ":" -f 2-)"
|
||||
fi
|
||||
|
||||
_savedomainconf "Le_LinkOrder" "$Le_LinkOrder"
|
||||
@@ -5523,7 +5599,7 @@ _deactivate() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
authzUri="$(echo "$responseHeaders" | grep "^Location:" | _head_n 1 | cut -d ' ' -f 2 | tr -d "\r\n")"
|
||||
authzUri="$(echo "$responseHeaders" | grep "^Location:" | _head_n 1 | cut -d ':' -f 2- | tr -d "\r\n")"
|
||||
_debug "authzUri" "$authzUri"
|
||||
if [ "$code" ] && [ ! "$code" = '201' ]; then
|
||||
_err "new-authz error: $response"
|
||||
@@ -5903,15 +5979,27 @@ install() {
|
||||
fi
|
||||
|
||||
if [ -z "$NO_DETECT_SH" ]; then
|
||||
_bash_path=""
|
||||
#Modify shebang
|
||||
if _exists bash; then
|
||||
_bash_path="$(bash -c "command -v bash 2>/dev/null")"
|
||||
if [ -z "$_bash_path" ]; then
|
||||
_bash_path="$(bash -c 'echo $SHELL')"
|
||||
fi
|
||||
if [ "$_bash_path" ]; then
|
||||
_info "Good, bash is found, so change the shebang to use bash as preferred."
|
||||
fi
|
||||
else
|
||||
_env="$(_findcommand env)"
|
||||
_envret="$?"
|
||||
_debug "_env" "$_env"
|
||||
if [ "$_envret" = "0" ] && [ "$_env" ] && [ "$_env" != "/usr/bin/env" ]; then
|
||||
_info "It seems env $_env is not in the default location."
|
||||
_info "Let's change env shebang."
|
||||
_bash_path="$_env sh"
|
||||
fi
|
||||
fi
|
||||
if [ "$_bash_path" ]; then
|
||||
_info "Good, bash is found, so change the shebang to use bash as preferred."
|
||||
_shebang='#!'"$_bash_path"
|
||||
_setShebang "$LE_WORKING_DIR/$PROJECT_ENTRY" "$_shebang"
|
||||
for subf in $_SUB_FOLDERS; do
|
||||
@@ -6059,7 +6147,7 @@ _send_notify() {
|
||||
_set_notify_hook() {
|
||||
_nhooks="$1"
|
||||
|
||||
_test_subject="Hello, this is notification from $PROJECT_NAME"
|
||||
_test_subject="Hello, this is a notification from $PROJECT_NAME"
|
||||
_test_content="If you receive this message, your notification works."
|
||||
|
||||
_send_notify "$_test_subject" "$_test_content" "$_nhooks" 0
|
||||
@@ -6215,7 +6303,7 @@ Parameters:
|
||||
--branch, -b Only valid for '--upgrade' command, specifies the branch name to upgrade to.
|
||||
|
||||
--notify-level 0|1|2|3 Set the notification level: Default value is $NOTIFY_LEVEL_DEFAULT.
|
||||
0: disabled, no notification will be sent.
|
||||
0: disabled, no notification will be sent.
|
||||
1: send notifications only when there is an error.
|
||||
2: send notifications when a cert is successfully renewed, or there is an error.
|
||||
3: send notifications when a cert is skipped, renewed, or error.
|
||||
@@ -6254,6 +6342,8 @@ _installOnline() {
|
||||
chmod +x $PROJECT_ENTRY
|
||||
if ./$PROJECT_ENTRY install "$_nocron" "" "$_noprofile"; then
|
||||
_info "Install success!"
|
||||
_initpath
|
||||
_saveaccountconf "UPGRADE_HASH" "$(_getMasterHash)"
|
||||
fi
|
||||
|
||||
cd ..
|
||||
@@ -6263,9 +6353,19 @@ _installOnline() {
|
||||
)
|
||||
}
|
||||
|
||||
_getMasterHash() {
|
||||
_b="$BRANCH"
|
||||
if [ -z "$_b" ]; then
|
||||
_b="master"
|
||||
fi
|
||||
_hash_url="https://api.github.com/repos/Neilpang/acme.sh/git/refs/heads/$_b"
|
||||
_get $_hash_url | tr -d "\r\n" | tr '{},' '\n' | grep '"sha":' | cut -d '"' -f 4
|
||||
}
|
||||
|
||||
upgrade() {
|
||||
if (
|
||||
_initpath
|
||||
[ -z "$FORCE" ] && [ "$(_getMasterHash)" = "$(_readaccountconf "UPGRADE_HASH")" ] && _info "Already uptodate!" && exit 0
|
||||
export LE_WORKING_DIR
|
||||
cd "$LE_WORKING_DIR"
|
||||
_installOnline "nocron" "noprofile"
|
||||
|
||||
@@ -77,15 +77,15 @@ gcore_cdn_deploy() {
|
||||
_debug _regex "$_regex"
|
||||
_resource=$(echo "$_response" | sed 's/},{/},\n{/g' | _egrep_o "$_regex")
|
||||
_debug _resource "$_resource"
|
||||
_regex=".*\"id\":\([0-9]*\),.*$"
|
||||
_regex=".*\"id\":\([0-9]*\).*\"rules\".*$"
|
||||
_debug _regex "$_regex"
|
||||
_resourceId=$(echo "$_resource" | sed -n "s/$_regex/\1/p")
|
||||
_debug _resourceId "$_resourceId"
|
||||
_regex=".*\"sslData\":\([0-9]*\)}.*$"
|
||||
_regex=".*\"sslData\":\([0-9]*\).*$"
|
||||
_debug _regex "$_regex"
|
||||
_sslDataOld=$(echo "$_resource" | sed -n "s/$_regex/\1/p")
|
||||
_debug _sslDataOld "$_sslDataOld"
|
||||
_regex=".*\"originGroup\":\([0-9]*\),.*$"
|
||||
_regex=".*\"originGroup\":\([0-9]*\).*$"
|
||||
_debug _regex "$_regex"
|
||||
_originGroup=$(echo "$_resource" | sed -n "s/$_regex/\1/p")
|
||||
_debug _originGroup "$_originGroup"
|
||||
@@ -101,7 +101,7 @@ gcore_cdn_deploy() {
|
||||
_debug _request "$_request"
|
||||
_response=$(_post "$_request" "https://api.gcdn.co/sslData")
|
||||
_debug _response "$_response"
|
||||
_regex=".*\"id\":\([0-9]*\),.*$"
|
||||
_regex=".*\"id\":\([0-9]*\).*$"
|
||||
_debug _regex "$_regex"
|
||||
_sslDataAdd=$(echo "$_response" | sed -n "s/$_regex/\1/p")
|
||||
_debug _sslDataAdd "$_sslDataAdd"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Script to create certificate to qiniu.com
|
||||
# Script to create certificate to qiniu.com
|
||||
#
|
||||
# This deployment required following variables
|
||||
# export QINIU_AK="QINIUACCESSKEY"
|
||||
|
||||
@@ -85,19 +85,19 @@ routeros_deploy() {
|
||||
scp "$_ckey" "$ROUTER_OS_USERNAME@$ROUTER_OS_HOST:$_cdomain.key"
|
||||
_info "Trying to push cert '$_cfullchain' to router"
|
||||
scp "$_cfullchain" "$ROUTER_OS_USERNAME@$ROUTER_OS_HOST:$_cdomain.cer"
|
||||
DEPLOY_SCRIPT_CMD="/system script add name=\"LE Cert Deploy - $_cdomain\" owner=admin policy=ftp,read,write,password,sensitive
|
||||
source=\"## generated by routeros deploy script in acme.sh
|
||||
\n/certificate remove [ find name=$_cdomain.cer_0 ]
|
||||
\n/certificate remove [ find name=$_cdomain.cer_1 ]
|
||||
\ndelay 1
|
||||
\n/certificate import file-name=$_cdomain.cer passphrase=\\\"\\\"
|
||||
\n/certificate import file-name=$_cdomain.key passphrase=\\\"\\\"
|
||||
\ndelay 1
|
||||
\n/file remove $_cdomain.cer
|
||||
\n/file remove $_cdomain.key
|
||||
\ndelay 2
|
||||
\n/ip service set www-ssl certificate=$_cdomain.cer_0
|
||||
\n$ROUTER_OS_ADDITIONAL_SERVICES
|
||||
DEPLOY_SCRIPT_CMD="/system script add name=\"LE Cert Deploy - $_cdomain\" owner=admin policy=ftp,read,write,password,sensitive \
|
||||
source=\"## generated by routeros deploy script in acme.sh;\
|
||||
\n/certificate remove [ find name=$_cdomain.cer_0 ];\
|
||||
\n/certificate remove [ find name=$_cdomain.cer_1 ];\
|
||||
\ndelay 1;\
|
||||
\n/certificate import file-name=$_cdomain.cer passphrase=\\\"\\\";\
|
||||
\n/certificate import file-name=$_cdomain.key passphrase=\\\"\\\";\
|
||||
\ndelay 1;\
|
||||
\n/file remove $_cdomain.cer;\
|
||||
\n/file remove $_cdomain.key;\
|
||||
\ndelay 2;\
|
||||
\n/ip service set www-ssl certificate=$_cdomain.cer_0;\
|
||||
\n$ROUTER_OS_ADDITIONAL_SERVICES;\
|
||||
\n\"
|
||||
"
|
||||
# shellcheck disable=SC2029
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
# Here is a script to deploy cert to hashicorp vault
|
||||
# (https://www.vaultproject.io/)
|
||||
#
|
||||
#
|
||||
# it requires the vault binary to be available in PATH, and the following
|
||||
# environment variables:
|
||||
#
|
||||
#
|
||||
# VAULT_PREFIX - this contains the prefix path in vault
|
||||
# VAULT_ADDR - vault requires this to find your vault server
|
||||
#
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#AWS_SECRET_ACCESS_KEY="xxxxxxx"
|
||||
|
||||
#This is the Amazon Route53 api wrapper for acme.sh
|
||||
#All `_sleep` commands are included to avoid Route53 throttling, see
|
||||
#https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html#limits-api-requests
|
||||
|
||||
AWS_HOST="route53.amazonaws.com"
|
||||
AWS_URL="https://$AWS_HOST"
|
||||
@@ -43,6 +45,7 @@ dns_aws_add() {
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
_sleep 1
|
||||
return 1
|
||||
fi
|
||||
_debug _domain_id "$_domain_id"
|
||||
@@ -51,6 +54,7 @@ dns_aws_add() {
|
||||
|
||||
_info "Getting existing records for $fulldomain"
|
||||
if ! aws_rest GET "2013-04-01$_domain_id/rrset" "name=$fulldomain&type=TXT"; then
|
||||
_sleep 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -63,6 +67,7 @@ dns_aws_add() {
|
||||
|
||||
if [ "$_resource_record" ] && _contains "$response" "$txtvalue"; then
|
||||
_info "The TXT record already exists. Skipping."
|
||||
_sleep 1
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -72,9 +77,10 @@ dns_aws_add() {
|
||||
|
||||
if aws_rest POST "2013-04-01$_domain_id/rrset/" "" "$_aws_tmpl_xml" && _contains "$response" "ChangeResourceRecordSetsResponse"; then
|
||||
_info "TXT record updated successfully."
|
||||
_sleep 1
|
||||
return 0
|
||||
fi
|
||||
|
||||
_sleep 1
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -93,6 +99,7 @@ dns_aws_rm() {
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
_sleep 1
|
||||
return 1
|
||||
fi
|
||||
_debug _domain_id "$_domain_id"
|
||||
@@ -101,6 +108,7 @@ dns_aws_rm() {
|
||||
|
||||
_info "Getting existing records for $fulldomain"
|
||||
if ! aws_rest GET "2013-04-01$_domain_id/rrset" "name=$fulldomain&type=TXT"; then
|
||||
_sleep 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -109,6 +117,7 @@ dns_aws_rm() {
|
||||
_debug "_resource_record" "$_resource_record"
|
||||
else
|
||||
_debug "no records exist, skip"
|
||||
_sleep 1
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -116,9 +125,10 @@ dns_aws_rm() {
|
||||
|
||||
if aws_rest POST "2013-04-01$_domain_id/rrset/" "" "$_aws_tmpl_xml" && _contains "$response" "ChangeResourceRecordSetsResponse"; then
|
||||
_info "TXT record deleted successfully."
|
||||
_sleep 1
|
||||
return 0
|
||||
fi
|
||||
|
||||
_sleep 1
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
197
dnsapi/dns_clouddns.sh
Executable file
197
dnsapi/dns_clouddns.sh
Executable file
@@ -0,0 +1,197 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Author: Radek Sprta <sprta@vshosting.cz>
|
||||
|
||||
#CLOUDDNS_EMAIL=XXXXX
|
||||
#CLOUDDNS_PASSWORD="YYYYYYYYY"
|
||||
#CLOUDDNS_CLIENT_ID=XXXXX
|
||||
|
||||
CLOUDDNS_API='https://admin.vshosting.cloud/clouddns'
|
||||
CLOUDDNS_LOGIN_API='https://admin.vshosting.cloud/api/public/auth/login'
|
||||
|
||||
######## Public functions #####################
|
||||
|
||||
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||
dns_clouddns_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
_debug "fulldomain" "$fulldomain"
|
||||
|
||||
CLOUDDNS_CLIENT_ID="${CLOUDDNS_CLIENT_ID:-$(_readaccountconf_mutable CLOUDDNS_CLIENT_ID)}"
|
||||
CLOUDDNS_EMAIL="${CLOUDDNS_EMAIL:-$(_readaccountconf_mutable CLOUDDNS_EMAIL)}"
|
||||
CLOUDDNS_PASSWORD="${CLOUDDNS_PASSWORD:-$(_readaccountconf_mutable CLOUDDNS_PASSWORD)}"
|
||||
|
||||
if [ -z "$CLOUDDNS_PASSWORD" ] || [ -z "$CLOUDDNS_EMAIL" ] || [ -z "$CLOUDDNS_CLIENT_ID" ]; then
|
||||
CLOUDDNS_CLIENT_ID=""
|
||||
CLOUDDNS_EMAIL=""
|
||||
CLOUDDNS_PASSWORD=""
|
||||
_err "You didn't specify a CloudDNS password, email and client ID yet."
|
||||
return 1
|
||||
fi
|
||||
if ! _contains "$CLOUDDNS_EMAIL" "@"; then
|
||||
_err "It seems that the CLOUDDNS_EMAIL=$CLOUDDNS_EMAIL is not a valid email address."
|
||||
_err "Please check and retry."
|
||||
return 1
|
||||
fi
|
||||
# Save CloudDNS client id, email and password to config file
|
||||
_saveaccountconf_mutable CLOUDDNS_CLIENT_ID "$CLOUDDNS_CLIENT_ID"
|
||||
_saveaccountconf_mutable CLOUDDNS_EMAIL "$CLOUDDNS_EMAIL"
|
||||
_saveaccountconf_mutable CLOUDDNS_PASSWORD "$CLOUDDNS_PASSWORD"
|
||||
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "Invalid domain"
|
||||
return 1
|
||||
fi
|
||||
_debug _domain_id "$_domain_id"
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
|
||||
# Add TXT record
|
||||
data="{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"value\":\"$txtvalue\",\"domainId\":\"$_domain_id\"}"
|
||||
if _clouddns_api POST "record-txt" "$data"; then
|
||||
if _contains "$response" "$txtvalue"; then
|
||||
_info "Added, OK"
|
||||
elif _contains "$response" '"code":4136'; then
|
||||
_info "Already exists, OK"
|
||||
else
|
||||
_err "Add TXT record error."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
_debug "Publishing record changes"
|
||||
_clouddns_api PUT "domain/$_domain_id/publish" "{\"soaTtl\":300}"
|
||||
}
|
||||
|
||||
# Usage: rm _acme-challenge.www.domain.com
|
||||
dns_clouddns_rm() {
|
||||
fulldomain=$1
|
||||
_debug "fulldomain" "$fulldomain"
|
||||
|
||||
CLOUDDNS_CLIENT_ID="${CLOUDDNS_CLIENT_ID:-$(_readaccountconf_mutable CLOUDDNS_CLIENT_ID)}"
|
||||
CLOUDDNS_EMAIL="${CLOUDDNS_EMAIL:-$(_readaccountconf_mutable CLOUDDNS_EMAIL)}"
|
||||
CLOUDDNS_PASSWORD="${CLOUDDNS_PASSWORD:-$(_readaccountconf_mutable CLOUDDNS_PASSWORD)}"
|
||||
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "Invalid domain"
|
||||
return 1
|
||||
fi
|
||||
_debug _domain_id "$_domain_id"
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
|
||||
# Get record ID
|
||||
_clouddns_api GET "domain/$_domain_id"
|
||||
if _contains "$response" "lastDomainRecordList"; then
|
||||
re="\"lastDomainRecordList\".*\"id\":\"([^\"}]*)\"[^}]*\"name\":\"$fulldomain.\","
|
||||
_last_domains=$(echo "$response" | _egrep_o "$re")
|
||||
re2="\"id\":\"([^\"}]*)\"[^}]*\"name\":\"$fulldomain.\","
|
||||
_record_id=$(echo "$_last_domains" | _egrep_o "$re2" | _head_n 1 | cut -d : -f 2 | cut -d , -f 1 | tr -d "\"")
|
||||
_debug _record_id "$_record_id"
|
||||
else
|
||||
_err "Could not retrieve record ID"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_info "Removing record"
|
||||
if _clouddns_api DELETE "record/$_record_id"; then
|
||||
if _contains "$response" "\"error\":"; then
|
||||
_err "Could not remove record"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
_debug "Publishing record changes"
|
||||
_clouddns_api PUT "domain/$_domain_id/publish" "{\"soaTtl\":300}"
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
|
||||
# Usage: _get_root _acme-challenge.www.domain.com
|
||||
# Returns:
|
||||
# _sub_domain=_acme-challenge.www
|
||||
# _domain=domain.com
|
||||
# _domain_id=sdjkglgdfewsdfg
|
||||
_get_root() {
|
||||
domain=$1
|
||||
|
||||
# Get domain root
|
||||
data="{\"search\": [{\"name\": \"clientId\", \"operator\": \"eq\", \"value\": \"$CLOUDDNS_CLIENT_ID\"}]}"
|
||||
_clouddns_api "POST" "domain/search" "$data"
|
||||
domain_slice="$domain"
|
||||
while [ -z "$domain_root" ]; do
|
||||
if _contains "$response" "\"domainName\":\"$domain_slice\.\""; then
|
||||
domain_root="$domain_slice"
|
||||
_debug domain_root "$domain_root"
|
||||
fi
|
||||
domain_slice="$(echo "$domain_slice" | cut -d . -f 2-)"
|
||||
done
|
||||
|
||||
# Get domain id
|
||||
data="{\"search\": [{\"name\": \"clientId\", \"operator\": \"eq\", \"value\": \"$CLOUDDNS_CLIENT_ID\"}, \
|
||||
{\"name\": \"domainName\", \"operator\": \"eq\", \"value\": \"$domain_root.\"}]}"
|
||||
_clouddns_api "POST" "domain/search" "$data"
|
||||
if _contains "$response" "\"id\":\""; then
|
||||
re='domainType\":\"[^\"]*\",\"id\":\"([^\"]*)\",' # Match domain id
|
||||
_domain_id=$(echo "$response" | _egrep_o "$re" | _head_n 1 | cut -d : -f 3 | tr -d "\",")
|
||||
if [ "$_domain_id" ]; then
|
||||
_sub_domain=$(printf "%s" "$domain" | sed "s/.$domain_root//")
|
||||
_domain="$domain_root"
|
||||
return 0
|
||||
fi
|
||||
_err 'Domain name not found on your CloudDNS account'
|
||||
return 1
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# Usage: _clouddns_api GET domain/search '{"data": "value"}'
|
||||
# Returns:
|
||||
# response='{"message": "api response"}'
|
||||
_clouddns_api() {
|
||||
method=$1
|
||||
endpoint="$2"
|
||||
data="$3"
|
||||
_debug endpoint "$endpoint"
|
||||
|
||||
if [ -z "$CLOUDDNS_TOKEN" ]; then
|
||||
_clouddns_login
|
||||
fi
|
||||
_debug CLOUDDNS_TOKEN "$CLOUDDNS_TOKEN"
|
||||
|
||||
export _H1="Content-Type: application/json"
|
||||
export _H2="Authorization: Bearer $CLOUDDNS_TOKEN"
|
||||
|
||||
if [ "$method" != "GET" ]; then
|
||||
_debug data "$data"
|
||||
response="$(_post "$data" "$CLOUDDNS_API/$endpoint" "" "$method" | tr -d '\t\r\n ')"
|
||||
else
|
||||
response="$(_get "$CLOUDDNS_API/$endpoint" | tr -d '\t\r\n ')"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2181
|
||||
if [ "$?" != "0" ]; then
|
||||
_err "Error $endpoint"
|
||||
return 1
|
||||
fi
|
||||
_debug2 response "$response"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Returns:
|
||||
# CLOUDDNS_TOKEN=dslfje2rj23l
|
||||
_clouddns_login() {
|
||||
login_data="{\"email\": \"$CLOUDDNS_EMAIL\", \"password\": \"$CLOUDDNS_PASSWORD\"}"
|
||||
response="$(_post "$login_data" "$CLOUDDNS_LOGIN_API" "" "POST" "Content-Type: application/json")"
|
||||
|
||||
if _contains "$response" "\"accessToken\":\""; then
|
||||
CLOUDDNS_TOKEN=$(echo "$response" | _egrep_o "\"accessToken\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")
|
||||
export CLOUDDNS_TOKEN
|
||||
else
|
||||
echo 'Could not get CloudDNS access token; check your credentials'
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
#
|
||||
# User must provide login data and URL to DirectAdmin incl. port.
|
||||
# You can create login key, by using the Login Keys function
|
||||
# ( https://da.example.com:8443/CMD_LOGIN_KEYS ), which only has access to
|
||||
# ( https://da.example.com:8443/CMD_LOGIN_KEYS ), which only has access to
|
||||
# - CMD_API_DNS_CONTROL
|
||||
# - CMD_API_SHOW_DOMAINS
|
||||
#
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Official Let's Encrypt API for do.de / Domain-Offensive
|
||||
#
|
||||
#
|
||||
# This is different from the dns_do adapter, because dns_do is only usable for enterprise customers
|
||||
# This API is also available to private customers/individuals
|
||||
#
|
||||
# Provide the required LetsEncrypt token like this:
|
||||
#
|
||||
# Provide the required LetsEncrypt token like this:
|
||||
# DO_LETOKEN="FmD408PdqT1E269gUK57"
|
||||
|
||||
DO_API="https://www.do.de/api/letsencrypt"
|
||||
|
||||
@@ -147,11 +147,11 @@ _dd_soap() {
|
||||
|
||||
# build SOAP XML
|
||||
_xml='<?xml version="1.0" encoding="utf-8"?>
|
||||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
|
||||
xmlns:tns="urn:'$_urn'"
|
||||
xmlns:types="urn:'$_urn'/encodedTypes"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
|
||||
xmlns:tns="urn:'$_urn'"
|
||||
xmlns:types="urn:'$_urn'/encodedTypes"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'"$body"'</soap:Body>
|
||||
</soap:Envelope>'
|
||||
|
||||
172
dnsapi/dns_easydns.sh
Normal file
172
dnsapi/dns_easydns.sh
Normal file
@@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#######################################################
|
||||
#
|
||||
# easyDNS REST API for acme.sh by Neilpang based on dns_cf.sh
|
||||
#
|
||||
# Please note: # API is currently beta and subject to constant change
|
||||
# http://sandbox.rest.easydns.net:3000/
|
||||
#
|
||||
# Author: wurzelpanzer [wurzelpanzer@maximolider.net]
|
||||
# Report Bugs here: https://github.com/Neilpang/acme.sh/issues/2647
|
||||
#
|
||||
#################### Public functions #################
|
||||
|
||||
#EASYDNS_Key="xxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
#EASYDNS_Token="xxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
EASYDNS_Api="https://rest.easydns.net"
|
||||
|
||||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||
dns_easydns_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
EASYDNS_Token="${EASYDNS_Token:-$(_readaccountconf_mutable EASYDNS_Token)}"
|
||||
EASYDNS_Key="${EASYDNS_Key:-$(_readaccountconf_mutable EASYDNS_Key)}"
|
||||
|
||||
if [ -z "$EASYDNS_Token" ] || [ -z "$EASYDNS_Key" ]; then
|
||||
_err "You didn't specify an easydns.net token or api key. Please sign up at http://docs.sandbox.rest.easydns.net/beta_signup.php"
|
||||
return 1
|
||||
else
|
||||
_saveaccountconf_mutable EASYDNS_Token "$EASYDNS_Token"
|
||||
_saveaccountconf_mutable EASYDNS_Key "$EASYDNS_Key"
|
||||
fi
|
||||
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
|
||||
_debug "Getting txt records"
|
||||
_EASYDNS_rest GET "zones/records/all/${_domain}/search/${_sub_domain}"
|
||||
|
||||
if ! printf "%s" "$response" | grep \"status\":200 >/dev/null; then
|
||||
_err "Error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_info "Adding record"
|
||||
if _EASYDNS_rest PUT "zones/records/add/$_domain/TXT" "{\"host\":\"$_sub_domain\",\"rdata\":\"$txtvalue\"}"; then
|
||||
if _contains "$response" "\"status\":201"; then
|
||||
_info "Added, OK"
|
||||
return 0
|
||||
elif _contains "$response" "Record already exists"; then
|
||||
_info "Already exists, OK"
|
||||
return 0
|
||||
else
|
||||
_err "Add txt record error."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
_err "Add txt record error."
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
dns_easydns_rm() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
EASYDNS_Token="${EASYDNS_Token:-$(_readaccountconf_mutable EASYDNS_Token)}"
|
||||
EASYDNS_Key="${EASYDNS_Key:-$(_readaccountconf_mutable EASYDNS_Key)}"
|
||||
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
|
||||
_debug "Getting txt records"
|
||||
_EASYDNS_rest GET "zones/records/all/${_domain}/search/${_sub_domain}"
|
||||
|
||||
if ! printf "%s" "$response" | grep \"status\":200 >/dev/null; then
|
||||
_err "Error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
count=$(printf "%s\n" "$response" | _egrep_o "\"count\":[^,]*" | cut -d : -f 2)
|
||||
_debug count "$count"
|
||||
if [ "$count" = "0" ]; then
|
||||
_info "Don't need to remove."
|
||||
else
|
||||
record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | head -n 1)
|
||||
_debug "record_id" "$record_id"
|
||||
if [ -z "$record_id" ]; then
|
||||
_err "Can not get record id to remove."
|
||||
return 1
|
||||
fi
|
||||
if ! _EASYDNS_rest DELETE "zones/records/$_domain/$record_id"; then
|
||||
_err "Delete record error."
|
||||
return 1
|
||||
fi
|
||||
_contains "$response" "\"status\":200"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
#_acme-challenge.www.domain.com
|
||||
#returns
|
||||
# _sub_domain=_acme-challenge.www
|
||||
# _domain=domain.com
|
||||
_get_root() {
|
||||
domain=$1
|
||||
i=1
|
||||
p=1
|
||||
while true; do
|
||||
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||
_debug h "$h"
|
||||
if [ -z "$h" ]; then
|
||||
#not valid
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! _EASYDNS_rest GET "zones/records/all/$h"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if _contains "$response" "\"status\":200"; then
|
||||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
|
||||
_domain=$h
|
||||
return 0
|
||||
fi
|
||||
|
||||
p=$i
|
||||
i=$(_math "$i" + 1)
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
_EASYDNS_rest() {
|
||||
m=$1
|
||||
ep="$2"
|
||||
data="$3"
|
||||
_debug "$ep"
|
||||
|
||||
basicauth=$(printf "%s" "$EASYDNS_Token":"$EASYDNS_Key" | _base64)
|
||||
|
||||
export _H1="accept: application/json"
|
||||
if [ "$basicauth" ]; then
|
||||
export _H2="Authorization: Basic $basicauth"
|
||||
fi
|
||||
|
||||
if [ "$m" != "GET" ]; then
|
||||
export _H3="Content-Type: application/json"
|
||||
_debug data "$data"
|
||||
response="$(_post "$data" "$EASYDNS_Api/$ep" "" "$m")"
|
||||
else
|
||||
response="$(_get "$EASYDNS_Api/$ep")"
|
||||
fi
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
_err "error $ep"
|
||||
return 1
|
||||
fi
|
||||
_debug2 response "$response"
|
||||
return 0
|
||||
}
|
||||
@@ -127,7 +127,7 @@ dns_euserv_rm() {
|
||||
else
|
||||
# find XML block where txtvalue is in. The record_id is allways prior this line!
|
||||
_endLine=$(echo "$response" | grep -n '>dns_record_content<.*>'"$txtvalue"'<' | cut -d ':' -f 1)
|
||||
# record_id is the last <name> Tag with a number before the row _endLine, identified by </name><value><struct>
|
||||
# record_id is the last <name> Tag with a number before the row _endLine, identified by </name><value><struct>
|
||||
_record_id=$(echo "$response" | sed -n '1,'"$_endLine"'p' | grep '</name><value><struct>' | _tail_n 1 | sed 's/.*<name>\([0-9]*\)<\/name>.*/\1/')
|
||||
_info "Deleting record"
|
||||
_euserv_delete_record "$_record_id"
|
||||
|
||||
@@ -303,9 +303,9 @@ _freedns_domain_id() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
domain_id="$(echo "$htmlpage" | tr -d "[:space:]" | sed 's/<tr>/@<tr>/g' | tr '@' '\n' \
|
||||
domain_id="$(echo "$htmlpage" | tr -d " \t\r\n\v\f" | sed 's/<tr>/@<tr>/g' | tr '@' '\n' \
|
||||
| grep "<td>$search_domain</td>\|<td>$search_domain(.*)</td>" \
|
||||
| _egrep_o "edit\.php\?edit_domain_id=[0-9a-zA-Z]+" \
|
||||
| sed -n 's/.*\(edit\.php?edit_domain_id=[0-9a-zA-Z]*\).*/\1/p' \
|
||||
| cut -d = -f 2)"
|
||||
# The above beauty extracts domain ID from the html page...
|
||||
# strip out all blank space and new lines. Then insert newlines
|
||||
@@ -349,17 +349,17 @@ _freedns_data_id() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
data_id="$(echo "$htmlpage" | tr -d "[:space:]" | sed 's/<tr>/@<tr>/g' | tr '@' '\n' \
|
||||
data_id="$(echo "$htmlpage" | tr -d " \t\r\n\v\f" | sed 's/<tr>/@<tr>/g' | tr '@' '\n' \
|
||||
| grep "<td[a-zA-Z=#]*>$record_type</td>" \
|
||||
| grep "<ahref.*>$search_domain</a>" \
|
||||
| _egrep_o "edit\.php\?data_id=[0-9a-zA-Z]+" \
|
||||
| sed -n 's/.*\(edit\.php?data_id=[0-9a-zA-Z]*\).*/\1/p' \
|
||||
| cut -d = -f 2)"
|
||||
# The above beauty extracts data ID from the html page...
|
||||
# strip out all blank space and new lines. Then insert newlines
|
||||
# before each table row <tr>
|
||||
# search for the record type withing each row (e.g. TXT)
|
||||
# search for the domain within each row (which is within a <a..>
|
||||
# </a> anchor. And finally extract the domain ID.
|
||||
# </a> anchor. And finally extract the domain ID.
|
||||
if [ -n "$data_id" ]; then
|
||||
printf "%s" "$data_id"
|
||||
return 0
|
||||
|
||||
@@ -131,7 +131,7 @@ _dns_gcloud_find_zone() {
|
||||
filter="$filter$part. "
|
||||
part="$(echo "$part" | sed 's/[^.]*\.*//')"
|
||||
done
|
||||
filter="$filter)"
|
||||
filter="$filter) AND visibility=public"
|
||||
_debug filter "$filter"
|
||||
|
||||
# List domains and find the zone with the deepest sub-domain (in case of some levels of delegation)
|
||||
|
||||
149
dnsapi/dns_leaseweb.sh
Normal file
149
dnsapi/dns_leaseweb.sh
Normal file
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#Author: Rolph Haspers <r.haspers@global.leaseweb.com>
|
||||
#Utilize leaseweb.com API to finish dns-01 verifications.
|
||||
#Requires a Leaseweb API Key (export LSW_Key="Your Key")
|
||||
#See http://developer.leaseweb.com for more information.
|
||||
######## Public functions #####################
|
||||
|
||||
LSW_API="https://api.leaseweb.com/hosting/v2/domains/"
|
||||
|
||||
#Usage: dns_leaseweb_add _acme-challenge.www.domain.com
|
||||
dns_leaseweb_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
LSW_Key="${LSW_Key:-$(_readaccountconf_mutable LSW_Key)}"
|
||||
if [ -z "$LSW_Key" ]; then
|
||||
LSW_Key=""
|
||||
_err "You don't specify Leaseweb api key yet."
|
||||
_err "Please create your key and try again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
#save the api key to the account conf file.
|
||||
_saveaccountconf_mutable LSW_Key "$LSW_Key"
|
||||
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug _root_domain "$_domain"
|
||||
_debug _domain "$fulldomain"
|
||||
|
||||
if _lsw_api "POST" "$_domain" "$fulldomain" "$txtvalue"; then
|
||||
if [ "$_code" = "201" ]; then
|
||||
_info "Added, OK"
|
||||
return 0
|
||||
else
|
||||
_err "Add txt record error, invalid code. Code: $_code"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
_err "Add txt record error."
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
#Usage: fulldomain txtvalue
|
||||
#Remove the txt record after validation.
|
||||
dns_leaseweb_rm() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
LSW_Key="${LSW_Key:-$(_readaccountconf_mutable LSW_Key)}"
|
||||
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug _root_domain "$_domain"
|
||||
_debug _domain "$fulldomain"
|
||||
|
||||
if _lsw_api "DELETE" "$_domain" "$fulldomain" "$txtvalue"; then
|
||||
if [ "$_code" = "204" ]; then
|
||||
_info "Deleted, OK"
|
||||
return 0
|
||||
else
|
||||
_err "Delete txt record error."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
_err "Delete txt record error."
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
# _acme-challenge.www.domain.com
|
||||
# returns
|
||||
# _domain=domain.com
|
||||
_get_root() {
|
||||
rdomain=$1
|
||||
i="$(echo "$rdomain" | tr '.' ' ' | wc -w)"
|
||||
i=$(_math "$i" - 1)
|
||||
|
||||
while true; do
|
||||
h=$(printf "%s" "$rdomain" | cut -d . -f "$i"-100)
|
||||
_debug h "$h"
|
||||
if [ -z "$h" ]; then
|
||||
return 1 #not valid domain
|
||||
fi
|
||||
|
||||
#Check API if domain exists
|
||||
if _lsw_api "GET" "$h"; then
|
||||
if [ "$_code" = "200" ]; then
|
||||
_domain="$h"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
i=$(_math "$i" - 1)
|
||||
if [ "$i" -lt 2 ]; then
|
||||
return 1 #not found, no need to check _acme-challenge.sub.domain in leaseweb api.
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
_lsw_api() {
|
||||
cmd=$1
|
||||
d=$2
|
||||
fd=$3
|
||||
tvalue=$4
|
||||
|
||||
# Construct the HTTP Authorization header
|
||||
export _H2="Content-Type: application/json"
|
||||
export _H1="X-Lsw-Auth: ${LSW_Key}"
|
||||
|
||||
if [ "$cmd" = "GET" ]; then
|
||||
response="$(_get "$LSW_API/$d")"
|
||||
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
|
||||
_debug "http response code $_code"
|
||||
_debug response "$response"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$cmd" = "POST" ]; then
|
||||
data="{\"name\": \"$fd.\",\"type\": \"TXT\",\"content\": [\"$tvalue\"],\"ttl\": 60}"
|
||||
response="$(_post "$data" "$LSW_API/$d/resourceRecordSets" "$data" "POST")"
|
||||
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
|
||||
_debug "http response code $_code"
|
||||
_debug response "$response"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$cmd" = "DELETE" ]; then
|
||||
response="$(_post "" "$LSW_API/$d/resourceRecordSets/$fd/TXT" "" "DELETE")"
|
||||
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
|
||||
_debug "http response code $_code"
|
||||
_debug response "$response"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
@@ -63,6 +63,16 @@ _lexicon_init() {
|
||||
_saveaccountconf_mutable "$Lx_domaintoken" "$Lx_domaintoken_v"
|
||||
eval export "$Lx_domaintoken"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2018,SC2019
|
||||
Lx_api_key=$(echo LEXICON_"${PROVIDER}"_API_KEY | tr 'a-z' 'A-Z')
|
||||
eval "$Lx_api_key=\${$Lx_api_key:-$(_readaccountconf_mutable "$Lx_api_key")}"
|
||||
Lx_api_key_v=$(eval echo \$"$Lx_api_key")
|
||||
_secure_debug "$Lx_api_key" "$Lx_api_key_v"
|
||||
if [ "$Lx_api_key_v" ]; then
|
||||
_saveaccountconf_mutable "$Lx_api_key" "$Lx_api_key_v"
|
||||
eval export "$Lx_api_key"
|
||||
fi
|
||||
}
|
||||
|
||||
######## Public functions #####################
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
# bug reports to dev@1e.ca
|
||||
|
||||
# ME_Key=qmlkdjflmkqdjf
|
||||
# ME_Key=qmlkdjflmkqdjf
|
||||
# ME_Secret=qmsdlkqmlksdvnnpae
|
||||
|
||||
ME_Api=https://api.dnsmadeeasy.com/V2.0/dns/managed
|
||||
|
||||
210
dnsapi/dns_miab.sh
Normal file
210
dnsapi/dns_miab.sh
Normal file
@@ -0,0 +1,210 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# Name: dns_miab.sh
|
||||
#
|
||||
# Authors:
|
||||
# Darven Dissek 2018
|
||||
# William Gertz 2019
|
||||
#
|
||||
# Thanks to Neil Pang and other developers here for code reused from acme.sh from DNS-01
|
||||
# used to communicate with the MailinaBox Custom DNS API
|
||||
# Report Bugs here:
|
||||
# https://github.com/billgertz/MIAB_dns_api (for dns_miab.sh)
|
||||
# https://github.com/Neilpang/acme.sh (for acme.sh)
|
||||
#
|
||||
######## Public functions #####################
|
||||
|
||||
#Usage: dns_miab_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||
dns_miab_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
_info "Using miab challange add"
|
||||
_debug fulldomain "$fulldomain"
|
||||
_debug txtvalue "$txtvalue"
|
||||
|
||||
#retrieve MIAB environemt vars
|
||||
if ! _retrieve_miab_env; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
#check domain and seperate into doamin and host
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "Cannot find any part of ${fulldomain} is hosted on ${MIAB_Server}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug2 _sub_domain "$_sub_domain"
|
||||
_debug2 _domain "$_domain"
|
||||
|
||||
#add the challenge record
|
||||
_api_path="custom/${fulldomain}/txt"
|
||||
_miab_rest "$txtvalue" "$_api_path" "POST"
|
||||
|
||||
#check if result was good
|
||||
if _contains "$response" "updated DNS"; then
|
||||
_info "Successfully created the txt record"
|
||||
return 0
|
||||
else
|
||||
_err "Error encountered during record add"
|
||||
_err "$response"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#Usage: dns_miab_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||
dns_miab_rm() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
_info "Using miab challage delete"
|
||||
_debug fulldomain "$fulldomain"
|
||||
_debug txtvalue "$txtvalue"
|
||||
|
||||
#retrieve MIAB environemt vars
|
||||
if ! _retrieve_miab_env; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
#check domain and seperate into doamin and host
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "Cannot find any part of ${fulldomain} is hosted on ${MIAB_Server}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug2 _sub_domain "$_sub_domain"
|
||||
_debug2 _domain "$_domain"
|
||||
|
||||
#Remove the challenge record
|
||||
_api_path="custom/${fulldomain}/txt"
|
||||
_miab_rest "$txtvalue" "$_api_path" "DELETE"
|
||||
|
||||
#check if result was good
|
||||
if _contains "$response" "updated DNS"; then
|
||||
_info "Successfully removed the txt record"
|
||||
return 0
|
||||
else
|
||||
_err "Error encountered during record remove"
|
||||
_err "$response"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
#
|
||||
#Usage: _get_root _acme-challenge.www.domain.com
|
||||
#Returns:
|
||||
# _sub_domain=_acme-challenge.www
|
||||
# _domain=domain.com
|
||||
_get_root() {
|
||||
_passed_domain=$1
|
||||
_debug _passed_domain "$_passed_domain"
|
||||
_i=2
|
||||
_p=1
|
||||
|
||||
#get the zones hosed on MIAB server, must be a json stream
|
||||
_miab_rest "" "zones" "GET"
|
||||
|
||||
if ! _is_json "$response"; then
|
||||
_err "ERROR fetching domain list"
|
||||
_err "$response"
|
||||
return 1
|
||||
fi
|
||||
|
||||
#cycle through the passed domain seperating out a test domain discarding
|
||||
# the subdomain by marching thorugh the dots
|
||||
while true; do
|
||||
_test_domain=$(printf "%s" "$_passed_domain" | cut -d . -f ${_i}-100)
|
||||
_debug _test_domain "$_test_domain"
|
||||
|
||||
if [ -z "$_test_domain" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
#report found if the test domain is in the json response and
|
||||
# report the subdomain
|
||||
if _contains "$response" "\"$_test_domain\""; then
|
||||
_sub_domain=$(printf "%s" "$_passed_domain" | cut -d . -f 1-${_p})
|
||||
_domain=${_test_domain}
|
||||
return 0
|
||||
fi
|
||||
|
||||
#cycle to the next dot in the passed domain
|
||||
_p=${_i}
|
||||
_i=$(_math "$_i" + 1)
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
#Usage: _retrieve_miab_env
|
||||
#Returns (from store or environment variables):
|
||||
# MIAB_Username
|
||||
# MIAB_Password
|
||||
# MIAB_Server
|
||||
#retrieve MIAB environment variables, report errors and quit if problems
|
||||
_retrieve_miab_env() {
|
||||
MIAB_Username="${MIAB_Username:-$(_readaccountconf_mutable MIAB_Username)}"
|
||||
MIAB_Password="${MIAB_Password:-$(_readaccountconf_mutable MIAB_Password)}"
|
||||
MIAB_Server="${MIAB_Server:-$(_readaccountconf_mutable MIAB_Server)}"
|
||||
|
||||
#debug log the environmental variables
|
||||
_debug MIAB_Username "$MIAB_Username"
|
||||
_debug MIAB_Password "$MIAB_Password"
|
||||
_debug MIAB_Server "$MIAB_Server"
|
||||
|
||||
#check if MIAB environemt vars set and quit if not
|
||||
if [ -z "$MIAB_Username" ] || [ -z "$MIAB_Password" ] || [ -z "$MIAB_Server" ]; then
|
||||
_err "You didn't specify one or more of MIAB_Username, MIAB_Password or MIAB_Server."
|
||||
_err "Please check these environment variables and try again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
#save the credentials to the account conf file.
|
||||
_saveaccountconf_mutable MIAB_Username "$MIAB_Username"
|
||||
_saveaccountconf_mutable MIAB_Password "$MIAB_Password"
|
||||
_saveaccountconf_mutable MIAB_Server "$MIAB_Server"
|
||||
}
|
||||
|
||||
#Useage: _miab_rest "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" "custom/_acme-challenge.www.domain.com/txt "POST"
|
||||
#Returns: "updated DNS: domain.com"
|
||||
#rest interface MIAB dns
|
||||
_miab_rest() {
|
||||
_data="$1"
|
||||
_api_path="$2"
|
||||
_httpmethod="$3"
|
||||
|
||||
#encode username and password for basic authentication
|
||||
_credentials="$(printf "%s" "$MIAB_Username:$MIAB_Password" | _base64)"
|
||||
export _H1="Authorization: Basic $_credentials"
|
||||
_url="https://${MIAB_Server}/admin/dns/${_api_path}"
|
||||
|
||||
_debug2 _data "$_data"
|
||||
_debug _api_path "$_api_path"
|
||||
_debug2 _url "$_url"
|
||||
_debug2 _credentails "$_credentials"
|
||||
_debug _httpmethod "$_httpmethod"
|
||||
|
||||
if [ "$_httpmethod" = "GET" ]; then
|
||||
response="$(_get "$_url")"
|
||||
else
|
||||
response="$(_post "$_data" "$_url" "" "$_httpmethod")"
|
||||
fi
|
||||
|
||||
_retcode="$?"
|
||||
|
||||
if [ "$_retcode" != "0" ]; then
|
||||
_err "MIAB REST authentication failed on $_httpmethod"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug response "$response"
|
||||
return 0
|
||||
}
|
||||
|
||||
#Usage: _is_json "\[\n "mydomain.com"\n]"
|
||||
#Reurns "\[\n "mydomain.com"\n]"
|
||||
#returns the string if it begins and ends with square braces
|
||||
_is_json() {
|
||||
_str="$(echo "$1" | _normalizeJson)"
|
||||
echo "$_str" | grep '^\[.*\]$' >/dev/null 2>&1
|
||||
}
|
||||
159
dnsapi/dns_misaka.sh
Executable file
159
dnsapi/dns_misaka.sh
Executable file
@@ -0,0 +1,159 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# bug reports to support+acmesh@misaka.io
|
||||
# based on dns_nsone.sh by dev@1e.ca
|
||||
|
||||
#
|
||||
#Misaka_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
|
||||
#
|
||||
|
||||
Misaka_Api="https://dnsapi.misaka.io/dns"
|
||||
|
||||
######## Public functions #####################
|
||||
|
||||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||
dns_misaka_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
if [ -z "$Misaka_Key" ]; then
|
||||
Misaka_Key=""
|
||||
_err "You didn't specify misaka.io dns api key yet."
|
||||
_err "Please create you key and try again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
#save the api key and email to the account conf file.
|
||||
_saveaccountconf Misaka_Key "$Misaka_Key"
|
||||
|
||||
_debug "checking root zone [$fulldomain]"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
|
||||
_debug "Getting txt records"
|
||||
_misaka_rest GET "zones/${_domain}/recordsets?search=${_sub_domain}"
|
||||
|
||||
if ! _contains "$response" "\"results\":"; then
|
||||
_err "Error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
count=$(printf "%s\n" "$response" | _egrep_o "\"name\":\"$_sub_domain\",[^{]*\"type\":\"TXT\"" | wc -l | tr -d " ")
|
||||
_debug count "$count"
|
||||
if [ "$count" = "0" ]; then
|
||||
_info "Adding record"
|
||||
|
||||
if _misaka_rest PUT "zones/${_domain}/recordsets/${_sub_domain}/TXT" "{\"records\":[{\"value\":\"\\\"$txtvalue\\\"\"}],\"filters\":[],\"ttl\":1}"; then
|
||||
_debug response "$response"
|
||||
if _contains "$response" "$_sub_domain"; then
|
||||
_info "Added"
|
||||
return 0
|
||||
else
|
||||
_err "Add txt record error."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
_err "Add txt record error."
|
||||
else
|
||||
_info "Updating record"
|
||||
|
||||
_misaka_rest POST "zones/${_domain}/recordsets/${_sub_domain}/TXT?append=true" "{\"records\": [{\"value\": \"\\\"$txtvalue\\\"\"}],\"ttl\":1}"
|
||||
if [ "$?" = "0" ] && _contains "$response" "$_sub_domain"; then
|
||||
_info "Updated!"
|
||||
#todo: check if the record takes effect
|
||||
return 0
|
||||
fi
|
||||
_err "Update error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
#fulldomain
|
||||
dns_misaka_rm() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
|
||||
_debug "Getting txt records"
|
||||
_misaka_rest GET "zones/${_domain}/recordsets?search=${_sub_domain}"
|
||||
|
||||
count=$(printf "%s\n" "$response" | _egrep_o "\"name\":\"$_sub_domain\",[^{]*\"type\":\"TXT\"" | wc -l | tr -d " ")
|
||||
_debug count "$count"
|
||||
if [ "$count" = "0" ]; then
|
||||
_info "Don't need to remove."
|
||||
else
|
||||
if ! _misaka_rest DELETE "zones/${_domain}/recordsets/${_sub_domain}/TXT"; then
|
||||
_err "Delete record error."
|
||||
return 1
|
||||
fi
|
||||
_contains "$response" ""
|
||||
fi
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
#_acme-challenge.www.domain.com
|
||||
#returns
|
||||
# _sub_domain=_acme-challenge.www
|
||||
# _domain=domain.com
|
||||
# _domain_id=sdjkglgdfewsdfg
|
||||
_get_root() {
|
||||
domain=$1
|
||||
i=2
|
||||
p=1
|
||||
if ! _misaka_rest GET "zones?limit=1000"; then
|
||||
return 1
|
||||
fi
|
||||
while true; do
|
||||
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||
_debug h "$h"
|
||||
if [ -z "$h" ]; then
|
||||
#not valid
|
||||
return 1
|
||||
fi
|
||||
|
||||
if _contains "$response" "\"name\":\"$h\""; then
|
||||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
|
||||
_domain="$h"
|
||||
return 0
|
||||
fi
|
||||
p=$i
|
||||
i=$(_math "$i" + 1)
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
_misaka_rest() {
|
||||
m=$1
|
||||
ep="$2"
|
||||
data="$3"
|
||||
_debug "$ep"
|
||||
|
||||
export _H1="Content-Type: application/json"
|
||||
export _H2="User-Agent: acme.sh/$VER misaka-dns-acmesh/20191213"
|
||||
export _H3="Authorization: Token $Misaka_Key"
|
||||
|
||||
if [ "$m" != "GET" ]; then
|
||||
_debug data "$data"
|
||||
response="$(_post "$data" "$Misaka_Api/$ep" "" "$m")"
|
||||
else
|
||||
response="$(_get "$Misaka_Api/$ep")"
|
||||
fi
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
_err "error $ep"
|
||||
return 1
|
||||
fi
|
||||
_debug2 response "$response"
|
||||
return 0
|
||||
}
|
||||
@@ -3,10 +3,10 @@
|
||||
# Namecheap API
|
||||
# https://www.namecheap.com/support/api/intro.aspx
|
||||
#
|
||||
# Requires Namecheap API key set in
|
||||
#NAMECHEAP_API_KEY,
|
||||
# Requires Namecheap API key set in
|
||||
#NAMECHEAP_API_KEY,
|
||||
#NAMECHEAP_USERNAME,
|
||||
#NAMECHEAP_SOURCEIP
|
||||
#NAMECHEAP_SOURCEIP
|
||||
# Due to Namecheap's API limitation all the records of your domain will be read and re applied, make sure to have a backup of your records you could apply if any issue would arise.
|
||||
|
||||
######## Public functions #####################
|
||||
|
||||
205
dnsapi/dns_nic.sh
Normal file
205
dnsapi/dns_nic.sh
Normal file
@@ -0,0 +1,205 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
#NIC_ClientID='0dc0xxxxxxxxxxxxxxxxxxxxxxxxce88'
|
||||
#NIC_ClientSecret='3LTtxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxnuW8'
|
||||
#NIC_Username="000000/NIC-D"
|
||||
#NIC_Password="xxxxxxx"
|
||||
|
||||
NIC_Api="https://api.nic.ru"
|
||||
|
||||
dns_nic_add() {
|
||||
fulldomain="${1}"
|
||||
txtvalue="${2}"
|
||||
|
||||
if ! _nic_get_authtoken save; then
|
||||
_err "get NIC auth token failed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug "First detect the root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "Invalid domain"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
_debug _service "$_service"
|
||||
|
||||
_info "Adding record"
|
||||
if ! _nic_rest PUT "services/$_service/zones/$_domain/records" "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><request><rr-list><rr><name>$_sub_domain</name><type>TXT</type><txt><string>$txtvalue</string></txt></rr></rr-list></request>"; then
|
||||
_err "Add TXT record error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! _nic_rest POST "services/$_service/zones/$_domain/commit" ""; then
|
||||
return 1
|
||||
fi
|
||||
_info "Added, OK"
|
||||
}
|
||||
|
||||
dns_nic_rm() {
|
||||
fulldomain="${1}"
|
||||
txtvalue="${2}"
|
||||
|
||||
if ! _nic_get_authtoken; then
|
||||
_err "get NIC auth token failed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "Invalid domain"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
_debug _service "$_service"
|
||||
|
||||
if ! _nic_rest GET "services/$_service/zones/$_domain/records"; then
|
||||
_err "Get records error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_domain_id=$(printf "%s" "$response" | grep "$_sub_domain" | grep -- "$txtvalue" | sed -r "s/.*<rr id=\"(.*)\".*/\1/g")
|
||||
|
||||
if ! _nic_rest DELETE "services/$_service/zones/$_domain/records/$_domain_id"; then
|
||||
_err "Delete record error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! _nic_rest POST "services/$_service/zones/$_domain/commit" ""; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
|
||||
#_nic_get_auth_elements [need2save]
|
||||
_nic_get_auth_elements() {
|
||||
_need2save=$1
|
||||
|
||||
NIC_ClientID="${NIC_ClientID:-$(_readaccountconf_mutable NIC_ClientID)}"
|
||||
NIC_ClientSecret="${NIC_ClientSecret:-$(_readaccountconf_mutable NIC_ClientSecret)}"
|
||||
NIC_Username="${NIC_Username:-$(_readaccountconf_mutable NIC_Username)}"
|
||||
NIC_Password="${NIC_Password:-$(_readaccountconf_mutable NIC_Password)}"
|
||||
|
||||
## for backward compatibility
|
||||
if [ -z "$NIC_ClientID" ] || [ -z "$NIC_ClientSecret" ]; then
|
||||
NIC_Token="${NIC_Token:-$(_readaccountconf_mutable NIC_Token)}"
|
||||
_debug NIC_Token "$NIC_Token"
|
||||
if [ -n "$NIC_Token" ]; then
|
||||
_two_values="$(echo "${NIC_Token}" | _dbase64)"
|
||||
_debug _two_values "$_two_values"
|
||||
NIC_ClientID=$(echo "$_two_values" | cut -d':' -f1)
|
||||
NIC_ClientSecret=$(echo "$_two_values" | cut -d':' -f2-)
|
||||
_debug restored_NIC_ClientID "$NIC_ClientID"
|
||||
_debug restored_NIC_ClientSecret "$NIC_ClientSecret"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$NIC_ClientID" ] || [ -z "$NIC_ClientSecret" ] || [ -z "$NIC_Username" ] || [ -z "$NIC_Password" ]; then
|
||||
NIC_ClientID=""
|
||||
NIC_ClientSecret=""
|
||||
NIC_Username=""
|
||||
NIC_Password=""
|
||||
_err "You must export variables: NIC_ClientID, NIC_ClientSecret, NIC_Username and NIC_Password"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$_need2save" ]; then
|
||||
_saveaccountconf_mutable NIC_ClientID "$NIC_ClientID"
|
||||
_saveaccountconf_mutable NIC_ClientSecret "$NIC_ClientSecret"
|
||||
_saveaccountconf_mutable NIC_Username "$NIC_Username"
|
||||
_saveaccountconf_mutable NIC_Password "$NIC_Password"
|
||||
fi
|
||||
|
||||
NIC_BasicAuth=$(printf "%s:%s" "${NIC_ClientID}" "${NIC_ClientSecret}" | _base64)
|
||||
_debug NIC_BasicAuth "$NIC_BasicAuth"
|
||||
|
||||
}
|
||||
|
||||
#_nic_get_authtoken [need2save]
|
||||
_nic_get_authtoken() {
|
||||
_need2save=$1
|
||||
|
||||
if ! _nic_get_auth_elements "$_need2save"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
_info "Getting NIC auth token"
|
||||
|
||||
export _H1="Authorization: Basic ${NIC_BasicAuth}"
|
||||
export _H2="Content-Type: application/x-www-form-urlencoded"
|
||||
|
||||
res=$(_post "grant_type=password&username=${NIC_Username}&password=${NIC_Password}&scope=%28GET%7CPUT%7CPOST%7CDELETE%29%3A%2Fdns-master%2F.%2B" "$NIC_Api/oauth/token" "" "POST")
|
||||
if _contains "$res" "access_token"; then
|
||||
_auth_token=$(printf "%s" "$res" | cut -d , -f2 | tr -d "\"" | sed "s/access_token://")
|
||||
_info "Token received"
|
||||
_debug _auth_token "$_auth_token"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
_get_root() {
|
||||
domain="$1"
|
||||
i=1
|
||||
p=1
|
||||
|
||||
if ! _nic_rest GET "zones"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
_all_domains=$(printf "%s" "$response" | grep "idn-name" | sed -r "s/.*idn-name=\"(.*)\" name=.*/\1/g")
|
||||
_debug2 _all_domains "$_all_domains"
|
||||
|
||||
while true; do
|
||||
h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
|
||||
_debug h "$h"
|
||||
|
||||
if [ -z "$h" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if _contains "$_all_domains" "^$h$"; then
|
||||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
|
||||
_domain=$h
|
||||
_service=$(printf "%s" "$response" | grep "idn-name=\"$_domain\"" | sed -r "s/.*service=\"(.*)\".*$/\1/")
|
||||
return 0
|
||||
fi
|
||||
p="$i"
|
||||
i=$(_math "$i" + 1)
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
_nic_rest() {
|
||||
m="$1"
|
||||
ep="$2"
|
||||
data="$3"
|
||||
_debug "$ep"
|
||||
|
||||
export _H1="Content-Type: application/xml"
|
||||
export _H2="Authorization: Bearer $_auth_token"
|
||||
|
||||
if [ "$m" != "GET" ]; then
|
||||
_debug data "$data"
|
||||
response=$(_post "$data" "$NIC_Api/dns-master/$ep" "" "$m")
|
||||
else
|
||||
response=$(_get "$NIC_Api/dns-master/$ep")
|
||||
fi
|
||||
|
||||
if _contains "$response" "<errors>"; then
|
||||
error=$(printf "%s" "$response" | grep "error code" | sed -r "s/.*<error code=.*>(.*)<\/error>/\1/g")
|
||||
_err "Error: $error"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! _contains "$response" "<status>success</status>"; then
|
||||
return 1
|
||||
fi
|
||||
_debug2 response "$response"
|
||||
return 0
|
||||
}
|
||||
@@ -27,7 +27,7 @@ dns_nsupdate_add() {
|
||||
[ -n "$DEBUG" ] && [ "$DEBUG" -ge "$DEBUG_LEVEL_2" ] && nsdebug="-D"
|
||||
if [ -z "${NSUPDATE_ZONE}" ]; then
|
||||
nsupdate -k "${NSUPDATE_KEY}" $nsdebug <<EOF
|
||||
server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}
|
||||
server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}
|
||||
update add ${fulldomain}. 60 in txt "${txtvalue}"
|
||||
send
|
||||
EOF
|
||||
@@ -64,7 +64,7 @@ dns_nsupdate_rm() {
|
||||
[ -n "$DEBUG" ] && [ "$DEBUG" -ge "$DEBUG_LEVEL_2" ] && nsdebug="-D"
|
||||
if [ -z "${NSUPDATE_ZONE}" ]; then
|
||||
nsupdate -k "${NSUPDATE_KEY}" $nsdebug <<EOF
|
||||
server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}
|
||||
server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}
|
||||
update delete ${fulldomain}. txt
|
||||
send
|
||||
EOF
|
||||
|
||||
414
dnsapi/dns_pleskxml.sh
Normal file
414
dnsapi/dns_pleskxml.sh
Normal file
@@ -0,0 +1,414 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
## Name: dns_pleskxml.sh
|
||||
## Created by Stilez.
|
||||
## Also uses some code from PR#1832 by @romanlum (https://github.com/Neilpang/acme.sh/pull/1832/files)
|
||||
|
||||
## This DNS-01 method uses the Plesk XML API described at:
|
||||
## https://docs.plesk.com/en-US/12.5/api-rpc/about-xml-api.28709
|
||||
## and more specifically: https://docs.plesk.com/en-US/12.5/api-rpc/reference.28784
|
||||
|
||||
## Note: a DNS ID with host = empty string is OK for this API, see
|
||||
## https://docs.plesk.com/en-US/obsidian/api-rpc/about-xml-api/reference/managing-dns/managing-dns-records/adding-dns-record.34798
|
||||
## For example, to add a TXT record to DNS alias domain "acme-alias.com" would be a valid Plesk action.
|
||||
## So this API module can handle such a request, if needed.
|
||||
|
||||
## For ACME v2 purposes, new TXT records are appended when added, and removing one TXT record will not affect any other TXT records.
|
||||
|
||||
## The user credentials (username+password) and URL/URI for the Plesk XML API must be set by the user
|
||||
## before this module is called (case sensitive):
|
||||
##
|
||||
## ```
|
||||
## export pleskxml_uri="https://address-of-my-plesk-server.net:8443/enterprise/control/agent.php"
|
||||
## (or probably something similar)
|
||||
## export pleskxml_user="my plesk username"
|
||||
## export pleskxml_pass="my plesk password"
|
||||
## ```
|
||||
|
||||
## Ok, let's issue a cert now:
|
||||
## ```
|
||||
## acme.sh --issue --dns dns_pleskxml -d example.com -d www.example.com
|
||||
## ```
|
||||
##
|
||||
## The `pleskxml_uri`, `pleskxml_user` and `pleskxml_pass` will be saved in `~/.acme.sh/account.conf` and reused when needed.
|
||||
|
||||
#################### INTERNAL VARIABLES + NEWLINE + API TEMPLATES ##################################
|
||||
|
||||
pleskxml_init_checks_done=0
|
||||
|
||||
# Variable containing bare newline - not a style issue
|
||||
# shellcheck disable=SC1004
|
||||
NEWLINE='\
|
||||
'
|
||||
|
||||
pleskxml_tplt_get_domains="<packet><customer><get-domain-list><filter/></get-domain-list></customer></packet>"
|
||||
# Get a list of domains that PLESK can manage, so we can check root domain + host for acme.sh
|
||||
# Also used to test credentials and URI.
|
||||
# No params.
|
||||
|
||||
pleskxml_tplt_get_dns_records="<packet><dns><get_rec><filter><site-id>%s</site-id></filter></get_rec></dns></packet>"
|
||||
# Get all DNS records for a Plesk domain ID.
|
||||
# PARAM = Plesk domain id to query
|
||||
|
||||
pleskxml_tplt_add_txt_record="<packet><dns><add_rec><site-id>%s</site-id><type>TXT</type><host>%s</host><value>%s</value></add_rec></dns></packet>"
|
||||
# Add a TXT record to a domain.
|
||||
# PARAMS = (1) Plesk internal domain ID, (2) "hostname" for the new record, eg '_acme_challenge', (3) TXT record value
|
||||
|
||||
pleskxml_tplt_rmv_dns_record="<packet><dns><del_rec><filter><id>%s</id></filter></del_rec></dns></packet>"
|
||||
# Delete a specific TXT record from a domain.
|
||||
# PARAM = the Plesk internal ID for the DNS record to be deleted
|
||||
|
||||
#################### Public functions ##################################
|
||||
|
||||
#Usage: dns_pleskxml_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||
dns_pleskxml_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
_info "Entering dns_pleskxml_add() to add TXT record '$txtvalue' to domain '$fulldomain'..."
|
||||
|
||||
# Get credentials if not already checked, and confirm we can log in to Plesk XML API
|
||||
if ! _credential_check; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get root and subdomain details, and Plesk domain ID
|
||||
if ! _pleskxml_get_root_domain "$fulldomain"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug 'Credentials OK, and domain identified. Calling Plesk XML API to add TXT record'
|
||||
|
||||
# printf using template in a variable - not a style issue
|
||||
# shellcheck disable=SC2059
|
||||
request="$(printf "$pleskxml_tplt_add_txt_record" "$root_domain_id" "$sub_domain_name" "$txtvalue")"
|
||||
if ! _call_api "$request"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# OK, we should have added a TXT record. Let's check and return success if so.
|
||||
# All that should be left in the result, is one section, containing <result><status>ok</status><id>NEW_DNS_RECORD_ID</id></result>
|
||||
|
||||
results="$(_api_response_split "$pleskxml_prettyprint_result" 'result' '<status>')"
|
||||
|
||||
if ! _value "$results" | grep '<status>ok</status>' | grep '<id>[0-9]\{1,\}</id>' >/dev/null; then
|
||||
# Error - doesn't contain expected string. Something's wrong.
|
||||
_err 'Error when calling Plesk XML API.'
|
||||
_err 'The result did not contain the expected <id>XXXXX</id> section, or contained other values as well.'
|
||||
_err 'This is unexpected: something has gone wrong.'
|
||||
_err 'The full response was:'
|
||||
_err "$pleskxml_prettyprint_result"
|
||||
return 1
|
||||
fi
|
||||
|
||||
recid="$(_value "$results" | grep '<id>[0-9]\{1,\}</id>' | sed 's/^.*<id>\([0-9]\{1,\}\)<\/id>.*$/\1/')"
|
||||
|
||||
_info "Success. TXT record appears to be correctly added (Plesk record ID=$recid). Exiting dns_pleskxml_add()."
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#Usage: dns_pleskxml_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||
dns_pleskxml_rm() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
_info "Entering dns_pleskxml_rm() to remove TXT record '$txtvalue' from domain '$fulldomain'..."
|
||||
|
||||
# Get credentials if not already checked, and confirm we can log in to Plesk XML API
|
||||
if ! _credential_check; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get root and subdomain details, and Plesk domain ID
|
||||
if ! _pleskxml_get_root_domain "$fulldomain"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug 'Credentials OK, and domain identified. Calling Plesk XML API to get list of TXT records and their IDs'
|
||||
|
||||
# printf using template in a variable - not a style issue
|
||||
# shellcheck disable=SC2059
|
||||
request="$(printf "$pleskxml_tplt_get_dns_records" "$root_domain_id")"
|
||||
if ! _call_api "$request"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Reduce output to one line per DNS record, filtered for TXT records with a record ID only (which they should all have)
|
||||
# Also strip out spaces between tags, redundant <data> and </data> group tags and any <self-closing/> tags
|
||||
reclist="$(_api_response_split "$pleskxml_prettyprint_result" 'result' '<status>ok</status>' \
|
||||
| sed 's# \{1,\}<\([a-zA-Z]\)#<\1#g;s#</\{0,1\}data>##g;s#<[a-z][^/<>]*/>##g' \
|
||||
| grep "<site-id>${root_domain_id}</site-id>" \
|
||||
| grep '<id>[0-9]\{1,\}</id>' \
|
||||
| grep '<type>TXT</type>'
|
||||
)"
|
||||
|
||||
if [ -z "$reclist" ]; then
|
||||
_err "No TXT records found for root domain ${root_domain_name} (Plesk domain ID ${root_domain_id}). Exiting."
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug "Got list of DNS TXT records for root domain '$root_domain_name':"
|
||||
_debug "$reclist"
|
||||
|
||||
recid="$(_value "$reclist" \
|
||||
| grep "<host>${fulldomain}.</host>" \
|
||||
| grep "<value>${txtvalue}</value>" \
|
||||
| sed 's/^.*<id>\([0-9]\{1,\}\)<\/id>.*$/\1/'
|
||||
)"
|
||||
|
||||
if ! _value "$recid" | grep '^[0-9]\{1,\}$' >/dev/null; then
|
||||
_err "DNS records for root domain '${root_domain_name}' (Plesk ID ${root_domain_id}) + host '${sub_domain_name}' do not contain the TXT record '${txtvalue}'"
|
||||
_err "Cannot delete TXT record. Exiting."
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug "Found Plesk record ID for target text string '${txtvalue}': ID=${recid}"
|
||||
_debug 'Calling Plesk XML API to remove TXT record'
|
||||
|
||||
# printf using template in a variable - not a style issue
|
||||
# shellcheck disable=SC2059
|
||||
request="$(printf "$pleskxml_tplt_rmv_dns_record" "$recid")"
|
||||
if ! _call_api "$request"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# OK, we should have removed a TXT record. Let's check and return success if so.
|
||||
# All that should be left in the result, is one section, containing <result><status>ok</status><id>PLESK_DELETED_DNS_RECORD_ID</id></result>
|
||||
|
||||
results="$(_api_response_split "$pleskxml_prettyprint_result" 'result' '<status>')"
|
||||
|
||||
if ! _value "$results" | grep '<status>ok</status>' | grep '<id>[0-9]\{1,\}</id>' >/dev/null; then
|
||||
# Error - doesn't contain expected string. Something's wrong.
|
||||
_err 'Error when calling Plesk XML API.'
|
||||
_err 'The result did not contain the expected <id>XXXXX</id> section, or contained other values as well.'
|
||||
_err 'This is unexpected: something has gone wrong.'
|
||||
_err 'The full response was:'
|
||||
_err "$pleskxml_prettyprint_result"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_info "Success. TXT record appears to be correctly removed. Exiting dns_pleskxml_rm()."
|
||||
return 0
|
||||
}
|
||||
|
||||
#################### Private functions below (utility functions) ##################################
|
||||
|
||||
# Outputs value of a variable without additional newlines etc
|
||||
_value() {
|
||||
printf '%s' "$1"
|
||||
}
|
||||
|
||||
# Outputs value of a variable (FQDN) and cuts it at 2 specified '.' delimiters, returning the text in between
|
||||
# $1, $2 = where to cut
|
||||
# $3 = FQDN
|
||||
_valuecut() {
|
||||
printf '%s' "$3" | cut -d . -f "${1}-${2}"
|
||||
}
|
||||
|
||||
# Counts '.' present in a domain name or other string
|
||||
# $1 = domain name
|
||||
_countdots() {
|
||||
_value "$1" | tr -dc '.' | wc -c | sed 's/ //g'
|
||||
}
|
||||
|
||||
# Cleans up an API response, splits it "one line per item in the response" and greps for a string that in the context, identifies "useful" lines
|
||||
# $1 - result string from API
|
||||
# $2 - plain text tag to resplit on (usually "result" or "domain"). NOT REGEX
|
||||
# $3 - basic regex to recognise useful return lines
|
||||
# note: $3 matches via basic NOT extended regex (BRE), as extended regex capabilities not needed at the moment.
|
||||
# Last line could change to <sed -n '/.../p'> instead, with suitable escaping of ['"/$],
|
||||
# if future Plesk XML API changes ever require extended regex
|
||||
_api_response_split() {
|
||||
printf '%s' "$1" \
|
||||
| sed 's/^ +//;s/ +$//' \
|
||||
| tr -d '\n\r' \
|
||||
| sed "s/<\/\{0,1\}$2>/${NEWLINE}/g" \
|
||||
| grep "$3"
|
||||
}
|
||||
|
||||
#################### Private functions below (DNS functions) ##################################
|
||||
|
||||
# Calls Plesk XML API, and checks results for obvious issues
|
||||
_call_api() {
|
||||
request="$1"
|
||||
errtext=''
|
||||
|
||||
_debug 'Entered _call_api(). Calling Plesk XML API with request:'
|
||||
_debug "'$request'"
|
||||
|
||||
export _H1="HTTP_AUTH_LOGIN: $pleskxml_user"
|
||||
export _H2="HTTP_AUTH_PASSWD: $pleskxml_pass"
|
||||
export _H3="content-Type: text/xml"
|
||||
export _H4="HTTP_PRETTY_PRINT: true"
|
||||
pleskxml_prettyprint_result="$(_post "${request}" "$pleskxml_uri" "" "POST")"
|
||||
pleskxml_retcode="$?"
|
||||
_debug 'The responses from the Plesk XML server were:'
|
||||
_debug "retcode=$pleskxml_retcode. Literal response:"
|
||||
_debug "'$pleskxml_prettyprint_result'"
|
||||
|
||||
# Detect any <status> that isn't "ok". None of the used calls should fail if the API is working correctly.
|
||||
# Also detect if there simply aren't any status lines (null result?) and report that, as well.
|
||||
|
||||
statuslines_count_total="$(echo "$pleskxml_prettyprint_result" | grep -c '^ *<status>[^<]*</status> *$')"
|
||||
statuslines_count_okay="$(echo "$pleskxml_prettyprint_result" | grep -c '^ *<status>ok</status> *$')"
|
||||
|
||||
if [ -z "$statuslines_count_total" ]; then
|
||||
|
||||
# We have no status lines at all. Results are empty
|
||||
errtext='The Plesk XML API unexpectedly returned an empty set of results for this call.'
|
||||
|
||||
elif [ "$statuslines_count_okay" -ne "$statuslines_count_total" ]; then
|
||||
|
||||
# We have some status lines that aren't "ok". Any available details are in API response fields "status" "errcode" and "errtext"
|
||||
# Workaround for basic regex:
|
||||
# - filter output to keep only lines like this: "SPACES<TAG>text</TAG>SPACES" (shouldn't be necessary with prettyprint but guarantees subsequent code is ok)
|
||||
# - then edit the 3 "useful" error tokens individually and remove closing tags on all lines
|
||||
# - then filter again to remove all lines not edited (which will be the lines not starting A-Z)
|
||||
errtext="$(_value "$pleskxml_prettyprint_result" \
|
||||
| grep '^ *<[a-z]\{1,\}>[^<]*<\/[a-z]\{1,\}> *$' \
|
||||
| sed 's/^ *<status>/Status: /;s/^ *<errcode>/Error code: /;s/^ *<errtext>/Error text: /;s/<\/.*$//' \
|
||||
| grep '^[A-Z]'
|
||||
)"
|
||||
|
||||
fi
|
||||
|
||||
if [ "$pleskxml_retcode" -ne 0 ] || [ "$errtext" != "" ]; then
|
||||
# Call failed, for reasons either in the retcode or the response text...
|
||||
|
||||
if [ "$pleskxml_retcode" -eq 0 ]; then
|
||||
_err "The POST request was successfully sent to the Plesk server."
|
||||
else
|
||||
_err "The return code for the POST request was $pleskxml_retcode (non-zero = failure in submitting request to server)."
|
||||
fi
|
||||
|
||||
if [ "$errtext" != "" ]; then
|
||||
_err 'The error responses received from the Plesk server were:'
|
||||
_err "$errtext"
|
||||
else
|
||||
_err "No additional error messages were received back from the Plesk server"
|
||||
fi
|
||||
|
||||
_err "The Plesk XML API call failed."
|
||||
return 1
|
||||
|
||||
fi
|
||||
|
||||
_debug "Leaving _call_api(). Successful call."
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Startup checks (credentials, URI)
|
||||
_credential_check() {
|
||||
_debug "Checking Plesk XML API login credentials and URI..."
|
||||
|
||||
if [ "$pleskxml_init_checks_done" -eq 1 ]; then
|
||||
_debug "Initial checks already done, no need to repeat. Skipped."
|
||||
return 0
|
||||
fi
|
||||
|
||||
pleskxml_user="${pleskxml_user:-$(_readaccountconf_mutable pleskxml_user)}"
|
||||
pleskxml_pass="${pleskxml_pass:-$(_readaccountconf_mutable pleskxml_pass)}"
|
||||
pleskxml_uri="${pleskxml_uri:-$(_readaccountconf_mutable pleskxml_uri)}"
|
||||
|
||||
if [ -z "$pleskxml_user" ] || [ -z "$pleskxml_pass" ] || [ -z "$pleskxml_uri" ]; then
|
||||
pleskxml_user=""
|
||||
pleskxml_pass=""
|
||||
pleskxml_uri=""
|
||||
_err "You didn't specify one or more of the Plesk XML API username, password, or URI."
|
||||
_err "Please create these and try again."
|
||||
_err "Instructions are in the 'dns_pleskxml' plugin source code or in the acme.sh documentation."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Test the API is usable, by trying to read the list of managed domains...
|
||||
_call_api "$pleskxml_tplt_get_domains"
|
||||
if [ "$pleskxml_retcode" -ne 0 ]; then
|
||||
_err 'Failed to access Plesk XML API.'
|
||||
_err "Please check your login credentials and Plesk URI, and that the URI is reachable, and try again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
_saveaccountconf_mutable pleskxml_uri "$pleskxml_uri"
|
||||
_saveaccountconf_mutable pleskxml_user "$pleskxml_user"
|
||||
_saveaccountconf_mutable pleskxml_pass "$pleskxml_pass"
|
||||
|
||||
_debug "Test login to Plesk XML API successful. Login credentials and URI successfully saved to the acme.sh configuration file for future use."
|
||||
|
||||
pleskxml_init_checks_done=1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# For a FQDN, identify the root domain managed by Plesk, its domain ID in Plesk, and the host if any.
|
||||
|
||||
# IMPORTANT NOTE: a result with host = empty string is OK for this API, see
|
||||
# https://docs.plesk.com/en-US/obsidian/api-rpc/about-xml-api/reference/managing-dns/managing-dns-records/adding-dns-record.34798
|
||||
# See notes at top of this file
|
||||
|
||||
_pleskxml_get_root_domain() {
|
||||
original_full_domain_name="$1"
|
||||
|
||||
_debug "Identifying DNS root domain for '$original_full_domain_name' that is managed by the Plesk account."
|
||||
|
||||
# test if the domain as provided is valid for splitting.
|
||||
|
||||
if [ "$(_countdots "$original_full_domain_name")" -eq 0 ]; then
|
||||
_err "Invalid domain. The ACME domain must contain at least two parts (aa.bb) to identify a domain and tld for the TXT record."
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug "Querying Plesk server for list of managed domains..."
|
||||
|
||||
_call_api "$pleskxml_tplt_get_domains"
|
||||
if [ "$pleskxml_retcode" -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Generate a crude list of domains known to this Plesk account.
|
||||
# We convert <ascii-name> tags to <name> so it'll flag on a hit with either <name> or <ascii-name> fields,
|
||||
# for non-Western character sets.
|
||||
# Output will be one line per known domain, containing 2 <name> tages and a single <id> tag
|
||||
# We don't actually need to check for type, name, *and* id, but it guarantees only usable lines are returned.
|
||||
|
||||
output="$(_api_response_split "$pleskxml_prettyprint_result" 'domain' '<type>domain</type>' | sed 's/<ascii-name>/<name>/g;s/<\/ascii-name>/<\/name>/g' | grep '<name>' | grep '<id>')"
|
||||
|
||||
_debug 'Domains managed by Plesk server are (ignore the hacked output):'
|
||||
_debug "$output"
|
||||
|
||||
# loop and test if domain, or any parent domain, is managed by Plesk
|
||||
# Loop until we don't have any '.' in the string we're testing as a candidate Plesk-managed domain
|
||||
|
||||
root_domain_name="$original_full_domain_name"
|
||||
|
||||
while true; do
|
||||
|
||||
_debug "Checking if '$root_domain_name' is managed by the Plesk server..."
|
||||
|
||||
root_domain_id="$(_value "$output" | grep "<name>$root_domain_name</name>" | _head_n 1 | sed 's/^.*<id>\([0-9]\{1,\}\)<\/id>.*$/\1/')"
|
||||
|
||||
if [ -n "$root_domain_id" ]; then
|
||||
# Found a match
|
||||
# SEE IMPORTANT NOTE ABOVE - THIS FUNCTION CAN RETURN HOST='', AND THAT'S OK FOR PLESK XML API WHICH ALLOWS IT.
|
||||
# SO WE HANDLE IT AND DON'T PREVENT IT
|
||||
sub_domain_name="$(_value "$original_full_domain_name" | sed "s/\.\{0,1\}${root_domain_name}"'$//')"
|
||||
_info "Success. Matched host '$original_full_domain_name' to: DOMAIN '${root_domain_name}' (Plesk ID '${root_domain_id}'), HOST '${sub_domain_name}'. Returning."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# No match, try next parent up (if any)...
|
||||
|
||||
root_domain_name="$(_valuecut 2 1000 "$root_domain_name")"
|
||||
|
||||
if [ "$(_countdots "$root_domain_name")" -eq 0 ]; then
|
||||
_debug "No match, and next parent would be a TLD..."
|
||||
_err "Cannot find '$original_full_domain_name' or any parent domain of it, in Plesk."
|
||||
_err "Are you sure that this domain is managed by this Plesk server?"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug "No match, trying next parent up..."
|
||||
|
||||
done
|
||||
}
|
||||
224
dnsapi/dns_rcode0.sh
Executable file
224
dnsapi/dns_rcode0.sh
Executable file
@@ -0,0 +1,224 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#Rcode0 API Integration
|
||||
#https://my.rcodezero.at/api-doc
|
||||
#
|
||||
# log into https://my.rcodezero.at/enableapi and get your ACME API Token (the ACME API token has limited
|
||||
# access to the REST calls needed for acme.sh only)
|
||||
#
|
||||
#RCODE0_URL="https://my.rcodezero.at"
|
||||
#RCODE0_API_TOKEN="0123456789ABCDEF"
|
||||
#RCODE0_TTL=60
|
||||
|
||||
DEFAULT_RCODE0_URL="https://my.rcodezero.at"
|
||||
DEFAULT_RCODE0_TTL=60
|
||||
|
||||
######## Public functions #####################
|
||||
#Usage: add _acme-challenge.www.domain.com "123456789ABCDEF0000000000000000000000000000000000000"
|
||||
#fulldomain
|
||||
#txtvalue
|
||||
dns_rcode0_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
RCODE0_API_TOKEN="${RCODE0_API_TOKEN:-$(_readaccountconf_mutable RCODE0_API_TOKEN)}"
|
||||
RCODE0_URL="${RCODE0_URL:-$(_readaccountconf_mutable RCODE0_URL)}"
|
||||
RCODE0_TTL="${RCODE0_TTL:-$(_readaccountconf_mutable RCODE0_TTL)}"
|
||||
|
||||
if [ -z "$RCODE0_URL" ]; then
|
||||
RCODE0_URL="$DEFAULT_RCODE0_URL"
|
||||
fi
|
||||
|
||||
if [ -z "$RCODE0_API_TOKEN" ]; then
|
||||
RCODE0_API_TOKEN=""
|
||||
_err "Missing Rcode0 ACME API Token."
|
||||
_err "Please login and create your token at httsp://my.rcodezero.at/enableapi and try again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$RCODE0_TTL" ]; then
|
||||
RCODE0_TTL="$DEFAULT_RCODE0_TTL"
|
||||
fi
|
||||
|
||||
#save the token to the account conf file.
|
||||
_saveaccountconf_mutable RCODE0_API_TOKEN "$RCODE0_API_TOKEN"
|
||||
|
||||
if [ "$RCODE0_URL" != "$DEFAULT_RCODE0_URL" ]; then
|
||||
_saveaccountconf_mutable RCODE0_URL "$RCODE0_URL"
|
||||
fi
|
||||
|
||||
if [ "$RCODE0_TTL" != "$DEFAULT_RCODE0_TTL" ]; then
|
||||
_saveaccountconf_mutable RCODE0_TTL "$RCODE0_TTL"
|
||||
fi
|
||||
|
||||
_debug "Detect root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "No 'MASTER' zone for $fulldomain found at RcodeZero Anycast."
|
||||
return 1
|
||||
fi
|
||||
_debug _domain "$_domain"
|
||||
|
||||
_debug "Adding record"
|
||||
|
||||
_record_string=""
|
||||
_build_record_string "$txtvalue"
|
||||
_list_existingchallenges
|
||||
for oldchallenge in $_existing_challenges; do
|
||||
_build_record_string "$oldchallenge"
|
||||
done
|
||||
|
||||
_debug "Challenges: $_existing_challenges"
|
||||
|
||||
if [ -z "$_existing_challenges" ]; then
|
||||
if ! _rcode0_rest "PATCH" "/api/v1/acme/zones/$_domain/rrsets" "[{\"changetype\": \"add\", \"name\": \"$fulldomain.\", \"type\": \"TXT\", \"ttl\": $RCODE0_TTL, \"records\": [$_record_string]}]"; then
|
||||
_err "Add txt record error."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
# try update in case a records exists (need for wildcard certs)
|
||||
if ! _rcode0_rest "PATCH" "/api/v1/acme/zones/$_domain/rrsets" "[{\"changetype\": \"update\", \"name\": \"$fulldomain.\", \"type\": \"TXT\", \"ttl\": $RCODE0_TTL, \"records\": [$_record_string]}]"; then
|
||||
_err "Set txt record error."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#fulldomain txtvalue
|
||||
dns_rcode0_rm() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
|
||||
RCODE0_API_TOKEN="${RCODE0_API_TOKEN:-$(_readaccountconf_mutable RCODE0_API_TOKEN)}"
|
||||
RCODE0_URL="${RCODE0_URL:-$(_readaccountconf_mutable RCODE0_URL)}"
|
||||
RCODE0_TTL="${RCODE0_TTL:-$(_readaccountconf_mutable RCODE0_TTL)}"
|
||||
|
||||
if [ -z "$RCODE0_URL" ]; then
|
||||
RCODE0_URL="$DEFAULT_RCODE0_URL"
|
||||
fi
|
||||
|
||||
if [ -z "$RCODE0_API_TOKEN" ]; then
|
||||
RCODE0_API_TOKEN=""
|
||||
_err "Missing Rcode0 API Token."
|
||||
_err "Please login and create your token at httsp://my.rcodezero.at/enableapi and try again."
|
||||
return 1
|
||||
fi
|
||||
|
||||
#save the api addr and key to the account conf file.
|
||||
_saveaccountconf_mutable RCODE0_URL "$RCODE0_URL"
|
||||
_saveaccountconf_mutable RCODE0_API_TOKEN "$RCODE0_API_TOKEN"
|
||||
|
||||
if [ "$RCODE0_TTL" != "$DEFAULT_RCODE0_TTL" ]; then
|
||||
_saveaccountconf_mutable RCODE0_TTL "$RCODE0_TTL"
|
||||
fi
|
||||
|
||||
if [ -z "$RCODE0_TTL" ]; then
|
||||
RCODE0_TTL="$DEFAULT_RCODE0_TTL"
|
||||
fi
|
||||
|
||||
_debug "Detect root zone"
|
||||
if ! _get_root "$fulldomain"; then
|
||||
_err "invalid domain"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug "Remove record"
|
||||
|
||||
#Enumerate existing acme challenges
|
||||
_list_existingchallenges
|
||||
|
||||
if _contains "$_existing_challenges" "$txtvalue"; then
|
||||
#Delete all challenges (PowerDNS API does not allow to delete content)
|
||||
if ! _rcode0_rest "PATCH" "/api/v1/acme/zones/$_domain/rrsets" "[{\"changetype\": \"delete\", \"name\": \"$fulldomain.\", \"type\": \"TXT\"}]"; then
|
||||
_err "Delete txt record error."
|
||||
return 1
|
||||
fi
|
||||
_record_string=""
|
||||
#If the only existing challenge was the challenge to delete: nothing to do
|
||||
if ! [ "$_existing_challenges" = "$txtvalue" ]; then
|
||||
for oldchallenge in $_existing_challenges; do
|
||||
#Build up the challenges to re-add, ommitting the one what should be deleted
|
||||
if ! [ "$oldchallenge" = "$txtvalue" ]; then
|
||||
_build_record_string "$oldchallenge"
|
||||
fi
|
||||
done
|
||||
#Recreate the existing challenges
|
||||
if ! _rcode0_rest "PATCH" "/api/v1/acme/zones/$_domain/rrsets" "[{\"changetype\": \"update\", \"name\": \"$fulldomain.\", \"type\": \"TXT\", \"ttl\": $RCODE0_TTL, \"records\": [$_record_string]}]"; then
|
||||
_err "Set txt record error."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
_info "Record not found, nothing to remove"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
#_acme-challenge.www.domain.com
|
||||
#returns
|
||||
# _domain=domain.com
|
||||
_get_root() {
|
||||
domain=$1
|
||||
i=1
|
||||
|
||||
while true; do
|
||||
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||
|
||||
_debug "try to find: $h"
|
||||
if _rcode0_rest "GET" "/api/v1/acme/zones/$h"; then
|
||||
if [ "$response" = "[\"found\"]" ]; then
|
||||
_domain="$h"
|
||||
if [ -z "$h" ]; then
|
||||
_domain="=2E"
|
||||
fi
|
||||
return 0
|
||||
elif [ "$response" = "[\"not a master domain\"]" ]; then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$h" ]; then
|
||||
return 1
|
||||
fi
|
||||
i=$(_math $i + 1)
|
||||
done
|
||||
_debug "no matching domain for $domain found"
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
_rcode0_rest() {
|
||||
method=$1
|
||||
ep=$2
|
||||
data=$3
|
||||
|
||||
export _H1="Authorization: Bearer $RCODE0_API_TOKEN"
|
||||
|
||||
if [ ! "$method" = "GET" ]; then
|
||||
_debug data "$data"
|
||||
response="$(_post "$data" "$RCODE0_URL$ep" "" "$method")"
|
||||
else
|
||||
response="$(_get "$RCODE0_URL$ep")"
|
||||
fi
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
_err "error $ep"
|
||||
return 1
|
||||
fi
|
||||
_debug2 response "$response"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
_build_record_string() {
|
||||
_record_string="${_record_string:+${_record_string}, }{\"content\": \"\\\"${1}\\\"\", \"disabled\": false}"
|
||||
}
|
||||
|
||||
_list_existingchallenges() {
|
||||
_rcode0_rest "GET" "/api/v1/acme/zones/$_domain/rrsets"
|
||||
_existing_challenges=$(echo "$response" | _normalizeJson | _egrep_o "\"name\":\"${fulldomain}[^]]*}" | _egrep_o 'content\":\"\\"[^\\]*' | sed -n 's/^content":"\\"//p')
|
||||
_debug2 "$_existing_challenges"
|
||||
}
|
||||
@@ -52,7 +52,7 @@ dns_unoeuro_add() {
|
||||
fi
|
||||
_info "Adding record"
|
||||
|
||||
if _uno_rest POST "my/products/$h/dns/records" "{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":120}"; then
|
||||
if _uno_rest POST "my/products/$h/dns/records" "{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":120,\"priority\":0}"; then
|
||||
if _contains "$response" "\"status\": 200" >/dev/null; then
|
||||
_info "Added, OK"
|
||||
return 0
|
||||
|
||||
147
dnsapi/dns_variomedia.sh
Normal file
147
dnsapi/dns_variomedia.sh
Normal file
@@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
#VARIOMEDIA_API_TOKEN=000011112222333344445555666677778888
|
||||
|
||||
VARIOMEDIA_API="https://api.variomedia.de"
|
||||
|
||||
######## Public functions #####################
|
||||
|
||||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||
dns_variomedia_add() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
_debug fulldomain "$fulldomain"
|
||||
_debug txtvalue "$txtvalue"
|
||||
|
||||
VARIOMEDIA_API_TOKEN="${VARIOMEDIA_API_TOKEN:-$(_readaccountconf_mutable VARIOMEDIA_API_TOKEN)}"
|
||||
if test -z "$VARIOMEDIA_API_TOKEN"; then
|
||||
VARIOMEDIA_API_TOKEN=""
|
||||
_err 'VARIOMEDIA_API_TOKEN was not exported'
|
||||
return 1
|
||||
fi
|
||||
|
||||
_saveaccountconf_mutable VARIOMEDIA_API_TOKEN "$VARIOMEDIA_API_TOKEN"
|
||||
|
||||
_debug 'First detect the root zone'
|
||||
if ! _get_root "$fulldomain"; then
|
||||
return 1
|
||||
fi
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
|
||||
if ! _variomedia_rest POST "dns-records" "{\"data\": {\"type\": \"dns-record\", \"attributes\": {\"record_type\": \"TXT\", \"name\": \"$_sub_domain\", \"domain\": \"$_domain\", \"data\": \"$txtvalue\", \"ttl\":300}}}"; then
|
||||
_err "$response"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug2 _response "$response"
|
||||
return 0
|
||||
}
|
||||
|
||||
#fulldomain txtvalue
|
||||
dns_variomedia_rm() {
|
||||
fulldomain=$1
|
||||
txtvalue=$2
|
||||
_debug fulldomain "$fulldomain"
|
||||
_debug txtvalue "$txtvalue"
|
||||
|
||||
VARIOMEDIA_API_TOKEN="${VARIOMEDIA_API_TOKEN:-$(_readaccountconf_mutable VARIOMEDIA_API_TOKEN)}"
|
||||
if test -z "$VARIOMEDIA_API_TOKEN"; then
|
||||
VARIOMEDIA_API_TOKEN=""
|
||||
_err 'VARIOMEDIA_API_TOKEN was not exported'
|
||||
return 1
|
||||
fi
|
||||
|
||||
_saveaccountconf_mutable VARIOMEDIA_API_TOKEN "$VARIOMEDIA_API_TOKEN"
|
||||
|
||||
_debug 'First detect the root zone'
|
||||
if ! _get_root "$fulldomain"; then
|
||||
return 1
|
||||
fi
|
||||
_debug _sub_domain "$_sub_domain"
|
||||
_debug _domain "$_domain"
|
||||
|
||||
_debug 'Getting txt records'
|
||||
|
||||
if ! _variomedia_rest GET "dns-records?filter[domain]=$_domain"; then
|
||||
_err 'Error'
|
||||
return 1
|
||||
fi
|
||||
|
||||
_record_id="$(echo "$response" | cut -d '[' -f2 | cut -d']' -f1 | sed 's/},[ \t]*{/\},§\{/g' | tr § '\n' | grep "$_sub_domain" | grep "$txtvalue" | sed 's/^{//;s/}[,]?$//' | tr , '\n' | tr -d '\"' | grep ^id | cut -d : -f2 | tr -d ' ')"
|
||||
_debug _record_id "$_record_id"
|
||||
if [ "$_record_id" ]; then
|
||||
_info "Successfully retrieved the record id for ACME challenge."
|
||||
else
|
||||
_info "Empty record id, it seems no such record."
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! _variomedia_rest DELETE "/dns-records/$_record_id"; then
|
||||
_err "$response"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug2 _response "$response"
|
||||
return 0
|
||||
}
|
||||
|
||||
#################### Private functions below ##################################
|
||||
#_acme-challenge.www.domain.com
|
||||
#returns
|
||||
# _sub_domain=_acme-challenge.www
|
||||
# _domain=domain.com
|
||||
_get_root() {
|
||||
fulldomain=$1
|
||||
i=1
|
||||
while true; do
|
||||
h=$(printf "%s" "$fulldomain" | cut -d . -f $i-100)
|
||||
_debug h "$h"
|
||||
if [ -z "$h" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! _variomedia_rest GET "domains/$h"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if _startswith "$response" "\{\"data\":"; then
|
||||
if _contains "$response" "\"id\": \"$h\""; then
|
||||
_sub_domain="$(echo "$fulldomain" | sed "s/\\.$h\$//")"
|
||||
_domain=$h
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
i=$(_math "$i" + 1)
|
||||
done
|
||||
|
||||
_debug "root domain not found"
|
||||
return 1
|
||||
}
|
||||
|
||||
_variomedia_rest() {
|
||||
m=$1
|
||||
ep="$2"
|
||||
data="$3"
|
||||
_debug "$ep"
|
||||
|
||||
export _H1="Authorization: token $VARIOMEDIA_API_TOKEN"
|
||||
export _H2="Content-Type: application/vnd.api+json"
|
||||
export _H3="Accept: application/vnd.variomedia.v1+json"
|
||||
|
||||
if [ "$m" != "GET" ]; then
|
||||
_debug data "$data"
|
||||
response="$(_post "$data" "$VARIOMEDIA_API/$ep" "" "$m")"
|
||||
else
|
||||
response="$(_get "$VARIOMEDIA_API/$ep")"
|
||||
fi
|
||||
|
||||
if [ "$?" != "0" ]; then
|
||||
_err "Error $ep"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_debug2 response "$response"
|
||||
return 0
|
||||
}
|
||||
@@ -102,7 +102,7 @@ _get_root() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
hostedzone="$(echo "$response" | _egrep_o "{.*\"name\":\s*\"$h\".*}")"
|
||||
hostedzone="$(echo "$response" | tr "{" "\n" | _egrep_o "\"name\":\s*\"$h\".*}")"
|
||||
if [ "$hostedzone" ]; then
|
||||
_domain_id=$(printf "%s\n" "$hostedzone" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ )
|
||||
if [ "$_domain_id" ]; then
|
||||
|
||||
@@ -106,9 +106,9 @@ _get_root() {
|
||||
domain=$1
|
||||
i=1
|
||||
while true; do
|
||||
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||
_debug h "$h"
|
||||
if [ -z "$h" ]; then
|
||||
_domain=$(printf "%s" "$domain" | cut -d . -f $i-100)
|
||||
_debug h "$_domain"
|
||||
if [ -z "$_domain" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -119,11 +119,9 @@ _get_root() {
|
||||
if printf "%s\n" "$response" | grep '^\[.*\]' >/dev/null; then
|
||||
if _contains "$response" "\"domain\":\"$_domain\""; then
|
||||
_sub_domain="$(echo "$fulldomain" | sed "s/\\.$_domain\$//")"
|
||||
_domain=$_domain
|
||||
return 0
|
||||
else
|
||||
_err 'Invalid domain'
|
||||
return 1
|
||||
_debug "Go to next level of $_domain"
|
||||
fi
|
||||
else
|
||||
_err "$response"
|
||||
|
||||
@@ -136,10 +136,10 @@ _get_root() {
|
||||
if [ -z "$h" ]; then
|
||||
return 1
|
||||
fi
|
||||
if ! _zone_rest GET "dns/$h/a"; then
|
||||
if ! _zone_rest GET "dns/$h"; then
|
||||
return 1
|
||||
fi
|
||||
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then
|
||||
if _contains "$response" "\"identificator\":\"$h\"" >/dev/null; then
|
||||
_domain=$h
|
||||
return 0
|
||||
fi
|
||||
|
||||
68
notify/dingtalk.sh
Normal file
68
notify/dingtalk.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#Support dingtalk webhooks api
|
||||
|
||||
#DINGTALK_WEBHOOK="xxxx"
|
||||
|
||||
#optional
|
||||
#DINGTALK_KEYWORD="yyyy"
|
||||
|
||||
#DINGTALK_SIGNING_KEY="SEC08ffdbd403cbc3fc8a65xxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
# subject content statusCode
|
||||
dingtalk_send() {
|
||||
_subject="$1"
|
||||
_content="$2"
|
||||
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
|
||||
_debug "_subject" "$_subject"
|
||||
_debug "_content" "$_content"
|
||||
_debug "_statusCode" "$_statusCode"
|
||||
|
||||
DINGTALK_WEBHOOK="${DINGTALK_WEBHOOK:-$(_readaccountconf_mutable DINGTALK_WEBHOOK)}"
|
||||
if [ -z "$DINGTALK_WEBHOOK" ]; then
|
||||
DINGTALK_WEBHOOK=""
|
||||
_err "You didn't specify a dingtalk webhooks DINGTALK_WEBHOOK yet."
|
||||
_err "You can get yours from https://dingtalk.com"
|
||||
return 1
|
||||
fi
|
||||
_saveaccountconf_mutable DINGTALK_WEBHOOK "$DINGTALK_WEBHOOK"
|
||||
|
||||
DINGTALK_KEYWORD="${DINGTALK_KEYWORD:-$(_readaccountconf_mutable DINGTALK_KEYWORD)}"
|
||||
if [ "$DINGTALK_KEYWORD" ]; then
|
||||
_saveaccountconf_mutable DINGTALK_KEYWORD "$DINGTALK_KEYWORD"
|
||||
fi
|
||||
|
||||
# DINGTALK_SIGNING_KEY="${DINGTALK_SIGNING_KEY:-$(_readaccountconf_mutable DINGTALK_SIGNING_KEY)}"
|
||||
# if [ -z "$DINGTALK_SIGNING_KEY" ]; then
|
||||
# DINGTALK_SIGNING_KEY="value1"
|
||||
# _info "The DINGTALK_SIGNING_KEY is not set, so use the default value1 as key."
|
||||
# elif ! _hasfield "$_IFTTT_AVAIL_MSG_KEYS" "$DINGTALK_SIGNING_KEY"; then
|
||||
# _err "The DINGTALK_SIGNING_KEY \"$DINGTALK_SIGNING_KEY\" is not available, should be one of $_IFTTT_AVAIL_MSG_KEYS"
|
||||
# DINGTALK_SIGNING_KEY=""
|
||||
# return 1
|
||||
# else
|
||||
# _saveaccountconf_mutable DINGTALK_SIGNING_KEY "$DINGTALK_SIGNING_KEY"
|
||||
# fi
|
||||
|
||||
# if [ "$DINGTALK_SIGNING_KEY" = "$IFTTT_CONTENT_KEY" ]; then
|
||||
# DINGTALK_SIGNING_KEY=""
|
||||
# IFTTT_CONTENT_KEY=""
|
||||
# _err "The DINGTALK_SIGNING_KEY must not be same as IFTTT_CONTENT_KEY."
|
||||
# return 1
|
||||
# fi
|
||||
|
||||
_content=$(echo "$_content" | _json_encode)
|
||||
_subject=$(echo "$_subject" | _json_encode)
|
||||
_data="{\"msgtype\": \"text\", \"text\": {\"content\": \"[$DINGTALK_KEYWORD]\n$_subject\n$_content\"}}"
|
||||
|
||||
response="$(_post "$_data" "$DINGTALK_WEBHOOK" "" "POST" "application/json")"
|
||||
|
||||
if [ "$?" = "0" ] && _contains "$response" "errmsg\":\"ok"; then
|
||||
_info "dingtalk webhooks event fired success."
|
||||
return 0
|
||||
fi
|
||||
|
||||
_err "dingtalk webhooks event fired error."
|
||||
_err "$response"
|
||||
return 1
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#MAILGUN_REGION="us|eu" #optional, use "us" as default
|
||||
#MAILGUN_API_DOMAIN="xxxxxx.com" #optional, use the default sandbox domain
|
||||
#MAILGUN_FROM="xxx@xxxxx.com" #optional, use the default sendbox account
|
||||
#MAILGUN_FROM="xxx@xxxxx.com" #optional, use the default sandbox account
|
||||
|
||||
_MAILGUN_BASE_US="https://api.mailgun.net/v3"
|
||||
_MAILGUN_BASE_EU="https://api.eu.mailgun.net/v3"
|
||||
|
||||
Reference in New Issue
Block a user