]*>/,/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" "$top_domain"; then
+ line="$(echo "$subdomain_csv" | sed -n ${i}p)"
+ _debug2 line "$line"
+ if [ $found = 0 ] && _contains "$line" " | $top_domain | "; 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.*' | cut -d '>' -f 2 | cut -d '<' -f 1)"
+ _debug2 DNSname "$DNSname"
+ DNStype="$(echo "$line" | sed 's/' -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/ | ' -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][^>]*>$//Ig' \
- | sed 's/<\/T[DH][^>]*>]*>/,/Ig' \
- | grep 'edit.php?' \
- | grep "$fulldomain")"
+ subdomain_csv="$(echo "$htmlpage" | tr -d "\n\r" | _egrep_o ' |