@@ -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
114108json_select DomainRecords
115109json_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