Skip to content
Merged
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
2 changes: 1 addition & 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:=83
PKG_RELEASE:=85

PKG_LICENSE:=GPL-2.0

Expand Down
83 changes: 75 additions & 8 deletions net/ddns-scripts/files/usr/lib/ddns/update_aliyun_com.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,85 @@ json_get_var __RECORD_COUNT TotalCount
return 1
}

# if multiple records are found, only use the first one
[ "$__RECORD_COUNT" -gt 1 ] && {
write_log 4 "WARNING: found multiple records of $__HOST, only use the first one"
# extract RecordId from parameters
extract_record_id() {
local param_enc="$1"
local extracted_id=""

# Extract RecordId from parameters safely
if [ -n "$(echo "${param_enc}" | grep RecordId)" ]; then
extracted_id=$(echo "$param_enc" | grep -o 'RecordId=[^&]*' | cut -d'=' -f2)
fi

echo "$extracted_id"
}

# find matching record by RecordId
find_matching_record() {
local target_id="$1"
local found_match=false

if [ -n "$target_id" ]; then
write_log 7 "specRecordId: ${target_id}"
local idx=1
while json_is_a $idx object; do
json_select $idx
json_get_var tmp RecordId
write_log 7 "The $idx Domain RecordId: ${tmp}"
if [ "$tmp" = "$target_id" ]; then
__RECORD_ID=$target_id
json_get_var __RECORD_VALUE Value
write_log 7 "The $idx Domain Record Value: ${__RECORD_VALUE}"
found_match=true
json_select ..
break
fi
idx=$((idx+1))
json_select ..
done
fi

if [ "$found_match" = true ]; then
return 0
else
return 1
fi
}

# select the first record as fallback
select_first_record() {
write_log 7 "Using default logic to select record"

# Check if __RECORD_COUNT is set before using it
if [ "$__RECORD_COUNT" -gt 1 ]; then
write_log 4 "WARNING: found multiple records of $__HOST, only use the first one"
fi

# Select the first DNS record
json_select 1
# Get the record id of the first DNS record
json_get_var __RECORD_ID RecordId
json_get_var __RECORD_VALUE Value
}

# select the first DNS record
json_select DomainRecords
json_select Record
json_select 1
# get the record id of the first DNS record
json_get_var __RECORD_ID RecordId
json_get_var __RECORD_VALUE Value

# Log the original parameter
write_log 7 "param_enc: `echo ${param_enc}`"
paramEnc=${param_enc}

# Try to extract RecordId from parameters
specRecordId=$(extract_record_id "$paramEnc")

# If RecordId is successfully extracted, try to match it
if [ -n "$specRecordId" ] && find_matching_record "$specRecordId"; then
write_log 7 "Found matching record for ID: $specRecordId"
else
# No matching record found or no RecordId to match, use default logic
select_first_record
fi


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