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
+21 -5
+21 -5
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 [ "$recordIP" = "$myIP" ]; then
if [ "$recordCD" = "1" ]; then if [ "$recordCD" = "1" ]; then
echo $recordRS | sed 's/.*,"value":"\([0-9\.]*\)".*/\1/' echo $recordIP
return 1 return 0
fi fi
# Echo error message # Echo error message
echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/' echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/'
return 1
else
echo "Update Failed! Please check your network."
return 1
fi
} }
# DDNS Check # DDNS Check
@@ -180,18 +188,26 @@ 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")
if [ $? -eq 0 ]; then
echo "lastIP: ${lastIP}" echo "lastIP: ${lastIP}"
if [ "$lastIP" != "$hostIP" ]; then if [ "$lastIP" != "$hostIP" ]; then
postRS=$(arDdnsUpdate $1 $2) postRS=$(arDdnsUpdate $1 $2)
if [ $? -eq 0 ]; then
echo "postRS: ${postRS}" echo "postRS: ${postRS}"
if [ $? -ne 1 ]; then
return 0 return 0
else
echo ${postRS}
return 1
fi fi
fi fi
echo "Last IP is the same as current IP!" echo "Last IP is the same as current IP!"
return 1 return 1
fi
echo ${lastIP}
return 1
} }
# DDNS # DDNS