mirror of
https://github.com/plantroon/acme.sh.git
synced 2024-12-22 13:11:41 +00:00
Merge pull request #1125 from Neilpang/freedns
fix https://github.com/Neilpang/acme.sh/issues/1109
This commit is contained in:
commit
bf942a4cb3
@ -53,6 +53,8 @@ dns_freedns_add() {
|
|||||||
i="$(_math "$i" - 1)"
|
i="$(_math "$i" - 1)"
|
||||||
sub_domain="$(echo "$fulldomain" | cut -d. -f -"$i")"
|
sub_domain="$(echo "$fulldomain" | cut -d. -f -"$i")"
|
||||||
|
|
||||||
|
_debug top_domain "$top_domain"
|
||||||
|
_debug sub_domain "$sub_domain"
|
||||||
# Sometimes FreeDNS does not return the subdomain page but rather
|
# Sometimes FreeDNS does not return the subdomain page but rather
|
||||||
# returns a page regarding becoming a premium member. This usually
|
# returns a page regarding becoming a premium member. This usually
|
||||||
# happens after a period of inactivity. Immediately trying again
|
# happens after a period of inactivity. Immediately trying again
|
||||||
@ -61,7 +63,6 @@ dns_freedns_add() {
|
|||||||
attempts=2
|
attempts=2
|
||||||
while [ "$attempts" -gt "0" ]; do
|
while [ "$attempts" -gt "0" ]; do
|
||||||
attempts="$(_math "$attempts" - 1)"
|
attempts="$(_math "$attempts" - 1)"
|
||||||
|
|
||||||
htmlpage="$(_freedns_retrieve_subdomain_page "$FREEDNS_COOKIE")"
|
htmlpage="$(_freedns_retrieve_subdomain_page "$FREEDNS_COOKIE")"
|
||||||
if [ "$?" != "0" ]; then
|
if [ "$?" != "0" ]; then
|
||||||
if [ "$using_cached_cookies" = "true" ]; then
|
if [ "$using_cached_cookies" = "true" ]; then
|
||||||
@ -70,19 +71,11 @@ dns_freedns_add() {
|
|||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
_debug2 htmlpage "$htmlpage"
|
||||||
|
|
||||||
|
subdomain_csv="$(echo "$htmlpage" | tr -d "\n\r" | _egrep_o '<form .*</form>' | sed 's/<tr>/@<tr>/g' | tr '@' '\n' | grep edit.php | grep $top_domain)"
|
||||||
|
_debug2 subdomain_csv "$subdomain_csv"
|
||||||
|
|
||||||
# Now convert the tables in the HTML to CSV. This litte gem from
|
|
||||||
# http://stackoverflow.com/questions/1403087/how-can-i-convert-an-html-table-to-csv
|
|
||||||
subdomain_csv="$(echo "$htmlpage" \
|
|
||||||
| grep -i -e '</\?TABLE\|</\?TD\|</\?TR\|</\?TH' \
|
|
||||||
| sed 's/^[\ \t]*//g' \
|
|
||||||
| tr -d '\n' \
|
|
||||||
| sed 's/<\/TR[^>]*>/\n/Ig' \
|
|
||||||
| sed 's/<\/\?\(TABLE\|TR\)[^>]*>//Ig' \
|
|
||||||
| sed 's/^<T[DH][^>]*>\|<\/\?T[DH][^>]*>$//Ig' \
|
|
||||||
| sed 's/<\/T[DH][^>]*><T[DH][^>]*>/,/Ig' \
|
|
||||||
| grep 'edit.php?' \
|
|
||||||
| grep "$top_domain")"
|
|
||||||
# The above beauty ends with striping out rows that do not have an
|
# The above beauty ends with striping out rows that do not have an
|
||||||
# href to edit.php and do not have the top domain we are looking for.
|
# href to edit.php and do not have the top domain we are looking for.
|
||||||
# So all we should be left with is CSV of table of subdomains we are
|
# So all we should be left with is CSV of table of subdomains we are
|
||||||
@ -90,30 +83,32 @@ dns_freedns_add() {
|
|||||||
|
|
||||||
# Now we have to read through this table and extract the data we need
|
# Now we have to read through this table and extract the data we need
|
||||||
lines="$(echo "$subdomain_csv" | wc -l)"
|
lines="$(echo "$subdomain_csv" | wc -l)"
|
||||||
nl='
|
|
||||||
'
|
|
||||||
i=0
|
i=0
|
||||||
found=0
|
found=0
|
||||||
while [ "$i" -lt "$lines" ]; do
|
while [ "$i" -lt "$lines" ]; do
|
||||||
i="$(_math "$i" + 1)"
|
i="$(_math "$i" + 1)"
|
||||||
line="$(echo "$subdomain_csv" | cut -d "$nl" -f "$i")"
|
line="$(echo "$subdomain_csv" | sed -n ${i}p)"
|
||||||
tmp="$(echo "$line" | cut -d ',' -f 1)"
|
_debug2 line "$line"
|
||||||
if [ $found = 0 ] && _startswith "$tmp" "<td>$top_domain"; then
|
if [ $found = 0 ] && _contains "$line" "<td>$top_domain</td>"; then
|
||||||
# this line will contain DNSdomainid for the top_domain
|
# this line will contain DNSdomainid for the top_domain
|
||||||
DNSdomainid="$(echo "$line" | cut -d ',' -f 2 | sed 's/^.*domain_id=//;s/>.*//')"
|
DNSdomainid="$(echo "$line" | _egrep_o "edit_domain_id *= *.*>" | cut -d = -f 2 | cut -d '>' -f 1)"
|
||||||
|
_debug2 DNSdomainid "$DNSdomainid"
|
||||||
found=1
|
found=1
|
||||||
else
|
else
|
||||||
# lines contain DNS records for all subdomains
|
# lines contain DNS records for all subdomains
|
||||||
DNSname="$(echo "$line" | cut -d ',' -f 2 | sed 's/^[^>]*>//;s/<\/a>.*//')"
|
DNSname="$(echo "$line" | _egrep_o 'edit.php.*</a>' | cut -d '>' -f 2 | cut -d '<' -f 1)"
|
||||||
DNStype="$(echo "$line" | cut -d ',' -f 3)"
|
_debug2 DNSname "$DNSname"
|
||||||
|
DNStype="$(echo "$line" | sed 's/<td/@<td/g' | tr '@' '\n' | sed -n '4p' | cut -d '>' -f 2 | cut -d '<' -f 1)"
|
||||||
|
_debug2 DNStype "$DNStype"
|
||||||
if [ "$DNSname" = "$fulldomain" ] && [ "$DNStype" = "TXT" ]; then
|
if [ "$DNSname" = "$fulldomain" ] && [ "$DNStype" = "TXT" ]; then
|
||||||
DNSdataid="$(echo "$line" | cut -d ',' -f 2 | sed 's/^.*data_id=//;s/>.*//')"
|
DNSdataid="$(echo "$line" | _egrep_o 'data_id=.*' | cut -d = -f 2 | cut -d '>' -f 1)"
|
||||||
# Now get current value for the TXT record. This method may
|
# Now get current value for the TXT record. This method may
|
||||||
# not produce accurate results as the value field is truncated
|
# not produce accurate results as the value field is truncated
|
||||||
# on this webpage. To get full value we would need to load
|
# on this webpage. To get full value we would need to load
|
||||||
# another page. However we don't really need this so long as
|
# another page. However we don't really need this so long as
|
||||||
# there is only one TXT record for the acme challenge subdomain.
|
# there is only one TXT record for the acme challenge subdomain.
|
||||||
DNSvalue="$(echo "$line" | cut -d ',' -f 4 | sed 's/^[^"]*"//;s/".*//;s/<\/td>.*//')"
|
DNSvalue="$(echo "$line" | sed 's/<td/@<td/g' | tr '@' '\n' | sed -n '5p' | cut -d '>' -f 2 | cut -d '<' -f 1)"
|
||||||
|
_debug2 DNSvalue "$DNSvalue"
|
||||||
if [ $found != 0 ]; then
|
if [ $found != 0 ]; then
|
||||||
break
|
break
|
||||||
# we are breaking out of the loop at the first match of DNS name
|
# we are breaking out of the loop at the first match of DNS name
|
||||||
@ -169,8 +164,7 @@ dns_freedns_add() {
|
|||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
# Delete the old TXT record (with the wrong value)
|
# Delete the old TXT record (with the wrong value)
|
||||||
_freedns_delete_txt_record "$FREEDNS_COOKIE" "$DNSdataid"
|
if _freedns_delete_txt_record "$FREEDNS_COOKIE" "$DNSdataid"; then
|
||||||
if [ "$?" = "0" ]; then
|
|
||||||
# And add in new TXT record with the value provided
|
# And add in new TXT record with the value provided
|
||||||
_freedns_add_txt_record "$FREEDNS_COOKIE" "$DNSdomainid" "$sub_domain" "$txtvalue"
|
_freedns_add_txt_record "$FREEDNS_COOKIE" "$DNSdomainid" "$sub_domain" "$txtvalue"
|
||||||
fi
|
fi
|
||||||
@ -210,18 +204,9 @@ dns_freedns_rm() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Now convert the tables in the HTML to CSV. This litte gem from
|
subdomain_csv="$(echo "$htmlpage" | tr -d "\n\r" | _egrep_o '<form .*</form>' | sed 's/<tr>/@<tr>/g' | tr '@' '\n' | grep edit.php | grep $fulldomain)"
|
||||||
# http://stackoverflow.com/questions/1403087/how-can-i-convert-an-html-table-to-csv
|
_debug2 subdomain_csv "$subdomain_csv"
|
||||||
subdomain_csv="$(echo "$htmlpage" \
|
|
||||||
| grep -i -e '</\?TABLE\|</\?TD\|</\?TR\|</\?TH' \
|
|
||||||
| sed 's/^[\ \t]*//g' \
|
|
||||||
| tr -d '\n' \
|
|
||||||
| sed 's/<\/TR[^>]*>/\n/Ig' \
|
|
||||||
| sed 's/<\/\?\(TABLE\|TR\)[^>]*>//Ig' \
|
|
||||||
| sed 's/^<T[DH][^>]*>\|<\/\?T[DH][^>]*>$//Ig' \
|
|
||||||
| sed 's/<\/T[DH][^>]*><T[DH][^>]*>/,/Ig' \
|
|
||||||
| grep 'edit.php?' \
|
|
||||||
| grep "$fulldomain")"
|
|
||||||
# The above beauty ends with striping out rows that do not have an
|
# The above beauty ends with striping out rows that do not have an
|
||||||
# href to edit.php and do not have the domain name we are looking for.
|
# href to edit.php and do not have the domain name we are looking for.
|
||||||
# So all we should be left with is CSV of table of subdomains we are
|
# So all we should be left with is CSV of table of subdomains we are
|
||||||
@ -229,19 +214,21 @@ dns_freedns_rm() {
|
|||||||
|
|
||||||
# Now we have to read through this table and extract the data we need
|
# Now we have to read through this table and extract the data we need
|
||||||
lines="$(echo "$subdomain_csv" | wc -l)"
|
lines="$(echo "$subdomain_csv" | wc -l)"
|
||||||
nl='
|
|
||||||
'
|
|
||||||
i=0
|
i=0
|
||||||
found=0
|
found=0
|
||||||
while [ "$i" -lt "$lines" ]; do
|
while [ "$i" -lt "$lines" ]; do
|
||||||
i="$(_math "$i" + 1)"
|
i="$(_math "$i" + 1)"
|
||||||
line="$(echo "$subdomain_csv" | cut -d "$nl" -f "$i")"
|
line="$(echo "$subdomain_csv" | sed -n ${i}p)"
|
||||||
DNSname="$(echo "$line" | cut -d ',' -f 2 | sed 's/^[^>]*>//;s/<\/a>.*//')"
|
_debug2 line "$line"
|
||||||
DNStype="$(echo "$line" | cut -d ',' -f 3)"
|
DNSname="$(echo "$line" | _egrep_o 'edit.php.*</a>' | cut -d '>' -f 2 | cut -d '<' -f 1)"
|
||||||
|
_debug2 DNSname "$DNSname"
|
||||||
|
DNStype="$(echo "$line" | sed 's/<td/@<td/g' | tr '@' '\n' | sed -n '4p' | cut -d '>' -f 2 | cut -d '<' -f 1)"
|
||||||
|
_debug2 DNStype "$DNStype"
|
||||||
if [ "$DNSname" = "$fulldomain" ] && [ "$DNStype" = "TXT" ]; then
|
if [ "$DNSname" = "$fulldomain" ] && [ "$DNStype" = "TXT" ]; then
|
||||||
DNSdataid="$(echo "$line" | cut -d ',' -f 2 | sed 's/^.*data_id=//;s/>.*//')"
|
DNSdataid="$(echo "$line" | _egrep_o 'data_id=.*' | cut -d = -f 2 | cut -d '>' -f 1)"
|
||||||
DNSvalue="$(echo "$line" | cut -d ',' -f 4 | sed 's/^[^"]*"//;s/".*//;s/<\/td>.*//')"
|
_debug2 DNSdataid "$DNSdataid"
|
||||||
_debug "DNSvalue: $DNSvalue"
|
DNSvalue="$(echo "$line" | sed 's/<td/@<td/g' | tr '@' '\n' | sed -n '5p' | cut -d '>' -f 2 | cut -d '<' -f 1)"
|
||||||
|
_debug2 DNSvalue "$DNSvalue"
|
||||||
# if [ "$DNSvalue" = "$txtvalue" ]; then
|
# if [ "$DNSvalue" = "$txtvalue" ]; then
|
||||||
# Testing value match fails. Website is truncating the value
|
# Testing value match fails. Website is truncating the value
|
||||||
# field. So for now we will assume that there is only one TXT
|
# field. So for now we will assume that there is only one TXT
|
||||||
|
Loading…
Reference in New Issue
Block a user