Add a check when updated IP is the same as what we updated.

I have look at the API doc, the value of IP is optional, So if we update some text the "code"s value will still return "1".
This commit is contained in:
wzhy90 committed 2017-03-05 18:13:16 +08:00
1 parent 808066b5a3
commit f471b3502b
1 file changed
+16 -7
+16 -7
View File
@@ -152,7 +152,7 @@ arApiPost() {
# Update
# arg: main domain sub domain
arDdnsUpdate() {
local domainID recordID recordRS recordCD myIP
local domainID recordID recordRS recordCD recordIP myIP
# Get domain ID
domainID=$(arApiPost "Domain.Info" "domain=${1}")
domainID=$(echo $domainID | sed 's/.*{"id":"\([0-9]*\)".*/\1/')
@@ -165,15 +165,21 @@ arDdnsUpdate() {
myIP=$(arIpAddress)
recordRS=$(arApiPost "Record.Ddns" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认")
recordCD=$(echo $recordRS | sed 's/.*{"code":"\([0-9]*\)".*/\1/')
recordIP=$(echo $recordRS | sed 's/.*,"value":"\([0-9\.]*\)".*/\1/')
# Output IP
if [ "$recordCD" = "1" ]; then
echo $recordRS | sed 's/.*,"value":"\([0-9\.]*\)".*/\1/'
return 0
if [ "$recordIP" = "$myIP" ]; then
if [ "$recordCD" = "1" ]; then
echo $recordIP
return 0
fi
# Echo error message
echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/'
return 1
else
echo "Update Failed! Please check your network."
return 1
fi
# Echo error message
echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/'
return 1
}
# DDNS Check
@@ -192,6 +198,9 @@ arDdnsCheck() {
if [ $? -eq 0 ]; then
echo "postRS: ${postRS}"
return 0
else
echo ${postRS}
return 1
fi
fi
echo "Last IP is the same as current IP!"