b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | # sample script for sending user defined updates |
| 2 | # 2014-2015 Christian Schoenebeck <christian dot schoenebeck at gmail dot com> |
| 3 | # |
| 4 | # activated inside /etc/config/ddns by setting |
| 5 | # |
| 6 | # option update_script '/usr/lib/ddns/update_sample.sh' |
| 7 | # |
| 8 | # the script is parsed (not executed) inside send_update() function |
| 9 | # of /usr/lib/ddns/dynamic_dns_functions.sh |
| 10 | # so you can use all available functions and global variables inside this script |
| 11 | # already defined in dynamic_dns_updater.sh and dynamic_dns_functions.sh |
| 12 | # |
| 13 | # It make sence to define the update url ONLY inside this script |
| 14 | # because it's anyway unique to the update script |
| 15 | # otherwise it should work with the default scripts |
| 16 | # |
| 17 | # the code here is the copy of the default used inside send_update() |
| 18 | # |
| 19 | # tested with spdns.de |
| 20 | local __URL="http://[USERNAME]:[PASSWORD]@update.spdns.de/nic/update?hostname=[DOMAIN]&myip=[IP]" |
| 21 | # inside url we need domain, username and password |
| 22 | [ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'" |
| 23 | [ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'" |
| 24 | [ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'" |
| 25 | |
| 26 | # do replaces in URL |
| 27 | __URL=$(echo $__URL | | sed -e "s#\[USERNAME\]#$URL_USER#g" -e "s#\[PASSWORD\]#$URL_PASS#g" \ |
| 28 | -e "s#\[PARAMENC\]#$URL_PENC#g" -e "s#\[PARAMOPT\]#$param_opt#g" \ |
| 29 | -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g") |
| 30 | [ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#') |
| 31 | |
| 32 | do_transfer "$__URL" || return 1 |
| 33 | |
| 34 | write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)" |
| 35 | |
| 36 | # analyse provider answers |
| 37 | # "good [IP_ADR]" = successful |
| 38 | # "nochg [IP_ADR]" = no change but OK |
| 39 | grep -i -E "good|nochg" $DATFILE >/dev/null 2>&1 |
| 40 | return $? # "0" if "good" or "nochg" found |
| 41 | |