|
@@ -0,0 +1,371 @@
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+dns_freedns_add() {
|
|
|
|
+ fulldomain="$1"
|
|
|
|
+ txtvalue="$2"
|
|
|
|
+
|
|
|
|
+ _info "Add TXT record using FreeDNS"
|
|
|
|
+ _debug "fulldomain: $fulldomain"
|
|
|
|
+ _debug "txtvalue: $txtvalue"
|
|
|
|
+
|
|
|
|
+ if [ -z "$FREEDNS_User" ] || [ -z "$FREEDNS_Password" ]; then
|
|
|
|
+ FREEDNS_User=""
|
|
|
|
+ FREEDNS_Password=""
|
|
|
|
+ if [ -z "$FREEDNS_COOKIE" ]; then
|
|
|
|
+ _err "You did not specify the FreeDNS username and password yet."
|
|
|
|
+ _err "Please export as FREEDNS_User / FREEDNS_Password and try again."
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+ using_cached_cookies="true"
|
|
|
|
+ else
|
|
|
|
+ FREEDNS_COOKIE="$(_freedns_login "$FREEDNS_User" "$FREEDNS_Password")"
|
|
|
|
+ if [ -z "$FREEDNS_COOKIE" ]; then
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+ using_cached_cookies="false"
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ _debug "FreeDNS login cookies: $FREEDNS_COOKIE (cached = $using_cached_cookies)"
|
|
|
|
+
|
|
|
|
+ _saveaccountconf FREEDNS_COOKIE "$FREEDNS_COOKIE"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ i="$(echo "$fulldomain" | tr '.' ' ' | wc -w)"
|
|
|
|
+ i="$(_math "$i" - 1)"
|
|
|
|
+ top_domain="$(echo "$fulldomain" | cut -d. -f "$i"-100)"
|
|
|
|
+ i="$(_math "$i" - 1)"
|
|
|
|
+ sub_domain="$(echo "$fulldomain" | cut -d. -f -"$i")"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
+ _err "Has your FreeDNS username and password channged? If so..."
|
|
|
|
+ _err "Please export as FREEDNS_User / FREEDNS_Password and try again."
|
|
|
|
+ fi
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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")"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
+
|
|
|
|
+ DNSdomainid="$(echo "$line" | cut -d ',' -f 2 | sed 's/^.*domain_id=//;s/>.*//')"
|
|
|
|
+ found=1
|
|
|
|
+ else
|
|
|
|
+
|
|
|
|
+ DNSname="$(echo "$line" | cut -d ',' -f 2 | sed 's/^[^>]*>//;s/<\/a>.*//')"
|
|
|
|
+ DNStype="$(echo "$line" | cut -d ',' -f 3)"
|
|
|
|
+ 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>.*//')"
|
|
|
|
+ if [ $found != 0 ]; then
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ fi
|
|
|
|
+ else
|
|
|
|
+ DNSname=""
|
|
|
|
+ DNStype=""
|
|
|
|
+ fi
|
|
|
|
+ fi
|
|
|
|
+ done
|
|
|
|
+
|
|
|
|
+ _debug "DNSname: $DNSname DNStype: $DNStype DNSdomainid: $DNSdomainid DNSdataid: $DNSdataid"
|
|
|
|
+ _debug "DNSvalue: $DNSvalue"
|
|
|
|
+
|
|
|
|
+ if [ -z "$DNSdomainid" ]; then
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if [ "$attempts" = "0" ]; then
|
|
|
|
+
|
|
|
|
+ _debug "$htmlpage"
|
|
|
|
+ _debug "$subdomain_csv"
|
|
|
|
+ _err "Domain $top_domain not found at FreeDNS"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+ else
|
|
|
|
+
|
|
|
|
+ break
|
|
|
|
+ fi
|
|
|
|
+ _info "Domain $top_domain not found at FreeDNS"
|
|
|
|
+ _info "Retry loading subdomain page ($attempts attempts remaining)"
|
|
|
|
+ done
|
|
|
|
+
|
|
|
|
+ if [ -z "$DNSdataid" ]; then
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ _freedns_add_txt_record "$FREEDNS_COOKIE" "$DNSdomainid" "$sub_domain" "$txtvalue"
|
|
|
|
+ return $?
|
|
|
|
+ else
|
|
|
|
+ if [ "$txtvalue" = "$DNSvalue" ]; then
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ _info "No update necessary for $fulldomain at FreeDNS"
|
|
|
|
+ return 0
|
|
|
|
+ else
|
|
|
|
+
|
|
|
|
+ _freedns_delete_txt_record "$FREEDNS_COOKIE" "$DNSdataid"
|
|
|
|
+ if [ "$?" = "0" ]; then
|
|
|
|
+
|
|
|
|
+ _freedns_add_txt_record "$FREEDNS_COOKIE" "$DNSdomainid" "$sub_domain" "$txtvalue"
|
|
|
|
+ fi
|
|
|
|
+ return $?
|
|
|
|
+ fi
|
|
|
|
+ fi
|
|
|
|
+ return 0
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+dns_freedns_rm() {
|
|
|
|
+ fulldomain="$1"
|
|
|
|
+ txtvalue="$2"
|
|
|
|
+
|
|
|
|
+ _info "Delete TXT record using FreeDNS"
|
|
|
|
+ _debug "fulldomain: $fulldomain"
|
|
|
|
+ _debug "txtvalue: $txtvalue"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ FREEDNS_COOKIE="$(_read_conf "$ACCOUNT_CONF_PATH" "FREEDNS_COOKIE")"
|
|
|
|
+ _debug "FreeDNS login cookies: $FREEDNS_COOKIE"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ attempts=2
|
|
|
|
+ while [ "$attempts" -gt "0" ]; do
|
|
|
|
+ attempts="$(_math "$attempts" - 1)"
|
|
|
|
+
|
|
|
|
+ htmlpage="$(_freedns_retrieve_subdomain_page "$FREEDNS_COOKIE")"
|
|
|
|
+ if [ "$?" != "0" ]; then
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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")"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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)"
|
|
|
|
+ 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"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ _freedns_delete_txt_record "$FREEDNS_COOKIE" "$DNSdataid"
|
|
|
|
+ return $?
|
|
|
|
+
|
|
|
|
+ fi
|
|
|
|
+ done
|
|
|
|
+ done
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ _debug2 "$subdomain_csv"
|
|
|
|
+ _info "Cannot delete TXT record for $fulldomain/$txtvalue. Does not exist at FreeDNS"
|
|
|
|
+ return 0
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+_freedns_login() {
|
|
|
|
+ username="$1"
|
|
|
|
+ password="$2"
|
|
|
|
+ url="https://freedns.afraid.org/zc.php?step=2"
|
|
|
|
+
|
|
|
|
+ _debug "Login to FreeDNS as user $username"
|
|
|
|
+
|
|
|
|
+ htmlpage="$(_post "username=$(printf '%s' "$username" | _url_encode)&password=$(printf '%s' "$password" | _url_encode)&submit=Login&action=auth" "$url")"
|
|
|
|
+
|
|
|
|
+ if [ "$?" != "0" ]; then
|
|
|
|
+ _err "FreeDNS login failed for user $username bad RC from _post"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ cookies="$(grep -i '^Set-Cookie.*dns_cookie.*$' "$HTTP_HEADER" | _head_n 1 | tr -d "\r\n" | cut -d " " -f 2)"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if [ -z "$cookies" ]; then
|
|
|
|
+ _debug "$htmlpage"
|
|
|
|
+ _err "FreeDNS login failed for user $username. Check $HTTP_HEADER file"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ printf "%s" "$cookies"
|
|
|
|
+ return 0
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+_freedns_retrieve_subdomain_page() {
|
|
|
|
+ export _H1="Cookie:$1"
|
|
|
|
+ url="https://freedns.afraid.org/subdomain/"
|
|
|
|
+
|
|
|
|
+ _debug "Retrieve subdmoain page from FreeDNS"
|
|
|
|
+
|
|
|
|
+ htmlpage="$(_get "$url")"
|
|
|
|
+
|
|
|
|
+ if [ "$?" != "0" ]; then
|
|
|
|
+ _err "FreeDNS retrieve subdomins failed bad RC from _get"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ if [ -z "$htmlpage" ]; then
|
|
|
|
+ _err "FreeDNS returned empty subdomain page"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ _debug2 "$htmlpage"
|
|
|
|
+
|
|
|
|
+ printf "%s" "$htmlpage"
|
|
|
|
+ return 0
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+_freedns_add_txt_record() {
|
|
|
|
+ export _H1="Cookie:$1"
|
|
|
|
+ domain_id="$2"
|
|
|
|
+ subdomain="$3"
|
|
|
|
+ value="$(printf '%s' "$4" | _url_encode)"
|
|
|
|
+ url="http://freedns.afraid.org/subdomain/save.php?step=2"
|
|
|
|
+
|
|
|
|
+ htmlpage="$(_post "type=TXT&domain_id=$domain_id&subdomain=$subdomain&address=%22$value%22&send=Save%21" "$url")"
|
|
|
|
+
|
|
|
|
+ if [ "$?" != "0" ]; then
|
|
|
|
+ _err "FreeDNS failed to add TXT record for $subdomain bad RC from _post"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ if ! grep "200 OK" "$HTTP_HEADER" >/dev/null; then
|
|
|
|
+ _debug "$htmlpage"
|
|
|
|
+ _err "FreeDNS failed to add TXT record for $subdomain. Check $HTTP_HEADER file"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+ _info "Added acme challenge TXT record for $fulldomain at FreeDNS"
|
|
|
|
+ return 0
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+_freedns_delete_txt_record() {
|
|
|
|
+ export _H1="Cookie:$1"
|
|
|
|
+ data_id="$2"
|
|
|
|
+ url="https://freedns.afraid.org/subdomain/delete2.php"
|
|
|
|
+
|
|
|
|
+ htmlheader="$(_get "$url?data_id%5B%5D=$data_id&submit=delete+selected" "onlyheader")"
|
|
|
|
+
|
|
|
|
+ if [ "$?" != "0" ]; then
|
|
|
|
+ _err "FreeDNS failed to delete TXT record for $data_id bad RC from _get"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ if ! _contains "$htmlheader" "200 OK"; then
|
|
|
|
+ _debug "$htmlheader"
|
|
|
|
+ _err "FreeDNS failed to delete TXT record $data_id"
|
|
|
|
+ return 1
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ _info "Deleted acme challenge TXT record for $fulldomain at FreeDNS"
|
|
|
|
+ return 0
|
|
|
|
+}
|
|
|
|
+
|