forked from Github/acme.sh
Ne-Lexa
6 years ago
16 changed files with 1160 additions and 52 deletions
-
1Dockerfile
-
6README.md
-
98acme.sh
-
36deploy/README.md
-
12deploy/vault_cli.sh
-
129dnsapi/README.md
-
2dnsapi/dns_azure.sh
-
36dnsapi/dns_cf.sh
-
4dnsapi/dns_cx.sh
-
168dnsapi/dns_exoscale.sh
-
4dnsapi/dns_he.sh
-
109dnsapi/dns_hostingde.sh
-
185dnsapi/dns_linode_v4.sh
-
210dnsapi/dns_mydnsjp.sh
-
181dnsapi/dns_neodigit.sh
-
27dnsapi/dns_nsupdate.sh
@ -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,109 @@ |
|||||
|
#!/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 |
||||
|
} |
||||
|
|
||||
|
dns_hostingde_rm() { |
||||
|
fulldomain="${1}" |
||||
|
txtvalue="${2}" |
||||
|
_debug "Calling: _hostingde_removeRecord() '${fulldomain}' '${txtvalue}'" |
||||
|
_hostingde_apiKey && _hostingde_getZoneConfig && _hostingde_removeRecord |
||||
|
} |
||||
|
|
||||
|
#################### 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_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}'" |
||||
|
|
||||
|
# read ZoneConfigId for later update |
||||
|
zoneConfigId=$(echo "${curResult}" | _egrep_o '"id":.*' | cut -d ':' -f 2 | cut -d '"' -f 2) |
||||
|
_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_addRecord() { |
||||
|
_info "Adding record to zone" |
||||
|
curData="{\"authToken\":\"${HOSTINGDE_APIKEY}\",\"zoneConfig\":{\"id\":\"${zoneConfigId}\"},\"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" |
||||
|
curData="{\"authToken\":\"${HOSTINGDE_APIKEY}\",\"zoneConfig\":{\"id\":\"${zoneConfigId}\"},\"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,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_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_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,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,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 |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue