Skip to content

Commit 2778d86

Browse files
committed
ddns-scripts: add multiple DNS records support for aliyun ddns
Added logic to extract and match DNS record ID from parameters, with fallback to default selection if no match is found. Signed-off-by: monokoo <[email protected]>
1 parent 0ca33e7 commit 2778d86

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

net/ddns-scripts/Makefile

Lines changed: 1 addition & 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:=81
11+
PKG_RELEASE:=82
1212

1313
PKG_LICENSE:=GPL-2.0
1414

net/ddns-scripts/files/usr/lib/ddns/update_aliyun_com.sh

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,53 @@ json_get_var __RECORD_COUNT TotalCount
113113
# select the first DNS record
114114
json_select DomainRecords
115115
json_select Record
116-
json_select 1
117-
# get the record id of the first DNS record
118-
json_get_var __RECORD_ID RecordId
119-
json_get_var __RECORD_VALUE Value
116+
117+
# Log the original parameter
118+
write_log 7 "param_enc: `echo ${param_enc}`"
119+
paramEnc=${param_enc}
120+
121+
# Initialize variables
122+
specRecordId=""
123+
found_match=false
124+
125+
# Extract RecordId from parameters
126+
if [ -n "$(echo "${paramEnc}" | grep RecordId)" ]; then
127+
specRecordId=$(echo "$paramEnc" | grep -o 'RecordId=[^&]*' | cut -d'=' -f2)
128+
fi
129+
130+
# If RecordId is successfully extracted, try to match it
131+
if [ -n "$specRecordId" ]; then
132+
write_log 7 "specRecordId: ${specRecordId}"
133+
idx=1
134+
while json_is_a $idx object
135+
do
136+
json_select $idx
137+
json_get_var tmp RecordId
138+
write_log 7 "The $idx Domain RecordId: ${tmp}"
139+
if [ "$tmp" = "$specRecordId" ]; then
140+
__RECORD_ID=$specRecordId
141+
json_get_var __RECORD_VALUE Value
142+
write_log 7 "The $idx Domain Record Value: ${__RECORD_VALUE}"
143+
found_match=true
144+
break
145+
fi
146+
idx=$((idx+1))
147+
json_select ..
148+
done
149+
fi
150+
151+
# Fallback to default logic if no match found
152+
if [ "$found_match" = false ]; then
153+
write_log 7 "Using default logic to select record"
154+
# If multiple records are found, only use the first one
155+
if [ "$__RECORD_COUNT" -gt 1 ]; then
156+
write_log 4 "WARNING: found multiple records of $__HOST, only use the first one"
157+
fi
158+
json_select 1
159+
# Get the record id of the first DNS record
160+
json_get_var __RECORD_ID RecordId
161+
json_get_var __RECORD_VALUE Value
162+
fi
120163

121164
# dont update if the ip has not changed
122165
[ "$__RECORD_VALUE" = "$__IP" ] && {

0 commit comments

Comments
 (0)