aboutsummaryrefslogtreecommitdiff
path: root/net/ddns-scripts/files/usr/lib
diff options
context:
space:
mode:
authorRichard Yu <yurichard3839@gmail.com>2021-12-15 18:22:56 +0800
committerRichard Yu <yurichard3839@gmail.com>2021-12-15 18:22:56 +0800
commit9e6dd114847a55c751b6618d691e5cd51417d5ba (patch)
treeb12b57e17cf51dcd2c0728bd24c08c2fc82c11bc /net/ddns-scripts/files/usr/lib
parentf614850285e87621a62e19c9adb5e71737d08947 (diff)
ddns-scripts: add ns1.com provider
Signed-off-by: Richard Yu <yurichard3839@gmail.com>
Diffstat (limited to 'net/ddns-scripts/files/usr/lib')
-rw-r--r--net/ddns-scripts/files/usr/lib/ddns/update_ns1_com.sh77
1 files changed, 77 insertions, 0 deletions
diff --git a/net/ddns-scripts/files/usr/lib/ddns/update_ns1_com.sh b/net/ddns-scripts/files/usr/lib/ddns/update_ns1_com.sh
new file mode 100644
index 000000000..4b965339c
--- /dev/null
+++ b/net/ddns-scripts/files/usr/lib/ddns/update_ns1_com.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+# Derived from update_gandi_net.sh
+
+. /usr/share/libubox/jshn.sh
+
+local __ENDPOINT="https://api.nsone.net/v1"
+local __TTL=600
+local __RRTYPE
+local __URL
+local __STATUS
+
+[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing zone as 'username'"
+[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing API Key as 'password'"
+
+[ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
+
+# Construct JSON payload
+json_init
+# {"answers":[{"answer":["1.1.1.1"]}]}
+json_add_array answers
+json_add_object
+json_add_array answer
+json_add_string "" "$__IP"
+json_close_array
+json_close_object
+json_close_array
+
+__URL="$__ENDPOINT/zones/$username/$domain/$__RRTYPE"
+
+__STATUS=$(curl -s -X POST "$__URL" \
+ -H "X-NSONE-Key: $password" \
+ -H "Content-Type: application/json" \
+ -d "$(json_dump)" \
+ -w "%{http_code}\n" -o $DATFILE 2>$ERRFILE)
+
+if [ $? -ne 0 ]; then
+ write_log 14 "Curl failed: $(cat $ERRFILE)"
+ return 1
+elif [ -z $__STATUS ] || [ $__STATUS != 200 ]; then
+ write_log 4 "Request failed: $__STATUS, NS1 answered: $(cat $DATFILE)"
+ if [ $__STATUS = 404 ]; then
+ write_log 4 "Status is 404, trying to create a DNS record"
+
+ json_init
+ json_add_string "zone" "$username"
+ json_add_string "domain" "$domain"
+ json_add_string "type" "$__RRTYPE"
+ json_add_string "ttl" "$__TTL"
+ json_add_array answers
+ json_add_object
+ json_add_array answer
+ json_add_string "" "$__IP"
+ json_close_array
+ json_close_object
+ json_close_array
+
+ __STATUS=$(curl -s -X PUT "$__URL" \
+ -H "X-NSONE-Key: $password" \
+ -H "Content-Type: application/json" \
+ -d "$(json_dump)" \
+ -w "%{http_code}\n" -o $DATFILE 2>$ERRFILE)
+
+ if [ $? -ne 0 ]; then
+ write_log 14 "Curl failed: $(cat $ERRFILE)"
+ return 1
+ elif [ -z $__STATUS ] || [ $__STATUS != 200 ]; then
+ write_log 14 "Request failed: $__STATUS, NS1 answered: $(cat $DATFILE)"
+ return 1
+ fi
+ else
+ return 1
+ fi
+fi
+
+write_log 7 "NS1 answered: $(cat $DATFILE)"
+
+return 0