@ -53,6 +53,8 @@ dns_freedns_add() {
i = " $( _math " $i " - 1) "
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
# returns a page regarding becoming a premium member. This usually
# happens after a period of inactivity. Immediately trying again
@ -61,7 +63,6 @@ dns_freedns_add() {
attempts = 2
while [ " $attempts " -gt "0" ] ; do
attempts = " $( _math " $attempts " - 1) "
htmlpage = " $( _freedns_retrieve_subdomain_page " $FREEDNS_COOKIE " ) "
if [ " $? " != "0" ] ; then
if [ " $using_cached_cookies " = "true" ] ; then
@ -70,19 +71,11 @@ dns_freedns_add() {
fi
return 1
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
# 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
@ -90,30 +83,32 @@ dns_freedns_add() {
# Now we have to read through this table and extract the data we need
lines = " $( echo " $subdomain_csv " | wc -l) "
nl = '
'
i = 0
found = 0
while [ " $i " -lt " $lines " ] ; do
i = " $( _math " $i " + 1) "
line = " $( echo " $subdomain_csv " | cut -d " $nl " -f " $i " ) "
tmp = " $( echo " $line " | cut -d ',' -f 1) "
if [ $found = 0 ] && _startswith " $tmp " " <td> $top_domain " ; then
line = " $( echo " $subdomain_csv " | sed -n " ${ i } p " ) "
_debug2 line " $line "
if [ $found = 0 ] && _contains " $line " " <td> $top_domain </td> " ; then
# 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
else
# lines contain DNS records for all subdomains
DNSname = " $( echo " $line " | cut -d ',' -f 2 | sed 's/^[^>]*>//;s/<\/a>.*//' ) "
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
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
# not produce accurate results as the value field is truncated
# on this webpage. To get full value we would need to load
# another page. However we don't really need this so long as
# 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
break
# we are breaking out of the loop at the first match of DNS name
@ -169,8 +164,7 @@ dns_freedns_add() {
return 0
else
# Delete the old TXT record (with the wrong value)
_freedns_delete_txt_record " $FREEDNS_COOKIE " " $DNSdataid "
if [ " $? " = "0" ] ; then
if _freedns_delete_txt_record " $FREEDNS_COOKIE " " $DNSdataid " ; then
# And add in new TXT record with the value provided
_freedns_add_txt_record " $FREEDNS_COOKIE " " $DNSdomainid " " $sub_domain " " $txtvalue "
fi
@ -210,18 +204,9 @@ dns_freedns_rm() {
return 1
fi
# 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 " $fulldomain " ) "
subdomain_csv = " $( echo " $htmlpage " | tr -d "\n\r" | _egrep_o '<form .*</form>' | sed 's/<tr>/@<tr>/g' | tr '@' '\n' | grep edit.php | grep " $fulldomain " ) "
_debug2 subdomain_csv " $subdomain_csv "
# 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.
# 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
lines = " $( echo " $subdomain_csv " | wc -l) "
nl = '
'
i = 0
found = 0
while [ " $i " -lt " $lines " ] ; do
i = " $( _math " $i " + 1) "
line = " $( echo " $subdomain_csv " | cut -d " $nl " -f " $i " ) "
DNSname = " $( echo " $line " | cut -d ',' -f 2 | sed 's/^[^>]*>//;s/<\/a>.*//' ) "
DNStype = " $( echo " $line " | cut -d ',' -f 3) "
line = " $( echo " $subdomain_csv " | sed -n " ${ i } p " ) "
_debug2 line " $line "
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
DNSdataid = " $( echo " $line " | cut -d ',' -f 2 | sed 's/^.*data_id=//;s/>.*//' ) "
DNSvalue = " $( echo " $line " | cut -d ',' -f 4 | sed 's/^[^"]*"//;s/".*//;s/<\/td>.*//' ) "
_debug " DNSvalue: $DNSvalue "
DNSdataid = " $( echo " $line " | _egrep_o 'data_id=.*' | cut -d = -f 2 | cut -d '>' -f 1) "
_debug2 DNSdataid " $DNSdataid "
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
# Testing value match fails. Website is truncating the value
# field. So for now we will assume that there is only one TXT