Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion net/ddns-scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -271,6 +271,20 @@ 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 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
Expand Down Expand Up @@ -446,6 +460,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
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line contains inconsistent indentation - it uses spaces instead of tabs. The rest of the Makefile uses tabs for indentation. This line should use a tab character at the beginning to match the surrounding code style.

Suggested change
rm $(1)/usr/share/ddns/default/beget.com.json
rm $(1)/usr/share/ddns/default/beget.com.json

Copilot uses AI. Check for mistakes.
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
Expand Down Expand Up @@ -749,6 +764,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 \
Expand Down Expand Up @@ -898,6 +932,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))
Expand Down
43 changes: 43 additions & 0 deletions net/ddns-scripts/files/usr/lib/ddns/update_beget_com.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/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
local __CHANGE_ENDPOINT_API="https://api.beget.com/api/dns/changeRecords"

local __RRTYPE
local __STATUS
Comment on lines +7 to +10
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable __CHANGE_ENDPOINT_API is declared as local at the script's top level, which is outside any function. In shell scripts, local is only meaningful inside functions. This should be declared without the local keyword, similar to how other DDNS update scripts handle their variables at the top level.

Suggested change
local __CHANGE_ENDPOINT_API="https://api.beget.com/api/dns/changeRecords"
local __RRTYPE
local __STATUS
__CHANGE_ENDPOINT_API="https://api.beget.com/api/dns/changeRecords"
__RRTYPE
__STATUS

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +10
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables __RRTYPE and __STATUS are declared as local at the script's top level, which is outside any function. In shell scripts, local is only meaningful inside functions. These should be declared without the local keyword, similar to how other DDNS update scripts handle their variables at the top level.

Suggested change
local __CHANGE_ENDPOINT_API="https://api.beget.com/api/dns/changeRecords"
local __RRTYPE
local __STATUS
__CHANGE_ENDPOINT_API="https://api.beget.com/api/dns/changeRecords"
__RRTYPE=
__STATUS=

Copilot uses AI. Check for mistakes.

[ -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_int "priority" 10
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The priority field is hardcoded to 10. According to DNS standards, priority is typically only relevant for MX (mail exchange) and SRV (service) records, not for A or AAAA records which are being set here. This field may be unnecessary or could cause API errors. Verify if the Beget API requires or accepts a priority field for A/AAAA records, and if not, this field should be removed.

Suggested change
json_add_int "priority" 10

Copilot uses AI. Check for mistakes.
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)

Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace at the end of this line. This should be removed to maintain code cleanliness and consistency with the rest of the codebase.

Suggested change

Copilot uses AI. Check for mistakes.
write_log 7 "Beget API curl response: $(cat $DATFILE)"

Comment on lines +38 to +42
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script does not check the curl exit code or HTTP status code returned from the API. Unlike other DDNS update scripts (e.g., update_gandi_net.sh, update_digitalocean_com_v2.sh), there's no validation that the API call succeeded. The script should check if curl failed and validate that the HTTP status code indicates success before returning 0. Without this validation, DNS update failures may go undetected.

Suggested change
-w "%{http_code}\n" \
-o $DATFILE 2>$ERRFILE)
write_log 7 "Beget API curl response: $(cat $DATFILE)"
-w "%{http_code}" \
-o "$DATFILE" 2>"$ERRFILE")
__CURL_RC=$?
write_log 7 "Beget API curl response: $(cat $DATFILE)"
if [ "$__CURL_RC" -ne 0 ]; then
write_log 3 "Beget API curl request failed with exit code $__CURL_RC"
return 1
fi
case "$__STATUS" in
2??)
# HTTP 2xx, consider this a success
;;
*)
write_log 3 "Beget API returned HTTP error code $__STATUS"
return 1
;;
esac

Copilot uses AI. Check for mistakes.
return 0
9 changes: 9 additions & 0 deletions net/ddns-scripts/files/usr/share/ddns/default/beget.com.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "beget.com",
"ipv4": {
"url": "update_beget_com.sh"
},
"ipv6": {
"url": "update_beget_com.sh"
}
}