Merge pull request #16 from wzhy90/master

This commit is contained in:
Fan Jiang authored and GitHub committed 2017-03-05 20:35:48 +09:00
commit 69db8e365d
1 file changed
+29 -13
+29 -13
View File
@@ -127,10 +127,11 @@ arDdnsInfo() {
case "$recordIP" in case "$recordIP" in
[1-9][0-9]*) [1-9][0-9]*)
echo $recordIP echo $recordIP
return 1 return 0
;; ;;
*) *)
echo "Get Record Info Failed!" echo "Get Record Info Failed!"
return 1
;; ;;
esac esac
} }
@@ -151,7 +152,7 @@ arApiPost() {
# Update # Update
# arg: main domain sub domain # arg: main domain sub domain
arDdnsUpdate() { arDdnsUpdate() {
local domainID recordID recordRS recordCD myIP local domainID recordID recordRS recordCD recordIP myIP
# Get domain ID # Get domain ID
domainID=$(arApiPost "Domain.Info" "domain=${1}") domainID=$(arApiPost "Domain.Info" "domain=${1}")
domainID=$(echo $domainID | sed 's/.*{"id":"\([0-9]*\)".*/\1/') domainID=$(echo $domainID | sed 's/.*{"id":"\([0-9]*\)".*/\1/')
@@ -164,14 +165,21 @@ arDdnsUpdate() {
myIP=$(arIpAddress) myIP=$(arIpAddress)
recordRS=$(arApiPost "Record.Ddns" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认") 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/') recordCD=$(echo $recordRS | sed 's/.*{"code":"\([0-9]*\)".*/\1/')
recordIP=$(echo $recordRS | sed 's/.*,"value":"\([0-9\.]*\)".*/\1/')
# Output IP # Output IP
if [ "$recordCD" = "1" ]; then if [ "$recordIP" = "$myIP" ]; then
echo $recordRS | sed 's/.*,"value":"\([0-9\.]*\)".*/\1/' 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 return 1
fi fi
# Echo error message
echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/'
} }
# DDNS Check # DDNS Check
@@ -180,17 +188,25 @@ arDdnsCheck() {
local postRS local postRS
local lastIP local lastIP
local hostIP=$(arIpAddress) local hostIP=$(arIpAddress)
echo "Updating Domain: ${2}.${1}"
echo "hostIP: ${hostIP}" echo "hostIP: ${hostIP}"
lastIP=$(arDdnsInfo "$1 $2") lastIP=$(arDdnsInfo "$1 $2")
echo "lastIP: ${lastIP}" if [ $? -eq 0 ]; then
if [ "$lastIP" != "$hostIP" ]; then echo "lastIP: ${lastIP}"
postRS=$(arDdnsUpdate $1 $2) if [ "$lastIP" != "$hostIP" ]; then
echo "postRS: ${postRS}" postRS=$(arDdnsUpdate $1 $2)
if [ $? -ne 1 ]; then if [ $? -eq 0 ]; then
return 0 echo "postRS: ${postRS}"
return 0
else
echo ${postRS}
return 1
fi
fi fi
echo "Last IP is the same as current IP!"
return 1
fi fi
echo "Last IP is the same as current IP!" echo ${lastIP}
return 1 return 1
} }