mirror of
https://github.com/openwrt/packages.git
synced 2026-01-10 19:54:50 +00:00
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>
This commit is contained in:
committed by
Florian Eckert
parent
639fdb4008
commit
a13c76304e
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=ddns-scripts
|
||||
PKG_VERSION:=2.8.2
|
||||
PKG_RELEASE:=82
|
||||
PKG_RELEASE:=83
|
||||
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
|
||||
@@ -271,6 +271,21 @@ define Package/ddns-scripts-gandi/description
|
||||
endef
|
||||
|
||||
|
||||
define Package/ddns-scripts-beget
|
||||
$(call Package/ddns-scripts/Default)
|
||||
TITLE:=Beget API
|
||||
DEPENDS:=ddns-scripts +curl
|
||||
endef
|
||||
|
||||
define Package/ddns-scripts-beget/description
|
||||
Dynamic DNS Client scripts extension for 'beget.com'.
|
||||
It requires:
|
||||
'option domain' to contain the domain
|
||||
'option username' to be a valid username for beget.com
|
||||
'option password' to be a valid API key for beget.com
|
||||
endef
|
||||
|
||||
|
||||
define Package/ddns-scripts-pdns
|
||||
$(call Package/ddns-scripts/Default)
|
||||
TITLE:=PowerDNS API
|
||||
@@ -446,6 +461,7 @@ define Package/ddns-scripts-services/install
|
||||
rm $(1)/usr/share/ddns/default/route53-v1.json
|
||||
rm $(1)/usr/share/ddns/default/cnkuai.cn.json
|
||||
rm $(1)/usr/share/ddns/default/gandi.net.json
|
||||
rm $(1)/usr/share/ddns/default/beget.com.json
|
||||
rm $(1)/usr/share/ddns/default/pdns.json
|
||||
rm $(1)/usr/share/ddns/default/scaleway.com.json
|
||||
rm $(1)/usr/share/ddns/default/transip.nl.json
|
||||
@@ -749,6 +765,25 @@ exit 0
|
||||
endef
|
||||
|
||||
|
||||
define Package/ddns-scripts-beget/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/ddns
|
||||
$(INSTALL_BIN) ./files/usr/lib/ddns/update_beget_com.sh \
|
||||
$(1)/usr/lib/ddns
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/share/ddns/default
|
||||
$(INSTALL_DATA) ./files/usr/share/ddns/default/beget.com.json \
|
||||
$(1)/usr/share/ddns/default
|
||||
endef
|
||||
|
||||
define Package/ddns-scripts-beget/prerm
|
||||
#!/bin/sh
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
/etc/init.d/ddns stop
|
||||
fi
|
||||
exit 0
|
||||
endef
|
||||
|
||||
|
||||
define Package/ddns-scripts-pdns/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/ddns
|
||||
$(INSTALL_BIN) ./files/usr/lib/ddns/update_pdns.sh \
|
||||
@@ -898,6 +933,7 @@ $(eval $(call BuildPackage,ddns-scripts-nsupdate))
|
||||
$(eval $(call BuildPackage,ddns-scripts-route53))
|
||||
$(eval $(call BuildPackage,ddns-scripts-cnkuai))
|
||||
$(eval $(call BuildPackage,ddns-scripts-gandi))
|
||||
$(eval $(call BuildPackage,ddns-scripts-beget))
|
||||
$(eval $(call BuildPackage,ddns-scripts-pdns))
|
||||
$(eval $(call BuildPackage,ddns-scripts-scaleway))
|
||||
$(eval $(call BuildPackage,ddns-scripts-transip))
|
||||
|
||||
57
net/ddns-scripts/files/usr/lib/ddns/update_beget_com.sh
Normal file
57
net/ddns-scripts/files/usr/lib/ddns/update_beget_com.sh
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
# following script was referenced: https://github.com/openwrt/packages/blob/master/net/ddns-scripts/files/usr/lib/ddns/update_gandi_net.sh
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
# Beget API description: https://beget.com/en/kb/api/dns-administration-functions#changerecords
|
||||
__CHANGE_ENDPOINT_API="https://api.beget.com/api/dns/changeRecords"
|
||||
|
||||
[ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'"
|
||||
[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
|
||||
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
|
||||
|
||||
[ "$use_ipv6" -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
|
||||
|
||||
json_init
|
||||
|
||||
json_add_string "fqdn" "$domain"
|
||||
|
||||
json_add_object "records"
|
||||
json_add_array "$__RRTYPE"
|
||||
json_add_object ""
|
||||
json_add_string "value" "$__IP"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
|
||||
json_payload=$(json_dump)
|
||||
|
||||
__STATUS=$(curl -X POST "$__CHANGE_ENDPOINT_API" \
|
||||
-d "input_format=json" \
|
||||
-d "output_format=json" \
|
||||
--data-urlencode "login=$username" \
|
||||
--data-urlencode "passwd=$password" \
|
||||
--data-urlencode "input_data=$json_payload" \
|
||||
-w "%{http_code}\n" \
|
||||
-o $DATFILE 2>$ERRFILE)
|
||||
|
||||
__ERRNO=$?
|
||||
if [[ $__ERRNO -ne 0 ]]; then
|
||||
write_log 14 "Curl failed with $__ERRNO: $(cat $ERRFILE)"
|
||||
return 1
|
||||
elif [[ -z $__STATUS || $__STATUS != 200 ]]; then
|
||||
write_log 14 "Beget reponded with non-200 status \"$__STATUS\": $(cat $ERRFILE)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
json_load "$DATFILE"
|
||||
json_getvar beget_resp_status "status"
|
||||
|
||||
if [[ -z $beget_resp_status || $beget_resp_status != "success" ]]; then
|
||||
write_log 14 "Beget response status was \"$beget_resp_status\" != \"success\". $(cat $DATFILE)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
write_log 7 "Success. Beget API curl response: $(cat $DATFILE)"
|
||||
|
||||
return 0
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "beget.com",
|
||||
"ipv4": {
|
||||
"url": "update_beget_com.sh"
|
||||
},
|
||||
"ipv6": {
|
||||
"url": "update_beget_com.sh"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user