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.

39 lines
1.1 KiB

  1. #!/bin/sh
  2. # Thanks goes to Alex Griffin who provided this script.
  3. . /usr/share/libubox/jshn.sh
  4. local __TTL=600
  5. local __RRTYPE
  6. local __ENDPOINT="https://api.gandi.net/v5/livedns"
  7. local __STATUS
  8. [ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing subdomain as 'username'"
  9. [ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing API Key as 'password'"
  10. [ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
  11. # Construct JSON payload
  12. json_init
  13. json_add_int rrset_ttl "$__TTL"
  14. json_add_array rrset_values
  15. json_add_string "" "$__IP"
  16. json_close_array
  17. __STATUS=$(curl -s -X PUT "$__ENDPOINT/domains/$domain/records/$username/$__RRTYPE" \
  18. -H "Authorization: Apikey $password" \
  19. -H "Content-Type: application/json" \
  20. -d "$(json_dump)" \
  21. -w "%{http_code}\n" -o $DATFILE 2>$ERRFILE)
  22. if [ $? -ne 0 ]; then
  23. write_log 14 "Curl failed: $(cat $ERRFILE)"
  24. return 1
  25. elif [ -z $__STATUS ] || [ $__STATUS != 201 ]; then
  26. write_log 14 "LiveDNS failed: $__STATUS \ngandi.net answered: $(cat $DATFILE)"
  27. return 1
  28. fi
  29. write_log 7 "gandi.net answered: $(cat $DATFILE)"
  30. return 0