Unverified Commit dfe80556 authored by lufi42's avatar lufi42 Committed by GitHub
Browse files

Merge branch 'acmesh-official:dev' into dev

parents 6d2ab4d2 6ccf617d
...@@ -98,7 +98,7 @@ _dns_gcloud_remove_rrs() { ...@@ -98,7 +98,7 @@ _dns_gcloud_remove_rrs() {
--ttl="$ttl" \ --ttl="$ttl" \
--type=TXT \ --type=TXT \
--zone="$managedZone" \ --zone="$managedZone" \
--transaction-file="$tr"; then --transaction-file="$tr" --; then
_debug tr "$(cat "$tr")" _debug tr "$(cat "$tr")"
rm -r "$trd" rm -r "$trd"
_err "_dns_gcloud_remove_rrs: failed to remove RRs" _err "_dns_gcloud_remove_rrs: failed to remove RRs"
...@@ -113,7 +113,7 @@ _dns_gcloud_add_rrs() { ...@@ -113,7 +113,7 @@ _dns_gcloud_add_rrs() {
--ttl="$ttl" \ --ttl="$ttl" \
--type=TXT \ --type=TXT \
--zone="$managedZone" \ --zone="$managedZone" \
--transaction-file="$tr"; then --transaction-file="$tr" --; then
_debug tr "$(cat "$tr")" _debug tr "$(cat "$tr")"
rm -r "$trd" rm -r "$trd"
_err "_dns_gcloud_add_rrs: failed to add RRs" _err "_dns_gcloud_add_rrs: failed to add RRs"
......
#!/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() {
#args $1: fulldomain, $2: txtvalue
#returns id of dns entry, if it exists
_myget "action=dns_primary_changeDNSsetup&user_domain=$_domain"
_debug3 "_result: $_result"
_tmp_result=$(echo "$_result" | tr -d '\n\r' | _egrep_o "<td>$1</td>\s*<td>$2</td>[^?]*[^&]*&id=[^&]*")
_debug _tmp_result "$_tmp_result"
if [ -z "${_tmp_result:-}" ]; then
_debug "The variable is _tmp_result is not supposed to be empty, there may be something wrong with the script"
fi
_id=$(echo "$_tmp_result" | sed 's/^.*=//')
if [ -n "$_id" ]; then
_debug "Entry found with _id=$_id"
return 0
fi
return 1
}
...@@ -58,6 +58,17 @@ dns_geoscaling_rm() { ...@@ -58,6 +58,17 @@ dns_geoscaling_rm() {
txt_value=$2 txt_value=$2
_info "Cleaning up after DNS-01 Geoscaling DNS2 hook" _info "Cleaning up after DNS-01 Geoscaling DNS2 hook"
GEOSCALING_Username="${GEOSCALING_Username:-$(_readaccountconf_mutable GEOSCALING_Username)}"
GEOSCALING_Password="${GEOSCALING_Password:-$(_readaccountconf_mutable GEOSCALING_Password)}"
if [ -z "$GEOSCALING_Username" ] || [ -z "$GEOSCALING_Password" ]; then
GEOSCALING_Username=
GEOSCALING_Password=
_err "No auth details provided. Please set user credentials using the \$GEOSCALING_Username and \$GEOSCALING_Password environment variables."
return 1
fi
_saveaccountconf_mutable GEOSCALING_Username "${GEOSCALING_Username}"
_saveaccountconf_mutable GEOSCALING_Password "${GEOSCALING_Password}"
# fills in the $zone_id # fills in the $zone_id
find_zone "${full_domain}" || return 1 find_zone "${full_domain}" || return 1
_debug "Zone id '${zone_id}' will be used." _debug "Zone id '${zone_id}' will be used."
......
#!/usr/bin/env sh #!/usr/bin/env sh
# Supports IONOS DNS API Beta v1.0.0 # Supports IONOS DNS API v1.0.1
# #
# Usage: # Usage:
# Export IONOS_PREFIX and IONOS_SECRET before calling acme.sh: # Export IONOS_PREFIX and IONOS_SECRET before calling acme.sh:
...@@ -26,7 +26,7 @@ dns_ionos_add() { ...@@ -26,7 +26,7 @@ dns_ionos_add() {
_body="[{\"name\":\"$_sub_domain.$_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"ttl\":$IONOS_TXT_TTL,\"prio\":$IONOS_TXT_PRIO,\"disabled\":false}]" _body="[{\"name\":\"$_sub_domain.$_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"ttl\":$IONOS_TXT_TTL,\"prio\":$IONOS_TXT_PRIO,\"disabled\":false}]"
if _ionos_rest POST "$IONOS_ROUTE_ZONES/$_zone_id/records" "$_body" && [ -z "$response" ]; then if _ionos_rest POST "$IONOS_ROUTE_ZONES/$_zone_id/records" "$_body" && [ "$_code" = "201" ]; then
_info "TXT record has been created successfully." _info "TXT record has been created successfully."
return 0 return 0
fi fi
...@@ -47,7 +47,7 @@ dns_ionos_rm() { ...@@ -47,7 +47,7 @@ dns_ionos_rm() {
return 1 return 1
fi fi
if _ionos_rest DELETE "$IONOS_ROUTE_ZONES/$_zone_id/records/$_record_id" && [ -z "$response" ]; then if _ionos_rest DELETE "$IONOS_ROUTE_ZONES/$_zone_id/records/$_record_id" && [ "$_code" = "200" ]; then
_info "TXT record has been deleted successfully." _info "TXT record has been deleted successfully."
return 0 return 0
fi fi
...@@ -85,7 +85,7 @@ _get_root() { ...@@ -85,7 +85,7 @@ _get_root() {
p=1 p=1
if _ionos_rest GET "$IONOS_ROUTE_ZONES"; then if _ionos_rest GET "$IONOS_ROUTE_ZONES"; then
response="$(echo "$response" | tr -d "\n")" _response="$(echo "$_response" | tr -d "\n")"
while true; do while true; do
h=$(printf "%s" "$domain" | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
...@@ -93,7 +93,7 @@ _get_root() { ...@@ -93,7 +93,7 @@ _get_root() {
return 1 return 1
fi fi
_zone="$(echo "$response" | _egrep_o "\"name\":\"$h\".*\}")" _zone="$(echo "$_response" | _egrep_o "\"name\":\"$h\".*\}")"
if [ "$_zone" ]; then if [ "$_zone" ]; then
_zone_id=$(printf "%s\n" "$_zone" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"') _zone_id=$(printf "%s\n" "$_zone" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"')
if [ "$_zone_id" ]; then if [ "$_zone_id" ]; then
...@@ -120,9 +120,9 @@ _ionos_get_record() { ...@@ -120,9 +120,9 @@ _ionos_get_record() {
txtrecord=$3 txtrecord=$3
if _ionos_rest GET "$IONOS_ROUTE_ZONES/$zone_id?recordName=$fulldomain&recordType=TXT"; then if _ionos_rest GET "$IONOS_ROUTE_ZONES/$zone_id?recordName=$fulldomain&recordType=TXT"; then
response="$(echo "$response" | tr -d "\n")" _response="$(echo "$_response" | tr -d "\n")"
_record="$(echo "$response" | _egrep_o "\"name\":\"$fulldomain\"[^\}]*\"type\":\"TXT\"[^\}]*\"content\":\"\\\\\"$txtrecord\\\\\"\".*\}")" _record="$(echo "$_response" | _egrep_o "\"name\":\"$fulldomain\"[^\}]*\"type\":\"TXT\"[^\}]*\"content\":\"\\\\\"$txtrecord\\\\\"\".*\}")"
if [ "$_record" ]; then if [ "$_record" ]; then
_record_id=$(printf "%s\n" "$_record" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"') _record_id=$(printf "%s\n" "$_record" | _egrep_o "\"id\":\"[a-fA-F0-9\-]*\"" | _head_n 1 | cut -d : -f 2 | tr -d '\"')
...@@ -142,22 +142,30 @@ _ionos_rest() { ...@@ -142,22 +142,30 @@ _ionos_rest() {
export _H1="X-API-Key: $IONOS_API_KEY" export _H1="X-API-Key: $IONOS_API_KEY"
# clear headers
: >"$HTTP_HEADER"
if [ "$method" != "GET" ]; then if [ "$method" != "GET" ]; then
export _H2="Accept: application/json" export _H2="Accept: application/json"
export _H3="Content-Type: application/json" export _H3="Content-Type: application/json"
response="$(_post "$data" "$IONOS_API$route" "" "$method" "application/json")" _response="$(_post "$data" "$IONOS_API$route" "" "$method" "application/json")"
else else
export _H2="Accept: */*" export _H2="Accept: */*"
export _H3= export _H3=
response="$(_get "$IONOS_API$route")"
_response="$(_get "$IONOS_API$route")"
fi fi
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
_err "Error $route: $response" _err "Error $route: $_response"
return 1 return 1
fi fi
_debug2 "response" "$response"
_debug2 "_response" "$_response"
_debug2 "_code" "$_code"
return 0 return 0
} }
...@@ -32,7 +32,7 @@ dns_ispconfig_rm() { ...@@ -32,7 +32,7 @@ dns_ispconfig_rm() {
#################### Private functions below ################################## #################### Private functions below ##################################
_ISPC_credentials() { _ISPC_credentials() {
if [ -z "${ISPC_User}" ] || [ -z "$ISPC_Password" ] || [ -z "${ISPC_Api}" ] || [ -z "${ISPC_Api_Insecure}" ]; then if [ -z "${ISPC_User}" ] || [ -z "${ISPC_Password}" ] || [ -z "${ISPC_Api}" ] || [ -z "${ISPC_Api_Insecure}" ]; then
ISPC_User="" ISPC_User=""
ISPC_Password="" ISPC_Password=""
ISPC_Api="" ISPC_Api=""
......
...@@ -32,8 +32,12 @@ dns_loopia_add() { ...@@ -32,8 +32,12 @@ dns_loopia_add() {
_info "Adding record" _info "Adding record"
_loopia_add_sub_domain "$_domain" "$_sub_domain" if ! _loopia_add_sub_domain "$_domain" "$_sub_domain"; then
_loopia_add_record "$_domain" "$_sub_domain" "$txtvalue" return 1
fi
if ! _loopia_add_record "$_domain" "$_sub_domain" "$txtvalue"; then
return 1
fi
} }
...@@ -70,12 +74,13 @@ dns_loopia_rm() { ...@@ -70,12 +74,13 @@ dns_loopia_rm() {
<value><string>%s</string></value> <value><string>%s</string></value>
</param> </param>
</params> </params>
</methodCall>' "$LOOPIA_User" "$LOOPIA_Password" "$_domain" "$_sub_domain") </methodCall>' "$LOOPIA_User" "$Encoded_Password" "$_domain" "$_sub_domain")
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
if ! _contains "$response" "OK"; then if ! _contains "$response" "OK"; then
_err "Error could not get txt records" err_response=$(echo "$response" | sed 's/.*<string>\(.*\)<\/string>.*/\1/')
_err "Error could not get txt records: $err_response"
return 1 return 1
fi fi
} }
...@@ -101,6 +106,12 @@ _loopia_load_config() { ...@@ -101,6 +106,12 @@ _loopia_load_config() {
return 1 return 1
fi fi
if _contains "$LOOPIA_Password" "'" || _contains "$LOOPIA_Password" '"'; then
_err "Password contains quoute or double quoute and this is not supported by dns_loopia.sh"
return 1
fi
Encoded_Password=$(_xml_encode "$LOOPIA_Password")
return 0 return 0
} }
...@@ -133,11 +144,12 @@ _loopia_get_records() { ...@@ -133,11 +144,12 @@ _loopia_get_records() {
<value><string>%s</string></value> <value><string>%s</string></value>
</param> </param>
</params> </params>
</methodCall>' "$LOOPIA_User" "$LOOPIA_Password" "$domain" "$sub_domain") </methodCall>' "$LOOPIA_User" "$Encoded_Password" "$domain" "$sub_domain")
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
if ! _contains "$response" "<array>"; then if ! _contains "$response" "<array>"; then
_err "Error" err_response=$(echo "$response" | sed 's/.*<string>\(.*\)<\/string>.*/\1/')
_err "Error: $err_response"
return 1 return 1
fi fi
return 0 return 0
...@@ -162,7 +174,7 @@ _get_root() { ...@@ -162,7 +174,7 @@ _get_root() {
<value><string>%s</string></value> <value><string>%s</string></value>
</param> </param>
</params> </params>
</methodCall>' "$LOOPIA_User" "$LOOPIA_Password") </methodCall>' "$LOOPIA_User" "$Encoded_Password")
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
while true; do while true; do
...@@ -228,12 +240,13 @@ _loopia_add_record() { ...@@ -228,12 +240,13 @@ _loopia_add_record() {
</value> </value>
</param> </param>
</params> </params>
</methodCall>' "$LOOPIA_User" "$LOOPIA_Password" "$domain" "$sub_domain" "$txtval") </methodCall>' "$LOOPIA_User" "$Encoded_Password" "$domain" "$sub_domain" "$txtval")
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
if ! _contains "$response" "OK"; then if ! _contains "$response" "OK"; then
_err "Error" err_response=$(echo "$response" | sed 's/.*<string>\(.*\)<\/string>.*/\1/')
_err "Error: $err_response"
return 1 return 1
fi fi
return 0 return 0
...@@ -257,7 +270,7 @@ _sub_domain_exists() { ...@@ -257,7 +270,7 @@ _sub_domain_exists() {
<value><string>%s</string></value> <value><string>%s</string></value>
</param> </param>
</params> </params>
</methodCall>' "$LOOPIA_User" "$LOOPIA_Password" "$domain") </methodCall>' "$LOOPIA_User" "$Encoded_Password" "$domain")
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
...@@ -292,13 +305,22 @@ _loopia_add_sub_domain() { ...@@ -292,13 +305,22 @@ _loopia_add_sub_domain() {
<value><string>%s</string></value> <value><string>%s</string></value>
</param> </param>
</params> </params>
</methodCall>' "$LOOPIA_User" "$LOOPIA_Password" "$domain" "$sub_domain") </methodCall>' "$LOOPIA_User" "$Encoded_Password" "$domain" "$sub_domain")
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")" response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
if ! _contains "$response" "OK"; then if ! _contains "$response" "OK"; then
_err "Error" err_response=$(echo "$response" | sed 's/.*<string>\(.*\)<\/string>.*/\1/')
_err "Error: $err_response"
return 1 return 1
fi fi
return 0 return 0
} }
_xml_encode() {
encoded_string=$1
encoded_string=$(echo "$encoded_string" | sed 's/&/\&amp;/')
encoded_string=$(echo "$encoded_string" | sed 's/</\&lt;/')
encoded_string=$(echo "$encoded_string" | sed 's/>/\&gt;/')
printf "%s" "$encoded_string"
}
...@@ -74,7 +74,7 @@ dns_mydevil_rm() { ...@@ -74,7 +74,7 @@ dns_mydevil_rm() {
validRecords="^${num}${w}${fulldomain}${w}TXT${w}${any}${txtvalue}$" 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 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" _info "Removing record $id from domain $domain"
devil dns del "$domain" "$id" || _err "Could not remove DNS record." echo "y" | devil dns del "$domain" "$id" || _err "Could not remove DNS record."
done done
} }
...@@ -87,7 +87,9 @@ mydevil_get_domain() { ...@@ -87,7 +87,9 @@ mydevil_get_domain() {
domain="" domain=""
for domain in $(devil dns list | cut -w -s -f 1 | tail -n+2); do for domain in $(devil dns list | cut -w -s -f 1 | tail -n+2); do
_debug "Checking domain: $domain"
if _endswith "$fulldomain" "$domain"; then if _endswith "$fulldomain" "$domain"; then
_debug "Fulldomain '$fulldomain' matches '$domain'"
printf -- "%s" "$domain" printf -- "%s" "$domain"
return 0 return 0
fi fi
......
...@@ -259,7 +259,7 @@ _set_namecheap_TXT() { ...@@ -259,7 +259,7 @@ _set_namecheap_TXT() {
_debug hosts "$hosts" _debug hosts "$hosts"
if [ -z "$hosts" ]; then if [ -z "$hosts" ]; then
_error "Hosts not found" _err "Hosts not found"
return 1 return 1
fi fi
...@@ -313,7 +313,7 @@ _del_namecheap_TXT() { ...@@ -313,7 +313,7 @@ _del_namecheap_TXT() {
_debug hosts "$hosts" _debug hosts "$hosts"
if [ -z "$hosts" ]; then if [ -z "$hosts" ]; then
_error "Hosts not found" _err "Hosts not found"
return 1 return 1
fi fi
......
#!/usr/bin/env sh #!/usr/bin/env sh
#NederHost_Key="sdfgikogfdfghjklkjhgfcdcfghjk" #NederHost_Key="sdfgikogfdfghjklkjhgfcdcfghj"
NederHost_Api="https://api.nederhost.nl/dns/v1" NederHost_Api="https://api.nederhost.nl/dns/v1"
...@@ -112,12 +112,8 @@ _nederhost_rest() { ...@@ -112,12 +112,8 @@ _nederhost_rest() {
export _H1="Authorization: Bearer $NederHost_Key" export _H1="Authorization: Bearer $NederHost_Key"
export _H2="Content-Type: application/json" export _H2="Content-Type: application/json"
if [ "$m" != "GET" ]; then _debug data "$data"
_debug data "$data" response="$(_post "$data" "$NederHost_Api/$ep" "" "$m")"
response="$(_post "$data" "$NederHost_Api/$ep" "" "$m")"
else
response="$(_get "$NederHost_Api/$ep")"
fi
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")" _code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
_debug "http response code $_code" _debug "http response code $_code"
......
...@@ -114,7 +114,7 @@ _get_root() { ...@@ -114,7 +114,7 @@ _get_root() {
fi fi
if _contains "$response" "\"name\":\"$h\"" >/dev/null; then if _contains "$response" "\"name\":\"$h\"" >/dev/null; then
_domain_id=$(echo "$response" | _egrep_o "\"[^\"]*\",\"name\":\"$h" | cut -d , -f 1 | tr -d \") _domain_id=$(echo "$response" | _egrep_o "\"[^\"]*\",\"name\":\"$h\"" | cut -d , -f 1 | tr -d \")
if [ "$_domain_id" ]; then if [ "$_domain_id" ]; then
if [ "$i" = 1 ]; then if [ "$i" = 1 ]; then
#create the record at the domain apex (@) if only the domain name was provided as --domain-alias #create the record at the domain apex (@) if only the domain name was provided as --domain-alias
......
...@@ -159,7 +159,7 @@ _oci_config() { ...@@ -159,7 +159,7 @@ _oci_config() {
fi fi
if [ "$(printf "%s\n" "$OCI_CLI_KEY" | wc -l)" -eq 1 ]; then if [ "$(printf "%s\n" "$OCI_CLI_KEY" | wc -l)" -eq 1 ]; then
OCI_CLI_KEY=$(printf "%s" "$OCI_CLI_KEY" | _dbase64 multiline) OCI_CLI_KEY=$(printf "%s" "$OCI_CLI_KEY" | _dbase64)
fi fi
return 0 return 0
......
...@@ -198,6 +198,8 @@ dns_ovh_rm() { ...@@ -198,6 +198,8 @@ dns_ovh_rm() {
if ! _ovh_rest DELETE "domain/zone/$_domain/record/$rid"; then if ! _ovh_rest DELETE "domain/zone/$_domain/record/$rid"; then
return 1 return 1
fi fi
_ovh_rest POST "domain/zone/$_domain/refresh"
_debug "Refresh:$response"
return 0 return 0
fi fi
done done
......
...@@ -76,7 +76,7 @@ dns_selectel_rm() { ...@@ -76,7 +76,7 @@ dns_selectel_rm() {
return 1 return 1
fi fi
_record_seg="$(echo "$response" | _egrep_o "\"content\" *: *\"$txtvalue\"[^}]*}")" _record_seg="$(echo "$response" | _egrep_o "[^{]*\"content\" *: *\"$txtvalue\"[^}]*}")"
_debug2 "_record_seg" "$_record_seg" _debug2 "_record_seg" "$_record_seg"
if [ -z "$_record_seg" ]; then if [ -z "$_record_seg" ]; then
_err "can not find _record_seg" _err "can not find _record_seg"
...@@ -120,7 +120,7 @@ _get_root() { ...@@ -120,7 +120,7 @@ _get_root() {
return 1 return 1
fi fi
if _contains "$response" "\"name\": \"$h\","; then if _contains "$response" "\"name\" *: *\"$h\","; then
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_domain=$h _domain=$h
_debug "Getting domain id for $h" _debug "Getting domain id for $h"
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#SIMPLY_AccountName="accountname" #SIMPLY_AccountName="accountname"
#SIMPLY_ApiKey="apikey" #SIMPLY_ApiKey="apikey"
# #
#SIMPLY_Api="https://api.simply.com/1/[ACCOUNTNAME]/[APIKEY]" #SIMPLY_Api="https://api.simply.com/2/"
SIMPLY_Api_Default="https://api.simply.com/1" SIMPLY_Api_Default="https://api.simply.com/2"
#This is used for determining success of REST call #This is used for determining success of REST call
SIMPLY_SUCCESS_CODE='"status":200' SIMPLY_SUCCESS_CODE='"status":200'
...@@ -237,12 +237,18 @@ _simply_rest() { ...@@ -237,12 +237,18 @@ _simply_rest() {
_debug2 ep "$ep" _debug2 ep "$ep"
_debug2 m "$m" _debug2 m "$m"
export _H1="Content-Type: application/json" basicauth=$(printf "%s:%s" "$SIMPLY_AccountName" "$SIMPLY_ApiKey" | _base64)
if [ "$basicauth" ]; then
export _H1="Authorization: Basic $basicauth"
fi
export _H2="Content-Type: application/json"
if [ "$m" != "GET" ]; then if [ "$m" != "GET" ]; then
response="$(_post "$data" "$SIMPLY_Api/$SIMPLY_AccountName/$SIMPLY_ApiKey/$ep" "" "$m")" response="$(_post "$data" "$SIMPLY_Api/$ep" "" "$m")"
else else
response="$(_get "$SIMPLY_Api/$SIMPLY_AccountName/$SIMPLY_ApiKey/$ep")" response="$(_get "$SIMPLY_Api/$ep")"
fi fi
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
# #
# ULTRA_PWD="some_password_goes_here" # ULTRA_PWD="some_password_goes_here"
ULTRA_API="https://restapi.ultradns.com/v2/" ULTRA_API="https://api.ultradns.com/v3/"
ULTRA_AUTH_API="https://api.ultradns.com/v2/"
#Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt" #Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt"
dns_ultra_add() { dns_ultra_add() {
...@@ -121,7 +122,7 @@ _get_root() { ...@@ -121,7 +122,7 @@ _get_root() {
return 1 return 1
fi fi
if _contains "${response}" "${h}." >/dev/null; then if _contains "${response}" "${h}." >/dev/null; then
_domain_id=$(echo "$response" | _egrep_o "${h}") _domain_id=$(echo "$response" | _egrep_o "${h}" | head -1)
if [ "$_domain_id" ]; then if [ "$_domain_id" ]; then
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_domain="${h}" _domain="${h}"
...@@ -142,23 +143,25 @@ _ultra_rest() { ...@@ -142,23 +143,25 @@ _ultra_rest() {
ep="$2" ep="$2"
data="$3" data="$3"
_debug "$ep" _debug "$ep"
_debug TOKEN "${AUTH_TOKEN}" if [ -z "$AUTH_TOKEN" ]; then
_ultra_login
fi
_debug TOKEN "$AUTH_TOKEN"
_ultra_login
export _H1="Content-Type: application/json" export _H1="Content-Type: application/json"
export _H2="Authorization: Bearer ${AUTH_TOKEN}" export _H2="Authorization: Bearer $AUTH_TOKEN"
if [ "$m" != "GET" ]; then if [ "$m" != "GET" ]; then
_debug data "${data}" _debug data "$data"
response="$(_post "${data}" "${ULTRA_API}"/"${ep}" "" "${m}")" response="$(_post "$data" "$ULTRA_API$ep" "" "$m")"
else else
response="$(_get "$ULTRA_API/$ep")" response="$(_get "$ULTRA_API$ep")"
fi fi
} }
_ultra_login() { _ultra_login() {
export _H1="" export _H1=""
export _H2="" export _H2=""
AUTH_TOKEN=$(_post "grant_type=password&username=${ULTRA_USR}&password=${ULTRA_PWD}" "${ULTRA_API}authorization/token" | cut -d, -f3 | cut -d\" -f4) AUTH_TOKEN=$(_post "grant_type=password&username=${ULTRA_USR}&password=${ULTRA_PWD}" "${ULTRA_AUTH_API}authorization/token" | cut -d, -f3 | cut -d\" -f4)
export AUTH_TOKEN export AUTH_TOKEN
} }
#!/usr/bin/env sh
# Vercel DNS API
#
# This is your API token which can be acquired on the account page.
# https://vercel.com/account/tokens
#
# VERCEL_TOKEN="sdfsdfsdfljlbjkljlkjsdfoiwje"
VERCEL_API="https://api.vercel.com"
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_vercel_add() {
fulldomain=$1
txtvalue=$2
_debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue"
VERCEL_TOKEN="${VERCEL_TOKEN:-$(_readaccountconf_mutable VERCEL_TOKEN)}"
if [ -z "$VERCEL_TOKEN" ]; then
VERCEL_TOKEN=""
_err "You have not set the Vercel API token yet."
_err "Please visit https://vercel.com/account/tokens to generate it."
return 1
fi
_saveaccountconf_mutable VERCEL_TOKEN "$VERCEL_TOKEN"
if ! _get_root "$fulldomain"; then
_err "invalid domain"
return 1
fi
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"
_info "Adding record"
if _vercel_rest POST "v2/domains/$_domain/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":\"$txtvalue\"}"; then
if printf -- "%s" "$response" | grep "\"uid\":\"" >/dev/null; then
_info "Added"
return 0
else
_err "Unexpected response while adding text record."
return 1
fi
fi
_err "Add txt record error."
}
dns_vercel_rm() {
fulldomain=$1
txtvalue=$2
if ! _get_root "$fulldomain"; then
_err "invalid domain"
return 1
fi
_vercel_rest GET "v2/domains/$_domain/records"
count=$(printf "%s\n" "$response" | _egrep_o "\"name\":\"$_sub_domain\",[^{]*\"type\":\"TXT\"" | wc -l | tr -d " ")
if [ "$count" = "0" ]; then
_info "Don't need to remove."
else
_record_id=$(printf "%s" "$response" | _egrep_o "\"id\":[^,]*,\"slug\":\"[^,]*\",\"name\":\"$_sub_domain\",[^{]*\"type\":\"TXT\",\"value\":\"$txtvalue\"" | cut -d: -f2 | cut -d, -f1 | tr -d '"')
if [ "$_record_id" ]; then
echo "$_record_id" | while read -r item; do
if _vercel_rest DELETE "v2/domains/$_domain/records/$item"; then
_info "removed record" "$item"
return 0
else
_err "failed to remove record" "$item"
return 1
fi
done
fi
fi
}
#################### Private functions below ##################################
#_acme-challenge.www.domain.com
#returns
# _sub_domain=_acme-challenge.www
# _domain=domain.com
_get_root() {
domain="$1"
ep="$2"
i=1
p=1
while true; do
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
if [ -z "$h" ]; then
#not valid
return 1
fi
if ! _vercel_rest GET "v4/domains/$h"; 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
}
_vercel_rest() {
m="$1"
ep="$2"
data="$3"
path="$VERCEL_API/$ep"
export _H1="Content-Type: application/json"
export _H2="Authorization: Bearer $VERCEL_TOKEN"
if [ "$m" != "GET" ]; then
_secure_debug2 data "$data"
response="$(_post "$data" "$path" "" "$m")"
else
response="$(_get "$path")"
fi
_ret="$?"
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
_debug "http response code $_code"
_secure_debug2 response "$response"
if [ "$_ret" != "0" ]; then
_err "error $ep"
return 1
fi
response="$(printf "%s" "$response" | _normalizeJson)"
return 0
}
...@@ -54,15 +54,14 @@ dns_world4you_add() { ...@@ -54,15 +54,14 @@ dns_world4you_add() {
if _contains "$res" "successfully"; then if _contains "$res" "successfully"; then
return 0 return 0
else else
msg=$(echo "$res" | tr '\n' '\t' | sed 's/.*<h3 class="mb-5">[^\t]*\t *\([^\t]*\)\t.*/\1/') msg=$(echo "$res" | grep -A 15 'data-type="danger"' | grep "<h3[^>]*>[^<]" | sed 's/<[^>]*>\|^\s*//g')
if _contains "$msg" '^<\!DOCTYPE html>'; then if [ "$msg" = '' ]; then
msg='Unknown error' _err "Unable to add record: Unknown error"
fi
_err "Unable to add record: $msg"
if _contains "$msg" '^<\!DOCTYPE html>'; then
echo "$ret" >'error-01.html' echo "$ret" >'error-01.html'
echo "$res" >'error-02.html' echo "$res" >'error-02.html'
_err "View error-01.html and error-02.html for debugging" _err "View error-01.html and error-02.html for debugging"
else
_err "Unable to add record: my.world4you.com: $msg"
fi fi
return 1 return 1
fi fi
...@@ -119,15 +118,14 @@ dns_world4you_rm() { ...@@ -119,15 +118,14 @@ dns_world4you_rm() {
if _contains "$res" "successfully"; then if _contains "$res" "successfully"; then
return 0 return 0
else else
msg=$(echo "$res" | tr '\n' '\t' | sed 's/.*<h3 class="mb-5">[^\t]*\t *\([^\t]*\)\t.*/\1/') msg=$(echo "$res" | grep -A 15 'data-type="danger"' | grep "<h3[^>]*>[^<]" | sed 's/<[^>]*>\|^\s*//g')
if _contains "$msg" '^<\!DOCTYPE html>'; then if [ "$msg" = '' ]; then
msg='Unknown error' _err "Unable to remove record: Unknown error"
fi
_err "Unable to remove record: $msg"
if _contains "$msg" '^<\!DOCTYPE html>'; then
echo "$ret" >'error-01.html' echo "$ret" >'error-01.html'
echo "$res" >'error-02.html' echo "$res" >'error-02.html'
_err "View error-01.html and error-02.html for debugging" _err "View error-01.html and error-02.html for debugging"
else
_err "Unable to remove record: my.world4you.com: $msg"
fi fi
return 1 return 1
fi fi
...@@ -199,6 +197,6 @@ _get_paketnr() { ...@@ -199,6 +197,6 @@ _get_paketnr() {
TLD="$domain" TLD="$domain"
_debug domain "$domain" _debug domain "$domain"
RECORD=$(echo "$fqdn" | cut -c"1-$((${#fqdn} - ${#TLD} - 1))") RECORD=$(echo "$fqdn" | cut -c"1-$((${#fqdn} - ${#TLD} - 1))")
PAKETNR=$(echo "$form" | grep "data-textfilter=\".* $domain " | _head_n 1 | sed 's/^.* \([0-9]*\) .*$/\1/') PAKETNR=$(echo "$form" | grep "data-textfilter=\".* $domain " | _tail_n 1 | sed "s|.*$WORLD4YOU_API/\\([0-9]*\\)/.*|\\1|")
return 0 return 0
} }
#!/usr/bin/env sh
#Support CallMeBot Whatsapp webhooks
#CALLMEBOT_YOUR_PHONE_NO=""
#CALLMEBOT_API_KEY=""
callmebotWhatsApp_send() {
_subject="$1"
_content="$2"
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_statusCode" "$_statusCode"
CALLMEBOT_YOUR_PHONE_NO="${CALLMEBOT_YOUR_PHONE_NO:-$(_readaccountconf_mutable CALLMEBOT_YOUR_PHONE_NO)}"
if [ -z "$CALLMEBOT_YOUR_PHONE_NO" ]; then
CALLMEBOT_YOUR_PHONE_NO=""
_err "You didn't specify a Slack webhook url CALLMEBOT_YOUR_PHONE_NO yet."
return 1
fi
_saveaccountconf_mutable CALLMEBOT_YOUR_PHONE_NO "$CALLMEBOT_YOUR_PHONE_NO"
CALLMEBOT_API_KEY="${CALLMEBOT_API_KEY:-$(_readaccountconf_mutable CALLMEBOT_API_KEY)}"
if [ "$CALLMEBOT_API_KEY" ]; then
_saveaccountconf_mutable CALLMEBOT_API_KEY "$CALLMEBOT_API_KEY"
fi
_waUrl="https://api.callmebot.com/whatsapp.php"
_Phone_No="$(printf "%s" "$CALLMEBOT_YOUR_PHONE_NO" | _url_encode)"
_apikey="$(printf "%s" "$CALLMEBOT_API_KEY" | _url_encode)"
_message="$(printf "*%s*\\n%s" "$_subject" "$_content" | _url_encode)"
_finalUrl="$_waUrl?phone=$_Phone_No&apikey=$_apikey&text=$_message"
response="$(_get "$_finalUrl")"
if [ "$?" = "0" ] && _contains ".<p><b>Message queued.</b> You will receive it in a few seconds."; then
_info "wa send success."
return 0
fi
_err "wa send error."
_debug "URL" "$_finalUrl"
_debug "Response" "$response"
return 1
}
#!/usr/bin/env sh
#Support Discord webhooks
# Required:
#DISCORD_WEBHOOK_URL=""
# Optional:
#DISCORD_USERNAME=""
#DISCORD_AVATAR_URL=""
discord_send() {
_subject="$1"
_content="$2"
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_statusCode" "$_statusCode"
DISCORD_WEBHOOK_URL="${DISCORD_WEBHOOK_URL:-$(_readaccountconf_mutable DISCORD_WEBHOOK_URL)}"
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
DISCORD_WEBHOOK_URL=""
_err "You didn't specify a Discord webhook url DISCORD_WEBHOOK_URL yet."
return 1
fi
_saveaccountconf_mutable DISCORD_WEBHOOK_URL "$DISCORD_WEBHOOK_URL"
DISCORD_USERNAME="${DISCORD_USERNAME:-$(_readaccountconf_mutable DISCORD_USERNAME)}"
if [ "$DISCORD_USERNAME" ]; then
_saveaccountconf_mutable DISCORD_USERNAME "$DISCORD_USERNAME"
fi
DISCORD_AVATAR_URL="${DISCORD_AVATAR_URL:-$(_readaccountconf_mutable DISCORD_AVATAR_URL)}"
if [ "$DISCORD_AVATAR_URL" ]; then
_saveaccountconf_mutable DISCORD_AVATAR_URL "$DISCORD_AVATAR_URL"
fi
export _H1="Content-Type: application/json"
_content="$(printf "**%s**\n%s" "$_subject" "$_content" | _json_encode)"
_data="{\"content\": \"$_content\" "
if [ "$DISCORD_USERNAME" ]; then
_data="$_data, \"username\": \"$DISCORD_USERNAME\" "
fi
if [ "$DISCORD_AVATAR_URL" ]; then
_data="$_data, \"avatar_url\": \"$DISCORD_AVATAR_URL\" "
fi
_data="$_data}"
if _post "$_data" "$DISCORD_WEBHOOK_URL?wait=true"; then
# shellcheck disable=SC2154
if [ "$response" ]; then
_info "discord send success."
return 0
fi
fi
_err "discord send error."
_err "$response"
return 1
}
#!/usr/bin/env sh
#Support weixin work webhooks api
#WEIXIN_WORK_WEBHOOK="xxxx"
#optional
#WEIXIN_WORK_KEYWORD="yyyy"
#`WEIXIN_WORK_SIGNING_KEY`="SEC08ffdbd403cbc3fc8a65xxxxxxxxxxxxxxxxxxxx"
# subject content statusCode
weixin_work_send() {
_subject="$1"
_content="$2"
_statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
_debug "_subject" "$_subject"
_debug "_content" "$_content"
_debug "_statusCode" "$_statusCode"
WEIXIN_WORK_WEBHOOK="${WEIXIN_WORK_WEBHOOK:-$(_readaccountconf_mutable WEIXIN_WORK_WEBHOOK)}"
if [ -z "$WEIXIN_WORK_WEBHOOK" ]; then
WEIXIN_WORK_WEBHOOK=""
_err "You didn't specify a weixin_work webhooks WEIXIN_WORK_WEBHOOK yet."
_err "You can get yours from https://work.weixin.qq.com/api/doc/90000/90136/91770"
return 1
fi
_saveaccountconf_mutable WEIXIN_WORK_WEBHOOK "$WEIXIN_WORK_WEBHOOK"
WEIXIN_WORK_KEYWORD="${WEIXIN_WORK_KEYWORD:-$(_readaccountconf_mutable WEIXIN_WORK_KEYWORD)}"
if [ "$WEIXIN_WORK_KEYWORD" ]; then
_saveaccountconf_mutable WEIXIN_WORK_KEYWORD "$WEIXIN_WORK_KEYWORD"
fi
_content=$(echo "$_content" | _json_encode)
_subject=$(echo "$_subject" | _json_encode)
_data="{\"msgtype\": \"text\", \"text\": {\"content\": \"[$WEIXIN_WORK_KEYWORD]\n$_subject\n$_content\"}}"
response="$(_post "$_data" "$WEIXIN_WORK_WEBHOOK" "" "POST" "application/json")"
if [ "$?" = "0" ] && _contains "$response" "errmsg\":\"ok"; then
_info "weixin_work webhooks event fired success."
return 0
fi
_err "weixin_work webhooks event fired error."
_err "$response"
return 1
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment