Open kylinfedora opened 8 years ago
修改了下代码,测试后是OK的 kylin@AC88U:/jffs/.koolshare/scripts# cat aliddns_update.sh
#!/bin/sh
eval `dbus export aliddns_`
if [ "$aliddns_enable" != "1" ]; then
nvram set ddns_hostname_x=`nvram get ddns_hostname_old`
echo "not enable"
exit
fi
now=`date`
ip=`curl http://whatismyip.akamai.com/ 2>/dev/null`
#fix remove manually the domain name in aliyun, always update the error
current_ip=`nslookup $aliddns_name.$aliddns_domain | grep -v 127.0.0.1 | grep "Address 1"|tail -n1|cut -d' ' -f3`
if [ "$current_ip" = "" ]
then
nslookup $aliddns_name.$aliddns_domain || unset aliddns_record_id
fi
if [ "$ip" = "$current_ip" ]
then
echo "skipping"
dbus set aliddns_last_act="$now: skipped($ip)"
nvram set ddns_hostname_x="$aliddns_name"."$aliddns_domain"
exit 0
fi
timestamp=`date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ"`
urlencode() {
# urlencode <string>
local length="${#1}"
i=0
out=""
for i in $(awk "BEGIN { for ( i=0; i<$length; i++ ) { print i; } }")
do
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9._-]) out="$out$c" ;;
*) out="$out`printf '%%%02X' "'$c"`" ;;
esac
i=$(($i + 1))
done
echo -n $out
}
send_request() {
local args="AccessKeyId=$aliddns_ak&Action=$1&Format=json&$2&Version=2015-01-09"
local hash=$(urlencode $(echo -n "GET&%2F&$(urlencode $args)" | openssl dgst -sha1 -hmac "$aliddns_sk&" -binary | openssl base64))
curl "http://alidns.aliyuncs.com/?$args&Signature=$hash" 2> /dev/null
}
get_recordid() {
grep -Eo '"RecordId":"[0-9]+"' | cut -d':' -f2 | tr -d '"'
}
query_recordid() {
send_request "DescribeSubDomainRecords" "SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&SubDomain=$aliddns_name1.$aliddns_domain&Timestamp=$timestamp"
kylin@AC88U:/jffs/.koolshare/scripts# cat aliddns_update.sh
#!/bin/sh
eval `dbus export aliddns_`
if [ "$aliddns_enable" != "1" ]; then
nvram set ddns_hostname_x=`nvram get ddns_hostname_old`
echo "not enable"
exit
fi
now=`date`
ip=`curl http://whatismyip.akamai.com/ 2>/dev/null`
#fix remove manually the domain name in aliyun, always update the error
current_ip=`nslookup $aliddns_name.$aliddns_domain | grep -v 127.0.0.1 | grep "Address 1"|tail -n1|cut -d' ' -f3`
if [ "$current_ip" = "" ]
then
nslookup $aliddns_name.$aliddns_domain || unset aliddns_record_id
fi
if [ "$ip" = "$current_ip" ]
then
echo "skipping"
dbus set aliddns_last_act="$now: skipped($ip)"
nvram set ddns_hostname_x="$aliddns_name"."$aliddns_domain"
exit 0
fi
timestamp=`date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ"`
urlencode() {
# urlencode <string>
local length="${#1}"
i=0
out=""
for i in $(awk "BEGIN { for ( i=0; i<$length; i++ ) { print i; } }")
do
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9._-]) out="$out$c" ;;
*) out="$out`printf '%%%02X' "'$c"`" ;;
esac
i=$(($i + 1))
done
echo -n $out
}
send_request() {
local args="AccessKeyId=$aliddns_ak&Action=$1&Format=json&$2&Version=2015-01-09"
local hash=$(urlencode $(echo -n "GET&%2F&$(urlencode $args)" | openssl dgst -sha1 -hmac "$aliddns_sk&" -binary | openssl base64))
curl "http://alidns.aliyuncs.com/?$args&Signature=$hash" 2> /dev/null
}
get_recordid() {
grep -Eo '"RecordId":"[0-9]+"' | cut -d':' -f2 | tr -d '"'
}
query_recordid() {
send_request "DescribeSubDomainRecords" "SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&SubDomain=$aliddns_name1.$aliddns_domain&Timestamp=$timestamp"
}
update_record() {
send_request "UpdateDomainRecord" "RR=$aliddns_name1&RecordId=$1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&Timestamp=$timestamp&Type=A&Value=$ip"
}
add_record() {
send_request "AddDomainRecord&DomainName=$aliddns_domain" "RR=$aliddns_name1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&Timestamp=$timestamp&Type=A&Value=$ip"
}
#add support * record
if [ "$aliddns_name" = "*" ]
then
aliddns_name1=%2A
else
aliddns_name1=$aliddns_name
fi
if [ "$aliddns_record_id" = "" ]
then
aliddns_record_id=`query_recordid | get_recordid`
fi
if [ "$aliddns_record_id" = "" ]
then
aliddns_record_id=`add_record | get_recordid`
echo "added record $aliddns_record_id"
else
update_record $aliddns_record_id
echo "updated record $aliddns_record_id"
fi
# save to file
if [ "$aliddns_record_id" = "" ]; then
# failed
dbus ram aliddns_last_act="$now: failed"
nvram set ddns_hostname_x=`nvram get ddns_hostname_old`
else
dbus ram aliddns_record_id=$aliddns_record_id
dbus ram aliddns_last_act="$now: success($ip)"
nvram set ddns_hostname_x="$aliddns_name"."$aliddns_domain"
现在无法更新了。 提示 "Message":"Specified signature is not matched with our calculation." 看看这个要如何解决!?
看到市场里面又更新了,我顺便更新下,支持*和@解析使用@解析时最好使用114.114.114.114,阿里的dns 223.5.5.5 解析时很多时候解析不到,造成后面一直执行添加 我的代码回顺便提交到作者的github上去 大家有问题可以回复我 /koolshare/scripts/aliddns_update.sh文件如下:
#!/bin/sh
eval `dbus export aliddns_`
if [ "$aliddns_enable" != "1" ]; then
nvram set ddns_hostname_x=`nvram get ddns_hostname_old`
echo "not enable"
exit
fi
now=`date`
die () {
echo $1
dbus ram aliddns_last_act="$now: failed($1)"
}
[ "$aliddns_curl" = "" ] && aliddns_curl="curl -s --interface ppp0 whatismyip.akamai.com"
[ "$aliddns_dns" = "" ] && aliddns_dns="223.5.5.5"
[ "$aliddns_ttl" = "" ] && aliddns_ttl="600"
ip=`$aliddns_curl 2>&1` || die "$ip"
if [ "$aliddns_name" = "@" ]
then
current_ip=`nslookup $aliddns_domain $aliddns_dns 2>&1`
else
current_ip=`nslookup $aliddns_name.$aliddns_domain $aliddns_dns 2>&1`
fi
if [ "$?" -eq "0" ]
then
current_ip=`echo "$current_ip" | grep 'Address 1' | tail -n1 | awk '{print $NF}'`
if [ "$ip" = "$current_ip" ]
then
echo "skipping"
dbus set aliddns_last_act="$now: skipped($ip)"
exit 0
fi
else
unset aliddns_record_id
fi
timestamp=`date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ"`
urlencode() {
# urlencode <string>
out=""
while read -n1 c
do
case $c in
[a-zA-Z0-9._-]) out="$out$c" ;;
*) out="$out`printf '%%%02X' "'$c"`" ;;
esac
done
echo -n $out
}
enc() {
echo -n "$1" | urlencode
}
send_request() {
local args="AccessKeyId=$aliddns_ak&Action=$1&Format=json&$2&Version=2015-01-09"
local hash=$(echo -n "GET&%2F&$(enc "$args")" | openssl dgst -sha1 -hmac "$aliddns_sk&" -binary | openssl base64)
curl -s "http://alidns.aliyuncs.com/?$args&Signature=$(enc "$hash")"
}
get_recordid() {
grep -Eo '"RecordId":"[0-9]+"' | cut -d':' -f2 | tr -d '"'
}
#add support */%2A and @/%40 record
case $aliddns_name in
\*)
aliddns_name1=%2A
;;
\@)
aliddns_name1=%40
;;
*)
aliddns_name1=$aliddns_name
;;
esac
query_recordid() {
send_request "DescribeSubDomainRecords" "SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&SubDomain=$aliddns_name1.$aliddns_domain&Timestamp=$timestamp"
}
update_record() {
send_request "UpdateDomainRecord" "RR=$aliddns_name1&RecordId=$1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddns_ttl&Timestamp=$timestamp&Type=A&Value=$ip"
}
add_record() {
send_request "AddDomainRecord&DomainName=$aliddns_domain" "RR=$aliddns_name1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddns_ttl&Timestamp=$timestamp&Type=A&Value=$ip"
}
if [ "$aliddns_record_id" = "" ]
then
aliddns_record_id=`query_recordid | get_recordid`
fi
if [ "$aliddns_record_id" = "" ]
then
aliddns_record_id=`add_record | get_recordid`
echo "added record $aliddns_record_id"
else
update_record $aliddns_record_id
echo "updated record $aliddns_record_id"
fi
# save to file
if [ "$aliddns_record_id" = "" ]; then
# failed
dbus ram aliddns_last_act="$now: failed"
nvram set ddns_hostname_x=`nvram get ddns_hostname_old`
else
dbus ram aliddns_record_id=$aliddns_record_id
dbus ram aliddns_last_act="$now: success($ip)"
nvram set ddns_hostname_x="$aliddns_name"."$aliddns_domain"
fi
大神 能不能搞个openwrt版本的 找了好几天了
看原代码那里好像没有更新,但ssh进路由后看到的是更新过的代码,应该是可以支持泛域名了,正在测试……
你好,貌似这个插件不支持泛解析,能不能辛苦下,再改改 * : 泛解析,所有子域名均被解析到统一地址(除单独设置的子域名解析);