Skip to content

Commit d0a16b0

Browse files
authored
Merge pull request #3499 from acmesh-official/dev
sync
2 parents edd46eb + 290beb9 commit d0a16b0

File tree

9 files changed

+458
-68
lines changed

9 files changed

+458
-68
lines changed

.github/workflows/DNS.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ jobs:
184184
- uses: actions/checkout@v2
185185
- name: Clone acmetest
186186
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/
187-
- uses: vmactions/freebsd-vm@v0.1.3
187+
- uses: vmactions/freebsd-vm@v0.1.4
188188
with:
189189
envs: 'TEST_DNS TestingDomain TEST_DNS_NO_WILDCARD TEST_DNS_SLEEP CASE TEST_LOCAL DEBUG ${{ secrets.TokenName1}} ${{ secrets.TokenName2}} ${{ secrets.TokenName3}} ${{ secrets.TokenName4}} ${{ secrets.TokenName5}}'
190190
prepare: pkg install -y socat curl

.github/workflows/LetsEncrypt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
- uses: actions/checkout@v2
112112
- name: Clone acmetest
113113
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/
114-
- uses: vmactions/freebsd-vm@v0.1.3
114+
- uses: vmactions/freebsd-vm@v0.1.4
115115
with:
116116
envs: 'NGROK_TOKEN TEST_LOCAL'
117117
prepare: pkg install -y socat curl

acme.sh

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ DEBUG_LEVEL_NONE=0
102102

103103
DOH_CLOUDFLARE=1
104104
DOH_GOOGLE=2
105+
DOH_ALI=3
106+
DOH_DP=4
105107

106108
HIDDEN_VALUE="[hidden](please add '--output-insecure' to see this value)"
107109

@@ -2038,7 +2040,7 @@ _send_signed_request() {
20382040
if _post "" "$nonceurl" "" "HEAD" "$__request_conent_type" >/dev/null; then
20392041
_headers="$(cat "$HTTP_HEADER")"
20402042
_debug2 _headers "$_headers"
2041-
_CACHED_NONCE="$(echo "$_headers" | grep -i "Replay-Nonce:" | _head_n 1 | tr -d "\r\n " | cut -d ':' -f 2)"
2043+
_CACHED_NONCE="$(echo "$_headers" | grep -i "Replay-Nonce:" | _head_n 1 | tr -d "\r\n " | cut -d ':' -f 2 | cut -d , -f 1)"
20422044
fi
20432045
fi
20442046
if [ -z "$_CACHED_NONCE" ]; then
@@ -2118,7 +2120,7 @@ _send_signed_request() {
21182120
fi
21192121
_debug2 response "$response"
21202122

2121-
_CACHED_NONCE="$(echo "$responseHeaders" | grep -i "Replay-Nonce:" | _head_n 1 | tr -d "\r\n " | cut -d ':' -f 2)"
2123+
_CACHED_NONCE="$(echo "$responseHeaders" | grep -i "Replay-Nonce:" | _head_n 1 | tr -d "\r\n " | cut -d ':' -f 2 | cut -d , -f 1)"
21222124

21232125
if ! _startswith "$code" "2"; then
21242126
_body="$response"
@@ -2266,7 +2268,7 @@ _getdeployconf() {
22662268
return 0 # do nothing
22672269
fi
22682270
_saved=$(_readdomainconf "SAVED_$_rac_key")
2269-
eval "export $_rac_key=\"$_saved\""
2271+
eval "export $_rac_key=\"\$_saved\""
22702272
}
22712273

22722274
#_saveaccountconf key value base64encode
@@ -2357,7 +2359,7 @@ _startserver() {
23572359
echo 'HTTP/1.0 200 OK'; \
23582360
echo 'Content-Length\: $_content_len'; \
23592361
echo ''; \
2360-
printf -- '$content';" &
2362+
printf '%s' '$content';" &
23612363
serverproc="$!"
23622364
}
23632365

@@ -3096,6 +3098,11 @@ _checkConf() {
30963098
_debug "Try include files"
30973099
for included in $(cat "$2" | tr "\t" " " | grep "^ *include *.*;" | sed "s/include //" | tr -d " ;"); do
30983100
_debug "check included $included"
3101+
if !_startswith "$included" "/" && _exists dirname; then
3102+
_relpath="$(dirname "$_c_file")"
3103+
_debug "_relpath" "$_relpath"
3104+
included="$_relpath/included"
3105+
fi
30993106
if _checkConf "$1" "$included"; then
31003107
return 0
31013108
fi
@@ -3916,7 +3923,15 @@ _ns_purge_cf() {
39163923

39173924
#checks if cf server is available
39183925
_ns_is_available_cf() {
3919-
if _get "https://cloudflare-dns.com" >/dev/null 2>&1; then
3926+
if _get "https://cloudflare-dns.com" "" 1 >/dev/null 2>&1; then
3927+
return 0
3928+
else
3929+
return 1
3930+
fi
3931+
}
3932+
3933+
_ns_is_available_google() {
3934+
if _get "https://dns.google" "" 1 >/dev/null 2>&1; then
39203935
return 0
39213936
else
39223937
return 1
@@ -3931,23 +3946,69 @@ _ns_lookup_google() {
39313946
_ns_lookup_impl "$_cf_ep" "$_cf_ld" "$_cf_ld_type"
39323947
}
39333948

3949+
_ns_is_available_ali() {
3950+
if _get "https://dns.alidns.com" "" 1 >/dev/null 2>&1; then
3951+
return 0
3952+
else
3953+
return 1
3954+
fi
3955+
}
3956+
3957+
#domain, type
3958+
_ns_lookup_ali() {
3959+
_cf_ld="$1"
3960+
_cf_ld_type="$2"
3961+
_cf_ep="https://dns.alidns.com/resolve"
3962+
_ns_lookup_impl "$_cf_ep" "$_cf_ld" "$_cf_ld_type"
3963+
}
3964+
3965+
_ns_is_available_dp() {
3966+
if _get "https://dns.alidns.com" "" 1 >/dev/null 2>&1; then
3967+
return 0
3968+
else
3969+
return 1
3970+
fi
3971+
}
3972+
3973+
#dnspod
3974+
_ns_lookup_dp() {
3975+
_cf_ld="$1"
3976+
_cf_ld_type="$2"
3977+
_cf_ep="https://doh.pub/dns-query"
3978+
_ns_lookup_impl "$_cf_ep" "$_cf_ld" "$_cf_ld_type"
3979+
}
3980+
39343981
#domain, type
39353982
_ns_lookup() {
39363983
if [ -z "$DOH_USE" ]; then
39373984
_debug "Detect dns server first."
39383985
if _ns_is_available_cf; then
39393986
_debug "Use cloudflare doh server"
39403987
export DOH_USE=$DOH_CLOUDFLARE
3941-
else
3988+
elif _ns_is_available_google; then
39423989
_debug "Use google doh server"
39433990
export DOH_USE=$DOH_GOOGLE
3991+
elif _ns_is_available_ali; then
3992+
_debug "Use aliyun doh server"
3993+
export DOH_USE=$DOH_ALI
3994+
elif _ns_is_available_dp; then
3995+
_debug "Use dns pod doh server"
3996+
export DOH_USE=$DOH_DP
3997+
else
3998+
_err "No doh"
39443999
fi
39454000
fi
39464001

39474002
if [ "$DOH_USE" = "$DOH_CLOUDFLARE" ] || [ -z "$DOH_USE" ]; then
39484003
_ns_lookup_cf "$@"
3949-
else
4004+
elif [ "$DOH_USE" = "$DOH_GOOGLE" ]; then
39504005
_ns_lookup_google "$@"
4006+
elif [ "$DOH_USE" = "$DOH_ALI" ]; then
4007+
_ns_lookup_ali "$@"
4008+
elif [ "$DOH_USE" = "$DOH_DP" ]; then
4009+
_ns_lookup_dp "$@"
4010+
else
4011+
_err "Unknown doh provider: DOH_USE=$DOH_USE"
39514012
fi
39524013

39534014
}
@@ -3972,7 +4033,7 @@ __purge_txt() {
39724033
if [ "$DOH_USE" = "$DOH_CLOUDFLARE" ] || [ -z "$DOH_USE" ]; then
39734034
_ns_purge_cf "$_p_txtdomain" "TXT"
39744035
else
3975-
_debug "no purge api for google dns api, just sleep 5 secs"
4036+
_debug "no purge api for this doh api, just sleep 5 secs"
39764037
_sleep 5
39774038
fi
39784039

@@ -4720,7 +4781,7 @@ $_authorizations_map"
47204781
_debug2 response "$response"
47214782

47224783
status=$(echo "$response" | _egrep_o '"status":"[^"]*' | cut -d : -f 2 | tr -d '"')
4723-
if [ "$status" = "valid" ]; then
4784+
if _contains "$status" "valid"; then
47244785
_info "$(__green Success)"
47254786
_stopserver "$serverproc"
47264787
serverproc=""

deploy/synology_dsm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ synology_dsm_deploy() {
121121
# we've verified this certificate description is a thing, so save it
122122
_savedeployconf SYNO_Certificate "$SYNO_Certificate"
123123

124-
default=false
124+
default=""
125125
if echo "$response" | sed -n "s/.*\"desc\":\"$SYNO_Certificate\",\([^{]*\).*/\1/p" | grep -- 'is_default":true' >/dev/null; then
126126
default=true
127127
fi

dnsapi/dns_aurora.sh

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/usr/bin/env sh
2+
3+
#
4+
#AURORA_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
5+
#
6+
#AURORA_Secret="sdfsdfsdfljlbjkljlkjsdfoiwje"
7+
8+
AURORA_Api="https://api.auroradns.eu"
9+
10+
######## Public functions #####################
11+
12+
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
13+
dns_aurora_add() {
14+
fulldomain=$1
15+
txtvalue=$2
16+
17+
AURORA_Key="${AURORA_Key:-$(_readaccountconf_mutable AURORA_Key)}"
18+
AURORA_Secret="${AURORA_Secret:-$(_readaccountconf_mutable AURORA_Secret)}"
19+
20+
if [ -z "$AURORA_Key" ] || [ -z "$AURORA_Secret" ]; then
21+
AURORA_Key=""
22+
AURORA_Secret=""
23+
_err "You didn't specify an Aurora api key and secret yet."
24+
_err "You can get yours from here https://cp.pcextreme.nl/auroradns/users."
25+
return 1
26+
fi
27+
28+
#save the api key and secret to the account conf file.
29+
_saveaccountconf_mutable AURORA_Key "$AURORA_Key"
30+
_saveaccountconf_mutable AURORA_Secret "$AURORA_Secret"
31+
32+
_debug "First detect the root zone"
33+
if ! _get_root "$fulldomain"; then
34+
_err "invalid domain"
35+
return 1
36+
fi
37+
_debug _domain_id "$_domain_id"
38+
_debug _sub_domain "$_sub_domain"
39+
_debug _domain "$_domain"
40+
41+
_info "Adding record"
42+
if _aurora_rest POST "zones/$_domain_id/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":300}"; then
43+
if _contains "$response" "$txtvalue"; then
44+
_info "Added, OK"
45+
return 0
46+
elif _contains "$response" "RecordExistsError"; then
47+
_info "Already exists, OK"
48+
return 0
49+
else
50+
_err "Add txt record error."
51+
return 1
52+
fi
53+
fi
54+
_err "Add txt record error."
55+
return 1
56+
57+
}
58+
59+
#fulldomain txtvalue
60+
dns_aurora_rm() {
61+
fulldomain=$1
62+
txtvalue=$2
63+
64+
AURORA_Key="${AURORA_Key:-$(_readaccountconf_mutable AURORA_Key)}"
65+
AURORA_Secret="${AURORA_Secret:-$(_readaccountconf_mutable AURORA_Secret)}"
66+
67+
_debug "First detect the root zone"
68+
if ! _get_root "$fulldomain"; then
69+
_err "invalid domain"
70+
return 1
71+
fi
72+
_debug _domain_id "$_domain_id"
73+
_debug _sub_domain "$_sub_domain"
74+
_debug _domain "$_domain"
75+
76+
_debug "Getting records"
77+
_aurora_rest GET "zones/${_domain_id}/records"
78+
79+
if ! _contains "$response" "$txtvalue"; then
80+
_info "Don't need to remove."
81+
else
82+
records=$(echo "$response" | _normalizeJson | tr -d "[]" | sed "s/},{/}|{/g" | tr "|" "\n")
83+
if [ "$(echo "$records" | wc -l)" -le 2 ]; then
84+
_err "Can not parse records."
85+
return 1
86+
fi
87+
record_id=$(echo "$records" | grep "\"type\": *\"TXT\"" | grep "\"name\": *\"$_sub_domain\"" | grep "\"content\": *\"$txtvalue\"" | _egrep_o "\"id\": *\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | _head_n 1 | tr -d " ")
88+
_debug "record_id" "$record_id"
89+
if [ -z "$record_id" ]; then
90+
_err "Can not get record id to remove."
91+
return 1
92+
fi
93+
if ! _aurora_rest DELETE "zones/$_domain_id/records/$record_id"; then
94+
_err "Delete record error."
95+
return 1
96+
fi
97+
fi
98+
return 0
99+
100+
}
101+
102+
#################### Private functions below ##################################
103+
#_acme-challenge.www.domain.com
104+
#returns
105+
# _sub_domain=_acme-challenge.www
106+
# _domain=domain.com
107+
# _domain_id=sdjkglgdfewsdfg
108+
_get_root() {
109+
domain=$1
110+
i=1
111+
p=1
112+
113+
while true; do
114+
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
115+
_debug h "$h"
116+
if [ -z "$h" ]; then
117+
#not valid
118+
return 1
119+
fi
120+
121+
if ! _aurora_rest GET "zones/$h"; then
122+
return 1
123+
fi
124+
125+
if _contains "$response" "\"name\": \"$h\""; then
126+
_domain_id=$(echo "$response" | _normalizeJson | tr -d "{}" | tr "," "\n" | grep "\"id\": *\"" | cut -d : -f 2 | tr -d \" | _head_n 1 | tr -d " ")
127+
_debug _domain_id "$_domain_id"
128+
if [ "$_domain_id" ]; then
129+
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
130+
_domain=$h
131+
return 0
132+
fi
133+
return 1
134+
fi
135+
p=$i
136+
i=$(_math "$i" + 1)
137+
done
138+
return 1
139+
}
140+
141+
_aurora_rest() {
142+
m=$1
143+
ep="$2"
144+
data="$3"
145+
_debug "$ep"
146+
147+
key_trimmed=$(echo "$AURORA_Key" | tr -d '"')
148+
secret_trimmed=$(echo "$AURORA_Secret" | tr -d '"')
149+
150+
timestamp=$(date -u +"%Y%m%dT%H%M%SZ")
151+
signature=$(printf "%s/%s%s" "$m" "$ep" "$timestamp" | _hmac sha256 "$(printf "%s" "$secret_trimmed" | _hex_dump | tr -d " ")" | _base64)
152+
authorization=$(printf "AuroraDNSv1 %s" "$(printf "%s:%s" "$key_trimmed" "$signature" | _base64)")
153+
154+
export _H1="Content-Type: application/json; charset=UTF-8"
155+
export _H2="X-AuroraDNS-Date: $timestamp"
156+
export _H3="Authorization: $authorization"
157+
158+
if [ "$m" != "GET" ]; then
159+
_debug data "$data"
160+
response="$(_post "$data" "$AURORA_Api/$ep" "" "$m")"
161+
else
162+
response="$(_get "$AURORA_Api/$ep")"
163+
fi
164+
165+
if [ "$?" != "0" ]; then
166+
_err "error $ep"
167+
return 1
168+
fi
169+
_debug2 response "$response"
170+
return 0
171+
}

0 commit comments

Comments
 (0)