Skip to content

Commit 556f8b7

Browse files
committed
Work on acme.sh hander
and dns providers
1 parent 339ee13 commit 556f8b7

File tree

19 files changed

+517
-80
lines changed

19 files changed

+517
-80
lines changed

backend/embed/acme.sh

Lines changed: 88 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ _inithttp() {
17681768
if [ -z "$ACME_HTTP_NO_REDIRECTS" ]; then
17691769
_ACME_CURL="$_ACME_CURL -L "
17701770
fi
1771-
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ]; then
1771+
if [ "$DEBUG" ] && [ "$DEBUG" -ge 2 ]; then
17721772
_CURL_DUMP="$(_mktemp)"
17731773
_ACME_CURL="$_ACME_CURL --trace-ascii $_CURL_DUMP "
17741774
fi
@@ -1808,13 +1808,42 @@ _inithttp() {
18081808

18091809
}
18101810

1811+
_HTTP_MAX_RETRY=8
1812+
18111813
# body url [needbase64] [POST|PUT|DELETE] [ContentType]
18121814
_post() {
18131815
body="$1"
18141816
_post_url="$2"
18151817
needbase64="$3"
18161818
httpmethod="$4"
18171819
_postContentType="$5"
1820+
_sleep_retry_sec=1
1821+
_http_retry_times=0
1822+
_hcode=0
1823+
while [ "${_http_retry_times}" -le "$_HTTP_MAX_RETRY" ]; do
1824+
[ "$_http_retry_times" = "$_HTTP_MAX_RETRY" ]
1825+
_lastHCode="$?"
1826+
_debug "Retrying post"
1827+
_post_impl "$body" "$_post_url" "$needbase64" "$httpmethod" "$_postContentType" "$_lastHCode"
1828+
_hcode="$?"
1829+
_debug _hcode "$_hcode"
1830+
if [ "$_hcode" = "0" ]; then
1831+
break
1832+
fi
1833+
_http_retry_times=$(_math $_http_retry_times + 1)
1834+
_sleep $_sleep_retry_sec
1835+
done
1836+
return $_hcode
1837+
}
1838+
1839+
# body url [needbase64] [POST|PUT|DELETE] [ContentType] [displayError]
1840+
_post_impl() {
1841+
body="$1"
1842+
_post_url="$2"
1843+
needbase64="$3"
1844+
httpmethod="$4"
1845+
_postContentType="$5"
1846+
displayError="$6"
18181847

18191848
if [ -z "$httpmethod" ]; then
18201849
httpmethod="POST"
@@ -1866,7 +1895,9 @@ _post() {
18661895
fi
18671896
_ret="$?"
18681897
if [ "$_ret" != "0" ]; then
1869-
_err "Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: $_ret"
1898+
if [ -z "$displayError" ] || [ "$displayError" = "0" ]; then
1899+
_err "Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: $_ret"
1900+
fi
18701901
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ]; then
18711902
_err "Here is the curl dump log:"
18721903
_err "$(cat "$_CURL_DUMP")"
@@ -1922,7 +1953,9 @@ _post() {
19221953
_debug "wget returns 8, the server returns a 'Bad request' response, lets process the response later."
19231954
fi
19241955
if [ "$_ret" != "0" ]; then
1925-
_err "Please refer to https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html for error code: $_ret"
1956+
if [ -z "$displayError" ] || [ "$displayError" = "0" ]; then
1957+
_err "Please refer to https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html for error code: $_ret"
1958+
fi
19261959
fi
19271960
_sed_i "s/^ *//g" "$HTTP_HEADER"
19281961
else
@@ -1936,13 +1969,38 @@ _post() {
19361969

19371970
# url getheader timeout
19381971
_get() {
1972+
url="$1"
1973+
onlyheader="$2"
1974+
t="$3"
1975+
_sleep_retry_sec=1
1976+
_http_retry_times=0
1977+
_hcode=0
1978+
while [ "${_http_retry_times}" -le "$_HTTP_MAX_RETRY" ]; do
1979+
[ "$_http_retry_times" = "$_HTTP_MAX_RETRY" ]
1980+
_lastHCode="$?"
1981+
_debug "Retrying GET"
1982+
_get_impl "$url" "$onlyheader" "$t" "$_lastHCode"
1983+
_hcode="$?"
1984+
_debug _hcode "$_hcode"
1985+
if [ "$_hcode" = "0" ]; then
1986+
break
1987+
fi
1988+
_http_retry_times=$(_math $_http_retry_times + 1)
1989+
_sleep $_sleep_retry_sec
1990+
done
1991+
return $_hcode
1992+
}
1993+
1994+
# url getheader timeout displayError
1995+
_get_impl() {
19391996
_debug GET
19401997
url="$1"
19411998
onlyheader="$2"
19421999
t="$3"
2000+
displayError="$4"
19432001
_debug url "$url"
19442002
_debug "timeout=$t"
1945-
2003+
_debug "displayError" "$displayError"
19462004
_inithttp
19472005

19482006
if [ "$_ACME_CURL" ] && [ "${ACME_USE_WGET:-0}" = "0" ]; then
@@ -1961,7 +2019,9 @@ _get() {
19612019
fi
19622020
ret=$?
19632021
if [ "$ret" != "0" ]; then
1964-
_err "Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: $ret"
2022+
if [ -z "$displayError" ] || [ "$displayError" = "0" ]; then
2023+
_err "Please refer to https://curl.haxx.se/libcurl/c/libcurl-errors.html for error code: $ret"
2024+
fi
19652025
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ]; then
19662026
_err "Here is the curl dump log:"
19672027
_err "$(cat "$_CURL_DUMP")"
@@ -1987,7 +2047,9 @@ _get() {
19872047
_debug "wget returns 8, the server returns a 'Bad request' response, lets process the response later."
19882048
fi
19892049
if [ "$ret" != "0" ]; then
1990-
_err "Please refer to https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html for error code: $ret"
2050+
if [ -z "$displayError" ] || [ "$displayError" = "0" ]; then
2051+
_err "Please refer to https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html for error code: $ret"
2052+
fi
19912053
fi
19922054
else
19932055
ret=$?
@@ -3925,7 +3987,7 @@ _ns_lookup_ali() {
39253987
}
39263988

39273989
_ns_is_available_dp() {
3928-
if _get "https://dns.alidns.com" "" 1 >/dev/null 2>&1; then
3990+
if _get "https://doh.pub" "" 1 >/dev/null 2>&1; then
39293991
return 0
39303992
else
39313993
return 1
@@ -4145,6 +4207,10 @@ issue() {
41454207
if [ -z "$_ACME_IS_RENEW" ]; then
41464208
_initpath "$_main_domain" "$_key_length"
41474209
mkdir -p "$DOMAIN_PATH"
4210+
else
4211+
Le_OrderFinalize=""
4212+
Le_LinkOrder=""
4213+
Le_LinkCert=""
41484214
fi
41494215

41504216
if _hasfield "$_web_roots" "$W_DNS" && [ -z "$FORCE_DNS_MANUAL" ]; then
@@ -4712,26 +4778,13 @@ $_authorizations_map"
47124778
return 1
47134779
fi
47144780

4715-
_debug "sleep 2 secs to verify"
4716-
sleep 2
4717-
_debug "checking"
4718-
4719-
_send_signed_request "$uri"
4720-
4721-
if [ "$?" != "0" ]; then
4722-
_err "$d:Verify error:$response"
4723-
_clearupwebbroot "$_currentRoot" "$removelevel" "$token"
4724-
_clearup
4725-
_on_issue_err "$_post_hook" "$vlist"
4726-
return 1
4727-
fi
47284781
_debug2 original "$response"
47294782

47304783
response="$(echo "$response" | _normalizeJson)"
47314784
_debug2 response "$response"
47324785

47334786
status=$(echo "$response" | _egrep_o '"status":"[^"]*' | cut -d : -f 2 | tr -d '"')
4734-
4787+
_debug2 status "$status"
47354788
if _contains "$status" "invalid"; then
47364789
error="$(echo "$response" | _egrep_o '"error":\{[^\}]*')"
47374790
_debug2 error "$error"
@@ -4763,17 +4816,29 @@ $_authorizations_map"
47634816
fi
47644817

47654818
if [ "$status" = "pending" ]; then
4766-
_info "Pending"
4819+
_info "Pending, The CA is processing your order, please just wait. ($waittimes/$MAX_RETRY_TIMES)"
47674820
elif [ "$status" = "processing" ]; then
4768-
_info "Processing"
4821+
_info "Processing, The CA is processing your order, please just wait. ($waittimes/$MAX_RETRY_TIMES)"
47694822
else
47704823
_err "$d:Verify error:$response"
47714824
_clearupwebbroot "$_currentRoot" "$removelevel" "$token"
47724825
_clearup
47734826
_on_issue_err "$_post_hook" "$vlist"
47744827
return 1
47754828
fi
4829+
_debug "sleep 2 secs to verify again"
4830+
sleep 2
4831+
_debug "checking"
47764832

4833+
_send_signed_request "$uri"
4834+
4835+
if [ "$?" != "0" ]; then
4836+
_err "$d:Verify error:$response"
4837+
_clearupwebbroot "$_currentRoot" "$removelevel" "$token"
4838+
_clearup
4839+
_on_issue_err "$_post_hook" "$vlist"
4840+
return 1
4841+
fi
47774842
done
47784843

47794844
done

backend/embed/api_docs/components/DNSProviderObject.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"created_on",
88
"modified_on",
99
"user_id",
10-
"provider_key",
1110
"name",
11+
"acme_sh_name",
1212
"meta"
1313
],
1414
"properties": {
@@ -28,15 +28,15 @@
2828
"type": "integer",
2929
"minimum": 1
3030
},
31-
"provider_key": {
31+
"name": {
3232
"type": "string",
3333
"minLength": 1,
3434
"maxLength": 100
3535
},
36-
"name": {
36+
"acme_sh_name": {
3737
"type": "string",
38-
"minLength": 1,
39-
"maxLength": 100
38+
"minLength": 4,
39+
"maxLength": 50
4040
},
4141
"meta": {
4242
"type": "object"

backend/embed/api_docs/paths/dns-providers/get.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,11 @@
6767
"created_on": 1602593653,
6868
"modified_on": 1602593653,
6969
"user_id": 1,
70-
"provider_key": "route53",
7170
"name": "Route53",
71+
"acme_sh_name": "dns_aws",
7272
"meta": {
73-
"access_key": "abc123",
74-
"access_secret": "def098",
75-
"zone_id": "ABC123"
73+
"AWS_ACCESS_KEY_ID": "abc123",
74+
"AWS_SECRET_ACCESS_KEY": "def098"
7675
}
7776
}
7877
]

backend/embed/api_docs/paths/dns-providers/post.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@
3636
"created_on": 1602593653,
3737
"modified_on": 1602593653,
3838
"user_id": 1,
39-
"provider_key": "route53",
4039
"name": "Route53",
40+
"acme_sh_name": "dns_aws",
4141
"meta": {
42-
"access_key": "abc123",
43-
"access_secret": "def098",
44-
"zone_id": "ABC123"
42+
"AWS_ACCESS_KEY_ID": "abc123",
43+
"AWS_SECRET_ACCESS_KEY": "def098"
4544
}
4645
}
4746
}

backend/embed/api_docs/paths/dns-providers/providerID/get.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@
4040
"created_on": 1602593653,
4141
"modified_on": 1602593653,
4242
"user_id": 1,
43-
"provider_key": "route53",
4443
"name": "Route53",
44+
"acme_sh_name": "dns_aws",
4545
"meta": {
46-
"access_key": "abc123",
47-
"access_secret": "def098",
48-
"zone_id": "ABC123"
46+
"AWS_ACCESS_KEY_ID": "abc123",
47+
"AWS_SECRET_ACCESS_KEY": "def098"
4948
}
5049
}
5150
}

backend/embed/api_docs/paths/dns-providers/providerID/put.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@
5050
"created_on": 1602593653,
5151
"modified_on": 1602593653,
5252
"user_id": 1,
53-
"provider_key": "route53",
5453
"name": "Route53",
54+
"acme_sh_name": "dns_aws",
5555
"meta": {
56-
"access_key": "abc123",
57-
"access_secret": "def098",
58-
"zone_id": "ABC123"
56+
"AWS_ACCESS_KEY_ID": "abc123",
57+
"AWS_SECRET_ACCESS_KEY": "def098"
5958
}
6059
}
6160
}

backend/embed/migrations/20201013035318_initial_schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ CREATE TABLE IF NOT EXISTS `dns_provider`
7070
created_on INTEGER NOT NULL DEFAULT 0,
7171
modified_on INTEGER NOT NULL DEFAULT 0,
7272
user_id INTEGER NOT NULL,
73-
provider_key TEXT NOT NULL,
7473
name TEXT NOT NULL,
74+
acme_sh_name TEXT NOT NULL,
7575
meta TEXT NOT NULL,
7676
is_deleted INTEGER NOT NULL DEFAULT 0,
7777
FOREIGN KEY (user_id) REFERENCES user (id)
@@ -92,6 +92,7 @@ CREATE TABLE IF NOT EXISTS `certificate`
9292
status TEXT NOT NULL, -- ready,requesting,failed,provided
9393
error_message text NOT NULL DEFAULT "",
9494
meta TEXT NOT NULL,
95+
is_ecc INTEGER NOT NULL DEFAULT 0,
9596
is_deleted INTEGER NOT NULL DEFAULT 0,
9697
FOREIGN KEY (user_id) REFERENCES user (id),
9798
FOREIGN KEY (certificate_authority_id) REFERENCES certificate_authority (id),

0 commit comments

Comments
 (0)