dns_rm support

This commit is contained in:
LLeny 2018-09-07 20:53:21 +08:00
parent 8868783476
commit b859dd660c

View File

@ -129,7 +129,7 @@ _namecheap_set_publicip() {
_publicip="$ip" _publicip="$ip"
elif [ -n "$addr" ]; then elif [ -n "$addr" ]; then
_publicip=$(_get "$addr") _publicip=$(_get "$addr")
else else
_err "No Source IP specified for Namecheap API." _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" _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 return 1
@ -162,12 +162,12 @@ _namecheap_parse_host() {
_host=$1 _host=$1
_debug _host "$_host" _debug _host "$_host"
_hostid=$(echo "$_host" | _egrep_o 'HostId=".*"' | cut -d '"' -f 2) _hostid=$(echo "$_host" | _egrep_o '\sHostId="[^"]*' | cut -d '"' -f 2)
_hostname=$(echo "$_host" | _egrep_o 'Name=".*"' | cut -d '"' -f 2) _hostname=$(echo "$_host" | _egrep_o '\sName="[^"]*' | cut -d '"' -f 2)
_hosttype=$(echo "$_host" | _egrep_o 'Type=".*"' | cut -d '"' -f 2) _hosttype=$(echo "$_host" | _egrep_o '\sType="[^"]*' | cut -d '"' -f 2)
_hostaddress=$(echo "$_host" | _egrep_o 'Address=".*"' | cut -d '"' -f 2) _hostaddress=$(echo "$_host" | _egrep_o '\sAddress="[^"]*' | cut -d '"' -f 2)
_hostmxpref=$(echo "$_host" | _egrep_o 'MXPref=".*"' | cut -d '"' -f 2) _hostmxpref=$(echo "$_host" | _egrep_o '\sMXPref="[^"]*' | cut -d '"' -f 2)
_hostttl=$(echo "$_host" | _egrep_o 'TTL=".*"' | cut -d '"' -f 2) _hostttl=$(echo "$_host" | _egrep_o '\sTTL="[^"]*' | cut -d '"' -f 2)
_debug hostid "$_hostid" _debug hostid "$_hostid"
_debug hostname "$_hostname" _debug hostname "$_hostname"
@ -210,7 +210,7 @@ _set_namecheap_TXT() {
return 1 return 1
fi fi
hosts=$(echo "$response" | _egrep_o '<host .+ />') hosts=$(echo "$response" | _egrep_o '<host[^>]*')
_debug hosts "$hosts" _debug hosts "$hosts"
if [ -z "$hosts" ]; then if [ -z "$hosts" ]; then
@ -219,29 +219,72 @@ _set_namecheap_TXT() {
fi fi
_namecheap_reset_hostList _namecheap_reset_hostList
while read -r host; do
if _contains "$host" "<host"; then
_namecheap_parse_host "$host"
_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
tld=$(echo "$1" | cut -d '.' -f 2)
sld=$(echo "$1" | cut -d '.' -f 1)
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 found=0
while read -r host; do while read -r host; do
if _contains "$host" "<host"; then if _contains "$host" "<host"; then
_namecheap_parse_host "$host" _namecheap_parse_host "$host"
if [ "$_hosttype" = "TXT" ] && [ "$_hostname" = "$subdomain" ]; then
if [ "$_hosttype" = "TXT" ] && [ "$_hostname" = "$subdomain" ]; then #&& [ "$_hostaddress" = "$txt" ]
_namecheap_add_host "$_hostname" "$_hosttype" "$txt" "$_hostmxpref" "$_hostttl" _debug "TXT entry found"
found=1 found=1
else else
_namecheap_add_host "$_hostname" "$_hosttype" "$_hostaddress" "$_hostmxpref" "$_hostttl" _namecheap_add_host "$_hostname" "$_hosttype" "$_hostaddress" "$_hostmxpref" "$_hostttl"
fi fi
fi fi
done <<EOT done <<EOT
echo "$hosts" echo "$hosts"
EOT EOT
if [ $found -eq 0 ]; then if [ $found -eq 0 ]; then
_namecheap_add_host "$subdomain" "TXT" "$txt" 10 120 _debug "TXT entry not found"
_debug "not found" return 0
fi fi
_debug hostrequestfinal "$_hostrequest" _debug hostrequestfinal "$_hostrequest"
@ -256,7 +299,6 @@ EOT
return 0 return 0
} }
_namecheap_reset_hostList() { _namecheap_reset_hostList() {
_hostindex=0 _hostindex=0
_hostrequest="" _hostrequest=""