3 HTTP_HEADER
="$(mktemp)"
6 openssl base64
-e |
tr -d '\r\n'
13 # Usage: hashalg [outputhex]
14 # Output Base64-encoded digest
18 if [ "$alg" = "sha256" ] ||
[ "$alg" = "sha1" ] ||
[ "$alg" = "md5" ]; then
20 openssl dgst
-"$alg" -hex | cut
-d = -f 2 |
tr -d ' '
22 openssl dgst
-"$alg" -binary | _base64
28 # shellcheck disable=SC2018,SC2019
33 # shellcheck disable=SC2018,SC2019
40 echo "$_str" |
grep "^$_sub" >/dev
/null
2>&1
46 echo "$_str" |
grep -- "$_sub\$" >/dev
/null
2>&1
52 echo "$_str" |
grep -- "$_sub" >/dev
/null
2>&1
61 if [ -z "$_sep" ]; then
66 while [ "$_ffi" -gt "0" ]; do
67 _fv
="$(echo "$_str" | cut -d "$_sep" -f "$_ffi")"
72 _ffi
="$(_math "$_ffi" - 1)"
75 printf -- "%s" "$_str"
81 if eval type type >/dev
/null
2>&1; then
82 type "$cmd" >/dev
/null
2>&1
84 command -v "$cmd" >/dev
/null
2>&1
93 printf "%s" "$(($_m_opts))"
97 if ! egrep -o "$1" 2>/dev
/null
; then
98 sed -n 's/.*\('"$1"'\).*/\1/p'
102 # body url [needbase64] [POST|PUT|DELETE] [ContentType]
108 _postContentType
="$5"
110 if [ -z "$httpmethod" ]; then
114 _CURL
="curl -L --silent --dump-header $HTTP_HEADER -g "
115 if [ "$HTTPS_INSECURE" ]; then
116 _CURL
="$_CURL --insecure "
118 if [ "$httpmethod" = "HEAD" ]; then
121 if [ "$needbase64" ]; then
123 if [ "$_postContentType" ]; then
124 response
="$($_CURL --user-agent "$USER_AGENT" -X $httpmethod -H "Content-Type
: $_postContentType" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" --data "$body" "$_post_url" | _base64)"
126 response
="$($_CURL --user-agent "$USER_AGENT" -X $httpmethod -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" --data "$body" "$_post_url" | _base64)"
129 if [ "$_postContentType" ]; then
130 response
="$($_CURL --user-agent "$USER_AGENT" -X $httpmethod -H "Content-Type
: $_postContentType" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" "$_post_url" | _base64)"
132 response
="$($_CURL --user-agent "$USER_AGENT" -X $httpmethod -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" "$_post_url" | _base64)"
137 if [ "$_postContentType" ]; then
138 response
="$($_CURL --user-agent "$USER_AGENT" -X $httpmethod -H "Content-Type
: $_postContentType" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" --data "$body" "$_post_url")"
140 response
="$($_CURL --user-agent "$USER_AGENT" -X $httpmethod -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" --data "$body" "$_post_url")"
143 if [ "$_postContentType" ]; then
144 response
="$($_CURL --user-agent "$USER_AGENT" -X $httpmethod -H "Content-Type
: $_postContentType" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" "$_post_url")"
146 response
="$($_CURL --user-agent "$USER_AGENT" -X $httpmethod -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" "$_post_url")"
151 if [ "$_ret" != "0" ]; then
152 _err
"Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: $_ret"
154 printf "%s" "$response"
158 # url getheader timeout
164 _CURL
="curl -L --silent --dump-header $HTTP_HEADER -g "
165 if [ "$HTTPS_INSECURE" ]; then
166 _CURL
="$_CURL --insecure "
169 _CURL
="$_CURL --connect-timeout $t"
171 if [ "$onlyheader" ]; then
172 $_CURL -I --user-agent "USER_AGENT" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" "$url"
174 $_CURL --user-agent "USER_AGENT" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" "$url"
177 if [ "$ret" != "0" ]; then
178 _err
"Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: $ret"
191 # stdin output hexstr splited by one space
193 # output: " 61 62 63"
195 od -A n
-v -t x1 |
tr -s " " |
sed 's/ $//' |
tr -d "\r\t\n"
200 _hex_str
=$
(_hex_dump
)
201 for _hex_code
in $_hex_str; do
203 case "${_hex_code}" in
409 printf '%%%s' "$_hex_code"
415 # Usage: hashalg secret_hex [outputhex]
422 if [ "$alg" = "sha256" ] ||
[ "$alg" = "sha1" ]; then
423 if [ "$outputhex" ]; then
424 (openssl dgst
-"$alg" -mac HMAC
-macopt "hexkey:$secret_hex" 2>/dev
/null || openssl dgst
-"$alg" -hmac "$(printf "%s
" "$secret_hex" | _h2b)") | cut
-d = -f 2 |
tr -d ' '
426 openssl dgst
-"$alg" -mac HMAC
-macopt "hexkey:$secret_hex" -binary 2>/dev
/null || openssl dgst
-"$alg" -hmac "$(printf "%s
" "$secret_hex" | _h2b)" -binary
434 _idn_temp
=$
(printf "%s" "$_is_idn_d" |
tr -d '0-9' |
tr -d 'a-z' |
tr -d 'A-Z' |
tr -d '*.,-_')
441 if ! _is_idn
"$__idn_d"; then
442 printf "%s" "$__idn_d"
447 idn
"$__idn_d" |
tr -d "\r\n"
449 _err
"Please install idn to process IDN names."
454 sed "s/\" *: *\([\"{\[]\)/\":\1/g" |
sed "s/^ *\([^ ]\)/\1/" |
tr -d "\r\n"
468 stat
-c '%U:%G' "$1" 2>/dev
/null
476 date -u "+%Y-%m-%d %H:%M:%S"
493 printf -- "%s" "[$(date)] " >&1
498 printf -- "%s" "[$(date)] " >&2
514 _readaccountconf_mutable
() {
515 _readaccountconf
"$1"
519 _clearaccountconf
() {
555 _saveaccountconf_mutable
() {
567 _source_plugin_config
() {
571 # Proxmox implementation to inject the DNSAPI variables
572 _load_plugin_config
() {
573 tmp_str
="${plugin_conf_string//[^,]}"
574 index
="$(_math ${#tmp_str} + 1)"
575 while [ "$index" -gt "0" ]
577 field
=$
(_getfield
$plugin_conf_string "$index" ",")
582 # decode base64 encoded values
583 value
=$
(echo $value |
/usr
/bin
/openssl base64
-d -A)
585 # acme.sh uses eval insted of export
586 export "$key"="$value"
587 index
="$(_math "$index" - 1)"