mirror of
https://github.com/acmesh-official/acme.sh.git
synced 2026-10-21 13:31:18 +00:00
1 parent
85408bfb4d
commit
010bd1111a
1 file changed
+57
-35
+57
-35
@@ -8,11 +8,7 @@ Options:
|
|||||||
SIMPLY_ApiKey API Key
|
SIMPLY_ApiKey API Key
|
||||||
'
|
'
|
||||||
|
|
||||||
#SIMPLY_Api="https://api.simply.com/2/"
|
SIMPLY_Api="https://api.simply.com/2"
|
||||||
SIMPLY_Api_Default="https://api.simply.com/2"
|
|
||||||
|
|
||||||
#This is used for determining success of REST call
|
|
||||||
SIMPLY_SUCCESS_CODE='"status":200'
|
|
||||||
|
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
||||||
@@ -72,7 +68,16 @@ dns_simply_rm() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
records=$(echo "$response" | tr '{' "\n" | grep 'record_id\|type\|data\|\name' | sed 's/\"record_id/;\"record_id/' | tr "\n" ' ' | tr -d ' ' | tr ';' ' ')
|
case "$_simply_http_code" in
|
||||||
|
2*) ;;
|
||||||
|
*)
|
||||||
|
_err "Failed to fetch DNS records (HTTP $_simply_http_code)"
|
||||||
|
_err "$response"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
records=$(echo "$response" | tr '{' "\n" | grep -E 'record_id|type|data|name' | sed 's/\"record_id/;\"record_id/' | tr "\n" ' ' | tr -d ' ' | tr ';' ' ')
|
||||||
|
|
||||||
nr_of_deleted_records=0
|
nr_of_deleted_records=0
|
||||||
_info "Fetching txt record"
|
_info "Fetching txt record"
|
||||||
@@ -95,7 +100,7 @@ dns_simply_rm() {
|
|||||||
|
|
||||||
if [ "$record_id" -gt 0 ]; then
|
if [ "$record_id" -gt 0 ]; then
|
||||||
|
|
||||||
if ! _simply_delete_record "$_domain" "$_sub_domain" "$record_id"; then
|
if ! _simply_delete_record "$_domain" "$record_id"; then
|
||||||
_err "Record with id $record_id could not be deleted"
|
_err "Record with id $record_id could not be deleted"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -122,14 +127,9 @@ dns_simply_rm() {
|
|||||||
#################### Private functions below ##################################
|
#################### Private functions below ##################################
|
||||||
|
|
||||||
_simply_load_config() {
|
_simply_load_config() {
|
||||||
SIMPLY_Api="${SIMPLY_Api:-$(_readaccountconf_mutable SIMPLY_Api)}"
|
|
||||||
SIMPLY_AccountName="${SIMPLY_AccountName:-$(_readaccountconf_mutable SIMPLY_AccountName)}"
|
SIMPLY_AccountName="${SIMPLY_AccountName:-$(_readaccountconf_mutable SIMPLY_AccountName)}"
|
||||||
SIMPLY_ApiKey="${SIMPLY_ApiKey:-$(_readaccountconf_mutable SIMPLY_ApiKey)}"
|
SIMPLY_ApiKey="${SIMPLY_ApiKey:-$(_readaccountconf_mutable SIMPLY_ApiKey)}"
|
||||||
|
|
||||||
if [ -z "$SIMPLY_Api" ]; then
|
|
||||||
SIMPLY_Api="$SIMPLY_Api_Default"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$SIMPLY_AccountName" ] || [ -z "$SIMPLY_ApiKey" ]; then
|
if [ -z "$SIMPLY_AccountName" ] || [ -z "$SIMPLY_ApiKey" ]; then
|
||||||
SIMPLY_AccountName=""
|
SIMPLY_AccountName=""
|
||||||
SIMPLY_ApiKey=""
|
SIMPLY_ApiKey=""
|
||||||
@@ -144,9 +144,6 @@ _simply_load_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_simply_save_config() {
|
_simply_save_config() {
|
||||||
if [ "$SIMPLY_Api" != "$SIMPLY_Api_Default" ]; then
|
|
||||||
_saveaccountconf_mutable SIMPLY_Api "$SIMPLY_Api"
|
|
||||||
fi
|
|
||||||
_saveaccountconf_mutable SIMPLY_AccountName "$SIMPLY_AccountName"
|
_saveaccountconf_mutable SIMPLY_AccountName "$SIMPLY_AccountName"
|
||||||
_saveaccountconf_mutable SIMPLY_ApiKey "$SIMPLY_ApiKey"
|
_saveaccountconf_mutable SIMPLY_ApiKey "$SIMPLY_ApiKey"
|
||||||
}
|
}
|
||||||
@@ -163,26 +160,39 @@ _simply_get_all_records() {
|
|||||||
|
|
||||||
_get_root() {
|
_get_root() {
|
||||||
domain=$1
|
domain=$1
|
||||||
|
|
||||||
|
if ! _simply_rest GET "my/products/"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$_simply_http_code" in
|
||||||
|
2*) ;;
|
||||||
|
*)
|
||||||
|
_err "Failed to fetch product list (HTTP $_simply_http_code)"
|
||||||
|
_err "$response"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
i=2
|
i=2
|
||||||
p=1
|
p=1
|
||||||
while true; do
|
while true; do
|
||||||
h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
|
h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
|
||||||
if [ -z "$h" ]; then
|
if [ -z "$h" ]; then
|
||||||
#not valid
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! _simply_rest GET "my/products/$h/dns/"; then
|
_domain=$(printf "%s" "$response" | tr '}' '\n' |
|
||||||
return 1
|
grep -F -e "\"object\":\"$h\"" -e "\"name\":\"$h\"" -e "\"name_idn\":\"$h\"" |
|
||||||
fi
|
sed -n 's/.*"object":"\([^"]*\)".*/\1/p' |
|
||||||
|
_head_n 1)
|
||||||
|
|
||||||
if ! _contains "$response" "$SIMPLY_SUCCESS_CODE"; then
|
if [ -n "$_domain" ]; then
|
||||||
_debug "$h not found"
|
|
||||||
else
|
|
||||||
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p")
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p")
|
||||||
_domain="$h"
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_debug "No Simply.com product found for $h"
|
||||||
p="$i"
|
p="$i"
|
||||||
i=$(_math "$i" + 1)
|
i=$(_math "$i" + 1)
|
||||||
done
|
done
|
||||||
@@ -194,39 +204,44 @@ _simply_add_record() {
|
|||||||
sub_domain=$2
|
sub_domain=$2
|
||||||
txtval=$3
|
txtval=$3
|
||||||
|
|
||||||
data="{\"name\": \"$sub_domain\", \"type\":\"TXT\", \"data\": \"$txtval\", \"priority\":0, \"ttl\": 3600}"
|
data="{\"name\": \"$sub_domain\", \"type\":\"TXT\", \"data\": \"$txtval\", \"priority\":0, \"ttl\": 120}"
|
||||||
|
|
||||||
if ! _simply_rest POST "my/products/$domain/dns/records/" "$data"; then
|
if ! _simply_rest POST "my/products/$domain/dns/records/" "$data"; then
|
||||||
_err "Adding record not successfull!"
|
_err "Adding record not successful!"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! _contains "$response" "$SIMPLY_SUCCESS_CODE"; then
|
case "$_simply_http_code" in
|
||||||
_err "Call to API not sucessfull, see below message for more details"
|
2*) ;;
|
||||||
|
*)
|
||||||
|
_err "Call to API not successful (HTTP $_simply_http_code), see below message for more details"
|
||||||
_err "$response"
|
_err "$response"
|
||||||
return 1
|
return 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
_simply_delete_record() {
|
_simply_delete_record() {
|
||||||
domain=$1
|
domain=$1
|
||||||
sub_domain=$2
|
record_id=$2
|
||||||
record_id=$3
|
|
||||||
|
|
||||||
_debug record_id "Delete record with id $record_id"
|
_debug record_id "Delete record with id $record_id"
|
||||||
|
|
||||||
if ! _simply_rest DELETE "my/products/$domain/dns/records/$record_id/"; then
|
if ! _simply_rest DELETE "my/products/$domain/dns/records/$record_id/"; then
|
||||||
_err "Deleting record not successfull!"
|
_err "Deleting record not successful!"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! _contains "$response" "$SIMPLY_SUCCESS_CODE"; then
|
case "$_simply_http_code" in
|
||||||
_err "Call to API not sucessfull, see below message for more details"
|
2*) ;;
|
||||||
|
*)
|
||||||
|
_err "Call to API not successful (HTTP $_simply_http_code), see below message for more details"
|
||||||
_err "$response"
|
_err "$response"
|
||||||
return 1
|
return 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -248,17 +263,24 @@ _simply_rest() {
|
|||||||
|
|
||||||
export _H2="Content-Type: application/json"
|
export _H2="Content-Type: application/json"
|
||||||
|
|
||||||
|
: >"$HTTP_HEADER"
|
||||||
|
|
||||||
if [ "$m" != "GET" ]; then
|
if [ "$m" != "GET" ]; then
|
||||||
response="$(_post "$data" "$SIMPLY_Api/$ep" "" "$m")"
|
response="$(_post "$data" "$SIMPLY_Api/$ep" "" "$m")"
|
||||||
else
|
else
|
||||||
response="$(_get "$SIMPLY_Api/$ep")"
|
response="$(_get "$SIMPLY_Api/$ep")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ]; then
|
_ret="$?"
|
||||||
|
unset _H1 _H2
|
||||||
|
|
||||||
|
if [ "$_ret" != "0" ]; then
|
||||||
_err "error $ep"
|
_err "error $ep"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_simply_http_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d' ' -f2 | tr -d '\r\n')"
|
||||||
|
|
||||||
response="$(echo "$response" | _normalizeJson)"
|
response="$(echo "$response" | _normalizeJson)"
|
||||||
|
|
||||||
_debug2 response "$response"
|
_debug2 response "$response"
|
||||||
|
|||||||