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.

52 lines
1.4 KiB

  1. #!/bin/sh
  2. # Derived from update_gandi_net.sh
  3. . /usr/share/libubox/jshn.sh
  4. local __TTL=600
  5. local __RRTYPE
  6. local __STATUS
  7. [ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing subdomain as 'username'"
  8. [ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing API Key as 'password'"
  9. [ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing PowerDNS URL as 'Optional Parameter'(param_opt)"
  10. # Create endpoint from $param_opt
  11. # e.g. param_opt=http://127.0.0.1:8081
  12. local __ENDPOINT="$param_opt/api/v1/servers/localhost/zones"
  13. [ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
  14. # Build JSON payload
  15. json_init
  16. json_add_array rrsets
  17. json_add_object
  18. json_add_string name "$username.$domain"
  19. json_add_string type "$__RRTYPE"
  20. json_add_int ttl $__TTL
  21. json_add_string changetype "REPLACE"
  22. json_add_array records
  23. json_add_object
  24. json_add_string content "$__IP"
  25. json_add_boolean disabled 0
  26. json_close_object
  27. json_close_array
  28. json_close_object
  29. json_close_array
  30. __STATUS=$(curl -Ss -X PATCH "$__ENDPOINT/$domain" \
  31. -H "X-Api-Key: $password" \
  32. -H "Content-Type: application/json" \
  33. -d "$(json_dump)" \
  34. -w "%{http_code}\n" \
  35. -o $DATFILE 2>$ERRFILE)
  36. if [ $? -ne 0 ]; then
  37. write_log 14 "Curl failed: $(cat $ERRFILE)"
  38. return 1
  39. elif [ -z $__STATUS ] || [ $__STATUS != 204 ]; then
  40. write_log 14 "PowerDNS request failed: $__STATUS \n$(cat $DATFILE)"
  41. return 1
  42. fi
  43. return 0