forked from Github/acme.sh
Pål Håland
6 years ago
58 changed files with 6048 additions and 475 deletions
-
11.travis.yml
-
5Dockerfile
-
77README.md
-
475acme.sh
-
138deploy/README.md
-
18deploy/cpanel_uapi.sh
-
12deploy/fritzbox.sh
-
80deploy/gitlab.sh
-
36deploy/haproxy.sh
-
6deploy/keychain.sh
-
59deploy/mydevil.sh
-
92deploy/qiniu.sh
-
4deploy/ssh.sh
-
11deploy/vault_cli.sh
-
514dnsapi/README.md
-
55dnsapi/dns_acmedns.sh
-
141dnsapi/dns_active24.sh
-
14dnsapi/dns_aws.sh
-
21dnsapi/dns_azure.sh
-
15dnsapi/dns_cf.sh
-
253dnsapi/dns_conoha.sh
-
4dnsapi/dns_cx.sh
-
153dnsapi/dns_dgon.sh
-
55dnsapi/dns_dnsimple.sh
-
59dnsapi/dns_doapi.sh
-
2dnsapi/dns_dp.sh
-
161dnsapi/dns_dpi.sh
-
26dnsapi/dns_dynu.sh
-
358dnsapi/dns_euserv.sh
-
168dnsapi/dns_exoscale.sh
-
62dnsapi/dns_gandi_livedns.sh
-
167dnsapi/dns_gcloud.sh
-
20dnsapi/dns_gd.sh
-
168dnsapi/dns_gdnsdk.sh
-
23dnsapi/dns_he.sh
-
161dnsapi/dns_hostingde.sh
-
51dnsapi/dns_inwx.sh
-
4dnsapi/dns_ispconfig.sh
-
107dnsapi/dns_kinghost.sh
-
55dnsapi/dns_lexicon.sh
-
185dnsapi/dns_linode_v4.sh
-
286dnsapi/dns_loopia.sh
-
97dnsapi/dns_mydevil.sh
-
210dnsapi/dns_mydnsjp.sh
-
407dnsapi/dns_namecheap.sh
-
2dnsapi/dns_namecom.sh
-
181dnsapi/dns_neodigit.sh
-
133dnsapi/dns_netcup.sh
-
4dnsapi/dns_nsone.sh
-
34dnsapi/dns_nsupdate.sh
-
211dnsapi/dns_nw.sh
-
217dnsapi/dns_online.sh
-
63dnsapi/dns_pdns.sh
-
164dnsapi/dns_pointhq.sh
-
207dnsapi/dns_rackspace.sh
-
69dnsapi/dns_tele3.sh
-
61dnsapi/dns_unoeuro.sh
-
139dnsapi/dns_zilore.sh
@ -0,0 +1,80 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Script to deploy certificate to a Gitlab hosted page |
||||
|
|
||||
|
# The following variables exported from environment will be used. |
||||
|
# If not set then values previously saved in domain.conf file are used. |
||||
|
|
||||
|
# All the variables are required |
||||
|
|
||||
|
# export GITLAB_TOKEN="xxxxxxx" |
||||
|
# export GITLAB_PROJECT_ID=012345 |
||||
|
# export GITLAB_DOMAIN="mydomain.com" |
||||
|
|
||||
|
gitlab_deploy() { |
||||
|
_cdomain="$1" |
||||
|
_ckey="$2" |
||||
|
_ccert="$3" |
||||
|
_cca="$4" |
||||
|
_cfullchain="$5" |
||||
|
|
||||
|
_debug _cdomain "$_cdomain" |
||||
|
_debug _ckey "$_ckey" |
||||
|
_debug _ccert "$_ccert" |
||||
|
_debug _cca "$_cca" |
||||
|
_debug _cfullchain "$_cfullchain" |
||||
|
|
||||
|
if [ -z "$GITLAB_TOKEN" ]; then |
||||
|
if [ -z "$Le_Deploy_gitlab_token" ]; then |
||||
|
_err "GITLAB_TOKEN not defined." |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
Le_Deploy_gitlab_token="$GITLAB_TOKEN" |
||||
|
_savedomainconf Le_Deploy_gitlab_token "$Le_Deploy_gitlab_token" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$GITLAB_PROJECT_ID" ]; then |
||||
|
if [ -z "$Le_Deploy_gitlab_project_id" ]; then |
||||
|
_err "GITLAB_PROJECT_ID not defined." |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
Le_Deploy_gitlab_project_id="$GITLAB_PROJECT_ID" |
||||
|
_savedomainconf Le_Deploy_gitlab_project_id "$Le_Deploy_gitlab_project_id" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$GITLAB_DOMAIN" ]; then |
||||
|
if [ -z "$Le_Deploy_gitlab_domain" ]; then |
||||
|
_err "GITLAB_DOMAIN not defined." |
||||
|
return 1 |
||||
|
fi |
||||
|
else |
||||
|
Le_Deploy_gitlab_domain="$GITLAB_DOMAIN" |
||||
|
_savedomainconf Le_Deploy_gitlab_domain "$Le_Deploy_gitlab_domain" |
||||
|
fi |
||||
|
|
||||
|
string_fullchain=$(_url_encode <"$_cfullchain") |
||||
|
string_key=$(_url_encode <"$_ckey") |
||||
|
|
||||
|
body="certificate=$string_fullchain&key=$string_key" |
||||
|
|
||||
|
export _H1="PRIVATE-TOKEN: $Le_Deploy_gitlab_token" |
||||
|
|
||||
|
gitlab_url="https://gitlab.com/api/v4/projects/$Le_Deploy_gitlab_project_id/pages/domains/$Le_Deploy_gitlab_domain" |
||||
|
|
||||
|
_response=$(_post "$body" "$gitlab_url" 0 PUT | _dbase64 "multiline") |
||||
|
|
||||
|
error_response="error" |
||||
|
|
||||
|
if test "${_response#*$error_response}" != "$_response"; then |
||||
|
_err "Error in deploying certificate:" |
||||
|
_err "$_response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug response "$_response" |
||||
|
_info "Certificate successfully deployed" |
||||
|
|
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,59 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# MyDevil.net API (2019-02-03) |
||||
|
# |
||||
|
# MyDevil.net already supports automatic Let's Encrypt certificates, |
||||
|
# except for wildcard domains. |
||||
|
# |
||||
|
# This script depends on `devil` command that MyDevil.net provides, |
||||
|
# which means that it works only on server side. |
||||
|
# |
||||
|
# Author: Marcin Konicki <https://ahwayakchih.neoni.net> |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: mydevil_deploy domain keyfile certfile cafile fullchain |
||||
|
mydevil_deploy() { |
||||
|
_cdomain="$1" |
||||
|
_ckey="$2" |
||||
|
_ccert="$3" |
||||
|
_cca="$4" |
||||
|
_cfullchain="$5" |
||||
|
ip="" |
||||
|
|
||||
|
_debug _cdomain "$_cdomain" |
||||
|
_debug _ckey "$_ckey" |
||||
|
_debug _ccert "$_ccert" |
||||
|
_debug _cca "$_cca" |
||||
|
_debug _cfullchain "$_cfullchain" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
ip=$(mydevil_get_ip "$_cdomain") |
||||
|
if [ -z "$ip" ]; then |
||||
|
_err "Could not find IP for domain $_cdomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# Delete old certificate first |
||||
|
_info "Removing old certificate for $_cdomain at $ip" |
||||
|
devil ssl www del "$ip" "$_cdomain" |
||||
|
|
||||
|
# Add new certificate |
||||
|
_info "Adding new certificate for $_cdomain at $ip" |
||||
|
devil ssl www add "$ip" "$_cfullchain" "$_ckey" "$_cdomain" || return 1 |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
# Usage: ip=$(mydevil_get_ip domain.com) |
||||
|
# echo $ip |
||||
|
mydevil_get_ip() { |
||||
|
devil dns list "$1" | cut -w -s -f 3,7 | grep "^A$(printf '\t')" | cut -w -s -f 2 || return 1 |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,92 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Script to create certificate to qiniu.com |
||||
|
# |
||||
|
# This deployment required following variables |
||||
|
# export QINIU_AK="QINIUACCESSKEY" |
||||
|
# export QINIU_SK="QINIUSECRETKEY" |
||||
|
# export QINIU_CDN_DOMAIN="cdn.example.com" |
||||
|
|
||||
|
QINIU_API_BASE="https://api.qiniu.com" |
||||
|
|
||||
|
qiniu_deploy() { |
||||
|
_cdomain="$1" |
||||
|
_ckey="$2" |
||||
|
_ccert="$3" |
||||
|
_cca="$4" |
||||
|
_cfullchain="$5" |
||||
|
|
||||
|
_debug _cdomain "$_cdomain" |
||||
|
_debug _ckey "$_ckey" |
||||
|
_debug _ccert "$_ccert" |
||||
|
_debug _cca "$_cca" |
||||
|
_debug _cfullchain "$_cfullchain" |
||||
|
|
||||
|
if [ -z "$QINIU_AK" ]; then |
||||
|
_err "QINIU_AK is not defined." |
||||
|
return 1 |
||||
|
else |
||||
|
_savedomainconf QINIU_AK "$QINIU_AK" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$QINIU_SK" ]; then |
||||
|
_err "QINIU_SK is not defined." |
||||
|
return 1 |
||||
|
else |
||||
|
_savedomainconf QINIU_SK "$QINIU_SK" |
||||
|
fi |
||||
|
|
||||
|
if [ "$QINIU_CDN_DOMAIN" ]; then |
||||
|
_savedomainconf QINIU_CDN_DOMAIN "$QINIU_CDN_DOMAIN" |
||||
|
else |
||||
|
QINIU_CDN_DOMAIN="$_cdomain" |
||||
|
fi |
||||
|
|
||||
|
## upload certificate |
||||
|
string_fullchain=$(sed 's/$/\\n/' "$_cfullchain" | tr -d '\n') |
||||
|
string_key=$(sed 's/$/\\n/' "$_ckey" | tr -d '\n') |
||||
|
|
||||
|
sslcert_path="/sslcert" |
||||
|
sslcerl_body="{\"name\":\"$_cdomain\",\"common_name\":\"$QINIU_CDN_DOMAIN\",\"ca\":\"$string_fullchain\",\"pri\":\"$string_key\"}" |
||||
|
sslcert_access_token="$(_make_access_token "$sslcert_path")" |
||||
|
_debug sslcert_access_token "$sslcert_access_token" |
||||
|
export _H1="Authorization: QBox $sslcert_access_token" |
||||
|
sslcert_response=$(_post "$sslcerl_body" "$QINIU_API_BASE$sslcert_path" 0 "POST" "application/json" | _dbase64 "multiline") |
||||
|
|
||||
|
if ! _contains "$sslcert_response" "certID"; then |
||||
|
_err "Error in creating certificate:" |
||||
|
_err "$sslcert_response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug sslcert_response "$sslcert_response" |
||||
|
_info "Certificate successfully uploaded, updating domain $_cdomain" |
||||
|
|
||||
|
## extract certId |
||||
|
_certId="$(printf "%s" "$sslcert_response" | _normalizeJson | _egrep_o "certID\": *\"[^\"]*\"" | cut -d : -f 2)" |
||||
|
_debug certId "$_certId" |
||||
|
|
||||
|
## update domain ssl config |
||||
|
update_path="/domain/$QINIU_CDN_DOMAIN/httpsconf" |
||||
|
update_body="{\"certid\":$_certId,\"forceHttps\":false}" |
||||
|
update_access_token="$(_make_access_token "$update_path")" |
||||
|
_debug update_access_token "$update_access_token" |
||||
|
export _H1="Authorization: QBox $update_access_token" |
||||
|
update_response=$(_post "$update_body" "$QINIU_API_BASE$update_path" 0 "PUT" "application/json" | _dbase64 "multiline") |
||||
|
|
||||
|
if _contains "$update_response" "error"; then |
||||
|
_err "Error in updating domain httpsconf:" |
||||
|
_err "$update_response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug update_response "$update_response" |
||||
|
_info "Certificate successfully deployed" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_make_access_token() { |
||||
|
_token="$(printf "%s\n" "$1" | _hmac "sha1" "$(printf "%s" "$QINIU_SK" | _hex_dump | tr -d " ")" | _base64)" |
||||
|
echo "$QINIU_AK:$_token" |
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# |
||||
|
#Author: Wolfgang Ebner |
||||
|
#Report Bugs here: https://github.com/webner/acme.sh |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_acmedns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_acmedns_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using acme-dns" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
ACMEDNS_UPDATE_URL="${ACMEDNS_UPDATE_URL:-$(_readaccountconf_mutable ACMEDNS_UPDATE_URL)}" |
||||
|
ACMEDNS_USERNAME="${ACMEDNS_USERNAME:-$(_readaccountconf_mutable ACMEDNS_USERNAME)}" |
||||
|
ACMEDNS_PASSWORD="${ACMEDNS_PASSWORD:-$(_readaccountconf_mutable ACMEDNS_PASSWORD)}" |
||||
|
ACMEDNS_SUBDOMAIN="${ACMEDNS_SUBDOMAIN:-$(_readaccountconf_mutable ACMEDNS_SUBDOMAIN)}" |
||||
|
|
||||
|
if [ "$ACMEDNS_UPDATE_URL" = "" ]; then |
||||
|
ACMEDNS_UPDATE_URL="https://auth.acme-dns.io/update" |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable ACMEDNS_UPDATE_URL "$ACMEDNS_UPDATE_URL" |
||||
|
_saveaccountconf_mutable ACMEDNS_USERNAME "$ACMEDNS_USERNAME" |
||||
|
_saveaccountconf_mutable ACMEDNS_PASSWORD "$ACMEDNS_PASSWORD" |
||||
|
_saveaccountconf_mutable ACMEDNS_SUBDOMAIN "$ACMEDNS_SUBDOMAIN" |
||||
|
|
||||
|
export _H1="X-Api-User: $ACMEDNS_USERNAME" |
||||
|
export _H2="X-Api-Key: $ACMEDNS_PASSWORD" |
||||
|
data="{\"subdomain\":\"$ACMEDNS_SUBDOMAIN\", \"txt\": \"$txtvalue\"}" |
||||
|
|
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$ACMEDNS_UPDATE_URL" "" "POST")" |
||||
|
_debug response "$response" |
||||
|
|
||||
|
if ! echo "$response" | grep "\"$txtvalue\"" >/dev/null; then |
||||
|
_err "invalid response of acme-dns" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_acmedns_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using acme-dns" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
@ -0,0 +1,141 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#ACTIVE24_Token="sdfsdfsdfljlbjkljlkjsdfoiwje" |
||||
|
|
||||
|
ACTIVE24_Api="https://api.active24.com" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
# Used to add txt record |
||||
|
dns_active24_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_active24_init |
||||
|
|
||||
|
_info "Adding txt record" |
||||
|
if _active24_rest POST "dns/$_domain/txt/v1" "{\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":0}"; then |
||||
|
if _contains "$response" "errors"; then |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
else |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# Usage: fulldomain txtvalue |
||||
|
# Used to remove the txt record after validation |
||||
|
dns_active24_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_active24_init |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_active24_rest GET "dns/$_domain/records/v1" |
||||
|
|
||||
|
if _contains "$response" "errors"; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hash_ids=$(echo "$response" | _egrep_o "[^{]+${txtvalue}[^}]+" | _egrep_o "hashId\":\"[^\"]+" | cut -c10-) |
||||
|
|
||||
|
for hash_id in $hash_ids; do |
||||
|
_debug "Removing hash_id" "$hash_id" |
||||
|
if _active24_rest DELETE "dns/$_domain/$hash_id/v1" ""; then |
||||
|
if _contains "$response" "errors"; then |
||||
|
_err "Unable to remove txt record." |
||||
|
return 1 |
||||
|
else |
||||
|
_info "Removed txt record." |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
_err "No txt records found." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
|
||||
|
if ! _active24_rest GET "dns/domains/v1"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug "h" "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"$h\"" >/dev/null; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_active24_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
|
||||
|
export _H1="Authorization: Bearer $ACTIVE24_Token" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug "data" "$data" |
||||
|
response="$(_post "$data" "$ACTIVE24_Api/$ep" "" "$m" "application/json")" |
||||
|
else |
||||
|
response="$(_get "$ACTIVE24_Api/$ep")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_active24_init() { |
||||
|
ACTIVE24_Token="${ACTIVE24_Token:-$(_readaccountconf_mutable ACTIVE24_Token)}" |
||||
|
if [ -z "$ACTIVE24_Token" ]; then |
||||
|
ACTIVE24_Token="" |
||||
|
_err "You didn't specify a Active24 api token yet." |
||||
|
_err "Please create the token and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable ACTIVE24_Token "ACTIVE24_Token" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
} |
@ -0,0 +1,253 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
CONOHA_DNS_EP_PREFIX_REGEXP="https://dns-service\." |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_conoha_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_conoha_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using conoha" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
_debug "Check uesrname and password" |
||||
|
CONOHA_Username="${CONOHA_Username:-$(_readaccountconf_mutable CONOHA_Username)}" |
||||
|
CONOHA_Password="${CONOHA_Password:-$(_readaccountconf_mutable CONOHA_Password)}" |
||||
|
CONOHA_TenantId="${CONOHA_TenantId:-$(_readaccountconf_mutable CONOHA_TenantId)}" |
||||
|
CONOHA_IdentityServiceApi="${CONOHA_IdentityServiceApi:-$(_readaccountconf_mutable CONOHA_IdentityServiceApi)}" |
||||
|
if [ -z "$CONOHA_Username" ] || [ -z "$CONOHA_Password" ] || [ -z "$CONOHA_TenantId" ] || [ -z "$CONOHA_IdentityServiceApi" ]; then |
||||
|
CONOHA_Username="" |
||||
|
CONOHA_Password="" |
||||
|
CONOHA_TenantId="" |
||||
|
CONOHA_IdentityServiceApi="" |
||||
|
_err "You didn't specify a conoha api username and password yet." |
||||
|
_err "Please create the user and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable CONOHA_Username "$CONOHA_Username" |
||||
|
_saveaccountconf_mutable CONOHA_Password "$CONOHA_Password" |
||||
|
_saveaccountconf_mutable CONOHA_TenantId "$CONOHA_TenantId" |
||||
|
_saveaccountconf_mutable CONOHA_IdentityServiceApi "$CONOHA_IdentityServiceApi" |
||||
|
|
||||
|
if token="$(_conoha_get_accesstoken "$CONOHA_IdentityServiceApi/tokens" "$CONOHA_Username" "$CONOHA_Password" "$CONOHA_TenantId")"; then |
||||
|
accesstoken="$(printf "%s" "$token" | sed -n 1p)" |
||||
|
CONOHA_Api="$(printf "%s" "$token" | sed -n 2p)" |
||||
|
else |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain" "$CONOHA_Api" "$accesstoken"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
body="{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"data\":\"$txtvalue\",\"ttl\":60}" |
||||
|
if _conoha_rest POST "$CONOHA_Api/v1/domains/$_domain_id/records" "$body" "$accesstoken"; then |
||||
|
if _contains "$response" '"data":"'"$txtvalue"'"'; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_conoha_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using conoha" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
_debug "Check uesrname and password" |
||||
|
CONOHA_Username="${CONOHA_Username:-$(_readaccountconf_mutable CONOHA_Username)}" |
||||
|
CONOHA_Password="${CONOHA_Password:-$(_readaccountconf_mutable CONOHA_Password)}" |
||||
|
CONOHA_TenantId="${CONOHA_TenantId:-$(_readaccountconf_mutable CONOHA_TenantId)}" |
||||
|
CONOHA_IdentityServiceApi="${CONOHA_IdentityServiceApi:-$(_readaccountconf_mutable CONOHA_IdentityServiceApi)}" |
||||
|
if [ -z "$CONOHA_Username" ] || [ -z "$CONOHA_Password" ] || [ -z "$CONOHA_TenantId" ] || [ -z "$CONOHA_IdentityServiceApi" ]; then |
||||
|
CONOHA_Username="" |
||||
|
CONOHA_Password="" |
||||
|
CONOHA_TenantId="" |
||||
|
CONOHA_IdentityServiceApi="" |
||||
|
_err "You didn't specify a conoha api username and password yet." |
||||
|
_err "Please create the user and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable CONOHA_Username "$CONOHA_Username" |
||||
|
_saveaccountconf_mutable CONOHA_Password "$CONOHA_Password" |
||||
|
_saveaccountconf_mutable CONOHA_TenantId "$CONOHA_TenantId" |
||||
|
_saveaccountconf_mutable CONOHA_IdentityServiceApi "$CONOHA_IdentityServiceApi" |
||||
|
|
||||
|
if token="$(_conoha_get_accesstoken "$CONOHA_IdentityServiceApi/tokens" "$CONOHA_Username" "$CONOHA_Password" "$CONOHA_TenantId")"; then |
||||
|
accesstoken="$(printf "%s" "$token" | sed -n 1p)" |
||||
|
CONOHA_Api="$(printf "%s" "$token" | sed -n 2p)" |
||||
|
else |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain" "$CONOHA_Api" "$accesstoken"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
if ! _conoha_rest GET "$CONOHA_Api/v1/domains/$_domain_id/records" "" "$accesstoken"; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
record_id=$(printf "%s" "$response" | _egrep_o '{[^}]*}' \ |
||||
|
| grep '"type":"TXT"' | grep "\"data\":\"$txtvalue\"" | _egrep_o "\"id\":\"[^\"]*\"" \ |
||||
|
| _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug record_id "$record_id" |
||||
|
|
||||
|
_info "Removing the txt record" |
||||
|
if ! _conoha_rest DELETE "$CONOHA_Api/v1/domains/$_domain_id/records/$record_id" "" "$accesstoken"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_conoha_rest() { |
||||
|
m="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
accesstoken="$4" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
if [ -n "$accesstoken" ]; then |
||||
|
export _H3="X-Auth-Token: $accesstoken" |
||||
|
fi |
||||
|
|
||||
|
_debug "$ep" |
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_secure_debug2 data "$data" |
||||
|
response="$(_post "$data" "$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$ep")" |
||||
|
fi |
||||
|
_ret="$?" |
||||
|
_secure_debug2 response "$response" |
||||
|
if [ "$_ret" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
response="$(printf "%s" "$response" | _normalizeJson)" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_conoha_get_accesstoken() { |
||||
|
ep="$1" |
||||
|
username="$2" |
||||
|
password="$3" |
||||
|
tenantId="$4" |
||||
|
|
||||
|
accesstoken="$(_readaccountconf_mutable conoha_accesstoken)" |
||||
|
expires="$(_readaccountconf_mutable conoha_tokenvalidto)" |
||||
|
CONOHA_Api="$(_readaccountconf_mutable conoha_dns_ep)" |
||||
|
|
||||
|
# can we reuse the access token? |
||||
|
if [ -n "$accesstoken" ] && [ -n "$expires" ] && [ -n "$CONOHA_Api" ]; then |
||||
|
utc_date="$(_utc_date | sed "s/ /T/")" |
||||
|
if expr "$utc_date" "<" "$expires" >/dev/null; then |
||||
|
# access token is still valid - reuse it |
||||
|
_debug "reusing access token" |
||||
|
printf "%s\n%s\n" "$accesstoken" "$CONOHA_Api" |
||||
|
return 0 |
||||
|
else |
||||
|
_debug "access token expired" |
||||
|
fi |
||||
|
fi |
||||
|
_debug "getting new access token" |
||||
|
|
||||
|
body="$(printf '{"auth":{"passwordCredentials":{"username":"%s","password":"%s"},"tenantId":"%s"}}' "$username" "$password" "$tenantId")" |
||||
|
if ! _conoha_rest POST "$ep" "$body" ""; then |
||||
|
_err error "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
accesstoken=$(printf "%s" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
expires=$(printf "%s" "$response" | _egrep_o "\"expires\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2-4 | tr -d \" | tr -d Z) #expect UTC |
||||
|
if [ -z "$accesstoken" ] || [ -z "$expires" ]; then |
||||
|
_err "no acccess token received. Check your Conoha settings see $WIKI" |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable conoha_accesstoken "$accesstoken" |
||||
|
_saveaccountconf_mutable conoha_tokenvalidto "$expires" |
||||
|
|
||||
|
CONOHA_Api=$(printf "%s" "$response" | _egrep_o 'publicURL":"'"$CONOHA_DNS_EP_PREFIX_REGEXP"'[^"]*"' | _head_n 1 | cut -d : -f 2-3 | tr -d \") |
||||
|
if [ -z "$CONOHA_Api" ]; then |
||||
|
_err "failed to get conoha dns endpoint url" |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable conoha_dns_ep "$CONOHA_Api" |
||||
|
|
||||
|
printf "%s\n%s\n" "$accesstoken" "$CONOHA_Api" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
domain="$1" |
||||
|
ep="$2" |
||||
|
accesstoken="$3" |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100). |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _conoha_rest GET "$ep/v1/domains?name=$h" "" "$accesstoken"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_domain_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | head -n 1 | cut -d : -f 2 | tr -d \") |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
@ -0,0 +1,59 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Official Let's Encrypt API for do.de / Domain-Offensive |
||||
|
# |
||||
|
# This is different from the dns_do adapter, because dns_do is only usable for enterprise customers |
||||
|
# This API is also available to private customers/individuals |
||||
|
# |
||||
|
# Provide the required LetsEncrypt token like this: |
||||
|
# DO_LETOKEN="FmD408PdqT1E269gUK57" |
||||
|
|
||||
|
DO_API="https://www.do.de/api/letsencrypt" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_doapi_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
DO_LETOKEN="${DO_LETOKEN:-$(_readaccountconf_mutable DO_LETOKEN)}" |
||||
|
if [ -z "$DO_LETOKEN" ]; then |
||||
|
DO_LETOKEN="" |
||||
|
_err "You didn't configure a do.de API token yet." |
||||
|
_err "Please set DO_LETOKEN and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable DO_LETOKEN "$DO_LETOKEN" |
||||
|
|
||||
|
_info "Adding TXT record to ${fulldomain}" |
||||
|
response="$(_get "$DO_API?token=$DO_LETOKEN&domain=${fulldomain}&value=${txtvalue}")" |
||||
|
if _contains "${response}" 'success'; then |
||||
|
return 0 |
||||
|
fi |
||||
|
_err "Could not create resource record, check logs" |
||||
|
_err "${response}" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
dns_doapi_rm() { |
||||
|
fulldomain=$1 |
||||
|
|
||||
|
DO_LETOKEN="${DO_LETOKEN:-$(_readaccountconf_mutable DO_LETOKEN)}" |
||||
|
if [ -z "$DO_LETOKEN" ]; then |
||||
|
DO_LETOKEN="" |
||||
|
_err "You didn't configure a do.de API token yet." |
||||
|
_err "Please set DO_LETOKEN and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable DO_LETOKEN "$DO_LETOKEN" |
||||
|
|
||||
|
_info "Deleting resource record $fulldomain" |
||||
|
response="$(_get "$DO_API?token=$DO_LETOKEN&domain=${fulldomain}&action=delete")" |
||||
|
if _contains "${response}" 'success'; then |
||||
|
return 0 |
||||
|
fi |
||||
|
_err "Could not delete resource record, check logs" |
||||
|
_err "${response}" |
||||
|
return 1 |
||||
|
} |
@ -0,0 +1,161 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Dnspod.com Domain api |
||||
|
# |
||||
|
#DPI_Id="1234" |
||||
|
# |
||||
|
#DPI_Key="sADDsdasdgdsf" |
||||
|
|
||||
|
REST_API="https://api.dnspod.com" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_dpi_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
DPI_Id="${DPI_Id:-$(_readaccountconf_mutable DPI_Id)}" |
||||
|
DPI_Key="${DPI_Key:-$(_readaccountconf_mutable DPI_Key)}" |
||||
|
if [ -z "$DPI_Id" ] || [ -z "$DPI_Key" ]; then |
||||
|
DPI_Id="" |
||||
|
DPI_Key="" |
||||
|
_err "You don't specify dnspod api key and key id yet." |
||||
|
_err "Please create you key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable DPI_Id "$DPI_Id" |
||||
|
_saveaccountconf_mutable DPI_Key "$DPI_Key" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
add_record "$_domain" "$_sub_domain" "$txtvalue" |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_dpi_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
DPI_Id="${DPI_Id:-$(_readaccountconf_mutable DPI_Id)}" |
||||
|
DPI_Key="${DPI_Key:-$(_readaccountconf_mutable DPI_Key)}" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _rest POST "Record.List" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain"; then |
||||
|
_err "Record.Lis error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" 'No records'; then |
||||
|
_info "Don't need to remove." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
record_id=$(echo "$response" | _egrep_o '{[^{]*"value":"'"$txtvalue"'"' | cut -d , -f 1 | cut -d : -f 2 | tr -d \") |
||||
|
_debug record_id "$record_id" |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _rest POST "Record.Remove" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&record_id=$record_id"; then |
||||
|
_err "Record.Remove error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_contains "$response" "Action completed successful" |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#add the txt record. |
||||
|
#usage: root sub txtvalue |
||||
|
add_record() { |
||||
|
root=$1 |
||||
|
sub=$2 |
||||
|
txtvalue=$3 |
||||
|
fulldomain="$sub.$root" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
|
||||
|
if ! _rest POST "Record.Create" "user_token=$DPI_Id,$DPI_Key&format=json&domain_id=$_domain_id&sub_domain=$_sub_domain&record_type=TXT&value=$txtvalue&record_line=default"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_contains "$response" "Action completed successful" || _contains "$response" "Domain record already exists" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _rest POST "Domain.Info" "user_token=$DPI_Id,$DPI_Key&format=json&domain=$h"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "Action completed successful"; then |
||||
|
_domain_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \") |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_domain="$h" |
||||
|
_debug _domain "$_domain" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p="$i" |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: method URI data |
||||
|
_rest() { |
||||
|
m="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
url="$REST_API/$ep" |
||||
|
|
||||
|
_debug url "$url" |
||||
|
|
||||
|
if [ "$m" = "GET" ]; then |
||||
|
response="$(_get "$url" | tr -d '\r')" |
||||
|
else |
||||
|
_debug2 data "$data" |
||||
|
response="$(_post "$data" "$url" | tr -d '\r')" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,358 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#This is the euserv.eu api wrapper for acme.sh |
||||
|
# |
||||
|
#Author: Michael Brueckner |
||||
|
#Report Bugs: https://www.github.com/initit/acme.sh or mbr@initit.de |
||||
|
|
||||
|
# |
||||
|
#EUSERV_Username="username" |
||||
|
# |
||||
|
#EUSERV_Password="password" |
||||
|
# |
||||
|
# Dependencies: |
||||
|
# ------------- |
||||
|
# - none - |
||||
|
|
||||
|
EUSERV_Api="https://api.euserv.net" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_euserv_add() { |
||||
|
fulldomain="$(echo "$1" | _lower_case)" |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
EUSERV_Username="${EUSERV_Username:-$(_readaccountconf_mutable EUSERV_Username)}" |
||||
|
EUSERV_Password="${EUSERV_Password:-$(_readaccountconf_mutable EUSERV_Password)}" |
||||
|
if [ -z "$EUSERV_Username" ] || [ -z "$EUSERV_Password" ]; then |
||||
|
EUSERV_Username="" |
||||
|
EUSERV_Password="" |
||||
|
_err "You don't specify euserv user and password yet." |
||||
|
_err "Please create your key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the user and email to the account conf file. |
||||
|
_saveaccountconf_mutable EUSERV_Username "$EUSERV_Username" |
||||
|
_saveaccountconf_mutable EUSERV_Password "$EUSERV_Password" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug "_sub_domain" "$_sub_domain" |
||||
|
_debug "_domain" "$_domain" |
||||
|
_info "Adding record" |
||||
|
if ! _euserv_add_record "$_domain" "$_sub_domain" "$txtvalue"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_euserv_rm() { |
||||
|
|
||||
|
fulldomain="$(echo "$1" | _lower_case)" |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
EUSERV_Username="${EUSERV_Username:-$(_readaccountconf_mutable EUSERV_Username)}" |
||||
|
EUSERV_Password="${EUSERV_Password:-$(_readaccountconf_mutable EUSERV_Password)}" |
||||
|
if [ -z "$EUSERV_Username" ] || [ -z "$EUSERV_Password" ]; then |
||||
|
EUSERV_Username="" |
||||
|
EUSERV_Password="" |
||||
|
_err "You don't specify euserv user and password yet." |
||||
|
_err "Please create your key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the user and email to the account conf file. |
||||
|
_saveaccountconf_mutable EUSERV_Username "$EUSERV_Username" |
||||
|
_saveaccountconf_mutable EUSERV_Password "$EUSERV_Password" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug "_sub_domain" "$_sub_domain" |
||||
|
_debug "_domain" "$_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>domain.dns_get_active_records</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value> |
||||
|
<struct> |
||||
|
<member> |
||||
|
<name>login</name> |
||||
|
<value> |
||||
|
<string>%s</string> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>password</name> |
||||
|
<value> |
||||
|
<string>%s</string> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>domain_id</name> |
||||
|
<value> |
||||
|
<int>%s</int> |
||||
|
</value> |
||||
|
</member> |
||||
|
</struct> |
||||
|
</value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$_euserv_domain_id") |
||||
|
|
||||
|
export _H1="Content-Type: text/xml" |
||||
|
response="$(_post "$xml_content" "$EUSERV_Api" "" "POST")" |
||||
|
|
||||
|
if ! _contains "$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then |
||||
|
_err "Error could not get txt records" |
||||
|
_debug "xml_content" "$xml_content" |
||||
|
_debug "response" "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! echo "$response" | grep '>dns_record_content<.*>'"$txtvalue"'<' >/dev/null; then |
||||
|
_info "Do not need to delete record" |
||||
|
else |
||||
|
# find XML block where txtvalue is in. The record_id is allways prior this line! |
||||
|
_endLine=$(echo "$response" | grep -n '>dns_record_content<.*>'"$txtvalue"'<' | cut -d ':' -f 1) |
||||
|
# record_id is the last <name> Tag with a number before the row _endLine, identified by </name><value><struct> |
||||
|
_record_id=$(echo "$response" | sed -n '1,'"$_endLine"'p' | grep '</name><value><struct>' | _tail_n 1 | sed 's/.*<name>\([0-9]*\)<\/name>.*/\1/') |
||||
|
_info "Deleting record" |
||||
|
_euserv_delete_record "$_record_id" |
||||
|
fi |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
_debug "get root" |
||||
|
|
||||
|
# Just to read the domain_orders once |
||||
|
|
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
if ! _euserv_get_domain_orders; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# Get saved response with domain_orders |
||||
|
response="$_euserv_domain_orders" |
||||
|
|
||||
|
while true; do |
||||
|
h=$(echo "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "$h"; then |
||||
|
_sub_domain=$(echo "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
if ! _euserv_get_domain_id "$_domain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_euserv_get_domain_orders() { |
||||
|
# returns: _euserv_domain_orders |
||||
|
|
||||
|
_debug "get domain_orders" |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>domain.get_domain_orders</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value> |
||||
|
<struct> |
||||
|
<member> |
||||
|
<name>login</name> |
||||
|
<value><string>%s</string></value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>password</name> |
||||
|
<value><string>%s</string></value> |
||||
|
</member> |
||||
|
</struct> |
||||
|
</value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' "$EUSERV_Username" "$EUSERV_Password") |
||||
|
|
||||
|
export _H1="Content-Type: text/xml" |
||||
|
response="$(_post "$xml_content" "$EUSERV_Api" "" "POST")" |
||||
|
|
||||
|
if ! _contains "$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then |
||||
|
_err "Error could not get domain orders" |
||||
|
_debug "xml_content" "$xml_content" |
||||
|
_debug "response" "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# save response to reduce API calls |
||||
|
_euserv_domain_orders="$response" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_euserv_get_domain_id() { |
||||
|
# returns: _euserv_domain_id |
||||
|
domain=$1 |
||||
|
_debug "get domain_id" |
||||
|
|
||||
|
# find line where the domain name is within the $response |
||||
|
_startLine=$(echo "$_euserv_domain_orders" | grep -n '>domain_name<.*>'"$domain"'<' | cut -d ':' -f 1) |
||||
|
# next occurency of domain_id after the domain_name is the correct one |
||||
|
_euserv_domain_id=$(echo "$_euserv_domain_orders" | sed -n "$_startLine"',$p' | grep '>domain_id<' | _head_n 1 | sed 's/.*<i4>\([0-9]*\)<\/i4>.*/\1/') |
||||
|
|
||||
|
if [ -z "$_euserv_domain_id" ]; then |
||||
|
_err "Could not find domain_id for domain $domain" |
||||
|
_debug "_euserv_domain_orders" "$_euserv_domain_orders" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_euserv_delete_record() { |
||||
|
record_id=$1 |
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>domain.dns_delete_record</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value> |
||||
|
<struct> |
||||
|
<member> |
||||
|
<name>login</name> |
||||
|
<value> |
||||
|
<string>%s</string> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>password</name> |
||||
|
<value> |
||||
|
<string>%s</string> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>dns_record_id</name> |
||||
|
<value> |
||||
|
<int>%s</int> |
||||
|
</value> |
||||
|
</member> |
||||
|
</struct> |
||||
|
</value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$record_id") |
||||
|
|
||||
|
export _H1="Content-Type: text/xml" |
||||
|
response="$(_post "$xml_content" "$EUSERV_Api" "" "POST")" |
||||
|
|
||||
|
if ! _contains "$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then |
||||
|
_err "Error deleting record" |
||||
|
_debug "xml_content" "$xml_content" |
||||
|
_debug "response" "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
|
||||
|
} |
||||
|
|
||||
|
_euserv_add_record() { |
||||
|
domain=$1 |
||||
|
sub_domain=$2 |
||||
|
txtval=$3 |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>domain.dns_create_record</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value> |
||||
|
<struct> |
||||
|
<member> |
||||
|
<name>login</name> |
||||
|
<value> |
||||
|
<string>%s</string> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>password</name> |
||||
|
<value> |
||||
|
<string>%s</string></value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>domain_id</name> |
||||
|
<value> |
||||
|
<int>%s</int> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>dns_record_subdomain</name> |
||||
|
<value> |
||||
|
<string>%s</string> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>dns_record_type</name> |
||||
|
<value> |
||||
|
<string>TXT</string> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>dns_record_value</name> |
||||
|
<value> |
||||
|
<string>%s</string> |
||||
|
</value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>dns_record_ttl</name> |
||||
|
<value> |
||||
|
<int>300</int> |
||||
|
</value> |
||||
|
</member> |
||||
|
</struct> |
||||
|
</value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' "$EUSERV_Username" "$EUSERV_Password" "$_euserv_domain_id" "$sub_domain" "$txtval") |
||||
|
|
||||
|
export _H1="Content-Type: text/xml" |
||||
|
response="$(_post "$xml_content" "$EUSERV_Api" "" "POST")" |
||||
|
|
||||
|
if ! _contains "$response" "<member><name>status</name><value><i4>100</i4></value></member>"; then |
||||
|
_err "Error could not create record" |
||||
|
_debug "xml_content" "$xml_content" |
||||
|
_debug "response" "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,168 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
EXOSCALE_API=https://api.exoscale.com/dns/v1 |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
# Used to add txt record |
||||
|
dns_exoscale_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _checkAuth; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
if _exoscale_rest POST "domains/$_domain_id/records" "{\"record\":{\"name\":\"$_sub_domain\",\"record_type\":\"TXT\",\"content\":\"$txtvalue\",\"ttl\":120}}" "$_domain_token"; then |
||||
|
if _contains "$response" "$txtvalue"; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
|
||||
|
} |
||||
|
|
||||
|
# Usage: fulldomain txtvalue |
||||
|
# Used to remove the txt record after validation |
||||
|
dns_exoscale_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _checkAuth; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_exoscale_rest GET "domains/${_domain_id}/records?type=TXT&name=$_sub_domain" "" "$_domain_token" |
||||
|
if _contains "$response" "\"name\":\"$_sub_domain\"" >/dev/null; then |
||||
|
_record_id=$(echo "$response" | tr '{' "\n" | grep "\"content\":\"$txtvalue\"" | _egrep_o "\"id\":[^,]+" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$_record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "Deleting record $_record_id" |
||||
|
|
||||
|
if ! _exoscale_rest DELETE "domains/$_domain_id/records/$_record_id" "" "$_domain_token"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_checkAuth() { |
||||
|
EXOSCALE_API_KEY="${EXOSCALE_API_KEY:-$(_readaccountconf_mutable EXOSCALE_API_KEY)}" |
||||
|
EXOSCALE_SECRET_KEY="${EXOSCALE_SECRET_KEY:-$(_readaccountconf_mutable EXOSCALE_SECRET_KEY)}" |
||||
|
|
||||
|
if [ -z "$EXOSCALE_API_KEY" ] || [ -z "$EXOSCALE_SECRET_KEY" ]; then |
||||
|
EXOSCALE_API_KEY="" |
||||
|
EXOSCALE_SECRET_KEY="" |
||||
|
_err "You don't specify Exoscale application key and application secret yet." |
||||
|
_err "Please create you key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable EXOSCALE_API_KEY "$EXOSCALE_API_KEY" |
||||
|
_saveaccountconf_mutable EXOSCALE_SECRET_KEY "$EXOSCALE_SECRET_KEY" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
# _domain_token=sdjkglgdfewsdfg |
||||
|
_get_root() { |
||||
|
|
||||
|
if ! _exoscale_rest GET "domains"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_domain_id=$(echo "$response" | tr '{' "\n" | grep "\"name\":\"$h\"" | _egrep_o "\"id\":[^,]+" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
_domain_token=$(echo "$response" | tr '{' "\n" | grep "\"name\":\"$h\"" | _egrep_o "\"token\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
if [ "$_domain_token" ] && [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# returns response |
||||
|
_exoscale_rest() { |
||||
|
method=$1 |
||||
|
path="$2" |
||||
|
data="$3" |
||||
|
token="$4" |
||||
|
request_url="$EXOSCALE_API/$path" |
||||
|
_debug "$path" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
|
||||
|
if [ "$token" ]; then |
||||
|
export _H2="X-DNS-Domain-Token: $token" |
||||
|
else |
||||
|
export _H2="X-DNS-Token: $EXOSCALE_API_KEY:$EXOSCALE_SECRET_KEY" |
||||
|
fi |
||||
|
|
||||
|
if [ "$data" ] || [ "$method" = "DELETE" ]; then |
||||
|
export _H3="Content-Type: application/json" |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$request_url" "" "$method")" |
||||
|
else |
||||
|
response="$(_get "$request_url" "" "" "$method")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $request_url" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,167 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Author: Janos Lenart <janos@lenart.io> |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: dns_gcloud_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_gcloud_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using gcloud" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
_dns_gcloud_find_zone || return $? |
||||
|
|
||||
|
# Add an extra RR |
||||
|
_dns_gcloud_start_tr || return $? |
||||
|
_dns_gcloud_get_rrdatas || return $? |
||||
|
echo "$rrdatas" | _dns_gcloud_remove_rrs || return $? |
||||
|
printf "%s\n%s\n" "$rrdatas" "\"$txtvalue\"" | grep -v '^$' | _dns_gcloud_add_rrs || return $? |
||||
|
_dns_gcloud_execute_tr || return $? |
||||
|
|
||||
|
_info "$fulldomain record added" |
||||
|
} |
||||
|
|
||||
|
# Usage: dns_gcloud_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
# Remove the txt record after validation. |
||||
|
dns_gcloud_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using gcloud" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
_dns_gcloud_find_zone || return $? |
||||
|
|
||||
|
# Remove one RR |
||||
|
_dns_gcloud_start_tr || return $? |
||||
|
_dns_gcloud_get_rrdatas || return $? |
||||
|
echo "$rrdatas" | _dns_gcloud_remove_rrs || return $? |
||||
|
echo "$rrdatas" | grep -F -v "\"$txtvalue\"" | _dns_gcloud_add_rrs || return $? |
||||
|
_dns_gcloud_execute_tr || return $? |
||||
|
|
||||
|
_info "$fulldomain record added" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_dns_gcloud_start_tr() { |
||||
|
if ! trd=$(mktemp -d); then |
||||
|
_err "_dns_gcloud_start_tr: failed to create temporary directory" |
||||
|
return 1 |
||||
|
fi |
||||
|
tr="$trd/tr.yaml" |
||||
|
_debug tr "$tr" |
||||
|
|
||||
|
if ! gcloud dns record-sets transaction start \ |
||||
|
--transaction-file="$tr" \ |
||||
|
--zone="$managedZone"; then |
||||
|
rm -r "$trd" |
||||
|
_err "_dns_gcloud_start_tr: failed to execute transaction" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_execute_tr() { |
||||
|
if ! gcloud dns record-sets transaction execute \ |
||||
|
--transaction-file="$tr" \ |
||||
|
--zone="$managedZone"; then |
||||
|
_debug tr "$(cat "$tr")" |
||||
|
rm -r "$trd" |
||||
|
_err "_dns_gcloud_execute_tr: failed to execute transaction" |
||||
|
return 1 |
||||
|
fi |
||||
|
rm -r "$trd" |
||||
|
|
||||
|
for i in $(seq 1 120); do |
||||
|
if gcloud dns record-sets changes list \ |
||||
|
--zone="$managedZone" \ |
||||
|
--filter='status != done' \ |
||||
|
| grep -q '^.*'; then |
||||
|
_info "_dns_gcloud_execute_tr: waiting for transaction to be comitted ($i/120)..." |
||||
|
sleep 5 |
||||
|
else |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
_err "_dns_gcloud_execute_tr: transaction is still pending after 10 minutes" |
||||
|
rm -r "$trd" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_remove_rrs() { |
||||
|
if ! xargs --no-run-if-empty gcloud dns record-sets transaction remove \ |
||||
|
--name="$fulldomain." \ |
||||
|
--ttl="$ttl" \ |
||||
|
--type=TXT \ |
||||
|
--zone="$managedZone" \ |
||||
|
--transaction-file="$tr"; then |
||||
|
_debug tr "$(cat "$tr")" |
||||
|
rm -r "$trd" |
||||
|
_err "_dns_gcloud_remove_rrs: failed to remove RRs" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_add_rrs() { |
||||
|
ttl=60 |
||||
|
if ! xargs --no-run-if-empty gcloud dns record-sets transaction add \ |
||||
|
--name="$fulldomain." \ |
||||
|
--ttl="$ttl" \ |
||||
|
--type=TXT \ |
||||
|
--zone="$managedZone" \ |
||||
|
--transaction-file="$tr"; then |
||||
|
_debug tr "$(cat "$tr")" |
||||
|
rm -r "$trd" |
||||
|
_err "_dns_gcloud_add_rrs: failed to add RRs" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_find_zone() { |
||||
|
# Prepare a filter that matches zones that are suiteable for this entry. |
||||
|
# For example, _acme-challenge.something.domain.com might need to go into something.domain.com or domain.com; |
||||
|
# this function finds the longest postfix that has a managed zone. |
||||
|
part="$fulldomain" |
||||
|
filter="dnsName=( " |
||||
|
while [ "$part" != "" ]; do |
||||
|
filter="$filter$part. " |
||||
|
part="$(echo "$part" | sed 's/[^.]*\.*//')" |
||||
|
done |
||||
|
filter="$filter)" |
||||
|
_debug filter "$filter" |
||||
|
|
||||
|
# List domains and find the longest match (in case of some levels of delegation) |
||||
|
if ! match=$(gcloud dns managed-zones list \ |
||||
|
--format="value(name, dnsName)" \ |
||||
|
--filter="$filter" \ |
||||
|
| while read -r dnsName name; do |
||||
|
printf "%s\t%s\t%s\n" "${#dnsName}" "$dnsName" "$name" |
||||
|
done \ |
||||
|
| sort -n -r | _head_n 1 | cut -f2,3 | grep '^.*'); then |
||||
|
_err "_dns_gcloud_find_zone: Can't find a matching managed zone! Perhaps wrong project or gcloud credentials?" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
dnsName=$(echo "$match" | cut -f2) |
||||
|
_debug dnsName "$dnsName" |
||||
|
managedZone=$(echo "$match" | cut -f1) |
||||
|
_debug managedZone "$managedZone" |
||||
|
} |
||||
|
|
||||
|
_dns_gcloud_get_rrdatas() { |
||||
|
if ! rrdatas=$(gcloud dns record-sets list \ |
||||
|
--zone="$managedZone" \ |
||||
|
--name="$fulldomain." \ |
||||
|
--type=TXT \ |
||||
|
--format="value(ttl,rrdatas)"); then |
||||
|
_err "_dns_gcloud_get_rrdatas: Failed to list record-sets" |
||||
|
rm -r "$trd" |
||||
|
return 1 |
||||
|
fi |
||||
|
ttl=$(echo "$rrdatas" | cut -f1) |
||||
|
rrdatas=$(echo "$rrdatas" | cut -f2 | sed 's/","/"\n"/g') |
||||
|
} |
@ -0,0 +1,168 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
#Author: Herman Sletteng |
||||
|
#Report Bugs here: https://github.com/loial/acme.sh |
||||
|
# |
||||
|
# |
||||
|
# Note, gratisdns requires a login first, so the script needs to handle |
||||
|
# temporary cookies. Since acme.sh _get/_post currently don't directly support |
||||
|
# cookies, I've defined wrapper functions _myget/_mypost to set the headers |
||||
|
|
||||
|
GDNSDK_API="https://admin.gratisdns.com" |
||||
|
######## Public functions ##################### |
||||
|
#Usage: dns_gdnsdk_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_gdnsdk_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using gratisdns.dk" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
if ! _gratisdns_login; then |
||||
|
_err "Login failed!" |
||||
|
return 1 |
||||
|
fi |
||||
|
#finding domain zone |
||||
|
if ! _get_domain; then |
||||
|
_err "No matching root domain for $fulldomain found" |
||||
|
return 1 |
||||
|
fi |
||||
|
# adding entry |
||||
|
_info "Adding the entry" |
||||
|
_mypost "action=dns_primary_record_added_txt&user_domain=$_domain&name=$fulldomain&txtdata=$txtvalue&ttl=1" |
||||
|
if _successful_update; then return 0; fi |
||||
|
_err "Couldn't create entry!" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_gdnsdk_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using gratisdns.dk" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
if ! _gratisdns_login; then |
||||
|
_err "Login failed!" |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _get_domain; then |
||||
|
_err "No matching root domain for $fulldomain found" |
||||
|
return 1 |
||||
|
fi |
||||
|
_findentry "$fulldomain" "$txtvalue" |
||||
|
if [ -z "$_id" ]; then |
||||
|
_info "Entry doesn't exist, nothing to delete" |
||||
|
return 0 |
||||
|
fi |
||||
|
_debug "Deleting record..." |
||||
|
_mypost "action=dns_primary_delete_txt&user_domain=$_domain&id=$_id" |
||||
|
# removing entry |
||||
|
|
||||
|
if _successful_update; then return 0; fi |
||||
|
_err "Couldn't delete entry!" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_checkcredentials() { |
||||
|
GDNSDK_Username="${GDNSDK_Username:-$(_readaccountconf_mutable GDNSDK_Username)}" |
||||
|
GDNSDK_Password="${GDNSDK_Password:-$(_readaccountconf_mutable GDNSDK_Password)}" |
||||
|
|
||||
|
if [ -z "$GDNSDK_Username" ] || [ -z "$GDNSDK_Password" ]; then |
||||
|
GDNSDK_Username="" |
||||
|
GDNSDK_Password="" |
||||
|
_err "You haven't specified gratisdns.dk username and password yet." |
||||
|
_err "Please add credentials and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
#save the credentials to the account conf file. |
||||
|
_saveaccountconf_mutable GDNSDK_Username "$GDNSDK_Username" |
||||
|
_saveaccountconf_mutable GDNSDK_Password "$GDNSDK_Password" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_checkcookie() { |
||||
|
GDNSDK_Cookie="${GDNSDK_Cookie:-$(_readaccountconf_mutable GDNSDK_Cookie)}" |
||||
|
if [ -z "$GDNSDK_Cookie" ]; then |
||||
|
_debug "No cached cookie found" |
||||
|
return 1 |
||||
|
fi |
||||
|
_myget "action=" |
||||
|
if (echo "$_result" | grep -q "logmeout"); then |
||||
|
_debug "Cached cookie still valid" |
||||
|
return 0 |
||||
|
fi |
||||
|
_debug "Cached cookie no longer valid" |
||||
|
GDNSDK_Cookie="" |
||||
|
_saveaccountconf_mutable GDNSDK_Cookie "$GDNSDK_Cookie" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_gratisdns_login() { |
||||
|
if ! _checkcredentials; then return 1; fi |
||||
|
|
||||
|
if _checkcookie; then |
||||
|
_debug "Already logged in" |
||||
|
return 0 |
||||
|
fi |
||||
|
_debug "Logging into GratisDNS with user $GDNSDK_Username" |
||||
|
|
||||
|
if ! _mypost "login=$GDNSDK_Username&password=$GDNSDK_Password&action=logmein"; then |
||||
|
_err "GratisDNS login failed for user $GDNSDK_Username bad RC from _post" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
GDNSDK_Cookie="$(grep -A 15 '302 Found' "$HTTP_HEADER" | _egrep_o 'Cookie: [^;]*' | _head_n 1 | cut -d ' ' -f2)" |
||||
|
|
||||
|
if [ -z "$GDNSDK_Cookie" ]; then |
||||
|
_err "GratisDNS login failed for user $GDNSDK_Username. Check $HTTP_HEADER file" |
||||
|
return 1 |
||||
|
fi |
||||
|
export GDNSDK_Cookie |
||||
|
_saveaccountconf_mutable GDNSDK_Cookie "$GDNSDK_Cookie" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_myget() { |
||||
|
#Adds cookie to request |
||||
|
export _H1="Cookie: $GDNSDK_Cookie" |
||||
|
_result=$(_get "$GDNSDK_API?$1") |
||||
|
} |
||||
|
_mypost() { |
||||
|
#Adds cookie to request |
||||
|
export _H1="Cookie: $GDNSDK_Cookie" |
||||
|
_result=$(_post "$1" "$GDNSDK_API") |
||||
|
} |
||||
|
|
||||
|
_get_domain() { |
||||
|
_myget 'action=dns_primarydns' |
||||
|
_domains=$(echo "$_result" | _egrep_o ' domain="[[:alnum:].-_]+' | sed 's/^.*"//') |
||||
|
if [ -z "$_domains" ]; then |
||||
|
_err "Primary domain list not found!" |
||||
|
return 1 |
||||
|
fi |
||||
|
for _domain in $_domains; do |
||||
|
if (_endswith "$fulldomain" "$_domain"); then |
||||
|
_debug "Root domain: $_domain" |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_successful_update() { |
||||
|
if (echo "$_result" | grep -q 'table-success'); then return 0; fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_findentry() { |
||||
|
#returns id of dns entry, if it exists |
||||
|
_myget "action=dns_primary_changeDNSsetup&user_domain=$_domain" |
||||
|
_id=$(echo "$_result" | _egrep_o "<td>$1</td>\s*<td>$2</td>[^?]*[^&]*&id=[^&]*" | sed 's/^.*=//') |
||||
|
if [ -n "$_id" ]; then |
||||
|
_debug "Entry found with _id=$_id" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
@ -0,0 +1,161 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# hosting.de API |
||||
|
|
||||
|
# Values to export: |
||||
|
# export HOSTINGDE_ENDPOINT='https://secure.hosting.de' |
||||
|
# export HOSTINGDE_APIKEY='xxxxx' |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
dns_hostingde_add() { |
||||
|
fulldomain="${1}" |
||||
|
txtvalue="${2}" |
||||
|
_debug "Calling: _hostingde_addRecord() '${fulldomain}' '${txtvalue}'" |
||||
|
_hostingde_apiKey && _hostingde_getZoneConfig && _hostingde_addRecord |
||||
|
return $? |
||||
|
} |
||||
|
|
||||
|
dns_hostingde_rm() { |
||||
|
fulldomain="${1}" |
||||
|
txtvalue="${2}" |
||||
|
_debug "Calling: _hostingde_removeRecord() '${fulldomain}' '${txtvalue}'" |
||||
|
_hostingde_apiKey && _hostingde_getZoneConfig && _hostingde_removeRecord |
||||
|
return $? |
||||
|
} |
||||
|
|
||||
|
#################### own Private functions below ################################## |
||||
|
|
||||
|
_hostingde_apiKey() { |
||||
|
HOSTINGDE_APIKEY="${HOSTINGDE_APIKEY:-$(_readaccountconf_mutable HOSTINGDE_APIKEY)}" |
||||
|
if [ -z "$HOSTINGDE_APIKEY" ] || [ -z "$HOSTINGDE_ENDPOINT" ]; then |
||||
|
HOSTINGDE_APIKEY="" |
||||
|
HOSTINGDE_ENDPOINT="" |
||||
|
_err "You haven't specified hosting.de API key or endpoint yet." |
||||
|
_err "Please create your key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable HOSTINGDE_APIKEY "$HOSTINGDE_APIKEY" |
||||
|
_saveaccountconf_mutable HOSTINGDE_ENDPOINT "$HOSTINGDE_ENDPOINT" |
||||
|
} |
||||
|
|
||||
|
_hostingde_parse() { |
||||
|
find="${1}" |
||||
|
if [ "${2}" ]; then |
||||
|
notfind="${2}" |
||||
|
fi |
||||
|
if [ "${notfind}" ]; then |
||||
|
_egrep_o \""${find}\":.*" | grep -v "${notfind}" | cut -d ':' -f 2 | cut -d ',' -f 1 | tr -d ' ' |
||||
|
else |
||||
|
_egrep_o \""${find}\":.*" | cut -d ':' -f 2 | cut -d ',' -f 1 | tr -d ' ' |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_hostingde_getZoneConfig() { |
||||
|
_info "Getting ZoneConfig" |
||||
|
curZone="${fulldomain#*.}" |
||||
|
returnCode=1 |
||||
|
while _contains "${curZone}" "\\."; do |
||||
|
curData="{\"filter\":{\"field\":\"zoneName\",\"value\":\"${curZone}\"},\"limit\":1,\"authToken\":\"${HOSTINGDE_APIKEY}\"}" |
||||
|
curResult="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneConfigsFind")" |
||||
|
_debug "Calling zoneConfigsFind: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneConfigsFind'" |
||||
|
_debug "Result of zoneConfigsFind: '$curResult'" |
||||
|
if _contains "${curResult}" '"status": "error"'; then |
||||
|
if _contains "${curResult}" '"code": 10109'; then |
||||
|
_err "The API-Key is invalid or could not be found" |
||||
|
else |
||||
|
_err "UNKNOWN API ERROR" |
||||
|
fi |
||||
|
returnCode=1 |
||||
|
break |
||||
|
fi |
||||
|
if _contains "${curResult}" '"totalEntries": 1'; then |
||||
|
_info "Retrieved zone data." |
||||
|
_debug "Zone data: '${curResult}'" |
||||
|
zoneConfigId=$(echo "${curResult}" | _hostingde_parse "id") |
||||
|
zoneConfigName=$(echo "${curResult}" | _hostingde_parse "name") |
||||
|
zoneConfigType=$(echo "${curResult}" | _hostingde_parse "type" "FindZoneConfigsResult") |
||||
|
zoneConfigExpire=$(echo "${curResult}" | _hostingde_parse "expire") |
||||
|
zoneConfigNegativeTtl=$(echo "${curResult}" | _hostingde_parse "negativeTtl") |
||||
|
zoneConfigRefresh=$(echo "${curResult}" | _hostingde_parse "refresh") |
||||
|
zoneConfigRetry=$(echo "${curResult}" | _hostingde_parse "retry") |
||||
|
zoneConfigTtl=$(echo "${curResult}" | _hostingde_parse "ttl") |
||||
|
zoneConfigDnsServerGroupId=$(echo "${curResult}" | _hostingde_parse "dnsServerGroupId") |
||||
|
zoneConfigEmailAddress=$(echo "${curResult}" | _hostingde_parse "emailAddress") |
||||
|
zoneConfigDnsSecMode=$(echo "${curResult}" | _hostingde_parse "dnsSecMode") |
||||
|
if [ "${zoneConfigType}" != "\"NATIVE\"" ]; then |
||||
|
_err "Zone is not native" |
||||
|
returnCode=1 |
||||
|
break |
||||
|
fi |
||||
|
_debug "zoneConfigId '${zoneConfigId}'" |
||||
|
returnCode=0 |
||||
|
break |
||||
|
fi |
||||
|
curZone="${curZone#*.}" |
||||
|
done |
||||
|
if [ $returnCode -ne 0 ]; then |
||||
|
_info "ZoneEnd reached, Zone ${curZone} not found in hosting.de API" |
||||
|
fi |
||||
|
return $returnCode |
||||
|
} |
||||
|
|
||||
|
_hostingde_getZoneStatus() { |
||||
|
_debug "Checking Zone status" |
||||
|
curData="{\"filter\":{\"field\":\"zoneConfigId\",\"value\":${zoneConfigId}},\"limit\":1,\"authToken\":\"${HOSTINGDE_APIKEY}\"}" |
||||
|
curResult="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zonesFind")" |
||||
|
_debug "Calling zonesFind '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zonesFind'" |
||||
|
_debug "Result of zonesFind '$curResult'" |
||||
|
zoneStatus=$(echo "${curResult}" | _hostingde_parse "status" "success") |
||||
|
_debug "zoneStatus '${zoneStatus}'" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_hostingde_addRecord() { |
||||
|
_info "Adding record to zone" |
||||
|
_hostingde_getZoneStatus |
||||
|
_debug "Result of zoneStatus: '${zoneStatus}'" |
||||
|
while [ "${zoneStatus}" != "\"active\"" ]; do |
||||
|
_sleep 5 |
||||
|
_hostingde_getZoneStatus |
||||
|
_debug "Result of zoneStatus: '${zoneStatus}'" |
||||
|
done |
||||
|
curData="{\"authToken\":\"${HOSTINGDE_APIKEY}\",\"zoneConfig\":{\"id\":${zoneConfigId},\"name\":${zoneConfigName},\"type\":${zoneConfigType},\"dnsServerGroupId\":${zoneConfigDnsServerGroupId},\"dnsSecMode\":${zoneConfigDnsSecMode},\"emailAddress\":${zoneConfigEmailAddress},\"soaValues\":{\"expire\":${zoneConfigExpire},\"negativeTtl\":${zoneConfigNegativeTtl},\"refresh\":${zoneConfigRefresh},\"retry\":${zoneConfigRetry},\"ttl\":${zoneConfigTtl}}},\"recordsToAdd\":[{\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"content\":\"\\\"${txtvalue}\\\"\",\"ttl\":3600}]}" |
||||
|
curResult="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate")" |
||||
|
_debug "Calling zoneUpdate: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate'" |
||||
|
_debug "Result of zoneUpdate: '$curResult'" |
||||
|
if _contains "${curResult}" '"status": "error"'; then |
||||
|
if _contains "${curResult}" '"code": 10109'; then |
||||
|
_err "The API-Key is invalid or could not be found" |
||||
|
else |
||||
|
_err "UNKNOWN API ERROR" |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_hostingde_removeRecord() { |
||||
|
_info "Removing record from zone" |
||||
|
_hostingde_getZoneStatus |
||||
|
_debug "Result of zoneStatus: '$zoneStatus'" |
||||
|
while [ "$zoneStatus" != "\"active\"" ]; do |
||||
|
_sleep 5 |
||||
|
_hostingde_getZoneStatus |
||||
|
_debug "Result of zoneStatus: '$zoneStatus'" |
||||
|
done |
||||
|
curData="{\"authToken\":\"${HOSTINGDE_APIKEY}\",\"zoneConfig\":{\"id\":${zoneConfigId},\"name\":${zoneConfigName},\"type\":${zoneConfigType},\"dnsServerGroupId\":${zoneConfigDnsServerGroupId},\"dnsSecMode\":${zoneConfigDnsSecMode},\"emailAddress\":${zoneConfigEmailAddress},\"soaValues\":{\"expire\":${zoneConfigExpire},\"negativeTtl\":${zoneConfigNegativeTtl},\"refresh\":${zoneConfigRefresh},\"retry\":${zoneConfigRetry},\"ttl\":${zoneConfigTtl}}},\"recordsToDelete\":[{\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"content\":\"\\\"${txtvalue}\\\"\"}]}" |
||||
|
curResult="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate")" |
||||
|
_debug "Calling zoneUpdate: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate'" |
||||
|
_debug "Result of zoneUpdate: '$curResult'" |
||||
|
if _contains "${curResult}" '"status": "error"'; then |
||||
|
if _contains "${curResult}" '"code": 10109'; then |
||||
|
_err "The API-Key is invalid or could not be found" |
||||
|
else |
||||
|
_err "UNKNOWN API ERROR" |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,107 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
############################################################ |
||||
|
# KingHost API support # |
||||
|
# http://api.kinghost.net/doc/ # |
||||
|
# # |
||||
|
# Author: Felipe Keller Braz <felipebraz@kinghost.com.br> # |
||||
|
# Report Bugs here: https://github.com/kinghost/acme.sh # |
||||
|
# # |
||||
|
# Values to export: # |
||||
|
# export KINGHOST_Username="email@provider.com" # |
||||
|
# export KINGHOST_Password="xxxxxxxxxx" # |
||||
|
############################################################ |
||||
|
|
||||
|
KING_Api="https://api.kinghost.net/acme" |
||||
|
|
||||
|
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
# Used to add txt record |
||||
|
dns_kinghost_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
KINGHOST_Username="${KINGHOST_Username:-$(_readaccountconf_mutable KINGHOST_Username)}" |
||||
|
KINGHOST_Password="${KINGHOST_Password:-$(_readaccountconf_mutable KINGHOST_Password)}" |
||||
|
if [ -z "$KINGHOST_Username" ] || [ -z "$KINGHOST_Password" ]; then |
||||
|
KINGHOST_Username="" |
||||
|
KINGHOST_Password="" |
||||
|
_err "You don't specify KingHost api password and email yet." |
||||
|
_err "Please create you key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the credentials to the account conf file. |
||||
|
_saveaccountconf_mutable KINGHOST_Username "$KINGHOST_Username" |
||||
|
_saveaccountconf_mutable KINGHOST_Password "$KINGHOST_Password" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_kinghost_rest GET "dns" "name=$fulldomain&content=$txtvalue" |
||||
|
|
||||
|
#This API call returns "status":"ok" if dns record does not exists |
||||
|
#We are creating a new txt record here, so we expect the "ok" status |
||||
|
if ! echo "$response" | grep '"status":"ok"' >/dev/null; then |
||||
|
_err "Error" |
||||
|
_err "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_kinghost_rest POST "dns" "name=$fulldomain&content=$txtvalue" |
||||
|
if ! echo "$response" | grep '"status":"ok"' >/dev/null; then |
||||
|
_err "Error" |
||||
|
_err "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
# Usage: fulldomain txtvalue |
||||
|
# Used to remove the txt record after validation |
||||
|
dns_kinghost_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
KINGHOST_Password="${KINGHOST_Password:-$(_readaccountconf_mutable KINGHOST_Password)}" |
||||
|
KINGHOST_Username="${KINGHOST_Username:-$(_readaccountconf_mutable KINGHOST_Username)}" |
||||
|
if [ -z "$KINGHOST_Password" ] || [ -z "$KINGHOST_Username" ]; then |
||||
|
KINGHOST_Password="" |
||||
|
KINGHOST_Username="" |
||||
|
_err "You don't specify KingHost api key and email yet." |
||||
|
_err "Please create you key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_kinghost_rest DELETE "dns" "name=$fulldomain&content=$txtvalue" |
||||
|
if ! echo "$response" | grep '"status":"ok"' >/dev/null; then |
||||
|
_err "Error" |
||||
|
_err "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
_kinghost_rest() { |
||||
|
method=$1 |
||||
|
uri="$2" |
||||
|
data="$3" |
||||
|
_debug "$uri" |
||||
|
|
||||
|
export _H1="X-Auth-Email: $KINGHOST_Username" |
||||
|
export _H2="X-Auth-Key: $KINGHOST_Password" |
||||
|
|
||||
|
if [ "$method" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$KING_Api/$uri.json" "" "$method")" |
||||
|
else |
||||
|
response="$(_get "$KING_Api/$uri.json?$data")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $uri" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,185 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#Original Author: Philipp Grosswiler <philipp.grosswiler@swiss-design.net> |
||||
|
#v4 Update Author: Aaron W. Swenson <aaron@grandmasfridge.org> |
||||
|
|
||||
|
LINODE_V4_API_URL="https://api.linode.com/v4/domains" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_linode_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_linode_v4_add() { |
||||
|
fulldomain="${1}" |
||||
|
txtvalue="${2}" |
||||
|
|
||||
|
if ! _Linode_API; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using Linode" |
||||
|
_debug "Calling: dns_linode_add() '${fulldomain}' '${txtvalue}'" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "Domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_payload="{ |
||||
|
\"type\": \"TXT\", |
||||
|
\"name\": \"$_sub_domain\", |
||||
|
\"target\": \"$txtvalue\" |
||||
|
}" |
||||
|
|
||||
|
if _rest POST "/$_domain_id/records" "$_payload" && [ -n "$response" ]; then |
||||
|
_resource_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\s*[0-9]+" | cut -d : -f 2 | tr -d " " | _head_n 1) |
||||
|
_debug _resource_id "$_resource_id" |
||||
|
|
||||
|
if [ -z "$_resource_id" ]; then |
||||
|
_err "Error adding the domain resource." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Domain resource successfully added." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: dns_linode_rm _acme-challenge.www.domain.com |
||||
|
dns_linode_v4_rm() { |
||||
|
fulldomain="${1}" |
||||
|
|
||||
|
if ! _Linode_API; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using Linode" |
||||
|
_debug "Calling: dns_linode_rm() '${fulldomain}'" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "Domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
if _rest GET "/$_domain_id/records" && [ -n "$response" ]; then |
||||
|
response="$(echo "$response" | tr -d "\n" | tr '{' "|" | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
|
||||
|
resource="$(echo "$response" | _egrep_o "{.*\"name\":\s*\"$_sub_domain\".*}")" |
||||
|
if [ "$resource" ]; then |
||||
|
_resource_id=$(printf "%s\n" "$resource" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "$_resource_id" ]; then |
||||
|
_debug _resource_id "$_resource_id" |
||||
|
|
||||
|
if _rest DELETE "/$_domain_id/records/$_resource_id" && [ -n "$response" ]; then |
||||
|
# On 200/OK, empty set is returned. Check for error, if any. |
||||
|
_error_response=$(printf "%s\n" "$response" | _egrep_o "\"errors\"" | cut -d : -f 2 | tr -d " " | _head_n 1) |
||||
|
|
||||
|
if [ -n "$_error_response" ]; then |
||||
|
_err "Error deleting the domain resource: $_error_response" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Domain resource successfully deleted." |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_Linode_API() { |
||||
|
if [ -z "$LINODE_V4_API_KEY" ]; then |
||||
|
LINODE_V4_API_KEY="" |
||||
|
|
||||
|
_err "You didn't specify the Linode v4 API key yet." |
||||
|
_err "Please create your key and try again." |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf LINODE_V4_API_KEY "$LINODE_V4_API_KEY" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=12345 |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
if _rest GET; then |
||||
|
response="$(echo "$response" | tr -d "\n" | tr '{' "|" | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hostedzone="$(echo "$response" | _egrep_o "{.*\"domain\":\s*\"$h\".*}")" |
||||
|
if [ "$hostedzone" ]; then |
||||
|
_domain_id=$(printf "%s\n" "$hostedzone" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#method method action data |
||||
|
_rest() { |
||||
|
mtd="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
|
||||
|
_debug mtd "$mtd" |
||||
|
_debug ep "$ep" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
export _H3="Authorization: Bearer $LINODE_V4_API_KEY" |
||||
|
|
||||
|
if [ "$mtd" != "GET" ]; then |
||||
|
# both POST and DELETE. |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$LINODE_V4_API_URL$ep" "" "$mtd")" |
||||
|
else |
||||
|
response="$(_get "$LINODE_V4_API_URL$ep$data")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,286 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# |
||||
|
#LOOPIA_User="username" |
||||
|
# |
||||
|
#LOOPIA_Password="password" |
||||
|
|
||||
|
LOOPIA_Api="https://api.loopia.se/RPCSERV" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_loopia_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
LOOPIA_User="${LOOPIA_User:-$(_readaccountconf_mutable LOOPIA_User)}" |
||||
|
LOOPIA_Password="${LOOPIA_Password:-$(_readaccountconf_mutable LOOPIA_Password)}" |
||||
|
if [ -z "$LOOPIA_User" ] || [ -z "$LOOPIA_Password" ]; then |
||||
|
LOOPIA_User="" |
||||
|
LOOPIA_Password="" |
||||
|
_err "You don't specify loopia user and password yet." |
||||
|
_err "Please create you key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable LOOPIA_User "$LOOPIA_User" |
||||
|
_saveaccountconf_mutable LOOPIA_Password "$LOOPIA_Password" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
|
||||
|
_loopia_add_sub_domain "$_domain" "$_sub_domain" |
||||
|
_loopia_add_record "$_domain" "$_sub_domain" "$txtvalue" |
||||
|
|
||||
|
} |
||||
|
|
||||
|
dns_loopia_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
LOOPIA_User="${LOOPIA_User:-$(_readaccountconf_mutable LOOPIA_User)}" |
||||
|
LOOPIA_Password="${LOOPIA_Password:-$(_readaccountconf_mutable LOOPIA_Password)}" |
||||
|
if [ -z "$LOOPIA_User" ] || [ -z "$LOOPIA_Password" ]; then |
||||
|
LOOPIA_User="" |
||||
|
LOOPIA_Password="" |
||||
|
_err "You don't specify LOOPIA user and password yet." |
||||
|
_err "Please create you key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable LOOPIA_User "$LOOPIA_User" |
||||
|
_saveaccountconf_mutable LOOPIA_Password "$LOOPIA_Password" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>removeSubdomain</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$_domain" "$_sub_domain") |
||||
|
|
||||
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
||||
|
|
||||
|
if ! _contains "$response" "OK"; then |
||||
|
_err "Error could not get txt records" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_loopia_get_records() { |
||||
|
domain=$1 |
||||
|
sub_domain=$2 |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>getZoneRecords</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain" "$sub_domain") |
||||
|
|
||||
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
||||
|
if ! _contains "$response" "<array>"; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
_debug "get root" |
||||
|
|
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>getDomains</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' $LOOPIA_User $LOOPIA_Password) |
||||
|
|
||||
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
||||
|
while true; do |
||||
|
h=$(echo "$domain" | cut -d . -f $i-100) |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "$h"; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
return 0 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
|
||||
|
} |
||||
|
|
||||
|
_loopia_add_record() { |
||||
|
domain=$1 |
||||
|
sub_domain=$2 |
||||
|
txtval=$3 |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>addZoneRecord</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<struct> |
||||
|
<member> |
||||
|
<name>type</name> |
||||
|
<value><string>TXT</string></value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>priority</name> |
||||
|
<value><int>0</int></value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>ttl</name> |
||||
|
<value><int>60</int></value> |
||||
|
</member> |
||||
|
<member> |
||||
|
<name>rdata</name> |
||||
|
<value><string>%s</string></value> |
||||
|
</member> |
||||
|
</struct> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain" "$sub_domain" "$txtval") |
||||
|
|
||||
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
||||
|
|
||||
|
if ! _contains "$response" "OK"; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_sub_domain_exists() { |
||||
|
domain=$1 |
||||
|
sub_domain=$2 |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>getSubdomains</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain") |
||||
|
|
||||
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
||||
|
|
||||
|
if _contains "$response" "$sub_domain"; then |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_loopia_add_sub_domain() { |
||||
|
domain=$1 |
||||
|
sub_domain=$2 |
||||
|
|
||||
|
if _sub_domain_exists "$domain" "$sub_domain"; then |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<methodCall> |
||||
|
<methodName>addSubdomain</methodName> |
||||
|
<params> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
<param> |
||||
|
<value><string>%s</string></value> |
||||
|
</param> |
||||
|
</params> |
||||
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain" "$sub_domain") |
||||
|
|
||||
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" |
||||
|
|
||||
|
if ! _contains "$response" "OK"; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,97 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# MyDevil.net API (2019-02-03) |
||||
|
# |
||||
|
# MyDevil.net already supports automatic Let's Encrypt certificates, |
||||
|
# except for wildcard domains. |
||||
|
# |
||||
|
# This script depends on `devil` command that MyDevil.net provides, |
||||
|
# which means that it works only on server side. |
||||
|
# |
||||
|
# Author: Marcin Konicki <https://ahwayakchih.neoni.net> |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_mydevil_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_mydevil_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
domain="" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using mydevil" |
||||
|
|
||||
|
domain=$(mydevil_get_domain "$fulldomain") |
||||
|
if [ -z "$domain" ]; then |
||||
|
_err "Invalid domain name: could not find root domain of $fulldomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# No need to check if record name exists, `devil` always adds new record. |
||||
|
# In worst case scenario, we end up with multiple identical records. |
||||
|
|
||||
|
_info "Adding $fulldomain record for domain $domain" |
||||
|
if devil dns add "$domain" "$fulldomain" TXT "$txtvalue"; then |
||||
|
_info "Successfully added TXT record, ready for validation." |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Unable to add DNS record." |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_mydevil_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
domain="" |
||||
|
|
||||
|
if ! _exists "devil"; then |
||||
|
_err "Could not find 'devil' command." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using mydevil" |
||||
|
|
||||
|
domain=$(mydevil_get_domain "$fulldomain") |
||||
|
if [ -z "$domain" ]; then |
||||
|
_err "Invalid domain name: could not find root domain of $fulldomain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# catch one or more numbers |
||||
|
num='[0-9][0-9]*' |
||||
|
# catch one or more whitespace |
||||
|
w=$(printf '[\t ][\t ]*') |
||||
|
# catch anything, except newline |
||||
|
any='.*' |
||||
|
# filter to make sure we do not delete other records |
||||
|
validRecords="^${num}${w}${fulldomain}${w}TXT${w}${any}${txtvalue}$" |
||||
|
for id in $(devil dns list "$domain" | tail -n+2 | grep "${validRecords}" | cut -w -s -f 1); do |
||||
|
_info "Removing record $id from domain $domain" |
||||
|
devil dns del "$domain" "$id" || _err "Could not remove DNS record." |
||||
|
done |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
# Usage: domain=$(mydevil_get_domain "_acme-challenge.www.domain.com" || _err "Invalid domain name") |
||||
|
# echo $domain |
||||
|
mydevil_get_domain() { |
||||
|
fulldomain=$1 |
||||
|
domain="" |
||||
|
|
||||
|
for domain in $(devil dns list | cut -w -s -f 1 | tail -n+2); do |
||||
|
if _endswith "$fulldomain" "$domain"; then |
||||
|
printf -- "%s" "$domain" |
||||
|
return 0 |
||||
|
fi |
||||
|
done |
||||
|
|
||||
|
return 1 |
||||
|
} |
@ -0,0 +1,210 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#Here is a api script for MyDNS.JP. |
||||
|
#This file name is "dns_mydnsjp.sh" |
||||
|
#So, here must be a method dns_mydnsjp_add() |
||||
|
#Which will be called by acme.sh to add the txt record to your api system. |
||||
|
#returns 0 means success, otherwise error. |
||||
|
# |
||||
|
#Author: epgdatacapbon |
||||
|
#Report Bugs here: https://github.com/epgdatacapbon/acme.sh |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Export MyDNS.JP MasterID and Password in following variables... |
||||
|
# MYDNSJP_MasterID=MasterID |
||||
|
# MYDNSJP_Password=Password |
||||
|
|
||||
|
MYDNSJP_API="https://www.mydns.jp" |
||||
|
|
||||
|
#Usage: dns_mydnsjp_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_mydnsjp_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_info "Using mydnsjp" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
# Load the credentials from the account conf file |
||||
|
MYDNSJP_MasterID="${MYDNSJP_MasterID:-$(_readaccountconf_mutable MYDNSJP_MasterID)}" |
||||
|
MYDNSJP_Password="${MYDNSJP_Password:-$(_readaccountconf_mutable MYDNSJP_Password)}" |
||||
|
if [ -z "$MYDNSJP_MasterID" ] || [ -z "$MYDNSJP_Password" ]; then |
||||
|
MYDNSJP_MasterID="" |
||||
|
MYDNSJP_Password="" |
||||
|
_err "You don't specify mydnsjp api MasterID and Password yet." |
||||
|
_err "Please export as MYDNSJP_MasterID / MYDNSJP_Password and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# Save the credentials to the account conf file |
||||
|
_saveaccountconf_mutable MYDNSJP_MasterID "$MYDNSJP_MasterID" |
||||
|
_saveaccountconf_mutable MYDNSJP_Password "$MYDNSJP_Password" |
||||
|
|
||||
|
_debug "First detect the root zone." |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
if _mydnsjp_api "REGIST" "$_domain" "$txtvalue"; then |
||||
|
if printf -- "%s" "$response" | grep "OK." >/dev/null; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_mydnsjp_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_info "Removing TXT record" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
# Load the credentials from the account conf file |
||||
|
MYDNSJP_MasterID="${MYDNSJP_MasterID:-$(_readaccountconf_mutable MYDNSJP_MasterID)}" |
||||
|
MYDNSJP_Password="${MYDNSJP_Password:-$(_readaccountconf_mutable MYDNSJP_Password)}" |
||||
|
if [ -z "$MYDNSJP_MasterID" ] || [ -z "$MYDNSJP_Password" ]; then |
||||
|
MYDNSJP_MasterID="" |
||||
|
MYDNSJP_Password="" |
||||
|
_err "You don't specify mydnsjp api MasterID and Password yet." |
||||
|
_err "Please export as MYDNSJP_MasterID / MYDNSJP_Password and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
if _mydnsjp_api "DELETE" "$_domain" "$txtvalue"; then |
||||
|
if printf -- "%s" "$response" | grep "OK." >/dev/null; then |
||||
|
_info "Deleted, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Delete txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Delete txt record error." |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
# _acme-challenge.www.domain.com |
||||
|
# returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
fulldomain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
# Get the root domain |
||||
|
_mydnsjp_retrieve_domain |
||||
|
if [ "$?" != "0" ]; then |
||||
|
# not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
while true; do |
||||
|
_domain=$(printf "%s" "$fulldomain" | cut -d . -f $i-100) |
||||
|
|
||||
|
if [ -z "$_domain" ]; then |
||||
|
# not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if [ "$_domain" = "$_root_domain" ]; then |
||||
|
_sub_domain=$(printf "%s" "$fulldomain" | cut -d . -f 1-$p) |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# Retrieve the root domain |
||||
|
# returns 0 success |
||||
|
_mydnsjp_retrieve_domain() { |
||||
|
_debug "Login to MyDNS.JP" |
||||
|
|
||||
|
response="$(_post "masterid=$MYDNSJP_MasterID&masterpwd=$MYDNSJP_Password" "$MYDNSJP_API/?MENU=100")" |
||||
|
cookie="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _head_n 1 | cut -d " " -f 2)" |
||||
|
|
||||
|
# If cookies is not empty then logon successful |
||||
|
if [ -z "$cookie" ]; then |
||||
|
_err "Fail to get a cookie." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "Retrieve DOMAIN INFO page" |
||||
|
|
||||
|
export _H1="Cookie:${cookie}" |
||||
|
|
||||
|
response="$(_get "$MYDNSJP_API/?MENU=300")" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "Fail to retrieve DOMAIN INFO." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_root_domain=$(echo "$response" | grep "DNSINFO\[domainname\]" | sed 's/^.*value="\([^"]*\)".*/\1/') |
||||
|
|
||||
|
# Logout |
||||
|
response="$(_get "$MYDNSJP_API/?MENU=090")" |
||||
|
|
||||
|
_debug _root_domain "$_root_domain" |
||||
|
|
||||
|
if [ -z "$_root_domain" ]; then |
||||
|
_err "Fail to get the root domain." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_mydnsjp_api() { |
||||
|
cmd=$1 |
||||
|
domain=$2 |
||||
|
txtvalue=$3 |
||||
|
|
||||
|
# Base64 encode the credentials |
||||
|
credentials=$(printf "%s:%s" "$MYDNSJP_MasterID" "$MYDNSJP_Password" | _base64) |
||||
|
|
||||
|
# Construct the HTTP Authorization header |
||||
|
export _H1="Content-Type: application/x-www-form-urlencoded" |
||||
|
export _H2="Authorization: Basic ${credentials}" |
||||
|
|
||||
|
response="$(_post "CERTBOT_DOMAIN=$domain&CERTBOT_VALIDATION=$txtvalue&EDIT_CMD=$cmd" "$MYDNSJP_API/directedit.html")" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug2 response "$response" |
||||
|
|
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,407 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Namecheap API |
||||
|
# https://www.namecheap.com/support/api/intro.aspx |
||||
|
# |
||||
|
# Requires Namecheap API key set in |
||||
|
#NAMECHEAP_API_KEY, |
||||
|
#NAMECHEAP_USERNAME, |
||||
|
#NAMECHEAP_SOURCEIP |
||||
|
# Due to Namecheap's API limitation all the records of your domain will be read and re applied, make sure to have a backup of your records you could apply if any issue would arise. |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
NAMECHEAP_API="https://api.namecheap.com/xml.response" |
||||
|
|
||||
|
#Usage: dns_namecheap_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_namecheap_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _namecheap_check_config; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _namecheap_set_publicip; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
_debug domain "$_domain" |
||||
|
_debug sub_domain "$_sub_domain" |
||||
|
|
||||
|
_set_namecheap_TXT "$_domain" "$_sub_domain" "$txtvalue" |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_namecheap_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _namecheap_set_publicip; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _namecheap_check_config; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
_debug domain "$_domain" |
||||
|
_debug sub_domain "$_sub_domain" |
||||
|
|
||||
|
_del_namecheap_TXT "$_domain" "$_sub_domain" "$txtvalue" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
fulldomain=$1 |
||||
|
|
||||
|
if ! _get_root_by_getList "$fulldomain"; then |
||||
|
_debug "Failed domain lookup via domains.getList api call. Trying domain lookup via domains.dns.getHosts api." |
||||
|
# The above "getList" api will only return hosts *owned* by the calling user. However, if the calling |
||||
|
# user is not the owner, but still has administrative rights, we must query the getHosts api directly. |
||||
|
# See this comment and the official namecheap response: http://disq.us/p/1q6v9x9 |
||||
|
if ! _get_root_by_getHosts "$fulldomain"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_get_root_by_getList() { |
||||
|
domain=$1 |
||||
|
|
||||
|
if ! _namecheap_post "namecheap.domains.getList"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
while true; do |
||||
|
|
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _contains "$h" "\\."; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _contains "$response" "$h"; then |
||||
|
_debug "$h not found" |
||||
|
else |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
return 0 |
||||
|
fi |
||||
|
p="$i" |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_get_root_by_getHosts() { |
||||
|
i=100 |
||||
|
p=99 |
||||
|
|
||||
|
while [ $p -ne 0 ]; do |
||||
|
|
||||
|
h=$(printf "%s" "$1" | cut -d . -f $i-100) |
||||
|
if [ -n "$h" ]; then |
||||
|
if _contains "$h" "\\."; then |
||||
|
_debug h "$h" |
||||
|
if _namecheap_set_tld_sld "$h"; then |
||||
|
_sub_domain=$(printf "%s" "$1" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
return 0 |
||||
|
else |
||||
|
_debug "$h not found" |
||||
|
fi |
||||
|
fi |
||||
|
fi |
||||
|
i="$p" |
||||
|
p=$(_math "$p" - 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_namecheap_set_publicip() { |
||||
|
|
||||
|
if [ -z "$NAMECHEAP_SOURCEIP" ]; then |
||||
|
_err "No Source IP specified for Namecheap API." |
||||
|
_err "Use your public ip address or an url to retrieve it (e.g. https://ipconfig.co/ip) and export it as NAMECHEAP_SOURCEIP" |
||||
|
return 1 |
||||
|
else |
||||
|
_saveaccountconf NAMECHEAP_SOURCEIP "$NAMECHEAP_SOURCEIP" |
||||
|
_debug sourceip "$NAMECHEAP_SOURCEIP" |
||||
|
|
||||
|
ip=$(echo "$NAMECHEAP_SOURCEIP" | _egrep_o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') |
||||
|
addr=$(echo "$NAMECHEAP_SOURCEIP" | _egrep_o '(http|https)://.*') |
||||
|
|
||||
|
_debug2 ip "$ip" |
||||
|
_debug2 addr "$addr" |
||||
|
|
||||
|
if [ -n "$ip" ]; then |
||||
|
_publicip="$ip" |
||||
|
elif [ -n "$addr" ]; then |
||||
|
_publicip=$(_get "$addr") |
||||
|
else |
||||
|
_err "No Source IP specified for Namecheap API." |
||||
|
_err "Use your public ip address or an url to retrieve it (e.g. https://ipconfig.co/ip) and export it as NAMECHEAP_SOURCEIP" |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
_debug publicip "$_publicip" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_namecheap_post() { |
||||
|
command=$1 |
||||
|
data="ApiUser=${NAMECHEAP_USERNAME}&ApiKey=${NAMECHEAP_API_KEY}&ClientIp=${_publicip}&UserName=${NAMECHEAP_USERNAME}&Command=${command}" |
||||
|
_debug2 "_namecheap_post data" "$data" |
||||
|
response="$(_post "$data" "$NAMECHEAP_API" "" "POST")" |
||||
|
_debug2 response "$response" |
||||
|
|
||||
|
if _contains "$response" "Status=\"ERROR\"" >/dev/null; then |
||||
|
error=$(echo "$response" | _egrep_o ">.*<\\/Error>" | cut -d '<' -f 1 | tr -d '>') |
||||
|
_err "error $error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_namecheap_parse_host() { |
||||
|
_host=$1 |
||||
|
_debug _host "$_host" |
||||
|
|
||||
|
_hostid=$(echo "$_host" | _egrep_o ' HostId="[^"]*' | cut -d '"' -f 2) |
||||
|
_hostname=$(echo "$_host" | _egrep_o ' Name="[^"]*' | cut -d '"' -f 2) |
||||
|
_hosttype=$(echo "$_host" | _egrep_o ' Type="[^"]*' | cut -d '"' -f 2) |
||||
|
_hostaddress=$(echo "$_host" | _egrep_o ' Address="[^"]*' | cut -d '"' -f 2) |
||||
|
_hostmxpref=$(echo "$_host" | _egrep_o ' MXPref="[^"]*' | cut -d '"' -f 2) |
||||
|
_hostttl=$(echo "$_host" | _egrep_o ' TTL="[^"]*' | cut -d '"' -f 2) |
||||
|
|
||||
|
_debug hostid "$_hostid" |
||||
|
_debug hostname "$_hostname" |
||||
|
_debug hosttype "$_hosttype" |
||||
|
_debug hostaddress "$_hostaddress" |
||||
|
_debug hostmxpref "$_hostmxpref" |
||||
|
_debug hostttl "$_hostttl" |
||||
|
} |
||||
|
|
||||
|
_namecheap_check_config() { |
||||
|
|
||||
|
if [ -z "$NAMECHEAP_API_KEY" ]; then |
||||
|
_err "No API key specified for Namecheap API." |
||||
|
_err "Create your key and export it as NAMECHEAP_API_KEY" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if [ -z "$NAMECHEAP_USERNAME" ]; then |
||||
|
_err "No username key specified for Namecheap API." |
||||
|
_err "Create your key and export it as NAMECHEAP_USERNAME" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf NAMECHEAP_API_KEY "$NAMECHEAP_API_KEY" |
||||
|
_saveaccountconf NAMECHEAP_USERNAME "$NAMECHEAP_USERNAME" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_set_namecheap_TXT() { |
||||
|
subdomain=$2 |
||||
|
txt=$3 |
||||
|
|
||||
|
if ! _namecheap_set_tld_sld "$1"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
request="namecheap.domains.dns.getHosts&SLD=${_sld}&TLD=${_tld}" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hosts=$(echo "$response" | _egrep_o '<host[^>]*') |
||||
|
_debug hosts "$hosts" |
||||
|
|
||||
|
if [ -z "$hosts" ]; then |
||||
|
_error "Hosts not found" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_namecheap_reset_hostList |
||||
|
|
||||
|
while read -r host; do |
||||
|
if _contains "$host" "<host"; then |
||||
|
_namecheap_parse_host "$host" |
||||
|
_debug2 _hostname "_hostname" |
||||
|
_debug2 _hosttype "_hosttype" |
||||
|
_debug2 _hostaddress "_hostaddress" |
||||
|
_debug2 _hostmxpref "_hostmxpref" |
||||
|
_hostaddress="$(printf "%s" "$_hostaddress" | _url_encode)" |
||||
|
_debug2 "encoded _hostaddress" "_hostaddress" |
||||
|
_namecheap_add_host "$_hostname" "$_hosttype" "$_hostaddress" "$_hostmxpref" "$_hostttl" |
||||
|
fi |
||||
|
done <<EOT |
||||
|
echo "$hosts" |
||||
|
EOT |
||||
|
|
||||
|
_namecheap_add_host "$subdomain" "TXT" "$txt" 10 120 |
||||
|
|
||||
|
_debug hostrequestfinal "$_hostrequest" |
||||
|
|
||||
|
request="namecheap.domains.dns.setHosts&SLD=${_sld}&TLD=${_tld}${_hostrequest}" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_del_namecheap_TXT() { |
||||
|
subdomain=$2 |
||||
|
txt=$3 |
||||
|
|
||||
|
if ! _namecheap_set_tld_sld "$1"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
request="namecheap.domains.dns.getHosts&SLD=${_sld}&TLD=${_tld}" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hosts=$(echo "$response" | _egrep_o '<host[^>]*') |
||||
|
_debug hosts "$hosts" |
||||
|
|
||||
|
if [ -z "$hosts" ]; then |
||||
|
_error "Hosts not found" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_namecheap_reset_hostList |
||||
|
|
||||
|
found=0 |
||||
|
|
||||
|
while read -r host; do |
||||
|
if _contains "$host" "<host"; then |
||||
|
_namecheap_parse_host "$host" |
||||
|
if [ "$_hosttype" = "TXT" ] && [ "$_hostname" = "$subdomain" ] && [ "$_hostaddress" = "$txt" ]; then |
||||
|
_debug "TXT entry found" |
||||
|
found=1 |
||||
|
else |
||||
|
_hostaddress="$(printf "%s" "$_hostaddress" | _url_encode)" |
||||
|
_namecheap_add_host "$_hostname" "$_hosttype" "$_hostaddress" "$_hostmxpref" "$_hostttl" |
||||
|
fi |
||||
|
fi |
||||
|
done <<EOT |
||||
|
echo "$hosts" |
||||
|
EOT |
||||
|
|
||||
|
if [ $found -eq 0 ]; then |
||||
|
_debug "TXT entry not found" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
_debug hostrequestfinal "$_hostrequest" |
||||
|
|
||||
|
request="namecheap.domains.dns.setHosts&SLD=${_sld}&TLD=${_tld}${_hostrequest}" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_err "$error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_namecheap_reset_hostList() { |
||||
|
_hostindex=0 |
||||
|
_hostrequest="" |
||||
|
} |
||||
|
|
||||
|
#Usage: _namecheap_add_host HostName RecordType Address MxPref TTL |
||||
|
_namecheap_add_host() { |
||||
|
_hostindex=$(_math "$_hostindex" + 1) |
||||
|
_hostrequest=$(printf '%s&HostName%d=%s&RecordType%d=%s&Address%d=%s&MXPref%d=%d&TTL%d=%d' "$_hostrequest" "$_hostindex" "$1" "$_hostindex" "$2" "$_hostindex" "$3" "$_hostindex" "$4" "$_hostindex" "$5") |
||||
|
} |
||||
|
|
||||
|
_namecheap_set_tld_sld() { |
||||
|
domain=$1 |
||||
|
_tld="" |
||||
|
_sld="" |
||||
|
|
||||
|
i=2 |
||||
|
|
||||
|
while true; do |
||||
|
|
||||
|
_tld=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug tld "$_tld" |
||||
|
|
||||
|
if [ -z "$_tld" ]; then |
||||
|
_debug "invalid tld" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
j=$(_math "$i" - 1) |
||||
|
|
||||
|
_sld=$(printf "%s" "$domain" | cut -d . -f 1-"$j") |
||||
|
_debug sld "$_sld" |
||||
|
|
||||
|
if [ -z "$_sld" ]; then |
||||
|
_debug "invalid sld" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
request="namecheap.domains.dns.getHosts&SLD=$_sld&TLD=$_tld" |
||||
|
|
||||
|
if ! _namecheap_post "$request"; then |
||||
|
_debug "sld($_sld)/tld($_tld) not found" |
||||
|
else |
||||
|
_debug "sld($_sld)/tld($_tld) found" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
i=$(_math "$i" + 1) |
||||
|
|
||||
|
done |
||||
|
|
||||
|
} |
@ -0,0 +1,181 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# |
||||
|
# NEODIGIT_API_TOKEN="jasdfhklsjadhflnhsausdfas" |
||||
|
|
||||
|
# This is Neodigit.net api wrapper for acme.sh |
||||
|
# |
||||
|
# Author: Adrian Almenar |
||||
|
# Report Bugs here: https://github.com/tecnocratica/acme.sh |
||||
|
# |
||||
|
NEODIGIT_API_URL="https://api.neodigit.net/v1" |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_neodigit_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
NEODIGIT_API_TOKEN="${NEODIGIT_API_TOKEN:-$(_readaccountconf_mutable NEODIGIT_API_TOKEN)}" |
||||
|
if [ -z "$NEODIGIT_API_TOKEN" ]; then |
||||
|
NEODIGIT_API_TOKEN="" |
||||
|
_err "You haven't specified a Token api key." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable NEODIGIT_API_TOKEN "$NEODIGIT_API_TOKEN" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
_debug domain "$_domain" |
||||
|
_debug sub_domain "$_sub_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_neo_rest GET "dns/zones/${_domain_id}/records?type=TXT&name=$fulldomain" |
||||
|
|
||||
|
_debug _code "$_code" |
||||
|
|
||||
|
if [ "$_code" != "200" ]; then |
||||
|
_err "error retrieving data!" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
_debug domain "$_domain" |
||||
|
_debug sub_domain "$_sub_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
if _neo_rest POST "dns/zones/$_domain_id/records" "{\"record\":{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":60}}"; then |
||||
|
if printf -- "%s" "$response" | grep "$_sub_domain" >/dev/null; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_neodigit_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
NEODIGIT_API_TOKEN="${NEODIGIT_API_TOKEN:-$(_readaccountconf_mutable NEODIGIT_API_TOKEN)}" |
||||
|
if [ -z "$NEODIGIT_API_TOKEN" ]; then |
||||
|
NEODIGIT_API_TOKEN="" |
||||
|
_err "You haven't specified a Token api key." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable NEODIGIT_API_TOKEN "$NEODIGIT_API_TOKEN" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_neo_rest GET "dns/zones/${_domain_id}/records?type=TXT&name=$fulldomain&content=$txtvalue" |
||||
|
|
||||
|
if [ "$_code" != "200" ]; then |
||||
|
_err "error retrieving data!" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
record_id=$(echo "$response" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d: -f2 | cut -d, -f1) |
||||
|
_debug "record_id" "$record_id" |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _neo_rest DELETE "dns/zones/$_domain_id/records/$record_id"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=dasfdsafsadg5ythd |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _neo_rest GET "dns/zones?name=$h"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug p "$p" |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_domain_id=$(echo "$response" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d: -f2 | cut -d, -f1) |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_neo_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
|
||||
|
export _H1="X-TCPanel-Token: $NEODIGIT_API_TOKEN" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$NEODIGIT_API_URL/$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$NEODIGIT_API_URL/$ep")" |
||||
|
fi |
||||
|
|
||||
|
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,133 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
#developed by linux-insideDE |
||||
|
|
||||
|
NC_Apikey="${NC_Apikey:-$(_readaccountconf_mutable NC_Apikey)}" |
||||
|
NC_Apipw="${NC_Apipw:-$(_readaccountconf_mutable NC_Apipw)}" |
||||
|
NC_CID="${NC_CID:-$(_readaccountconf_mutable NC_CID)}" |
||||
|
end="https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON" |
||||
|
client="" |
||||
|
|
||||
|
dns_netcup_add() { |
||||
|
login |
||||
|
if [ "$NC_Apikey" = "" ] || [ "$NC_Apipw" = "" ] || [ "$NC_CID" = "" ]; then |
||||
|
_err "No Credentials given" |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable NC_Apikey "$NC_Apikey" |
||||
|
_saveaccountconf_mutable NC_Apipw "$NC_Apipw" |
||||
|
_saveaccountconf_mutable NC_CID "$NC_CID" |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
domain="" |
||||
|
exit=$(echo "$fulldomain" | tr -dc '.' | wc -c) |
||||
|
exit=$(_math "$exit" + 1) |
||||
|
i=$exit |
||||
|
|
||||
|
while |
||||
|
[ "$exit" -gt 0 ] |
||||
|
do |
||||
|
tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit") |
||||
|
if [ "$(_math "$i" - "$exit")" -eq 0 ]; then |
||||
|
domain="$tmp" |
||||
|
else |
||||
|
domain="$tmp.$domain" |
||||
|
fi |
||||
|
if [ "$(_math "$i" - "$exit")" -ge 1 ]; then |
||||
|
msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"\", \"hostname\": \"$fulldomain.\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"false\", \"state\": \"yes\"} ]}}}" "$end" "" "POST") |
||||
|
_debug "$msg" |
||||
|
if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
else |
||||
|
break |
||||
|
fi |
||||
|
fi |
||||
|
fi |
||||
|
exit=$(_math "$exit" - 1) |
||||
|
done |
||||
|
logout |
||||
|
} |
||||
|
|
||||
|
dns_netcup_rm() { |
||||
|
login |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
domain="" |
||||
|
exit=$(echo "$fulldomain" | tr -dc '.' | wc -c) |
||||
|
exit=$(_math "$exit" + 1) |
||||
|
i=$exit |
||||
|
rec="" |
||||
|
|
||||
|
while |
||||
|
[ "$exit" -gt 0 ] |
||||
|
do |
||||
|
tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit") |
||||
|
if [ "$(_math "$i" - "$exit")" -eq 0 ]; then |
||||
|
domain="$tmp" |
||||
|
else |
||||
|
domain="$tmp.$domain" |
||||
|
fi |
||||
|
if [ "$(_math "$i" - "$exit")" -ge 1 ]; then |
||||
|
msg=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$domain\"}}" "$end" "" "POST") |
||||
|
rec=$(echo "$msg" | sed 's/\[//g' | sed 's/\]//g' | sed 's/{\"serverrequestid\".*\"dnsrecords\"://g' | sed 's/},{/};{/g' | sed 's/{//g' | sed 's/}//g') |
||||
|
_debug "$msg" |
||||
|
if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
else |
||||
|
break |
||||
|
fi |
||||
|
fi |
||||
|
fi |
||||
|
exit=$(_math "$exit" - 1) |
||||
|
done |
||||
|
|
||||
|
ida=0000 |
||||
|
idv=0001 |
||||
|
ids=0000000000 |
||||
|
i=1 |
||||
|
while |
||||
|
[ "$i" -ne 0 ] |
||||
|
do |
||||
|
specrec=$(_getfield "$rec" "$i" ";") |
||||
|
idv="$ida" |
||||
|
ida=$(_getfield "$specrec" "1" "," | sed 's/\"id\":\"//g' | sed 's/\"//g') |
||||
|
txtv=$(_getfield "$specrec" "5" "," | sed 's/\"destination\":\"//g' | sed 's/\"//g') |
||||
|
i=$(_math "$i" + 1) |
||||
|
if [ "$txtvalue" = "$txtv" ]; then |
||||
|
i=0 |
||||
|
ids="$ida" |
||||
|
fi |
||||
|
if [ "$ida" = "$idv" ]; then |
||||
|
i=0 |
||||
|
fi |
||||
|
done |
||||
|
msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"$ids\", \"hostname\": \"$fulldomain.\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"TRUE\", \"state\": \"yes\"} ]}}}" "$end" "" "POST") |
||||
|
_debug "$msg" |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
fi |
||||
|
logout |
||||
|
} |
||||
|
|
||||
|
login() { |
||||
|
tmp=$(_post "{\"action\": \"login\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apipassword\": \"$NC_Apipw\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST") |
||||
|
sid=$(_getfield "$tmp" "8" | sed s/\"responsedata\":\{\"apisessionid\":\"//g | sed 's/\"\}\}//g') |
||||
|
_debug "$tmp" |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
logout() { |
||||
|
tmp=$(_post "{\"action\": \"logout\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST") |
||||
|
_debug "$tmp" |
||||
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then |
||||
|
_err "$msg" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
@ -0,0 +1,211 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
######################################################################## |
||||
|
# NocWorx script for acme.sh |
||||
|
# |
||||
|
# Handles DNS Updates for the Following vendors: |
||||
|
# - Nexcess.net |
||||
|
# - Thermo.io |
||||
|
# - Futurehosting.com |
||||
|
# |
||||
|
# Environment variables: |
||||
|
# |
||||
|
# - NW_API_TOKEN (Your API Token) |
||||
|
# - NW_API_ENDPOINT (One of the following listed below) |
||||
|
# |
||||
|
# Endpoints: |
||||
|
# - https://portal.nexcess.net (default) |
||||
|
# - https://core.thermo.io |
||||
|
# - https://my.futurehosting.com |
||||
|
# |
||||
|
# Note: If you do not have an API token, one can be generated at one |
||||
|
# of the following URLs: |
||||
|
# - https://portal.nexcess.net/api-token |
||||
|
# - https://core.thermo.io/api-token |
||||
|
# - https://my.futurehosting.com/api-token |
||||
|
# |
||||
|
# Author: Frank Laszlo <flaszlo@nexcess.net> |
||||
|
|
||||
|
NW_API_VERSION="0" |
||||
|
|
||||
|
# dns_nw_add() - Add TXT record |
||||
|
# Usage: dns_nw_add _acme-challenge.subdomain.domain.com "XyZ123..." |
||||
|
dns_nw_add() { |
||||
|
host="${1}" |
||||
|
txtvalue="${2}" |
||||
|
|
||||
|
_debug host "${host}" |
||||
|
_debug txtvalue "${txtvalue}" |
||||
|
|
||||
|
if ! _check_nw_api_creds; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using NocWorx (${NW_API_ENDPOINT})" |
||||
|
_debug "Calling: dns_nw_add() '${host}' '${txtvalue}'" |
||||
|
|
||||
|
_debug "Detecting root zone" |
||||
|
if ! _get_root "${host}"; then |
||||
|
_err "Zone for domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _zone_id "${_zone_id}" |
||||
|
_debug _sub_domain "${_sub_domain}" |
||||
|
_debug _domain "${_domain}" |
||||
|
|
||||
|
_post_data="{\"zone_id\": \"${_zone_id}\", \"type\": \"TXT\", \"host\": \"${host}\", \"target\": \"${txtvalue}\", \"ttl\": \"300\"}" |
||||
|
|
||||
|
if _rest POST "dns-record" "${_post_data}" && [ -n "${response}" ]; then |
||||
|
_record_id=$(printf "%s\n" "${response}" | _egrep_o "\"record_id\": *[0-9]+" | cut -d : -f 2 | tr -d " " | _head_n 1) |
||||
|
_debug _record_id "${_record_id}" |
||||
|
|
||||
|
if [ -z "$_record_id" ]; then |
||||
|
_err "Error adding the TXT record." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "TXT record successfully added." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# dns_nw_rm() - Remove TXT record |
||||
|
# Usage: dns_nw_rm _acme-challenge.subdomain.domain.com "XyZ123..." |
||||
|
dns_nw_rm() { |
||||
|
host="${1}" |
||||
|
txtvalue="${2}" |
||||
|
|
||||
|
_debug host "${host}" |
||||
|
_debug txtvalue "${txtvalue}" |
||||
|
|
||||
|
if ! _check_nw_api_creds; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Using NocWorx (${NW_API_ENDPOINT})" |
||||
|
_debug "Calling: dns_nw_rm() '${host}'" |
||||
|
|
||||
|
_debug "Detecting root zone" |
||||
|
if ! _get_root "${host}"; then |
||||
|
_err "Zone for domain does not exist." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _zone_id "${_zone_id}" |
||||
|
_debug _sub_domain "${_sub_domain}" |
||||
|
_debug _domain "${_domain}" |
||||
|
|
||||
|
_parameters="?zone_id=${_zone_id}" |
||||
|
|
||||
|
if _rest GET "dns-record" "${_parameters}" && [ -n "${response}" ]; then |
||||
|
response="$(echo "${response}" | tr -d "\n" | sed 's/^\[\(.*\)\]$/\1/' | sed -e 's/{"record_id":/|"record_id":/g' | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
_debug response "${response}" |
||||
|
|
||||
|
record="$(echo "${response}" | _egrep_o "{.*\"host\": *\"${_sub_domain}\", *\"target\": *\"${txtvalue}\".*}")" |
||||
|
_debug record "${record}" |
||||
|
|
||||
|
if [ "${record}" ]; then |
||||
|
_record_id=$(printf "%s\n" "${record}" | _egrep_o "\"record_id\": *[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "${_record_id}" ]; then |
||||
|
_debug _record_id "${_record_id}" |
||||
|
|
||||
|
_rest DELETE "dns-record/${_record_id}" |
||||
|
|
||||
|
_info "TXT record successfully deleted." |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_check_nw_api_creds() { |
||||
|
NW_API_TOKEN="${NW_API_TOKEN:-$(_readaccountconf_mutable NW_API_TOKEN)}" |
||||
|
NW_API_ENDPOINT="${NW_API_ENDPOINT:-$(_readaccountconf_mutable NW_API_ENDPOINT)}" |
||||
|
|
||||
|
if [ -z "${NW_API_ENDPOINT}" ]; then |
||||
|
NW_API_ENDPOINT="https://portal.nexcess.net" |
||||
|
fi |
||||
|
|
||||
|
if [ -z "${NW_API_TOKEN}" ]; then |
||||
|
_err "You have not defined your NW_API_TOKEN." |
||||
|
_err "Please create your token and try again." |
||||
|
_err "If you need to generate a new token, please visit one of the following URLs:" |
||||
|
_err " - https://portal.nexcess.net/api-token" |
||||
|
_err " - https://core.thermo.io/api-token" |
||||
|
_err " - https://my.futurehosting.com/api-token" |
||||
|
|
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable NW_API_TOKEN "${NW_API_TOKEN}" |
||||
|
_saveaccountconf_mutable NW_API_ENDPOINT "${NW_API_ENDPOINT}" |
||||
|
} |
||||
|
|
||||
|
_get_root() { |
||||
|
domain="${1}" |
||||
|
i=2 |
||||
|
p=1 |
||||
|
|
||||
|
if _rest GET "dns-zone"; then |
||||
|
response="$(echo "${response}" | tr -d "\n" | sed 's/^\[\(.*\)\]$/\1/' | sed -e 's/{"zone_id":/|"zone_id":/g' | sed 's/|/&{/g' | tr "|" "\n")" |
||||
|
|
||||
|
_debug response "${response}" |
||||
|
while true; do |
||||
|
h=$(printf "%s" "${domain}" | cut -d . -f $i-100) |
||||
|
_debug h "${h}" |
||||
|
if [ -z "${h}" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
hostedzone="$(echo "${response}" | _egrep_o "{.*\"domain\": *\"${h}\".*}")" |
||||
|
if [ "${hostedzone}" ]; then |
||||
|
_zone_id=$(printf "%s\n" "${hostedzone}" | _egrep_o "\"zone_id\": *[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) |
||||
|
if [ "${_zone_id}" ]; then |
||||
|
_sub_domain=$(printf "%s" "${domain}" | cut -d . -f 1-${p}) |
||||
|
_domain="${h}" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "${i}" + 1) |
||||
|
done |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_rest() { |
||||
|
method="${1}" |
||||
|
ep="/${2}" |
||||
|
data="${3}" |
||||
|
|
||||
|
_debug method "${method}" |
||||
|
_debug ep "${ep}" |
||||
|
|
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
export _H3="Api-Version: ${NW_API_VERSION}" |
||||
|
export _H4="User-Agent: NW-ACME-CLIENT" |
||||
|
export _H5="Authorization: Bearer ${NW_API_TOKEN}" |
||||
|
|
||||
|
if [ "${method}" != "GET" ]; then |
||||
|
_debug data "${data}" |
||||
|
response="$(_post "${data}" "${NW_API_ENDPOINT}${ep}" "" "${method}")" |
||||
|
else |
||||
|
response="$(_get "${NW_API_ENDPOINT}${ep}${data}")" |
||||
|
fi |
||||
|
|
||||
|
if [ "${?}" != "0" ]; then |
||||
|
_err "error ${ep}" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "${response}" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,217 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Online API |
||||
|
# https://console.online.net/en/api/ |
||||
|
# |
||||
|
# Requires Online API key set in ONLINE_API_KEY |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
ONLINE_API="https://api.online.net/api/v1" |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_online_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _online_check_config; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
_debug _real_dns_version "$_real_dns_version" |
||||
|
|
||||
|
_info "Creating temporary zone version" |
||||
|
_online_create_temporary_zone_version |
||||
|
_info "Enabling temporary zone version" |
||||
|
_online_enable_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
_online_create_TXT_record "$_real_dns_version" "$_sub_domain" "$txtvalue" |
||||
|
_info "Disabling temporary version" |
||||
|
_online_enable_zone "$_real_dns_version" |
||||
|
_info "Destroying temporary version" |
||||
|
_online_destroy_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Record added." |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#fulldomain |
||||
|
dns_online_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
if ! _online_check_config; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
_debug _real_dns_version "$_real_dns_version" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
if ! _online_rest GET "domain/$_domain/version/active"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
rid=$(echo "$response" | _egrep_o "\"id\":[0-9]+,\"name\":\"$_sub_domain\",\"data\":\"\\\u0022$txtvalue\\\u0022\"" | cut -d ':' -f 2 | cut -d ',' -f 1) |
||||
|
_debug rid "$rid" |
||||
|
if [ -z "$rid" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Creating temporary zone version" |
||||
|
_online_create_temporary_zone_version |
||||
|
_info "Enabling temporary zone version" |
||||
|
_online_enable_zone "$_temporary_dns_version" |
||||
|
|
||||
|
_info "Removing DNS record" |
||||
|
_online_rest DELETE "domain/$_domain/version/$_real_dns_version/zone/$rid" |
||||
|
_info "Disabling temporary version" |
||||
|
_online_enable_zone "$_real_dns_version" |
||||
|
_info "Destroying temporary version" |
||||
|
_online_destroy_zone "$_temporary_dns_version" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_online_check_config() { |
||||
|
ONLINE_API_KEY="${ONLINE_API_KEY:-$(_readaccountconf_mutable ONLINE_API_KEY)}" |
||||
|
if [ -z "$ONLINE_API_KEY" ]; then |
||||
|
_err "No API key specified for Online API." |
||||
|
_err "Create your key and export it as ONLINE_API_KEY" |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _online_rest GET "domain/"; then |
||||
|
_err "Invalid API key specified for Online API." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable ONLINE_API_KEY "$ONLINE_API_KEY" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_online_rest GET "domain/$h/version/active" |
||||
|
|
||||
|
if ! _contains "$response" "Domain not found" >/dev/null; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
_real_dns_version=$(echo "$response" | _egrep_o '"uuid_ref":.*' | cut -d ':' -f 2 | cut -d '"' -f 2) |
||||
|
return 0 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
_err "Unable to retrive DNS zone matching this domain" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# this function create a temporary zone version |
||||
|
# as online.net does not allow updating an active version |
||||
|
_online_create_temporary_zone_version() { |
||||
|
|
||||
|
_online_rest POST "domain/$_domain/version" "name=acme.sh" |
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_temporary_dns_version=$(echo "$response" | _egrep_o '"uuid_ref":.*' | cut -d ':' -f 2 | cut -d '"' -f 2) |
||||
|
|
||||
|
# Creating a dummy record in this temporary version, because online.net doesn't accept enabling an empty version |
||||
|
_online_create_TXT_record "$_temporary_dns_version" "dummy.acme.sh" "dummy" |
||||
|
|
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_destroy_zone() { |
||||
|
version_id=$1 |
||||
|
_online_rest DELETE "domain/$_domain/version/$version_id" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_enable_zone() { |
||||
|
version_id=$1 |
||||
|
_online_rest PATCH "domain/$_domain/version/$version_id/enable" |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_online_create_TXT_record() { |
||||
|
version=$1 |
||||
|
txt_name=$2 |
||||
|
txt_value=$3 |
||||
|
|
||||
|
_online_rest POST "domain/$_domain/version/$version/zone" "type=TXT&name=$txt_name&data=%22$txt_value%22&ttl=60&priority=0" |
||||
|
|
||||
|
# Note : the normal, expected response SHOULD be "Unknown method". |
||||
|
# this happens because the API HTTP response contains a Location: header, that redirect |
||||
|
# to an unknown online.net endpoint. |
||||
|
if [ "$?" != "0" ] || _contains "$response" "Unknown method" || _contains "$response" "\$ref"; then |
||||
|
return 0 |
||||
|
else |
||||
|
_err "error $response" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_online_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
_online_url="$ONLINE_API/$ep" |
||||
|
_debug2 _online_url "$_online_url" |
||||
|
export _H1="Authorization: Bearer $ONLINE_API_KEY" |
||||
|
export _H2="X-Pretty-JSON: 1" |
||||
|
if [ "$data" ] || [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$_online_url" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$_online_url")" |
||||
|
fi |
||||
|
if [ "$?" != "0" ] || _contains "$response" "invalid_grant" || _contains "$response" "Method not allowed"; then |
||||
|
_err "error $response" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,164 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# |
||||
|
#PointHQ_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" |
||||
|
# |
||||
|
#PointHQ_Email="xxxx@sss.com" |
||||
|
|
||||
|
PointHQ_Api="https://api.pointhq.com" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_pointhq_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
PointHQ_Key="${PointHQ_Key:-$(_readaccountconf_mutable PointHQ_Key)}" |
||||
|
PointHQ_Email="${PointHQ_Email:-$(_readaccountconf_mutable PointHQ_Email)}" |
||||
|
if [ -z "$PointHQ_Key" ] || [ -z "$PointHQ_Email" ]; then |
||||
|
PointHQ_Key="" |
||||
|
PointHQ_Email="" |
||||
|
_err "You didn't specify a PointHQ API key and email yet." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _contains "$PointHQ_Email" "@"; then |
||||
|
_err "It seems that the PointHQ_Email=$PointHQ_Email is not a valid email address." |
||||
|
_err "Please check and retry." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable PointHQ_Key "$PointHQ_Key" |
||||
|
_saveaccountconf_mutable PointHQ_Email "$PointHQ_Email" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
if _pointhq_rest POST "zones/$_domain/records" "{\"zone_record\": {\"name\":\"$_sub_domain\",\"record_type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":3600}}"; then |
||||
|
if printf -- "%s" "$response" | grep "$fulldomain" >/dev/null; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_pointhq_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
PointHQ_Key="${PointHQ_Key:-$(_readaccountconf_mutable PointHQ_Key)}" |
||||
|
PointHQ_Email="${PointHQ_Email:-$(_readaccountconf_mutable PointHQ_Email)}" |
||||
|
if [ -z "$PointHQ_Key" ] || [ -z "$PointHQ_Email" ]; then |
||||
|
PointHQ_Key="" |
||||
|
PointHQ_Email="" |
||||
|
_err "You didn't specify a PointHQ API key and email yet." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_debug "Getting txt records" |
||||
|
_pointhq_rest GET "zones/${_domain}/records?record_type=TXT&name=$_sub_domain" |
||||
|
|
||||
|
if ! printf "%s" "$response" | grep "^\[" >/dev/null; then |
||||
|
_err "Error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if [ "$response" = "[]" ]; then |
||||
|
_info "No records to remove." |
||||
|
else |
||||
|
record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":[^,]*" | cut -d : -f 2 | tr -d \" | head -n 1) |
||||
|
_debug "record_id" "$record_id" |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _pointhq_rest DELETE "zones/$_domain/records/$record_id"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
_contains "$response" '"status":"OK"' |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _pointhq_rest GET "zones"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_pointhq_rest() { |
||||
|
m=$1 |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug "$ep" |
||||
|
|
||||
|
_pointhq_auth=$(printf "%s:%s" "$PointHQ_Email" "$PointHQ_Key" | _base64) |
||||
|
|
||||
|
export _H1="Authorization: Basic $_pointhq_auth" |
||||
|
export _H2="Content-Type: application/json" |
||||
|
export _H3="Accept: application/json" |
||||
|
|
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$PointHQ_Api/$ep" "" "$m")" |
||||
|
else |
||||
|
response="$(_get "$PointHQ_Api/$ep")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
@ -0,0 +1,207 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# |
||||
|
# |
||||
|
#RACKSPACE_Username="" |
||||
|
# |
||||
|
#RACKSPACE_Apikey="" |
||||
|
|
||||
|
RACKSPACE_Endpoint="https://dns.api.rackspacecloud.com/v1.0" |
||||
|
|
||||
|
# 20190213 - The name & id fields swapped in the API response; fix sed |
||||
|
# 20190101 - Duplicating file for new pull request to dev branch |
||||
|
# Original - tcocca:rackspace_dnsapi https://github.com/Neilpang/acme.sh/pull/1297 |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_rackspace_add() { |
||||
|
fulldomain="$1" |
||||
|
_debug fulldomain="$fulldomain" |
||||
|
txtvalue="$2" |
||||
|
_debug txtvalue="$txtvalue" |
||||
|
_rackspace_check_auth || return 1 |
||||
|
_rackspace_check_rootzone || return 1 |
||||
|
_info "Creating TXT record." |
||||
|
if ! _rackspace_rest POST "$RACKSPACE_Tenant/domains/$_domain_id/records" "{\"records\":[{\"name\":\"$fulldomain\",\"type\":\"TXT\",\"data\":\"$txtvalue\",\"ttl\":300}]}"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
if ! _contains "$response" "$txtvalue" >/dev/null; then |
||||
|
_err "Could not add TXT record." |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_rackspace_rm() { |
||||
|
fulldomain=$1 |
||||
|
_debug fulldomain="$fulldomain" |
||||
|
txtvalue=$2 |
||||
|
_debug txtvalue="$txtvalue" |
||||
|
_rackspace_check_auth || return 1 |
||||
|
_rackspace_check_rootzone || return 1 |
||||
|
_info "Checking for TXT record." |
||||
|
if ! _get_recordid "$_domain_id" "$fulldomain" "$txtvalue"; then |
||||
|
_err "Could not get TXT record id." |
||||
|
return 1 |
||||
|
fi |
||||
|
if [ "$_dns_record_id" = "" ]; then |
||||
|
_err "TXT record not found." |
||||
|
return 1 |
||||
|
fi |
||||
|
_info "Removing TXT record." |
||||
|
if ! _delete_txt_record "$_domain_id" "$_dns_record_id"; then |
||||
|
_err "Could not remove TXT record $_dns_record_id." |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_get_root_zone() { |
||||
|
domain="$1" |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _rackspace_rest GET "$RACKSPACE_Tenant/domains"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then |
||||
|
# Response looks like: |
||||
|
# {"ttl":300,"accountId":12345,"id":1111111,"name":"example.com","emailAddress": ...<and so on> |
||||
|
_domain_id=$(echo "$response" | sed -n "s/^.*\"id\":\([^,]*\),\"name\":\"$h\",.*/\1/p") |
||||
|
_debug2 domain_id "$_domain_id" |
||||
|
if [ -n "$_domain_id" ]; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_get_recordid() { |
||||
|
domainid="$1" |
||||
|
fulldomain="$2" |
||||
|
txtvalue="$3" |
||||
|
if ! _rackspace_rest GET "$RACKSPACE_Tenant/domains/$domainid/records?name=$fulldomain&type=TXT"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug response "$response" |
||||
|
if ! _contains "$response" "$txtvalue"; then |
||||
|
_dns_record_id=0 |
||||
|
return 0 |
||||
|
fi |
||||
|
_dns_record_id=$(echo "$response" | tr '{' "\n" | grep "\"data\":\"$txtvalue\"" | sed -n 's/^.*"id":"\([^"]*\)".*/\1/p') |
||||
|
_debug _dns_record_id "$_dns_record_id" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_delete_txt_record() { |
||||
|
domainid="$1" |
||||
|
_dns_record_id="$2" |
||||
|
if ! _rackspace_rest DELETE "$RACKSPACE_Tenant/domains/$domainid/records?id=$_dns_record_id"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug response "$response" |
||||
|
if ! _contains "$response" "RUNNING"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_rest() { |
||||
|
m="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
_debug ep "$ep" |
||||
|
export _H1="Accept: application/json" |
||||
|
export _H2="X-Auth-Token: $RACKSPACE_Token" |
||||
|
export _H3="X-Project-Id: $RACKSPACE_Tenant" |
||||
|
export _H4="Content-Type: application/json" |
||||
|
if [ "$m" != "GET" ]; then |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$RACKSPACE_Endpoint/$ep" "" "$m")" |
||||
|
retcode=$? |
||||
|
else |
||||
|
_info "Getting $RACKSPACE_Endpoint/$ep" |
||||
|
response="$(_get "$RACKSPACE_Endpoint/$ep")" |
||||
|
retcode=$? |
||||
|
fi |
||||
|
|
||||
|
if [ "$retcode" != "0" ]; then |
||||
|
_err "error $ep" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_authorization() { |
||||
|
export _H1="Content-Type: application/json" |
||||
|
data="{\"auth\":{\"RAX-KSKEY:apiKeyCredentials\":{\"username\":\"$RACKSPACE_Username\",\"apiKey\":\"$RACKSPACE_Apikey\"}}}" |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "https://identity.api.rackspacecloud.com/v2.0/tokens" "" "POST")" |
||||
|
retcode=$? |
||||
|
_debug2 response "$response" |
||||
|
if [ "$retcode" != "0" ]; then |
||||
|
_err "Authentication failed." |
||||
|
return 1 |
||||
|
fi |
||||
|
if _contains "$response" "token"; then |
||||
|
RACKSPACE_Token="$(echo "$response" | _normalizeJson | sed -n 's/^.*"token":{.*,"id":"\([^"]*\)",".*/\1/p')" |
||||
|
RACKSPACE_Tenant="$(echo "$response" | _normalizeJson | sed -n 's/^.*"token":{.*,"id":"\([^"]*\)"}.*/\1/p')" |
||||
|
_debug RACKSPACE_Token "$RACKSPACE_Token" |
||||
|
_debug RACKSPACE_Tenant "$RACKSPACE_Tenant" |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_rackspace_check_auth() { |
||||
|
# retrieve the rackspace creds |
||||
|
RACKSPACE_Username="${RACKSPACE_Username:-$(_readaccountconf_mutable RACKSPACE_Username)}" |
||||
|
RACKSPACE_Apikey="${RACKSPACE_Apikey:-$(_readaccountconf_mutable RACKSPACE_Apikey)}" |
||||
|
# check their vals for null |
||||
|
if [ -z "$RACKSPACE_Username" ] || [ -z "$RACKSPACE_Apikey" ]; then |
||||
|
RACKSPACE_Username="" |
||||
|
RACKSPACE_Apikey="" |
||||
|
_err "You didn't specify a Rackspace username and api key." |
||||
|
_err "Please set those values and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
# save the username and api key to the account conf file. |
||||
|
_saveaccountconf_mutable RACKSPACE_Username "$RACKSPACE_Username" |
||||
|
_saveaccountconf_mutable RACKSPACE_Apikey "$RACKSPACE_Apikey" |
||||
|
if [ -z "$RACKSPACE_Token" ]; then |
||||
|
_info "Getting authorization token." |
||||
|
if ! _rackspace_authorization; then |
||||
|
_err "Can not get token." |
||||
|
fi |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
_rackspace_check_rootzone() { |
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root_zone "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _domain_id "$_domain_id" |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
} |
@ -0,0 +1,69 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# |
||||
|
# tele3.cz DNS API |
||||
|
# |
||||
|
# Author: Roman Blizik |
||||
|
# Report Bugs here: https://github.com/par-pa/acme.sh |
||||
|
# |
||||
|
# -- |
||||
|
# export TELE3_Key="MS2I4uPPaI..." |
||||
|
# export TELE3_Secret="kjhOIHGJKHg" |
||||
|
# -- |
||||
|
|
||||
|
TELE3_API="https://www.tele3.cz/acme/" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
dns_tele3_add() { |
||||
|
_info "Using TELE3 DNS" |
||||
|
data="\"ope\":\"add\", \"domain\":\"$1\", \"value\":\"$2\"" |
||||
|
if ! _tele3_call; then |
||||
|
_err "Publish zone failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Zone published" |
||||
|
} |
||||
|
|
||||
|
dns_tele3_rm() { |
||||
|
_info "Using TELE3 DNS" |
||||
|
data="\"ope\":\"rm\", \"domain\":\"$1\", \"value\":\"$2\"" |
||||
|
if ! _tele3_call; then |
||||
|
_err "delete TXT record failed" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "TXT record successfully deleted" |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_tele3_init() { |
||||
|
TELE3_Key="${TELE3_Key:-$(_readaccountconf_mutable TELE3_Key)}" |
||||
|
TELE3_Secret="${TELE3_Secret:-$(_readaccountconf_mutable TELE3_Secret)}" |
||||
|
if [ -z "$TELE3_Key" ] || [ -z "$TELE3_Secret" ]; then |
||||
|
TELE3_Key="" |
||||
|
TELE3_Secret="" |
||||
|
_err "You must export variables: TELE3_Key and TELE3_Secret" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the config variables to the account conf file. |
||||
|
_saveaccountconf_mutable TELE3_Key "$TELE3_Key" |
||||
|
_saveaccountconf_mutable TELE3_Secret "$TELE3_Secret" |
||||
|
} |
||||
|
|
||||
|
_tele3_call() { |
||||
|
_tele3_init |
||||
|
data="{\"key\":\"$TELE3_Key\", \"secret\":\"$TELE3_Secret\", $data}" |
||||
|
|
||||
|
_debug data "$data" |
||||
|
|
||||
|
response="$(_post "$data" "$TELE3_API" "" "POST")" |
||||
|
_debug response "$response" |
||||
|
|
||||
|
if [ "$response" != "success" ]; then |
||||
|
_err "$response" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
@ -0,0 +1,139 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
Zilore_API="https://api.zilore.com/dns/v1" |
||||
|
# Zilore_Key="YOUR-ZILORE-API-KEY" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
dns_zilore_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_info "Using Zilore" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
Zilore_Key="${Zilore_Key:-$(_readaccountconf_mutable Zilore_Key)}" |
||||
|
if [ -z "$Zilore_Key" ]; then |
||||
|
Zilore_Key="" |
||||
|
_err "Please define Zilore API key" |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable Zilore_Key "$Zilore_Key" |
||||
|
|
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "Unable to determine root domain" |
||||
|
return 1 |
||||
|
else |
||||
|
_debug _domain "$_domain" |
||||
|
fi |
||||
|
|
||||
|
if _zilore_rest POST "domains/$_domain/records?record_type=TXT&record_ttl=600&record_name=$fulldomain&record_value=\"$txtvalue\""; then |
||||
|
if _contains "$response" '"added"' >/dev/null; then |
||||
|
_info "Added TXT record, waiting for validation" |
||||
|
return 0 |
||||
|
else |
||||
|
_debug response "$response" |
||||
|
_err "Error while adding DNS records" |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
dns_zilore_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_info "Using Zilore" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
Zilore_Key="${Zilore_Key:-$(_readaccountconf_mutable Zilore_Key)}" |
||||
|
if [ -z "$Zilore_Key" ]; then |
||||
|
Zilore_Key="" |
||||
|
_err "Please define Zilore API key" |
||||
|
return 1 |
||||
|
fi |
||||
|
_saveaccountconf_mutable Zilore_Key "$Zilore_Key" |
||||
|
|
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "Unable to determine root domain" |
||||
|
return 1 |
||||
|
else |
||||
|
_debug _domain "$_domain" |
||||
|
fi |
||||
|
|
||||
|
_debug "Getting TXT records" |
||||
|
_zilore_rest GET "domains/${_domain}/records?search_text=$txtvalue&search_record_type=TXT" |
||||
|
_debug response "$response" |
||||
|
|
||||
|
if ! _contains "$response" '"ok"' >/dev/null; then |
||||
|
_err "Error while getting records list" |
||||
|
return 1 |
||||
|
else |
||||
|
_record_id=$(printf "%s\n" "$response" | _egrep_o "\"record_id\":\"[^\"]+\"" | cut -d : -f 2 | tr -d \" | _head_n 1) |
||||
|
if [ -z "$_record_id" ]; then |
||||
|
_err "Cannot determine _record_id" |
||||
|
return 1 |
||||
|
else |
||||
|
_debug _record_id "$_record_id" |
||||
|
fi |
||||
|
if ! _zilore_rest DELETE "domains/${_domain}/records?record_id=$_record_id"; then |
||||
|
_err "Error while deleting chosen record" |
||||
|
return 1 |
||||
|
fi |
||||
|
_contains "$response" '"ok"' |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
_get_root() { |
||||
|
domain=$1 |
||||
|
i=2 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _zilore_rest GET "domains?search_text=$h"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"$h\"" >/dev/null; then |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
else |
||||
|
_debug "$h not found" |
||||
|
fi |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_zilore_rest() { |
||||
|
method=$1 |
||||
|
param=$2 |
||||
|
data=$3 |
||||
|
|
||||
|
export _H1="X-Auth-Key: $Zilore_Key" |
||||
|
|
||||
|
if [ "$method" != "GET" ]; then |
||||
|
response="$(_post "$data" "$Zilore_API/$param" "" "$method")" |
||||
|
else |
||||
|
response="$(_get "$Zilore_API/$param")" |
||||
|
fi |
||||
|
|
||||
|
if [ "$?" != "0" ]; then |
||||
|
_err "error $param" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug2 response "$response" |
||||
|
return 0 |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue