Distinguish record ip unchanged event from updated event
This commit is contained in:
1 parent
aff816b955
commit
0bc7d9df3b
2 files changed
+38
-5
No files matched your search
@@ -24,6 +24,11 @@ if ! type arLog >/dev/null 2>&1; then
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# The error code to return when a ddns record is not changed
|
||||||
|
|
||||||
|
if [ -z "$arErrCodeUnchanged" ]; then
|
||||||
|
arErrCodeUnchanged=0 # By default, report unchanged event as success
|
||||||
|
fi
|
||||||
|
|
||||||
# Get IPv4
|
# Get IPv4
|
||||||
|
|
||||||
@@ -133,10 +138,26 @@ arDdnsUpdate() {
|
|||||||
|
|
||||||
local errMsg
|
local errMsg
|
||||||
|
|
||||||
|
local lastRecordIp
|
||||||
local recordRs
|
local recordRs
|
||||||
local recordCd
|
local recordCd
|
||||||
local recordIp
|
local recordIp
|
||||||
|
|
||||||
|
# if code for unchanged event is specified to be different from updated event, we fetch the last record ip
|
||||||
|
if [ $arErrCodeUnchanged -ne 0 ]; then
|
||||||
|
recordRs=$(arDdnsApi "Record.Info" "domain=$1&record_id=$3")
|
||||||
|
recordCd=$(echo $recordRs | sed 's/.*{"code":"\([0-9]*\)".*/\1/')
|
||||||
|
lastRecordIp=$(echo $recordRs | sed 's/.*,"value":"\([0-9a-fA-F\.\:]*\)".*/\1/')
|
||||||
|
|
||||||
|
if [ "$recordCd" != "1" ]; then
|
||||||
|
errMsg=$(echo $recordRs | sed 's/.*,"message":"\([^"]*\)".*/\1/')
|
||||||
|
arLog "> arDdnsUpdate - error: $errMsg"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
arLog "> arDdnsUpdate - last record ip: $lastRecordIp"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# update ip
|
# update ip
|
||||||
if [ -z "$5" ]; then
|
if [ -z "$5" ]; then
|
||||||
recordRs=$(arDdnsApi "Record.Ddns" "domain=$1&sub_domain=$2&record_id=$3&record_type=$4&record_line=%e9%bb%98%e8%ae%a4")
|
recordRs=$(arDdnsApi "Record.Ddns" "domain=$1&sub_domain=$2&record_id=$3&record_type=$4&record_line=%e9%bb%98%e8%ae%a4")
|
||||||
@@ -148,14 +169,22 @@ arDdnsUpdate() {
|
|||||||
recordCd=$(echo $recordRs | sed 's/.*{"code":"\([0-9]*\)".*/\1/')
|
recordCd=$(echo $recordRs | sed 's/.*{"code":"\([0-9]*\)".*/\1/')
|
||||||
recordIp=$(echo $recordRs | sed 's/.*,"value":"\([0-9a-fA-F\.\:]*\)".*/\1/')
|
recordIp=$(echo $recordRs | sed 's/.*,"value":"\([0-9a-fA-F\.\:]*\)".*/\1/')
|
||||||
|
|
||||||
if [ "$recordCd" = "1" ]; then
|
if [ "$recordCd" != "1" ]; then
|
||||||
arLog "> arDdnsUpdate - $recordIp"
|
errMsg=$(echo $recordRs | sed 's/.*,"message":"\([^"]*\)".*/\1/')
|
||||||
|
arLog "> arDdnsUpdate - error: $errMsg"
|
||||||
|
return 1
|
||||||
|
elif [ $arErrCodeUnchanged -eq 0 ]; then
|
||||||
|
arLog "> arDdnsUpdate - success: $recordIp" # both unchanged and updated event
|
||||||
echo $recordIp
|
echo $recordIp
|
||||||
return 0
|
return 0
|
||||||
|
elif [ "$recordIp" = "$lastRecordIp" ]; then
|
||||||
|
arLog "> arDdnsUpdate - unchanged: $recordIp" # unchanged event
|
||||||
|
echo $recordIp
|
||||||
|
return $arErrCodeUnchanged
|
||||||
else
|
else
|
||||||
errMsg=$(echo $recordRs | sed 's/.*,"message":"\([^"]*\)".*/\1/')
|
arLog "> arDdnsUpdate - updated: $recordIp" # updated event
|
||||||
arLog "> arDdnsUpdate - $errMsg"
|
echo $recordIp
|
||||||
return 1
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
# Combine your token ID and token together as follows
|
# Combine your token ID and token together as follows
|
||||||
arToken="12345,7676f344eaeaea9074c123451234512d"
|
arToken="12345,7676f344eaeaea9074c123451234512d"
|
||||||
|
|
||||||
|
# Return code when the last record IP is same as current host IP
|
||||||
|
# Set this to a value other than 0 to distinguish with a successful ddns update
|
||||||
|
# arErrCodeUnchanged=0
|
||||||
|
|
||||||
# Place each domain you want to check as follows
|
# Place each domain you want to check as follows
|
||||||
# you can have multiple arDdnsCheck blocks
|
# you can have multiple arDdnsCheck blocks
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user