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