Skip to content

Commit e748b5e

Browse files
monokooQiLei Niu
authored andcommitted
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: QiLei Niu <qilei.niu@gmail.com>
1 parent e367c1d commit e748b5e

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
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:=83
11+
PKG_RELEASE:=85
1212

1313
PKG_LICENSE:=GPL-2.0
1414

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

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,54 @@ json_get_var __RECORD_COUNT TotalCount
105105
return 1
106106
}
107107

108-
# if multiple records are found, only use the first one
109-
[ "$__RECORD_COUNT" -gt 1 ] && {
110-
write_log 4 "WARNING: found multiple records of $__HOST, only use the first one"
111-
}
112-
113-
# select the first DNS record
114108
json_select DomainRecords
115109
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
110+
# Log the original parameter
111+
write_log 7 "param_enc: `echo ${param_enc}`"
112+
paramEnc=${param_enc}
113+
114+
# Initialize variables
115+
specRecordId=""
116+
found_match=false
117+
118+
# Extract RecordId from parameters
119+
if [ -n "$(echo "${paramEnc}" | grep RecordId)" ]; then
120+
specRecordId=$(echo "$paramEnc" | grep -o 'RecordId=[^&]*' | cut -d'=' -f2)
121+
fi
122+
123+
# If RecordId is successfully extracted, try to match it
124+
if [ -n "$specRecordId" ]; then
125+
write_log 7 "specRecordId: ${specRecordId}"
126+
idx=1
127+
while json_is_a $idx object; do
128+
json_select $idx
129+
json_get_var tmp RecordId
130+
write_log 7 "The $idx Domain RecordId: ${tmp}"
131+
if [ "$tmp" = "$specRecordId" ]; then
132+
__RECORD_ID=$specRecordId
133+
json_get_var __RECORD_VALUE Value
134+
write_log 7 "The $idx Domain Record Value: ${__RECORD_VALUE}"
135+
found_match=true
136+
break
137+
fi
138+
idx=$((idx+1))
139+
json_select ..
140+
done
141+
fi
142+
143+
# Fallback to default logic if no match found
144+
if [ "$found_match" = false ]; then
145+
write_log 7 "Using default logic to select record"
146+
# If multiple records are found, only use the first one
147+
if [ "$__RECORD_COUNT" -gt 1 ]; then
148+
write_log 4 "WARNING: found multiple records of $__HOST, only use the first one"
149+
fi
150+
# select the first DNS record
151+
json_select 1
152+
# Get the record id of the first DNS record
153+
json_get_var __RECORD_ID RecordId
154+
json_get_var __RECORD_VALUE Value
155+
fi
120156

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

0 commit comments

Comments
 (0)