Skip to content

Commit 0a4500e

Browse files
authored
Merge pull request acmesh-official#6604 from acmesh-official/dev
sync
2 parents a1f4f9d + 9a994e7 commit 0a4500e

File tree

8 files changed

+252
-8
lines changed

8 files changed

+252
-8
lines changed

.github/workflows/PebbleStrict.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
run: |
6666
docker run --rm -itd --name=pebble \
6767
-e PEBBLE_VA_ALWAYS_VALID=1 \
68-
-p 14000:14000 -p 15000:15000 letsencrypt/pebble:latest pebble -config /test/config/pebble-config.json -strict
68+
-p 14000:14000 -p 15000:15000 ghcr.io/letsencrypt/pebble:latest -config /test/config/pebble-config.json -strict
6969
- name: Clone acmetest
7070
run: cd .. && git clone --depth=1 https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/
7171
- name: Run acmetest

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.21
1+
FROM alpine:3.22
22

33
RUN apk --no-cache add -f \
44
openssl \

deploy/keyhelp_api.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env sh
2+
3+
keyhelp_api_deploy() {
4+
_cdomain="$1"
5+
_ckey="$2"
6+
_ccert="$3"
7+
_cca="$4"
8+
9+
_debug _cdomain "$_cdomain"
10+
_debug _ckey "$_ckey"
11+
_debug _ccert "$_ccert"
12+
_debug _cca "$_cca"
13+
14+
# Read config from saved values or env
15+
_getdeployconf DEPLOY_KEYHELP_HOST
16+
_getdeployconf DEPLOY_KEYHELP_API_KEY
17+
18+
_debug DEPLOY_KEYHELP_HOST "$DEPLOY_KEYHELP_HOST"
19+
_secure_debug DEPLOY_KEYHELP_API_KEY "$DEPLOY_KEYHELP_API_KEY"
20+
21+
if [ -z "$DEPLOY_KEYHELP_HOST" ]; then
22+
_err "KeyHelp host not found, please define DEPLOY_KEYHELP_HOST."
23+
return 1
24+
fi
25+
if [ -z "$DEPLOY_KEYHELP_API_KEY" ]; then
26+
_err "KeyHelp api key not found, please define DEPLOY_KEYHELP_API_KEY."
27+
return 1
28+
fi
29+
30+
# Save current values
31+
_savedeployconf DEPLOY_KEYHELP_HOST "$DEPLOY_KEYHELP_HOST"
32+
_savedeployconf DEPLOY_KEYHELP_API_KEY "$DEPLOY_KEYHELP_API_KEY"
33+
34+
_request_key="$(tr '\n' ':' <"$_ckey" | sed 's/:/\\n/g')"
35+
_request_cert="$(tr '\n' ':' <"$_ccert" | sed 's/:/\\n/g')"
36+
_request_ca="$(tr '\n' ':' <"$_cca" | sed 's/:/\\n/g')"
37+
38+
_request_body="{
39+
\"name\": \"$_cdomain\",
40+
\"components\": {
41+
\"private_key\": \"$_request_key\",
42+
\"certificate\": \"$_request_cert\",
43+
\"ca_certificate\": \"$_request_ca\"
44+
}
45+
}"
46+
47+
_hosts="$(echo "$DEPLOY_KEYHELP_HOST" | tr "," " ")"
48+
_keys="$(echo "$DEPLOY_KEYHELP_API_KEY" | tr "," " ")"
49+
_i=1
50+
51+
for _host in $_hosts; do
52+
_key="$(_getfield "$_keys" "$_i" " ")"
53+
_i="$(_math "$_i" + 1)"
54+
55+
export _H1="X-API-Key: $_key"
56+
57+
_put_url="$_host/api/v2/certificates/name/$_cdomain"
58+
if _post "$_request_body" "$_put_url" "" "PUT" "application/json" >/dev/null; then
59+
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\r\n")"
60+
else
61+
_err "Cannot make PUT request to $_put_url"
62+
return 1
63+
fi
64+
65+
if [ "$_code" = "404" ]; then
66+
_info "$_cdomain not found, creating new entry at $_host"
67+
68+
_post_url="$_host/api/v2/certificates"
69+
if _post "$_request_body" "$_post_url" "" "POST" "application/json" >/dev/null; then
70+
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\r\n")"
71+
else
72+
_err "Cannot make POST request to $_post_url"
73+
return 1
74+
fi
75+
fi
76+
77+
if _startswith "$_code" "2"; then
78+
_info "$_cdomain set at $_host"
79+
else
80+
_err "HTTP status code is $_code"
81+
return 1
82+
fi
83+
done
84+
85+
return 0
86+
}

deploy/truenas_ws.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ with Client(uri="$_ws_uri") as c:
7171
fullchain = file.read()
7272
with open('$2', 'r') as file:
7373
privatekey = file.read()
74-
ret = c.call("certificate.create", {"name": "$3", "create_type": "CERTIFICATE_CREATE_IMPORTED", "certificate": fullchain, "privatekey": privatekey, "passphrase": ""}, job=True)
74+
ret = c.call("certificate.create", {"name": "$3", "create_type": "CERTIFICATE_CREATE_IMPORTED", "certificate": fullchain, "privatekey": privatekey}, job=True)
7575
print("R:" + str(ret["id"]))
7676
sys.exit(0)
7777
else:

deploy/unifi.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ unifi_deploy() {
143143

144144
# correct file ownership according to the directory, the keystore is placed in
145145
_unifi_keystore_dir=$(dirname "${_unifi_keystore}")
146-
_unifi_keystore_dir_owner=$(find "${_unifi_keystore_dir}" -maxdepth 0 -printf '%u\n')
147-
_unifi_keystore_owner=$(find "${_unifi_keystore}" -maxdepth 0 -printf '%u\n')
146+
# shellcheck disable=SC2012
147+
_unifi_keystore_dir_owner=$(ls -ld "${_unifi_keystore_dir}" | awk '{print $3}')
148+
# shellcheck disable=SC2012
149+
_unifi_keystore_owner=$(ls -l "${_unifi_keystore}" | awk '{print $3}')
148150
if ! [ "${_unifi_keystore_owner}" = "${_unifi_keystore_dir_owner}" ]; then
149151
_debug "Changing keystore owner to ${_unifi_keystore_dir_owner}"
150152
chown "$_unifi_keystore_dir_owner" "${_unifi_keystore}" >/dev/null 2>&1 # fail quietly if we're not running as root

dnsapi/dns_curanet.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CURANET_REST_URL="https://api.curanet.dk/dns/v1/Domains"
1515
CURANET_AUTH_URL="https://apiauth.dk.team.blue/auth/realms/Curanet/protocol/openid-connect/token"
1616
CURANET_ACCESS_TOKEN=""
1717

18-
######## Public functions #####################
18+
######## Public functions ####################
1919

2020
#Usage: dns_curanet_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
2121
dns_curanet_add() {
@@ -154,7 +154,7 @@ _get_root() {
154154
export _H3="Authorization: Bearer $CURANET_ACCESS_TOKEN"
155155
response="$(_get "$CURANET_REST_URL/$h/Records" "" "")"
156156

157-
if [ ! "$(echo "$response" | _egrep_o "Entity not found")" ]; then
157+
if [ ! "$(echo "$response" | _egrep_o "Entity not found|Bad Request")" ]; then
158158
_domain=$h
159159
return 0
160160
fi

notify/ntfy.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ ntfy_send() {
1414
_debug "_content" "$_content"
1515
_debug "_statusCode" "$_statusCode"
1616

17+
_priority_default="default"
18+
_priority_error="high"
19+
20+
_tag_success="white_check_mark"
21+
_tag_error="warning"
22+
_tag_info="information_source"
23+
1724
NTFY_URL="${NTFY_URL:-$(_readaccountconf_mutable NTFY_URL)}"
1825
if [ "$NTFY_URL" ]; then
1926
_saveaccountconf_mutable NTFY_URL "$NTFY_URL"
@@ -30,7 +37,26 @@ ntfy_send() {
3037
export _H1="Authorization: Bearer $NTFY_TOKEN"
3138
fi
3239

33-
_data="${_subject}. $_content"
40+
case "$_statusCode" in
41+
0)
42+
_priority="$_priority_default"
43+
_tag="$_tag_success"
44+
;;
45+
1)
46+
_priority="$_priority_error"
47+
_tag="$_tag_error"
48+
;;
49+
2)
50+
_priority="$_priority_default"
51+
_tag="$_tag_info"
52+
;;
53+
esac
54+
55+
export _H2="Priority: $_priority"
56+
export _H3="Tags: $_tag"
57+
export _H4="Title: $PROJECT_NAME: $_subject"
58+
59+
_data="$_content"
3460
response="$(_post "$_data" "$NTFY_URL/$NTFY_TOPIC" "" "POST" "")"
3561

3662
if [ "$?" = "0" ] && _contains "$response" "expires"; then

notify/opsgenie.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env sh
2+
3+
#Support OpsGenie API integration
4+
5+
#OPSGENIE_API_KEY="" Required, opsgenie api key
6+
#OPSGENIE_REGION="" Optional, opsgenie region, can be EU or US (default: US)
7+
#OPSGENIE_PRIORITY_SUCCESS="" Optional, opsgenie priority for success (default: P5)
8+
#OPSGENIE_PRIORITY_ERROR="" Optional, opsgenie priority for error (default: P2)
9+
#OPSGENIE_PRIORITY_SKIP="" Optional, opsgenie priority for renew skipped (default: P5)
10+
11+
_OPSGENIE_AVAIL_REGION="US,EU"
12+
_OPSGENIE_AVAIL_PRIORITIES="P1,P2,P3,P4,P5"
13+
14+
opsgenie_send() {
15+
_subject="$1"
16+
_content="$2"
17+
_status_code="$3" #0: success, 1: error, 2($RENEW_SKIP): skipped
18+
19+
OPSGENIE_API_KEY="${OPSGENIE_API_KEY:-$(_readaccountconf_mutable OPSGENIE_API_KEY)}"
20+
if [ -z "$OPSGENIE_API_KEY" ]; then
21+
OPSGENIE_API_KEY=""
22+
_err "You didn't specify an OpsGenie API key OPSGENIE_API_KEY yet."
23+
return 1
24+
fi
25+
_saveaccountconf_mutable OPSGENIE_API_KEY "$OPSGENIE_API_KEY"
26+
export _H1="Authorization: GenieKey $OPSGENIE_API_KEY"
27+
28+
OPSGENIE_REGION="${OPSGENIE_REGION:-$(_readaccountconf_mutable OPSGENIE_REGION)}"
29+
if [ -z "$OPSGENIE_REGION" ]; then
30+
OPSGENIE_REGION="US"
31+
_info "The OPSGENIE_REGION is not set, so use the default US as regeion."
32+
elif ! _hasfield "$_OPSGENIE_AVAIL_REGION" "$OPSGENIE_REGION"; then
33+
_err "The OPSGENIE_REGION \"$OPSGENIE_REGION\" is not available, should be one of $_OPSGENIE_AVAIL_REGION"
34+
OPSGENIE_REGION=""
35+
return 1
36+
else
37+
_saveaccountconf_mutable OPSGENIE_REGION "$OPSGENIE_REGION"
38+
fi
39+
40+
OPSGENIE_PRIORITY_SUCCESS="${OPSGENIE_PRIORITY_SUCCESS:-$(_readaccountconf_mutable OPSGENIE_PRIORITY_SUCCESS)}"
41+
if [ -z "$OPSGENIE_PRIORITY_SUCCESS" ]; then
42+
OPSGENIE_PRIORITY_SUCCESS="P5"
43+
_info "The OPSGENIE_PRIORITY_SUCCESS is not set, so use the default P5 as priority."
44+
elif ! _hasfield "$_OPSGENIE_AVAIL_PRIORITIES" "$OPSGENIE_PRIORITY_SUCCESS"; then
45+
_err "The OPSGENIE_PRIORITY_SUCCESS \"$OPSGENIE_PRIORITY_SUCCESS\" is not available, should be one of $_OPSGENIE_AVAIL_PRIORITIES"
46+
OPSGENIE_PRIORITY_SUCCESS=""
47+
return 1
48+
else
49+
_saveaccountconf_mutable OPSGENIE_PRIORITY_SUCCESS "$OPSGENIE_PRIORITY_SUCCESS"
50+
fi
51+
52+
OPSGENIE_PRIORITY_ERROR="${OPSGENIE_PRIORITY_ERROR:-$(_readaccountconf_mutable OPSGENIE_PRIORITY_ERROR)}"
53+
if [ -z "$OPSGENIE_PRIORITY_ERROR" ]; then
54+
OPSGENIE_PRIORITY_ERROR="P2"
55+
_info "The OPSGENIE_PRIORITY_ERROR is not set, so use the default P2 as priority."
56+
elif ! _hasfield "$_OPSGENIE_AVAIL_PRIORITIES" "$OPSGENIE_PRIORITY_ERROR"; then
57+
_err "The OPSGENIE_PRIORITY_ERROR \"$OPSGENIE_PRIORITY_ERROR\" is not available, should be one of $_OPSGENIE_AVAIL_PRIORITIES"
58+
OPSGENIE_PRIORITY_ERROR=""
59+
return 1
60+
else
61+
_saveaccountconf_mutable OPSGENIE_PRIORITY_ERROR "$OPSGENIE_PRIORITY_ERROR"
62+
fi
63+
64+
OPSGENIE_PRIORITY_SKIP="${OPSGENIE_PRIORITY_SKIP:-$(_readaccountconf_mutable OPSGENIE_PRIORITY_SKIP)}"
65+
if [ -z "$OPSGENIE_PRIORITY_SKIP" ]; then
66+
OPSGENIE_PRIORITY_SKIP="P5"
67+
_info "The OPSGENIE_PRIORITY_SKIP is not set, so use the default P5 as priority."
68+
elif ! _hasfield "$_OPSGENIE_AVAIL_PRIORITIES" "$OPSGENIE_PRIORITY_SKIP"; then
69+
_err "The OPSGENIE_PRIORITY_SKIP \"$OPSGENIE_PRIORITY_SKIP\" is not available, should be one of $_OPSGENIE_AVAIL_PRIORITIES"
70+
OPSGENIE_PRIORITY_SKIP=""
71+
return 1
72+
else
73+
_saveaccountconf_mutable OPSGENIE_PRIORITY_SKIP "$OPSGENIE_PRIORITY_SKIP"
74+
fi
75+
76+
case "$OPSGENIE_REGION" in
77+
"US")
78+
_opsgenie_url="https://api.opsgenie.com/v2/alerts"
79+
;;
80+
"EU")
81+
_opsgenie_url="https://api.eu.opsgenie.com/v2/alerts"
82+
;;
83+
*)
84+
_err "opsgenie region error."
85+
return 1
86+
;;
87+
esac
88+
89+
case $_status_code in
90+
0)
91+
_priority=$OPSGENIE_PRIORITY_SUCCESS
92+
;;
93+
1)
94+
_priority=$OPSGENIE_PRIORITY_ERROR
95+
;;
96+
2)
97+
_priority=$OPSGENIE_PRIORITY_SKIP
98+
;;
99+
*)
100+
_priority=$OPSGENIE_PRIORITY_ERROR
101+
;;
102+
esac
103+
104+
_subject_json=$(echo "$_subject" | _json_encode)
105+
_content_json=$(echo "$_content" | _json_encode)
106+
_subject_underscore=$(echo "$_subject" | sed 's/ /_/g')
107+
_alias_json=$(echo "acme.sh-$(hostname)-$_subject_underscore-$(date +%Y%m%d)" | base64 --wrap=0 | _json_encode)
108+
109+
_data="{
110+
\"message\": \"$_subject_json\",
111+
\"alias\": \"$_alias_json\",
112+
\"description\": \"$_content_json\",
113+
\"tags\": [
114+
\"acme.sh\",
115+
\"host:$(hostname)\"
116+
],
117+
\"entity\": \"$(hostname -f)\",
118+
\"priority\": \"$_priority\"
119+
}"
120+
121+
if response=$(_post "$_data" "$_opsgenie_url" "" "" "application/json"); then
122+
if ! _contains "$response" error; then
123+
_info "opsgenie send success."
124+
return 0
125+
fi
126+
fi
127+
_err "opsgenie send error."
128+
_err "$response"
129+
return 1
130+
}

0 commit comments

Comments
 (0)