Skip to content

Commit

Permalink
ddns-scripts_dnspod: login with token
Browse files Browse the repository at this point in the history
  • Loading branch information
qq57240 authored and 1715173329 committed Mar 20, 2023
1 parent 19d8374 commit d74f5b2
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions net/ddns-scripts_dnspod/files/update_dnspod_com.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
[ -z "$password" ] && write_log 14 "Configuration error! [Password] cannot be empty"

#检查外部调用工具
[ -n "$WGET_SSL" ] || write_log 13 "GNU Wget support is required to use Alibaba Cloud API. Please install first"
[ -n "$WGET_SSL" ] || write_log 13 "GNU Wget support is required to use DNSPod API. Please install first"

# 变量声明
local __URLBASE __HOST __DOMAIN __TYPE __CMDBASE __TOKEN __POST __POST1 __RECIP __RECID __value __TTL
local __URLBASE __HOST __DOMAIN __TYPE __CMDBASE __POST __POST1 __RECIP __RECID __value __TTL
__URLBASE="https://api.dnspod.com/"

# 从 $domain 分离主机和域名
Expand Down Expand Up @@ -59,34 +59,26 @@ dnspod_transfer() {
local __A=$1
local __CNT=0
local __ERR=0
local __B __C PID_SLEEP
local __B PID_SLEEP
case "$__A" in
0)
__B="$__CMDBASE 'login_email=$username&login_password=$password&format=json' ${__URLBASE}Auth"
__C=$__B
;;
1)
__B="$__CMDBASE '$__POST' ${__URLBASE}Record.List"
__C=1
;;
2)
1)
__B="$__CMDBASE '$__POST1' ${__URLBASE}Record.Create"
__C=1
;;
3)
2)
__B="$__CMDBASE '$__POST1&record_id=$__RECID&ttl=$__TTL' ${__URLBASE}Record.Modify"
__C=1
;;
esac

while : ; do
[ $__C -eq 1 ] && __C=$(echo -e "$__B" | sed -e "s/${__TOKEN#*,}/***PW***/g")
write_log 7 "#> $__C"
write_log 7 "#> $__B"
eval $__B
__ERR=`jsonfilter -i $DATFILE -e "@.status.code"`

[ $__ERR -eq 1 ] && return 0
[ $__A -eq 1 ] && [ $__ERR -eq 10 ] && return 0
[ $__A -eq 0 ] && [ $__ERR -eq 10 ] && return 0
write_log 3 "Error message:[$(jsonfilter -i $DATFILE -e "@.status.message")]"

if [ $VERBOSE -gt 1 ]; then
Expand All @@ -107,26 +99,24 @@ dnspod_transfer() {

#添加解析记录
add_domain() {
dnspod_transfer 2
dnspod_transfer 1
write_log 7 "Add new parsing record [${__HOST}.${__DOMAIN}],[type:$__TYPE],[ip:$__IP] successfully!"
return 0
}

#修改解析记录
update_domain() {
dnspod_transfer 3
dnspod_transfer 2
write_log 7 "Modify new parsing record [${__HOST}.${__DOMAIN}],[type:$__TYPE],[ip:$__IP],[TTL:$__TTL] successfully!"
return 0
}

#获取域名解析记录
describe_domain() {
ret=0
__POST="login_token=$username,$password&format=json&domain=$__DOMAIN&sub_domain=$__HOST&record_type=$__TYPE"
__POST1="$__POST&value=$__IP&record_type=$__TYPE&record_line_id=0"
dnspod_transfer 0
__TOKEN=`jsonfilter -i $DATFILE -e "@.user_token"`
__POST="user_token=$__TOKEN&format=json&domain=$__DOMAIN&sub_domain=$__HOST"
__POST1="$__POST&value=$__IP&record_type=$__TYPE&record_line=default"
dnspod_transfer 1
__TMP=`jsonfilter -i $DATFILE -e "@.records[@.type!='NS']"`
__value=`jsonfilter -s "$__TMP" -e "@.name"`
if [ "$__value" == "" ]; then
Expand Down

0 comments on commit d74f5b2

Please sign in to comment.