mirror of
https://github.com/plantroon/acme.sh.git
synced 2024-12-22 13:11:41 +00:00
fix wget support in dns api
This commit is contained in:
parent
94dc5f330c
commit
a4270efac9
31
acme.sh
31
acme.sh
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
VER=2.2.3
|
VER=2.2.4
|
||||||
|
|
||||||
PROJECT_NAME="acme.sh"
|
PROJECT_NAME="acme.sh"
|
||||||
|
|
||||||
@ -567,24 +567,29 @@ _calcjwk() {
|
|||||||
|
|
||||||
_debug2 HEADER "$HEADER"
|
_debug2 HEADER "$HEADER"
|
||||||
}
|
}
|
||||||
# body url [needbase64]
|
# body url [needbase64] [POST]
|
||||||
_post() {
|
_post() {
|
||||||
body="$1"
|
body="$1"
|
||||||
url="$2"
|
url="$2"
|
||||||
needbase64="$3"
|
needbase64="$3"
|
||||||
|
httpmethod="$4"
|
||||||
|
|
||||||
|
if [ -z "$httpmethod" ] ; then
|
||||||
|
httpmethod="POST"
|
||||||
|
fi
|
||||||
|
_debug $httpmethod
|
||||||
if _exists "curl" ; then
|
if _exists "curl" ; then
|
||||||
CURL="$CURL --dump-header $HTTP_HEADER "
|
CURL="$CURL --dump-header $HTTP_HEADER "
|
||||||
if [ "$needbase64" ] ; then
|
if [ "$needbase64" ] ; then
|
||||||
response="$($CURL -A "User-Agent: $USER_AGENT" -X POST --data "$body" $url | _base64)"
|
response="$($CURL -A "User-Agent: $USER_AGENT" -X $httpmethod -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" --data "$body" $url | _base64)"
|
||||||
else
|
else
|
||||||
response="$($CURL -A "User-Agent: $USER_AGENT" -X POST --data "$body" $url)"
|
response="$($CURL -A "User-Agent: $USER_AGENT" -X $httpmethod -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" --data "$body" $url)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "$needbase64" ] ; then
|
if [ "$needbase64" ] ; then
|
||||||
response="$($WGET -S -O - --user-agent="$USER_AGENT" --post-data="$body" $url 2>"$HTTP_HEADER" | _base64)"
|
response="$($WGET -S -O - --user-agent="$USER_AGENT" --method $httpmethod --header "$_H4" --header "$_H3" --header "$_H2" --header "$_H1" --body-data="$body" $url 2>"$HTTP_HEADER" | _base64)"
|
||||||
else
|
else
|
||||||
response="$($WGET -S -O - --user-agent="$USER_AGENT" --post-data="$body" $url 2>"$HTTP_HEADER")"
|
response="$($WGET -S -O - --user-agent="$USER_AGENT" --method $httpmethod --header "$_H4" --header "$_H3" --header "$_H2" --header "$_H1" --body-data="$body" $url 2>"$HTTP_HEADER")"
|
||||||
fi
|
fi
|
||||||
_sed_i "s/^ *//g" "$HTTP_HEADER"
|
_sed_i "s/^ *//g" "$HTTP_HEADER"
|
||||||
fi
|
fi
|
||||||
@ -594,21 +599,22 @@ _post() {
|
|||||||
|
|
||||||
# url getheader
|
# url getheader
|
||||||
_get() {
|
_get() {
|
||||||
|
_debug GET
|
||||||
url="$1"
|
url="$1"
|
||||||
onlyheader="$2"
|
onlyheader="$2"
|
||||||
_debug url $url
|
_debug url $url
|
||||||
if _exists "curl" ; then
|
if _exists "curl" ; then
|
||||||
if [ "$onlyheader" ] ; then
|
if [ "$onlyheader" ] ; then
|
||||||
$CURL -I -A "User-Agent: $USER_AGENT" $url
|
$CURL -I -A "User-Agent: $USER_AGENT" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" $url
|
||||||
else
|
else
|
||||||
$CURL -A "User-Agent: $USER_AGENT" $url
|
$CURL -A "User-Agent: $USER_AGENT" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" $url
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
_debug "WGET" "$WGET"
|
_debug "WGET" "$WGET"
|
||||||
if [ "$onlyheader" ] ; then
|
if [ "$onlyheader" ] ; then
|
||||||
eval $WGET --user-agent=\"$USER_AGENT\" -S -O /dev/null $url 2>&1 | sed 's/^[ ]*//g'
|
$WGET --user-agent="$USER_AGENT" --header "$_H4" --header "$_H3" --header "$_H2" --header "$_H1" -S -O /dev/null $url 2>&1 | sed 's/^[ ]*//g'
|
||||||
else
|
else
|
||||||
eval $WGET --user-agent=\"$USER_AGENT\" -O - $url
|
$WGET --user-agent="$USER_AGENT" --header "$_H4" --header "$_H3" --header "$_H2" --header "$_H1" -O - $url
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
ret=$?
|
ret=$?
|
||||||
@ -1061,8 +1067,9 @@ issue() {
|
|||||||
_initpath $Le_Domain
|
_initpath $Le_Domain
|
||||||
|
|
||||||
if [ -f "$DOMAIN_CONF" ] ; then
|
if [ -f "$DOMAIN_CONF" ] ; then
|
||||||
Le_NextRenewTime=$(grep "^Le_NextRenewTime=" "$DOMAIN_CONF" | cut -d '=' -f 2)
|
Le_NextRenewTime=$(grep "^Le_NextRenewTime=" "$DOMAIN_CONF" | cut -d '=' -f 2 | tr -d "'\"")
|
||||||
if [ -z "$FORCE" ] && [ "$Le_NextRenewTime" ] && [ "$(date -u "+%s" )" -lt "$Le_NextRenewTime" ] ; then
|
_debug Le_NextRenewTime "$Le_NextRenewTime"
|
||||||
|
if [ -z "$FORCE" ] && [ "$Le_NextRenewTime" ] && [ $(date -u "+%s" ) -lt $Le_NextRenewTime ] ; then
|
||||||
_info "Skip, Next renewal time is: $(grep "^Le_NextRenewTimeStr" "$DOMAIN_CONF" | cut -d '=' -f 2)"
|
_info "Skip, Next renewal time is: $(grep "^Le_NextRenewTimeStr" "$DOMAIN_CONF" | cut -d '=' -f 2)"
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#CF_Email="xxxx@sss.com"
|
#CF_Email="xxxx@sss.com"
|
||||||
|
|
||||||
|
|
||||||
CF_Api="https://api.cloudflare.com/client/v4/"
|
CF_Api="https://api.cloudflare.com/client/v4"
|
||||||
|
|
||||||
######## Public functions #####################
|
######## Public functions #####################
|
||||||
|
|
||||||
@ -36,18 +36,18 @@ dns_cf_add(){
|
|||||||
_debug _domain "$_domain"
|
_debug _domain "$_domain"
|
||||||
|
|
||||||
_debug "Getting txt records"
|
_debug "Getting txt records"
|
||||||
_cf_rest GET "/zones/${_domain_id}/dns_records?type=TXT&name=$fulldomain"
|
_cf_rest GET "zones/${_domain_id}/dns_records?type=TXT&name=$fulldomain"
|
||||||
|
|
||||||
if [ "$?" != "0" ] || ! printf $response | grep \"success\":true > /dev/null ; then
|
if ! printf "$response" | grep \"success\":true > /dev/null ; then
|
||||||
_err "Error"
|
_err "Error"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
count=$(printf $response | grep -o \"count\":[^,]* | cut -d : -f 2)
|
count=$(printf "$response" | grep -o \"count\":[^,]* | cut -d : -f 2)
|
||||||
|
_debug count "$count"
|
||||||
if [ "$count" == "0" ] ; then
|
if [ "$count" == "0" ] ; then
|
||||||
_info "Adding record"
|
_info "Adding record"
|
||||||
if _cf_rest POST "/zones/$_domain_id/dns_records" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
|
if _cf_rest POST "zones/$_domain_id/dns_records" "{\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
|
||||||
if printf $response | grep $fulldomain > /dev/null ; then
|
if printf $response | grep $fulldomain > /dev/null ; then
|
||||||
_info "Added, sleeping 10 seconds"
|
_info "Added, sleeping 10 seconds"
|
||||||
sleep 10
|
sleep 10
|
||||||
@ -61,10 +61,10 @@ dns_cf_add(){
|
|||||||
_err "Add txt record error."
|
_err "Add txt record error."
|
||||||
else
|
else
|
||||||
_info "Updating record"
|
_info "Updating record"
|
||||||
record_id=$(printf $response | grep -o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \")
|
record_id=$(printf "$response" | grep -o \"id\":\"[^\"]*\" | cut -d : -f 2 | tr -d \"| head -1)
|
||||||
_debug "record_id" $record_id
|
_debug "record_id" $record_id
|
||||||
|
|
||||||
_cf_rest PUT "/zones/$_domain_id/dns_records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"zone_name\":\"$_domain\"}"
|
_cf_rest PUT "zones/$_domain_id/dns_records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"zone_name\":\"$_domain\"}"
|
||||||
if [ "$?" == "0" ]; then
|
if [ "$?" == "0" ]; then
|
||||||
_info "Updated, sleeping 10 seconds"
|
_info "Updated, sleeping 10 seconds"
|
||||||
sleep 10
|
sleep 10
|
||||||
@ -117,17 +117,21 @@ _get_root() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_cf_rest() {
|
_cf_rest() {
|
||||||
m=$1
|
m=$1
|
||||||
ep="$2"
|
ep="$2"
|
||||||
|
data="$3"
|
||||||
_debug $ep
|
_debug $ep
|
||||||
if [ "$3" ] ; then
|
|
||||||
data="$3"
|
_H1="X-Auth-Email: $CF_Email"
|
||||||
|
_H2="X-Auth-Key: $CF_Key"
|
||||||
|
_H3="Content-Type: application/json"
|
||||||
|
|
||||||
|
if [ "$data" ] ; then
|
||||||
_debug data "$data"
|
_debug data "$data"
|
||||||
response="$(curl --silent -X $m "$CF_Api/$ep" -H "X-Auth-Email: $CF_Email" -H "X-Auth-Key: $CF_Key" -H "Content-Type: application/json" --data $data)"
|
response="$(_post "$data" "$CF_Api/$ep" "" $m)"
|
||||||
else
|
else
|
||||||
response="$(curl --silent -X $m "$CF_Api/$ep" -H "X-Auth-Email: $CF_Email" -H "X-Auth-Key: $CF_Key" -H "Content-Type: application/json")"
|
response="$(_get "$CF_Api/$ep")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ] ; then
|
||||||
|
@ -183,11 +183,16 @@ _rest() {
|
|||||||
_debug sec "$sec"
|
_debug sec "$sec"
|
||||||
hmac=$(printf "$sec"| openssl md5 |cut -d " " -f 2)
|
hmac=$(printf "$sec"| openssl md5 |cut -d " " -f 2)
|
||||||
_debug hmac "$hmac"
|
_debug hmac "$hmac"
|
||||||
|
|
||||||
if [ "$3" ] ; then
|
_H1="API-KEY: $CX_Key"
|
||||||
response="$(curl --silent -X $m "$url" -H "API-KEY: $CX_Key" -H "API-REQUEST-DATE: $cdate" -H "API-HMAC: $hmac" -H 'Content-Type: application/json' -d "$data")"
|
_H2="API-REQUEST-DATE: $cdate"
|
||||||
|
_H3="API-HMAC: $hmac"
|
||||||
|
_H4="Content-Type: application/json"
|
||||||
|
|
||||||
|
if [ "$data" ] ; then
|
||||||
|
response="$(_post "$data" "$url" "" $m)"
|
||||||
else
|
else
|
||||||
response="$(curl --silent -X $m "$url" -H "API-KEY: $CX_Key" -H "API-REQUEST-DATE: $cdate" -H "API-HMAC: $hmac" -H 'Content-Type: application/json')"
|
response="$(_get "$url")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ] ; then
|
||||||
|
@ -71,7 +71,6 @@ existing_records() {
|
|||||||
|
|
||||||
if printf "$response" | grep "Action completed successful" >/dev/null ; then
|
if printf "$response" | grep "Action completed successful" >/dev/null ; then
|
||||||
count=$(printf "$response" | grep '<type>TXT</type>' | wc -l)
|
count=$(printf "$response" | grep '<type>TXT</type>' | wc -l)
|
||||||
|
|
||||||
record_id=$(printf "$response" | grep '^<id>' | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1)
|
record_id=$(printf "$response" | grep '^<id>' | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1)
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
@ -175,17 +174,17 @@ _get_root() {
|
|||||||
_rest() {
|
_rest() {
|
||||||
m=$1
|
m=$1
|
||||||
ep="$2"
|
ep="$2"
|
||||||
|
data="$3"
|
||||||
_debug $ep
|
_debug $ep
|
||||||
url="$REST_API/$ep"
|
url="$REST_API/$ep"
|
||||||
|
|
||||||
_debug url "$url"
|
_debug url "$url"
|
||||||
|
|
||||||
if [ "$3" ] ; then
|
if [ "$data" ] ; then
|
||||||
data="$3"
|
|
||||||
_debug2 data "$data"
|
_debug2 data "$data"
|
||||||
response="$(curl --silent -X $m "$url" -d $data)"
|
response="$(_post $data "$url")"
|
||||||
else
|
else
|
||||||
response="$(curl --silent -X $m "$url" )"
|
response="$(_get "$url")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$?" != "0" ] ; then
|
if [ "$?" != "0" ] ; then
|
||||||
|
Loading…
Reference in New Issue
Block a user