Skip to content

Commit a1f4f9d

Browse files
authored
Merge pull request #6579 from acmesh-official/dev
sync
2 parents a5754e9 + 08246f7 commit a1f4f9d

File tree

7 files changed

+431
-3
lines changed

7 files changed

+431
-3
lines changed

deploy/cachefly.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env sh
2+
3+
# Script to deploy certificate to CacheFly
4+
# https://api.cachefly.com/api/2.5/docs#tag/Certificates/paths/~1certificates/post
5+
6+
# This deployment required following variables
7+
# export CACHEFLY_TOKEN="Your CacheFly API Token"
8+
9+
# returns 0 means success, otherwise error.
10+
11+
######## Public functions #####################
12+
13+
#domain keyfile certfile cafile fullchain
14+
CACHEFLY_API_BASE="https://api.cachefly.com/api/2.5"
15+
16+
cachefly_deploy() {
17+
_cdomain="$1"
18+
_ckey="$2"
19+
_ccert="$3"
20+
_cca="$4"
21+
_cfullchain="$5"
22+
23+
_debug _cdomain "$_cdomain"
24+
_debug _ckey "$_ckey"
25+
_debug _ccert "$_ccert"
26+
_debug _cca "$_cca"
27+
_debug _cfullchain "$_cfullchain"
28+
29+
if [ -z "$CACHEFLY_TOKEN" ]; then
30+
_err "CACHEFLY_TOKEN is not defined."
31+
return 1
32+
else
33+
_savedomainconf CACHEFLY_TOKEN "$CACHEFLY_TOKEN"
34+
fi
35+
36+
_info "Deploying certificate to CacheFly..."
37+
38+
## upload certificate
39+
string_fullchain=$(sed 's/$/\\n/' "$_cfullchain" | tr -d '\n')
40+
string_key=$(sed 's/$/\\n/' "$_ckey" | tr -d '\n')
41+
42+
_request_body="{\"certificate\":\"$string_fullchain\",\"certificateKey\":\"$string_key\"}"
43+
_debug _request_body "$_request_body"
44+
_debug CACHEFLY_TOKEN "$CACHEFLY_TOKEN"
45+
export _H1="Authorization: Bearer $CACHEFLY_TOKEN"
46+
_response=$(_post "$_request_body" "$CACHEFLY_API_BASE/certificates" "" "POST" "application/json")
47+
48+
if _contains "$_response" "message"; then
49+
_err "Error in deploying $_cdomain certificate to CacheFly."
50+
_err "$_response"
51+
return 1
52+
fi
53+
_debug response "$_response"
54+
_info "Domain $_cdomain certificate successfully deployed to CacheFly."
55+
return 0
56+
}

deploy/directadmin.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+
# Script to deploy certificate to DirectAdmin
4+
# https://docs.directadmin.com/directadmin/customizing-workflow/api-all-about.html#creating-a-login-key
5+
# https://docs.directadmin.com/changelog/version-1.24.4.html#cmd-api-catch-all-pop-passwords-frontpage-protected-dirs-ssl-certs
6+
7+
# This deployment required following variables
8+
# export DirectAdmin_SCHEME="https" # Optional, https or http, defaults to https
9+
# export DirectAdmin_ENDPOINT="example.com:2222"
10+
# export DirectAdmin_USERNAME="Your DirectAdmin Username"
11+
# export DirectAdmin_KEY="Your DirectAdmin Login Key or Password"
12+
# export DirectAdmin_MAIN_DOMAIN="Your DirectAdmin Main Domain, NOT Subdomain"
13+
14+
# returns 0 means success, otherwise error.
15+
16+
######## Public functions #####################
17+
18+
#domain keyfile certfile cafile fullchain
19+
directadmin_deploy() {
20+
_cdomain="$1"
21+
_ckey="$2"
22+
_ccert="$3"
23+
_cca="$4"
24+
_cfullchain="$5"
25+
26+
_debug _cdomain "$_cdomain"
27+
_debug _ckey "$_ckey"
28+
_debug _ccert "$_ccert"
29+
_debug _cca "$_cca"
30+
_debug _cfullchain "$_cfullchain"
31+
32+
if [ -z "$DirectAdmin_ENDPOINT" ]; then
33+
_err "DirectAdmin_ENDPOINT is not defined."
34+
return 1
35+
else
36+
_savedomainconf DirectAdmin_ENDPOINT "$DirectAdmin_ENDPOINT"
37+
fi
38+
if [ -z "$DirectAdmin_USERNAME" ]; then
39+
_err "DirectAdmin_USERNAME is not defined."
40+
return 1
41+
else
42+
_savedomainconf DirectAdmin_USERNAME "$DirectAdmin_USERNAME"
43+
fi
44+
if [ -z "$DirectAdmin_KEY" ]; then
45+
_err "DirectAdmin_KEY is not defined."
46+
return 1
47+
else
48+
_savedomainconf DirectAdmin_KEY "$DirectAdmin_KEY"
49+
fi
50+
if [ -z "$DirectAdmin_MAIN_DOMAIN" ]; then
51+
_err "DirectAdmin_MAIN_DOMAIN is not defined."
52+
return 1
53+
else
54+
_savedomainconf DirectAdmin_MAIN_DOMAIN "$DirectAdmin_MAIN_DOMAIN"
55+
fi
56+
57+
# Optional SCHEME
58+
_getdeployconf DirectAdmin_SCHEME
59+
# set default values for DirectAdmin_SCHEME
60+
[ -n "${DirectAdmin_SCHEME}" ] || DirectAdmin_SCHEME="https"
61+
62+
_info "Deploying certificate to DirectAdmin..."
63+
64+
# upload certificate
65+
string_cfullchain=$(sed 's/$/\\n/' "$_cfullchain" | tr -d '\n')
66+
string_key=$(sed 's/$/\\n/' "$_ckey" | tr -d '\n')
67+
68+
_request_body="{\"domain\":\"$DirectAdmin_MAIN_DOMAIN\",\"action\":\"save\",\"type\":\"paste\",\"certificate\":\"$string_key\n$string_cfullchain\n\"}"
69+
_debug _request_body "$_request_body"
70+
_debug DirectAdmin_ENDPOINT "$DirectAdmin_ENDPOINT"
71+
_debug DirectAdmin_USERNAME "$DirectAdmin_USERNAME"
72+
_debug DirectAdmin_KEY "$DirectAdmin_KEY"
73+
_debug DirectAdmin_MAIN_DOMAIN "$DirectAdmin_MAIN_DOMAIN"
74+
_response=$(_post "$_request_body" "$DirectAdmin_SCHEME://$DirectAdmin_USERNAME:$DirectAdmin_KEY@$DirectAdmin_ENDPOINT/CMD_API_SSL" "" "POST" "application/json")
75+
76+
if _contains "$_response" "error=1"; then
77+
_err "Error in deploying $_cdomain certificate to DirectAdmin Domain $DirectAdmin_MAIN_DOMAIN."
78+
_err "$_response"
79+
return 1
80+
fi
81+
82+
_info "$_response"
83+
_info "Domain $_cdomain certificate successfully deployed to DirectAdmin Domain $DirectAdmin_MAIN_DOMAIN."
84+
85+
return 0
86+
}

deploy/edgio.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+
# Here is a script to deploy cert to edgio using its API
4+
# https://docs.edg.io/guides/v7/develop/rest_api/authentication
5+
# https://docs.edg.io/rest_api/#tag/tls-certs/operation/postConfigV01TlsCerts
6+
7+
# This deployment required following variables
8+
# export EDGIO_CLIENT_ID="Your Edgio Client ID"
9+
# export EDGIO_CLIENT_SECRET="Your Edgio Client Secret"
10+
# export EDGIO_ENVIRONMENT_ID="Your Edgio Environment ID"
11+
12+
# If have more than one Environment ID
13+
# export EDGIO_ENVIRONMENT_ID="ENVIRONMENT_ID_1 ENVIRONMENT_ID_2"
14+
15+
# returns 0 means success, otherwise error.
16+
17+
######## Public functions #####################
18+
19+
#domain keyfile certfile cafile fullchain
20+
edgio_deploy() {
21+
_cdomain="$1"
22+
_ckey="$2"
23+
_ccert="$3"
24+
_cca="$4"
25+
_cfullchain="$5"
26+
27+
_debug _cdomain "$_cdomain"
28+
_debug _ckey "$_ckey"
29+
_debug _ccert "$_ccert"
30+
_debug _cca "$_cca"
31+
_debug _cfullchain "$_cfullchain"
32+
33+
if [ -z "$EDGIO_CLIENT_ID" ]; then
34+
_err "EDGIO_CLIENT_ID is not defined."
35+
return 1
36+
else
37+
_savedomainconf EDGIO_CLIENT_ID "$EDGIO_CLIENT_ID"
38+
fi
39+
40+
if [ -z "$EDGIO_CLIENT_SECRET" ]; then
41+
_err "EDGIO_CLIENT_SECRET is not defined."
42+
return 1
43+
else
44+
_savedomainconf EDGIO_CLIENT_SECRET "$EDGIO_CLIENT_SECRET"
45+
fi
46+
47+
if [ -z "$EDGIO_ENVIRONMENT_ID" ]; then
48+
_err "EDGIO_ENVIRONMENT_ID is not defined."
49+
return 1
50+
else
51+
_savedomainconf EDGIO_ENVIRONMENT_ID "$EDGIO_ENVIRONMENT_ID"
52+
fi
53+
54+
_info "Getting access token"
55+
_data="client_id=$EDGIO_CLIENT_ID&client_secret=$EDGIO_CLIENT_SECRET&grant_type=client_credentials&scope=app.config"
56+
_debug Get_access_token_data "$_data"
57+
_response=$(_post "$_data" "https://id.edgio.app/connect/token" "" "POST" "application/x-www-form-urlencoded")
58+
_debug Get_access_token_response "$_response"
59+
_access_token=$(echo "$_response" | _json_decode | _egrep_o '"access_token":"[^"]*' | cut -d : -f 2 | tr -d '"')
60+
_debug _access_token "$_access_token"
61+
if [ -z "$_access_token" ]; then
62+
_err "Error in getting access token"
63+
return 1
64+
fi
65+
66+
_info "Uploading certificate"
67+
string_ccert=$(sed 's/$/\\n/' "$_ccert" | tr -d '\n')
68+
string_cca=$(sed 's/$/\\n/' "$_cca" | tr -d '\n')
69+
string_key=$(sed 's/$/\\n/' "$_ckey" | tr -d '\n')
70+
71+
for ENVIRONMENT_ID in $EDGIO_ENVIRONMENT_ID; do
72+
_data="{\"environment_id\":\"$ENVIRONMENT_ID\",\"primary_cert\":\"$string_ccert\",\"intermediate_cert\":\"$string_cca\",\"private_key\":\"$string_key\"}"
73+
_debug Upload_certificate_data "$_data"
74+
_H1="Authorization: Bearer $_access_token"
75+
_response=$(_post "$_data" "https://edgioapis.com/config/v0.1/tls-certs" "" "POST" "application/json")
76+
if _contains "$_response" "message"; then
77+
_err "Error in deploying $_cdomain certificate to Edgio ENVIRONMENT_ID $ENVIRONMENT_ID."
78+
_err "$_response"
79+
return 1
80+
fi
81+
_debug Upload_certificate_response "$_response"
82+
_info "Domain $_cdomain certificate successfully deployed to Edgio ENVIRONMENT_ID $ENVIRONMENT_ID."
83+
done
84+
85+
return 0
86+
}

deploy/keyhelp.sh

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env sh
2+
3+
# Script to deploy certificate to KeyHelp
4+
# This deployment required following variables
5+
# export DEPLOY_KEYHELP_BASEURL="https://keyhelp.example.com"
6+
# export DEPLOY_KEYHELP_USERNAME="Your KeyHelp Username"
7+
# export DEPLOY_KEYHELP_PASSWORD="Your KeyHelp Password"
8+
# export DEPLOY_KEYHELP_DOMAIN_ID="Depoly certificate to this Domain ID"
9+
10+
# Open the 'Edit domain' page, and you will see id=xxx at the end of the URL. This is the Domain ID.
11+
# https://DEPLOY_KEYHELP_BASEURL/index.php?page=domains&action=edit&id=xxx
12+
13+
# If have more than one domain name
14+
# export DEPLOY_KEYHELP_DOMAIN_ID="111 222 333"
15+
16+
keyhelp_deploy() {
17+
_cdomain="$1"
18+
_ckey="$2"
19+
_ccert="$3"
20+
_cca="$4"
21+
_cfullchain="$5"
22+
23+
_debug _cdomain "$_cdomain"
24+
_debug _ckey "$_ckey"
25+
_debug _ccert "$_ccert"
26+
_debug _cca "$_cca"
27+
_debug _cfullchain "$_cfullchain"
28+
29+
if [ -z "$DEPLOY_KEYHELP_BASEURL" ]; then
30+
_err "DEPLOY_KEYHELP_BASEURL is not defined."
31+
return 1
32+
else
33+
_savedomainconf DEPLOY_KEYHELP_BASEURL "$DEPLOY_KEYHELP_BASEURL"
34+
fi
35+
36+
if [ -z "$DEPLOY_KEYHELP_USERNAME" ]; then
37+
_err "DEPLOY_KEYHELP_USERNAME is not defined."
38+
return 1
39+
else
40+
_savedomainconf DEPLOY_KEYHELP_USERNAME "$DEPLOY_KEYHELP_USERNAME"
41+
fi
42+
43+
if [ -z "$DEPLOY_KEYHELP_PASSWORD" ]; then
44+
_err "DEPLOY_KEYHELP_PASSWORD is not defined."
45+
return 1
46+
else
47+
_savedomainconf DEPLOY_KEYHELP_PASSWORD "$DEPLOY_KEYHELP_PASSWORD"
48+
fi
49+
50+
if [ -z "$DEPLOY_KEYHELP_DOMAIN_ID" ]; then
51+
_err "DEPLOY_KEYHELP_DOMAIN_ID is not defined."
52+
return 1
53+
else
54+
_savedomainconf DEPLOY_KEYHELP_DOMAIN_ID "$DEPLOY_KEYHELP_DOMAIN_ID"
55+
fi
56+
57+
# Optional DEPLOY_KEYHELP_ENFORCE_HTTPS
58+
_getdeployconf DEPLOY_KEYHELP_ENFORCE_HTTPS
59+
# set default values for DEPLOY_KEYHELP_ENFORCE_HTTPS
60+
[ -n "${DEPLOY_KEYHELP_ENFORCE_HTTPS}" ] || DEPLOY_KEYHELP_ENFORCE_HTTPS="1"
61+
62+
_info "Logging in to keyhelp panel"
63+
username_encoded="$(printf "%s" "${DEPLOY_KEYHELP_USERNAME}" | _url_encode)"
64+
password_encoded="$(printf "%s" "${DEPLOY_KEYHELP_PASSWORD}" | _url_encode)"
65+
_H1="Content-Type: application/x-www-form-urlencoded"
66+
_response=$(_get "$DEPLOY_KEYHELP_BASEURL/index.php?submit=1&username=$username_encoded&password=$password_encoded" "TRUE")
67+
_cookie="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _head_n 1 | cut -d " " -f 2)"
68+
69+
# If cookies is not empty then logon successful
70+
if [ -z "$_cookie" ]; then
71+
_err "Fail to get cookie."
72+
return 1
73+
fi
74+
_debug "cookie" "$_cookie"
75+
76+
_info "Uploading certificate"
77+
_date=$(date +"%Y%m%d")
78+
encoded_key="$(_url_encode <"$_ckey")"
79+
encoded_ccert="$(_url_encode <"$_ccert")"
80+
encoded_cca="$(_url_encode <"$_cca")"
81+
certificate_name="$_cdomain-$_date"
82+
83+
_request_body="submit=1&certificate_name=$certificate_name&add_type=upload&text_private_key=$encoded_key&text_certificate=$encoded_ccert&text_ca_certificate=$encoded_cca"
84+
_H1="Cookie: $_cookie"
85+
_response=$(_post "$_request_body" "$DEPLOY_KEYHELP_BASEURL/index.php?page=ssl_certificates&action=add" "" "POST")
86+
_message=$(echo "$_response" | grep -A 2 'message-body' | sed -n '/<div class="message-body ">/,/<\/div>/{//!p;}' | sed 's/<[^>]*>//g' | sed 's/^ *//;s/ *$//')
87+
_info "_message" "$_message"
88+
if [ -z "$_message" ]; then
89+
_err "Fail to upload certificate."
90+
return 1
91+
fi
92+
93+
for DOMAIN_ID in $DEPLOY_KEYHELP_DOMAIN_ID; do
94+
_info "Apply certificate to domain id $DOMAIN_ID"
95+
_response=$(_get "$DEPLOY_KEYHELP_BASEURL/index.php?page=domains&action=edit&id=$DOMAIN_ID")
96+
cert_value=$(echo "$_response" | grep "$certificate_name" | sed -n 's/.*value="\([^"]*\).*/\1/p')
97+
target_type=$(echo "$_response" | grep 'target_type' | grep 'checked' | sed -n 's/.*value="\([^"]*\).*/\1/p')
98+
if [ "$target_type" = "directory" ]; then
99+
path=$(echo "$_response" | awk '/name="path"/{getline; print}' | sed -n 's/.*value="\([^"]*\).*/\1/p')
100+
fi
101+
echo "$_response" | grep "is_prefer_https" | grep "checked" >/dev/null
102+
if [ $? -eq 0 ]; then
103+
is_prefer_https=1
104+
else
105+
is_prefer_https=0
106+
fi
107+
echo "$_response" | grep "hsts_enabled" | grep "checked" >/dev/null
108+
if [ $? -eq 0 ]; then
109+
hsts_enabled=1
110+
else
111+
hsts_enabled=0
112+
fi
113+
_debug "cert_value" "$cert_value"
114+
if [ -z "$cert_value" ]; then
115+
_err "Fail to get certificate id."
116+
return 1
117+
fi
118+
119+
_request_body="submit=1&id=$DOMAIN_ID&target_type=$target_type&path=$path&is_prefer_https=$is_prefer_https&hsts_enabled=$hsts_enabled&certificate_type=custom&certificate_id=$cert_value&enforce_https=$DEPLOY_KEYHELP_ENFORCE_HTTPS"
120+
_response=$(_post "$_request_body" "$DEPLOY_KEYHELP_BASEURL/index.php?page=domains&action=edit" "" "POST")
121+
_message=$(echo "$_response" | grep -A 2 'message-body' | sed -n '/<div class="message-body ">/,/<\/div>/{//!p;}' | sed 's/<[^>]*>//g' | sed 's/^ *//;s/ *$//')
122+
_info "_message" "$_message"
123+
if [ -z "$_message" ]; then
124+
_err "Fail to apply certificate."
125+
return 1
126+
fi
127+
done
128+
129+
_info "Domain $_cdomain certificate successfully deployed to KeyHelp Domain ID $DEPLOY_KEYHELP_DOMAIN_ID."
130+
return 0
131+
}

0 commit comments

Comments
 (0)