Skip to content

Commit a13c763

Browse files
LogExEfeckert
authored andcommitted
ddns-scripts: add beget.com api support
The Beget API provider was implemented according to https://beget.com/en/kb/api/dns-administration-functions Signed-off-by: Vladimir Tkachev <awesome149712@gmail.com>
1 parent 639fdb4 commit a13c763

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

net/ddns-scripts/Makefile

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
88

99
PKG_NAME:=ddns-scripts
1010
PKG_VERSION:=2.8.2
11-
PKG_RELEASE:=82
11+
PKG_RELEASE:=83
1212

1313
PKG_LICENSE:=GPL-2.0
1414

@@ -271,6 +271,21 @@ define Package/ddns-scripts-gandi/description
271271
endef
272272

273273

274+
define Package/ddns-scripts-beget
275+
$(call Package/ddns-scripts/Default)
276+
TITLE:=Beget API
277+
DEPENDS:=ddns-scripts +curl
278+
endef
279+
280+
define Package/ddns-scripts-beget/description
281+
Dynamic DNS Client scripts extension for 'beget.com'.
282+
It requires:
283+
'option domain' to contain the domain
284+
'option username' to be a valid username for beget.com
285+
'option password' to be a valid API key for beget.com
286+
endef
287+
288+
274289
define Package/ddns-scripts-pdns
275290
$(call Package/ddns-scripts/Default)
276291
TITLE:=PowerDNS API
@@ -446,6 +461,7 @@ define Package/ddns-scripts-services/install
446461
rm $(1)/usr/share/ddns/default/route53-v1.json
447462
rm $(1)/usr/share/ddns/default/cnkuai.cn.json
448463
rm $(1)/usr/share/ddns/default/gandi.net.json
464+
rm $(1)/usr/share/ddns/default/beget.com.json
449465
rm $(1)/usr/share/ddns/default/pdns.json
450466
rm $(1)/usr/share/ddns/default/scaleway.com.json
451467
rm $(1)/usr/share/ddns/default/transip.nl.json
@@ -749,6 +765,25 @@ exit 0
749765
endef
750766

751767

768+
define Package/ddns-scripts-beget/install
769+
$(INSTALL_DIR) $(1)/usr/lib/ddns
770+
$(INSTALL_BIN) ./files/usr/lib/ddns/update_beget_com.sh \
771+
$(1)/usr/lib/ddns
772+
773+
$(INSTALL_DIR) $(1)/usr/share/ddns/default
774+
$(INSTALL_DATA) ./files/usr/share/ddns/default/beget.com.json \
775+
$(1)/usr/share/ddns/default
776+
endef
777+
778+
define Package/ddns-scripts-beget/prerm
779+
#!/bin/sh
780+
if [ -z "$${IPKG_INSTROOT}" ]; then
781+
/etc/init.d/ddns stop
782+
fi
783+
exit 0
784+
endef
785+
786+
752787
define Package/ddns-scripts-pdns/install
753788
$(INSTALL_DIR) $(1)/usr/lib/ddns
754789
$(INSTALL_BIN) ./files/usr/lib/ddns/update_pdns.sh \
@@ -898,6 +933,7 @@ $(eval $(call BuildPackage,ddns-scripts-nsupdate))
898933
$(eval $(call BuildPackage,ddns-scripts-route53))
899934
$(eval $(call BuildPackage,ddns-scripts-cnkuai))
900935
$(eval $(call BuildPackage,ddns-scripts-gandi))
936+
$(eval $(call BuildPackage,ddns-scripts-beget))
901937
$(eval $(call BuildPackage,ddns-scripts-pdns))
902938
$(eval $(call BuildPackage,ddns-scripts-scaleway))
903939
$(eval $(call BuildPackage,ddns-scripts-transip))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
# following script was referenced: https://github.com/openwrt/packages/blob/master/net/ddns-scripts/files/usr/lib/ddns/update_gandi_net.sh
3+
4+
. /usr/share/libubox/jshn.sh
5+
6+
# Beget API description: https://beget.com/en/kb/api/dns-administration-functions#changerecords
7+
__CHANGE_ENDPOINT_API="https://api.beget.com/api/dns/changeRecords"
8+
9+
[ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'"
10+
[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
11+
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
12+
13+
[ "$use_ipv6" -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
14+
15+
json_init
16+
17+
json_add_string "fqdn" "$domain"
18+
19+
json_add_object "records"
20+
json_add_array "$__RRTYPE"
21+
json_add_object ""
22+
json_add_string "value" "$__IP"
23+
json_close_object
24+
json_close_array
25+
json_close_object
26+
27+
json_payload=$(json_dump)
28+
29+
__STATUS=$(curl -X POST "$__CHANGE_ENDPOINT_API" \
30+
-d "input_format=json" \
31+
-d "output_format=json" \
32+
--data-urlencode "login=$username" \
33+
--data-urlencode "passwd=$password" \
34+
--data-urlencode "input_data=$json_payload" \
35+
-w "%{http_code}\n" \
36+
-o $DATFILE 2>$ERRFILE)
37+
38+
__ERRNO=$?
39+
if [[ $__ERRNO -ne 0 ]]; then
40+
write_log 14 "Curl failed with $__ERRNO: $(cat $ERRFILE)"
41+
return 1
42+
elif [[ -z $__STATUS || $__STATUS != 200 ]]; then
43+
write_log 14 "Beget reponded with non-200 status \"$__STATUS\": $(cat $ERRFILE)"
44+
return 1
45+
fi
46+
47+
json_load "$DATFILE"
48+
json_getvar beget_resp_status "status"
49+
50+
if [[ -z $beget_resp_status || $beget_resp_status != "success" ]]; then
51+
write_log 14 "Beget response status was \"$beget_resp_status\" != \"success\". $(cat $DATFILE)"
52+
return 1
53+
fi
54+
55+
write_log 7 "Success. Beget API curl response: $(cat $DATFILE)"
56+
57+
return 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "beget.com",
3+
"ipv4": {
4+
"url": "update_beget_com.sh"
5+
},
6+
"ipv6": {
7+
"url": "update_beget_com.sh"
8+
}
9+
}

0 commit comments

Comments
 (0)