Skip to content

Commit 2ef2362

Browse files
committed
ddns-scripts: add beget.com api support
Signed-off-by: LogXx <[email protected]>
1 parent 63308ab commit 2ef2362

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

net/ddns-scripts/Makefile

Lines changed: 36 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,20 @@ 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 username' to be a valid username for beget.com
284+
'option password' to be a valid API key for beget.com
285+
endef
286+
287+
274288
define Package/ddns-scripts-pdns
275289
$(call Package/ddns-scripts/Default)
276290
TITLE:=PowerDNS API
@@ -446,6 +460,7 @@ define Package/ddns-scripts-services/install
446460
rm $(1)/usr/share/ddns/default/route53-v1.json
447461
rm $(1)/usr/share/ddns/default/cnkuai.cn.json
448462
rm $(1)/usr/share/ddns/default/gandi.net.json
463+
rm $(1)/usr/share/ddns/default/beget.com.json
449464
rm $(1)/usr/share/ddns/default/pdns.json
450465
rm $(1)/usr/share/ddns/default/scaleway.com.json
451466
rm $(1)/usr/share/ddns/default/transip.nl.json
@@ -749,6 +764,25 @@ exit 0
749764
endef
750765

751766

767+
define Package/ddns-scripts-beget/install
768+
$(INSTALL_DIR) $(1)/usr/lib/ddns
769+
$(INSTALL_BIN) ./files/usr/lib/ddns/update_beget_com.sh \
770+
$(1)/usr/lib/ddns
771+
772+
$(INSTALL_DIR) $(1)/usr/share/ddns/default
773+
$(INSTALL_DATA) ./files/usr/share/ddns/default/beget.com.json \
774+
$(1)/usr/share/ddns/default
775+
endef
776+
777+
define Package/ddns-scripts-beget/prerm
778+
#!/bin/sh
779+
if [ -z "$${IPKG_INSTROOT}" ]; then
780+
/etc/init.d/ddns stop
781+
fi
782+
exit 0
783+
endef
784+
785+
752786
define Package/ddns-scripts-pdns/install
753787
$(INSTALL_DIR) $(1)/usr/lib/ddns
754788
$(INSTALL_BIN) ./files/usr/lib/ddns/update_pdns.sh \
@@ -898,6 +932,7 @@ $(eval $(call BuildPackage,ddns-scripts-nsupdate))
898932
$(eval $(call BuildPackage,ddns-scripts-route53))
899933
$(eval $(call BuildPackage,ddns-scripts-cnkuai))
900934
$(eval $(call BuildPackage,ddns-scripts-gandi))
935+
$(eval $(call BuildPackage,ddns-scripts-beget))
901936
$(eval $(call BuildPackage,ddns-scripts-pdns))
902937
$(eval $(call BuildPackage,ddns-scripts-scaleway))
903938
$(eval $(call BuildPackage,ddns-scripts-transip))
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
local __CHANGE_ENDPOINT_API="https://api.beget.com/api/dns/changeRecords"
8+
9+
local __RRTYPE
10+
local __STATUS
11+
12+
[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
13+
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
14+
15+
[ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
16+
17+
json_init
18+
19+
json_add_string "fqdn" "$domain"
20+
21+
json_add_object "records"
22+
json_add_array "$__RRTYPE"
23+
json_add_object ""
24+
json_add_int "priority" 10
25+
json_add_string "value" "$__IP"
26+
json_close_object
27+
json_close_array
28+
json_close_object
29+
30+
json_payload=`json_dump`
31+
32+
__STATUS=$(curl -X POST "$__CHANGE_ENDPOINT_API" \
33+
-d "input_format=json" \
34+
-d "output_format=json" \
35+
--data-urlencode "login=$username" \
36+
--data-urlencode "passwd=$password" \
37+
--data-urlencode "input_data=$json_payload" \
38+
-w "%{http_code}\n" \
39+
-o $DATFILE 2>$ERRFILE)
40+
41+
write_log 7 "Beget API curl response: $(cat $DATFILE)"
42+
43+
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)