dyndns-update.sh 800 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. [[ $(uci get dyndns.superglue.enable) == '1' ]] || exit 1
  3. _DOMAIN=$(uci get dyndns.superglue.domain) &&
  4. _SUB=$(uci get dyndns.superglue.subdomain) &&
  5. _UPDATEURL=$(uci get dyndns.superglue.updateurl) &&
  6. _CLIENT=$(uci get dyndns.superglue.client)
  7. ## if we are on Superglue VPN talk to the VPN gateway
  8. if grep -q '0A040000' /proc/net/route; then
  9. _UPDATEURL='http://10.4.0.1/ddns/update'
  10. fi
  11. _JSON='{"jsonrpc": "2.0", "client": "'$_CLIENT'", "sub": "'$_SUB'", "domain": "'$_DOMAIN'"}'
  12. _OUT=$(/usr/bin/curl -s -w '\t%{http_code}' -k -d "data=$_JSON" "$_UPDATEURL" 2>&1)
  13. _ERR=$?
  14. if [[ $_ERR -gt 0 ]]; then
  15. printf -v _TIME '%(%Y-%m-%d %H:%M:%S)T' -1
  16. printf '%b\n' "$_TIME: $_OUT" >> "/www/log/dyndns.log"
  17. printf '%s' "$_ERR,Updater error"
  18. else
  19. printf '%s' "$_OUT"
  20. fi
  21. exit $_ERR