You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.2 KiB

  1. # Script for sending user defined updates using DO API
  2. # 2015 Artem Yakimenko <code at temik dot me>
  3. #
  4. # activated inside /etc/config/ddns by setting
  5. #
  6. # option update_script '/usr/lib/ddns/update_do.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. # Options are passed from /etc/config/ddns:
  18. # Username - the record name DO Zone
  19. # Password - API Token
  20. # Domain - the domain managed by DO
  21. # Parm_opt - The Record ID in the DO API structure
  22. local __URL="https://api.digitalocean.com/v2/domains/[DOMAIN]/records/[RECORD_ID]"
  23. local __HEADER="Authorization: Bearer [PASSWORD]"
  24. local __HEADER_CONTENT="Content-Type: application/json"
  25. local __BODY='{"name":"[NAME]","data": "[IP]"}'
  26. # inside url we need username and password
  27. [ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'"
  28. [ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'Zone name in Username'"
  29. [ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
  30. [ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing 'Zone ID in Optional Parameter'"
  31. # do replaces in URL, header and body:
  32. __URL=$(echo $__URL | sed -e "s#\[RECORD_ID\]#$param_opt#g" \
  33. -e "s#\[DOMAIN\]#$domain#g")
  34. __HEADER=$(echo $__HEADER| sed -e "s#\[PASSWORD\]#$password#g")
  35. __HEADER_CONTENT=$(echo $__HEADER_CONTENT)
  36. __BODY=$(echo $__BODY | sed -e "s#\[NAME\]#$username#g" -e "s#\[IP\]#$__IP#g")
  37. #Send PUT request
  38. curl -X PUT -H "$__HEADER_CONTENT" -H "$__HEADER" -d "$__BODY" "$__URL"
  39. write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)"
  40. # analyse provider answers
  41. # If IP is contained in the returned datastructure - API call was sucessful
  42. grep -E "$__IP" $DATFILE >/dev/null 2>&1
  43. return $? # "0" if IP has been changed or no change is needed