#!/usr/bin/env sh #This file name is "dns_freedns.sh" #So, here must be a method dns_freedns_add() #Which will be called by acme.sh to add the txt record to your api system. #returns 0 means success, otherwise error. # #Author: David Kerr #Report Bugs here: https://github.com/dkerr64/acme.sh # ######## Public functions ##################### # Export FreeDNS userid and password in following variables... # FREEDNS_User=username # FREEDNS_Password=password # login cookie is saved in acme account config file so userid / pw # need to be set only when changed. #Usage: dns_freedns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" 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" # split our full domain name into two parts... 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")" _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 # returns the correct subdomain page. So, we will try twice to # load the page and obtain our domain ID 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 changed? If so..." _err "Please export as FREEDNS_User / FREEDNS_Password and try again." fi return 1 fi _debug2 htmlpage "$htmlpage" subdomain_csv="$(echo "$htmlpage" | tr -d "\n\r" | _egrep_o '