neilpang
6 years ago
7 changed files with 719 additions and 39 deletions
-
4deploy/gcore_cdn.sh
-
282deploy/haproxy.sh
-
2dnsapi/README.md
-
2dnsapi/dns_ddnss.sh
-
64dnsapi/dns_nsd.sh
-
139dnsapi/dns_one.sh
-
261dnsapi/dns_schlundtech.sh
@ -1,4 +1,6 @@ |
|||||
# How to use DNS API |
# How to use DNS API |
||||
DNS api usage: |
DNS api usage: |
||||
|
|
||||
|
|
||||
https://github.com/Neilpang/acme.sh/wiki/dnsapi |
https://github.com/Neilpang/acme.sh/wiki/dnsapi |
||||
|
|
@ -0,0 +1,64 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#Nsd_ZoneFile="/etc/nsd/zones/example.com.zone" |
||||
|
#Nsd_Command="sudo nsd-control reload" |
||||
|
|
||||
|
# args: fulldomain txtvalue |
||||
|
dns_nsd_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
ttlvalue=300 |
||||
|
|
||||
|
Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}" |
||||
|
Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}" |
||||
|
|
||||
|
# Arg checks |
||||
|
if [ -z "$Nsd_ZoneFile" ] || [ -z "$Nsd_Command" ]; then |
||||
|
Nsd_ZoneFile="" |
||||
|
Nsd_Command="" |
||||
|
_err "Specify ENV vars Nsd_ZoneFile and Nsd_Command" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if [ ! -f "$Nsd_ZoneFile" ]; then |
||||
|
Nsd_ZoneFile="" |
||||
|
Nsd_Command="" |
||||
|
_err "No such file: $Nsd_ZoneFile" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_savedomainconf Nsd_ZoneFile "$Nsd_ZoneFile" |
||||
|
_savedomainconf Nsd_Command "$Nsd_Command" |
||||
|
|
||||
|
echo "$fulldomain. $ttlvalue IN TXT \"$txtvalue\"" >>"$Nsd_ZoneFile" |
||||
|
_info "Added TXT record for $fulldomain" |
||||
|
_debug "Running $Nsd_Command" |
||||
|
if eval "$Nsd_Command"; then |
||||
|
_info "Successfully updated the zone" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Problem updating the zone" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
# args: fulldomain txtvalue |
||||
|
dns_nsd_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
ttlvalue=300 |
||||
|
|
||||
|
Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}" |
||||
|
Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}" |
||||
|
|
||||
|
sed -i "/$fulldomain. $ttlvalue IN TXT \"$txtvalue\"/d" "$Nsd_ZoneFile" |
||||
|
_info "Removed TXT record for $fulldomain" |
||||
|
_debug "Running $Nsd_Command" |
||||
|
if eval "$Nsd_Command"; then |
||||
|
_info "Successfully reloaded NSD " |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Problem reloading NSD" |
||||
|
return 1 |
||||
|
fi |
||||
|
} |
@ -0,0 +1,139 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# -*- mode: sh; tab-width: 2; indent-tabs-mode: s; coding: utf-8 -*- |
||||
|
|
||||
|
# one.com ui wrapper for acme.sh |
||||
|
# Author: github: @diseq |
||||
|
# Created: 2019-02-17 |
||||
|
# |
||||
|
# export ONECOM_USER="username" |
||||
|
# export ONECOM_PASSWORD="password" |
||||
|
# |
||||
|
# Usage: |
||||
|
# acme.sh --issue --dns dns_one -d example.com |
||||
|
# |
||||
|
# only single domain supported atm |
||||
|
|
||||
|
dns_one_add() { |
||||
|
mysubdomain=$(printf -- "%s" "$1" | rev | cut -d"." -f3- | rev) |
||||
|
mydomain=$(printf -- "%s" "$1" | rev | cut -d"." -f1-2 | rev) |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
# get credentials |
||||
|
ONECOM_USER="${ONECOM_USER:-$(_readaccountconf_mutable ONECOM_USER)}" |
||||
|
ONECOM_PASSWORD="${ONECOM_PASSWORD:-$(_readaccountconf_mutable ONECOM_PASSWORD)}" |
||||
|
if [ -z "$ONECOM_USER" ] || [ -z "$ONECOM_PASSWORD" ]; then |
||||
|
ONECOM_USER="" |
||||
|
ONECOM_PASSWORD="" |
||||
|
_err "You didn't specify a one.com username and password yet." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
#save the api key and email to the account conf file. |
||||
|
_saveaccountconf_mutable ONECOM_USER "$ONECOM_USER" |
||||
|
_saveaccountconf_mutable ONECOM_PASSWORD "$ONECOM_PASSWORD" |
||||
|
|
||||
|
# Login with user and password |
||||
|
postdata="loginDomain=true" |
||||
|
postdata="$postdata&displayUsername=$ONECOM_USER" |
||||
|
postdata="$postdata&username=$ONECOM_USER" |
||||
|
postdata="$postdata&targetDomain=$mydomain" |
||||
|
postdata="$postdata&password1=$ONECOM_PASSWORD" |
||||
|
postdata="$postdata&loginTarget=" |
||||
|
#_debug postdata "$postdata" |
||||
|
|
||||
|
response="$(_post "$postdata" "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded")" |
||||
|
#_debug response "$response" |
||||
|
|
||||
|
JSESSIONID="$(grep "JSESSIONID" "$HTTP_HEADER" | grep "^[Ss]et-[Cc]ookie:" | _tail_n 1 | _egrep_o 'JSESSIONID=[^;]*;' | tr -d ';')" |
||||
|
_debug jsessionid "$JSESSIONID" |
||||
|
|
||||
|
export _H1="Cookie: ${JSESSIONID}" |
||||
|
|
||||
|
# get entries |
||||
|
response="$(_get "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records")" |
||||
|
_debug response "$response" |
||||
|
|
||||
|
CSRF_G_TOKEN="$(grep "CSRF_G_TOKEN=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'CSRF_G_TOKEN=[^;]*;' | tr -d ';')" |
||||
|
export _H2="Cookie: ${CSRF_G_TOKEN}" |
||||
|
|
||||
|
# Update the IP address for domain entry |
||||
|
postdata="{\"type\":\"dns_custom_records\",\"attributes\":{\"priority\":0,\"ttl\":600,\"type\":\"TXT\",\"prefix\":\"$mysubdomain\",\"content\":\"$txtvalue\"}}" |
||||
|
_debug postdata "$postdata" |
||||
|
response="$(_post "$postdata" "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records" "" "POST" "application/json")" |
||||
|
response="$(echo "$response" | _normalizeJson)" |
||||
|
_debug response "$response" |
||||
|
|
||||
|
id=$(printf -- "%s" "$response" | sed -n "s/{\"result\":{\"data\":{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$mysubdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}}},\"metadata\":null}/\1/p") |
||||
|
|
||||
|
if [ -z "$id" ]; then |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
else |
||||
|
_info "Added, OK ($id)" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
} |
||||
|
|
||||
|
dns_one_rm() { |
||||
|
mysubdomain=$(printf -- "%s" "$1" | rev | cut -d"." -f3- | rev) |
||||
|
mydomain=$(printf -- "%s" "$1" | rev | cut -d"." -f1-2 | rev) |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
# get credentials |
||||
|
ONECOM_USER="${ONECOM_USER:-$(_readaccountconf_mutable ONECOM_USER)}" |
||||
|
ONECOM_PASSWORD="${ONECOM_PASSWORD:-$(_readaccountconf_mutable ONECOM_PASSWORD)}" |
||||
|
if [ -z "$ONECOM_USER" ] || [ -z "$ONECOM_PASSWORD" ]; then |
||||
|
ONECOM_USER="" |
||||
|
ONECOM_PASSWORD="" |
||||
|
_err "You didn't specify a one.com username and password yet." |
||||
|
_err "Please create the key and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# Login with user and password |
||||
|
postdata="loginDomain=true" |
||||
|
postdata="$postdata&displayUsername=$ONECOM_USER" |
||||
|
postdata="$postdata&username=$ONECOM_USER" |
||||
|
postdata="$postdata&targetDomain=$mydomain" |
||||
|
postdata="$postdata&password1=$ONECOM_PASSWORD" |
||||
|
postdata="$postdata&loginTarget=" |
||||
|
|
||||
|
response="$(_post "$postdata" "https://www.one.com/admin/login.do" "" "POST" "application/x-www-form-urlencoded")" |
||||
|
#_debug response "$response" |
||||
|
|
||||
|
JSESSIONID="$(grep "JSESSIONID" "$HTTP_HEADER" | grep "^[Ss]et-[Cc]ookie:" | _tail_n 1 | _egrep_o 'JSESSIONID=[^;]*;' | tr -d ';')" |
||||
|
_debug jsessionid "$JSESSIONID" |
||||
|
|
||||
|
export _H1="Cookie: ${JSESSIONID}" |
||||
|
|
||||
|
# get entries |
||||
|
response="$(_get "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records")" |
||||
|
response="$(echo "$response" | _normalizeJson)" |
||||
|
_debug response "$response" |
||||
|
|
||||
|
CSRF_G_TOKEN="$(grep "CSRF_G_TOKEN=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'CSRF_G_TOKEN=[^;]*;' | tr -d ';')" |
||||
|
export _H2="Cookie: ${CSRF_G_TOKEN}" |
||||
|
|
||||
|
id=$(printf -- "%s" "$response" | sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"$mysubdomain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"priority\":0,\"ttl\":600}.*/\1/p") |
||||
|
|
||||
|
if [ -z "$id" ]; then |
||||
|
_err "Txt record not found." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# delete entry |
||||
|
response="$(_post "$postdata" "https://www.one.com/admin/api/domains/$mydomain/dns/custom_records/$id" "" "DELETE" "application/json")" |
||||
|
response="$(echo "$response" | _normalizeJson)" |
||||
|
_debug response "$response" |
||||
|
|
||||
|
if [ "$response" = '{"result":null,"metadata":null}' ]; then |
||||
|
_info "Removed, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Removing txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
} |
@ -0,0 +1,261 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
# -*- mode: sh; tab-width: 2; indent-tabs-mode: s; coding: utf-8 -*- |
||||
|
|
||||
|
# Schlundtech DNS API |
||||
|
# Author: mod242 |
||||
|
# Created: 2019-40-29 |
||||
|
# Completly based on the autoDNS xml api wrapper by auerswald@gmail.com |
||||
|
# |
||||
|
# export SCHLUNDTECH_USER="username" |
||||
|
# export SCHLUNDTECH_PASSWORD="password" |
||||
|
# |
||||
|
# Usage: |
||||
|
# acme.sh --issue --dns dns_schlundtech -d example.com |
||||
|
|
||||
|
SCHLUNDTECH_API="https://gateway.schlundtech.de" |
||||
|
|
||||
|
# Arguments: |
||||
|
# txtdomain |
||||
|
# txt |
||||
|
dns_schlundtech_add() { |
||||
|
fulldomain="$1" |
||||
|
txtvalue="$2" |
||||
|
|
||||
|
SCHLUNDTECH_USER="${SCHLUNDTECH_USER:-$(_readaccountconf_mutable SCHLUNDTECH_USER)}" |
||||
|
SCHLUNDTECH_PASSWORD="${SCHLUNDTECH_PASSWORD:-$(_readaccountconf_mutable SCHLUNDTECH_PASSWORD)}" |
||||
|
|
||||
|
if [ -z "$SCHLUNDTECH_USER" ] || [ -z "$SCHLUNDTECH_PASSWORD" ]; then |
||||
|
_err "You didn't specify schlundtech user and password." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable SCHLUNDTECH_USER "$SCHLUNDTECH_USER" |
||||
|
_saveaccountconf_mutable SCHLUNDTECH_PASSWORD "$SCHLUNDTECH_PASSWORD" |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
|
||||
|
if ! _get_autodns_zone "$fulldomain"; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _zone "$_zone" |
||||
|
_debug _system_ns "$_system_ns" |
||||
|
|
||||
|
_info "Adding TXT record" |
||||
|
|
||||
|
autodns_response="$(_autodns_zone_update "$_zone" "$_sub_domain" "$txtvalue" "$_system_ns")" |
||||
|
|
||||
|
if [ "$?" -eq "0" ]; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# Arguments: |
||||
|
# txtdomain |
||||
|
# txt |
||||
|
dns_schlundtech_rm() { |
||||
|
fulldomain="$1" |
||||
|
txtvalue="$2" |
||||
|
|
||||
|
SCHLUNDTECH_USER="${SCHLUNDTECH_USER:-$(_readaccountconf_mutable SCHLUNDTECH_USER)}" |
||||
|
SCHLUNDTECH_PASSWORD="${SCHLUNDTECH_PASSWORD:-$(_readaccountconf_mutable SCHLUNDTECH_PASSWORD)}" |
||||
|
|
||||
|
if [ -z "$SCHLUNDTECH_USER" ] || [ -z "$SCHLUNDTECH_PASSWORD" ]; then |
||||
|
_err "You didn't specify schlundtech user and password." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
|
||||
|
if ! _get_autodns_zone "$fulldomain"; then |
||||
|
_err "zone not found" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _zone "$_zone" |
||||
|
_debug _system_ns "$_system_ns" |
||||
|
|
||||
|
_info "Delete TXT record" |
||||
|
|
||||
|
autodns_response="$(_autodns_zone_cleanup "$_zone" "$_sub_domain" "$txtvalue" "$_system_ns")" |
||||
|
|
||||
|
if [ "$?" -eq "0" ]; then |
||||
|
_info "Deleted, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
# Arguments: |
||||
|
# fulldomain |
||||
|
# Returns: |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _zone=domain.com |
||||
|
# _system_ns |
||||
|
_get_autodns_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 |
||||
|
|
||||
|
autodns_response="$(_autodns_zone_inquire "$h")" |
||||
|
|
||||
|
if [ "$?" -ne "0" ]; then |
||||
|
_err "invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$autodns_response" "<summary>1</summary>" >/dev/null; then |
||||
|
_zone="$(echo "$autodns_response" | _egrep_o '<name>[^<]*</name>' | cut -d '>' -f 2 | cut -d '<' -f 1)" |
||||
|
_system_ns="$(echo "$autodns_response" | _egrep_o '<system_ns>[^<]*</system_ns>' | cut -d '>' -f 2 | cut -d '<' -f 1)" |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
|
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_build_request_auth_xml() { |
||||
|
printf "<auth> |
||||
|
<user>%s</user> |
||||
|
<password>%s</password> |
||||
|
<context>10</context> |
||||
|
</auth>" "$SCHLUNDTECH_USER" "$SCHLUNDTECH_PASSWORD" |
||||
|
} |
||||
|
|
||||
|
# Arguments: |
||||
|
# zone |
||||
|
_build_zone_inquire_xml() { |
||||
|
printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
||||
|
<request> |
||||
|
%s |
||||
|
<task> |
||||
|
<code>0205</code> |
||||
|
<view> |
||||
|
<children>1</children> |
||||
|
<limit>1</limit> |
||||
|
</view> |
||||
|
<where> |
||||
|
<key>name</key> |
||||
|
<operator>eq</operator> |
||||
|
<value>%s</value> |
||||
|
</where> |
||||
|
</task> |
||||
|
</request>" "$(_build_request_auth_xml)" "$1" |
||||
|
} |
||||
|
|
||||
|
# Arguments: |
||||
|
# zone |
||||
|
# subdomain |
||||
|
# txtvalue |
||||
|
# system_ns |
||||
|
_build_zone_update_xml() { |
||||
|
printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
||||
|
<request> |
||||
|
%s |
||||
|
<task> |
||||
|
<code>0202001</code> |
||||
|
<default> |
||||
|
<rr_add> |
||||
|
<name>%s</name> |
||||
|
<ttl>600</ttl> |
||||
|
<type>TXT</type> |
||||
|
<value>%s</value> |
||||
|
</rr_add> |
||||
|
</default> |
||||
|
<zone> |
||||
|
<name>%s</name> |
||||
|
<system_ns>%s</system_ns> |
||||
|
</zone> |
||||
|
</task> |
||||
|
</request>" "$(_build_request_auth_xml)" "$2" "$3" "$1" "$4" |
||||
|
} |
||||
|
|
||||
|
# Arguments: |
||||
|
# zone |
||||
|
_autodns_zone_inquire() { |
||||
|
request_data="$(_build_zone_inquire_xml "$1")" |
||||
|
autodns_response="$(_autodns_api_call "$request_data")" |
||||
|
ret="$?" |
||||
|
|
||||
|
printf "%s" "$autodns_response" |
||||
|
return "$ret" |
||||
|
} |
||||
|
|
||||
|
# Arguments: |
||||
|
# zone |
||||
|
# subdomain |
||||
|
# txtvalue |
||||
|
# system_ns |
||||
|
_autodns_zone_update() { |
||||
|
request_data="$(_build_zone_update_xml "$1" "$2" "$3" "$4")" |
||||
|
autodns_response="$(_autodns_api_call "$request_data")" |
||||
|
ret="$?" |
||||
|
|
||||
|
printf "%s" "$autodns_response" |
||||
|
return "$ret" |
||||
|
} |
||||
|
|
||||
|
# Arguments: |
||||
|
# zone |
||||
|
# subdomain |
||||
|
# txtvalue |
||||
|
# system_ns |
||||
|
_autodns_zone_cleanup() { |
||||
|
request_data="$(_build_zone_update_xml "$1" "$2" "$3" "$4")" |
||||
|
# replace 'rr_add>' with 'rr_rem>' in request_data |
||||
|
request_data="$(printf -- "%s" "$request_data" | sed 's/rr_add>/rr_rem>/g')" |
||||
|
autodns_response="$(_autodns_api_call "$request_data")" |
||||
|
ret="$?" |
||||
|
|
||||
|
printf "%s" "$autodns_response" |
||||
|
return "$ret" |
||||
|
} |
||||
|
|
||||
|
# Arguments: |
||||
|
# request_data |
||||
|
_autodns_api_call() { |
||||
|
request_data="$1" |
||||
|
|
||||
|
_debug request_data "$request_data" |
||||
|
|
||||
|
autodns_response="$(_post "$request_data" "$SCHLUNDTECH_API")" |
||||
|
ret="$?" |
||||
|
|
||||
|
_debug autodns_response "$autodns_response" |
||||
|
|
||||
|
if [ "$ret" -ne "0" ]; then |
||||
|
_err "error" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$autodns_response" "<type>success</type>" >/dev/null; then |
||||
|
_info "success" |
||||
|
printf "%s" "$autodns_response" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
return 1 |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue