From 9bff199572b60348303e766dcf03d37c6bcf7926 Mon Sep 17 00:00:00 2001 From: wzhy90 Date: Sun, 5 Mar 2017 18:04:51 +0800 Subject: [PATCH 1/3] Fixes when get record IP fail will still update IP. --- ddnspod.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ddnspod.sh b/ddnspod.sh index e5b85e7..cad008b 100755 --- a/ddnspod.sh +++ b/ddnspod.sh @@ -127,10 +127,11 @@ arDdnsInfo() { case "$recordIP" in [1-9][0-9]*) echo $recordIP - return 1 + return 0 ;; *) echo "Get Record Info Failed!" + return 1 ;; esac } @@ -180,17 +181,22 @@ arDdnsCheck() { local postRS local lastIP local hostIP=$(arIpAddress) + echo "Updating Domain: ${2}.${1}" echo "hostIP: ${hostIP}" lastIP=$(arDdnsInfo "$1 $2") - echo "lastIP: ${lastIP}" - if [ "$lastIP" != "$hostIP" ]; then - postRS=$(arDdnsUpdate $1 $2) - echo "postRS: ${postRS}" - if [ $? -ne 1 ]; then - return 0 + if [ $? -eq 0 ]; then + echo "lastIP: ${lastIP}" + if [ "$lastIP" != "$hostIP" ]; then + postRS=$(arDdnsUpdate $1 $2) + echo "postRS: ${postRS}" + if [ $? -ne 1 ]; then + return 0 + fi fi + echo "Last IP is the same as current IP!" + return 1 fi - echo "Last IP is the same as current IP!" + echo ${lastIP} return 1 } From 808066b5a3a4fbd86e78472a1347bba79aebd893 Mon Sep 17 00:00:00 2001 From: wzhy90 Date: Sun, 5 Mar 2017 18:09:44 +0800 Subject: [PATCH 2/3] Fixes update IP success or not. After echo some things, the return will allways be 0. --- ddnspod.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ddnspod.sh b/ddnspod.sh index cad008b..656a9a1 100755 --- a/ddnspod.sh +++ b/ddnspod.sh @@ -169,10 +169,11 @@ arDdnsUpdate() { # Output IP if [ "$recordCD" = "1" ]; then echo $recordRS | sed 's/.*,"value":"\([0-9\.]*\)".*/\1/' - return 1 + return 0 fi # Echo error message echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/' + return 1 } # DDNS Check @@ -188,8 +189,8 @@ arDdnsCheck() { echo "lastIP: ${lastIP}" if [ "$lastIP" != "$hostIP" ]; then postRS=$(arDdnsUpdate $1 $2) - echo "postRS: ${postRS}" - if [ $? -ne 1 ]; then + if [ $? -eq 0 ]; then + echo "postRS: ${postRS}" return 0 fi fi From f471b3502bb669d7769c389acce8ed94be4317f0 Mon Sep 17 00:00:00 2001 From: wzhy90 Date: Sun, 5 Mar 2017 18:13:16 +0800 Subject: [PATCH 3/3] 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". --- ddnspod.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ddnspod.sh b/ddnspod.sh index 656a9a1..542a8c5 100755 --- a/ddnspod.sh +++ b/ddnspod.sh @@ -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!"