ddns-scripts: Append ddns script for cnkuai.cn
A low-cost domain name service provider in China Signed-off-by: Chip Lee <chplee@gmail.com>
This commit is contained in:
parent
63586f98cd
commit
066b8b427a
2 changed files with 144 additions and 1 deletions
|
@ -12,7 +12,7 @@ PKG_NAME:=ddns-scripts
|
|||
PKG_VERSION:=2.7.8
|
||||
# Release == build
|
||||
# increase on changes of services files or tld_names.dat
|
||||
PKG_RELEASE:=16
|
||||
PKG_RELEASE:=17
|
||||
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
PKG_MAINTAINER:=
|
||||
|
@ -127,6 +127,21 @@ define Package/ddns-scripts_route53-v1/description
|
|||
"option domain" to contain the hosted zone ID
|
||||
endef
|
||||
|
||||
###### *************************************************************************
|
||||
define Package/ddns-scripts_cnkuai_cn
|
||||
$(call Package/ddns-scripts/Default)
|
||||
TITLE:=CnKuai API
|
||||
DEPENDS:=ddns-scripts +curl +giflib-utils
|
||||
endef
|
||||
define Package/ddns-scripts_cnkuai_cn/description
|
||||
Dynamic DNS Client scripts extension for CnKuai.Note: You
|
||||
must also install giflib-utils.
|
||||
It requires:
|
||||
"option username" to be a valid CnKuai control panel id
|
||||
"option password" to be the matching CnKuai control panel password
|
||||
"option domain" to contain the domain
|
||||
endef
|
||||
|
||||
###### *************************************************************************
|
||||
define Build/Configure
|
||||
endef
|
||||
|
@ -436,6 +451,47 @@ define Package/ddns-scripts_route53-v1/prerm
|
|||
exit 0 # suppress errors
|
||||
endef
|
||||
|
||||
###### *************************************************************************
|
||||
define Package/ddns-scripts_cnkuai_cn/preinst
|
||||
#!/bin/sh
|
||||
# if NOT run buildroot then stop service
|
||||
[ -z "$${IPKG_INSTROOT}" ] && /etc/init.d/ddns stop >/dev/null 2>&1
|
||||
exit 0 # suppress errors
|
||||
endef
|
||||
define Package/ddns-scripts_cnkuai_cn/install
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/ddns.defaults $(1)/etc/uci-defaults/ddns_cnkuai_cn
|
||||
$(INSTALL_DIR) $(1)/usr/lib/ddns
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/update_cnkuai_cn.sh $(1)/usr/lib/ddns
|
||||
endef
|
||||
define Package/ddns-scripts_cnkuai_cn/postinst
|
||||
#!/bin/sh
|
||||
# remove old services file entries
|
||||
/bin/sed -i '/cnkuai.cn/d' $${IPKG_INSTROOT}/etc/ddns/services >/dev/null 2>&1
|
||||
/bin/sed -i '/cnkuai.cn/d' $${IPKG_INSTROOT}/etc/ddns/services_ipv6 >/dev/null 2>&1
|
||||
# and create new
|
||||
printf "%s\\t%s\\n" '"cnkuai.cn"' '"update_cnkuai_cn.sh"' >> $${IPKG_INSTROOT}/etc/ddns/services
|
||||
printf "%s\\t%s\\n" '"cnkuai.cn"' '"update_cnkuai_cn.sh"' >> $${IPKG_INSTROOT}/etc/ddns/services_ipv6
|
||||
# on real system restart service if enabled
|
||||
[ -z "$${IPKG_INSTROOT}" ] && {
|
||||
[ -x /etc/uci-defaults/ddns_cnkuai_cn ] && \
|
||||
/etc/uci-defaults/ddns_cnkuai_cn && \
|
||||
rm -f /etc/uci-defaults/cnkuai.cn >/dev/null 2>&1
|
||||
/etc/init.d/ddns enabled \
|
||||
&& /etc/init.d/ddns start >/dev/null 2>&1
|
||||
}
|
||||
exit 0 # suppress errors
|
||||
endef
|
||||
define Package/ddns-scripts_cnkuai_cn/prerm
|
||||
#!/bin/sh
|
||||
# if NOT run buildroot then stop service
|
||||
[ -z "$${IPKG_INSTROOT}" ] && /etc/init.d/ddns stop >/dev/null 2>&1
|
||||
# remove services file entries
|
||||
/bin/sed -i 'cnkuai.cn/d' $${IPKG_INSTROOT}/etc/ddns/services >/dev/null 2>&1
|
||||
/bin/sed -i 'cnkuai.cn/d' $${IPKG_INSTROOT}/etc/ddns/services_ipv6 >/dev/null 2>&1
|
||||
exit 0 # suppress errors
|
||||
endef
|
||||
|
||||
###### *************************************************************************
|
||||
$(eval $(call BuildPackage,ddns-scripts))
|
||||
$(eval $(call BuildPackage,ddns-scripts_cloudflare.com-v4))
|
||||
|
@ -444,3 +500,4 @@ $(eval $(call BuildPackage,ddns-scripts_godaddy.com-v1))
|
|||
$(eval $(call BuildPackage,ddns-scripts_no-ip_com))
|
||||
$(eval $(call BuildPackage,ddns-scripts_nsupdate))
|
||||
$(eval $(call BuildPackage,ddns-scripts_route53-v1))
|
||||
$(eval $(call BuildPackage,ddns-scripts_cnkuai_cn))
|
||||
|
|
86
net/ddns-scripts/files/update_cnkuai_cn.sh
Executable file
86
net/ddns-scripts/files/update_cnkuai_cn.sh
Executable file
|
@ -0,0 +1,86 @@
|
|||
# inside url we need domain, username and password
|
||||
[ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'"
|
||||
[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
|
||||
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
|
||||
|
||||
local urlCp='http://cp.cnkuai.cn/'
|
||||
local urlLogin='http://cp.cnkuai.cn/userlogin.asp'
|
||||
local urlCaptcha='http://cp.cnkuai.cn/inc/image.asp'
|
||||
local urlDnsA='http://cp.cnkuai.cn/dns_a.asp'
|
||||
local urlDnsAAAA='http://cp.cnkuai.cn/dns_ipv6.asp'
|
||||
local urlDnsSave='http://cp.cnkuai.cn/dns_save.asp'
|
||||
|
||||
getPixel(){
|
||||
local filename=$1
|
||||
local x=$(($2*3))
|
||||
local y=$(($3*3))
|
||||
local width=48
|
||||
|
||||
hexdump -s "$((x+width*y))" -n 3 -e '3/1 "%02X"' "$filename"
|
||||
}
|
||||
|
||||
captchaChar(){
|
||||
local filename=$1
|
||||
local xoffset=$2
|
||||
|
||||
if [ "$(getPixel "$filename" $((xoffset+2)) 5)" = '000000' ]; then
|
||||
echo '1'
|
||||
elif [ "$(getPixel "$filename" $((xoffset+5)) 7)" = '000000' ]; then
|
||||
echo '2'
|
||||
elif [ "$(getPixel "$filename" $((xoffset+4)) 3)" = '000000' ]; then
|
||||
echo '4'
|
||||
elif [ "$(getPixel "$filename" $((xoffset+6)) 4)" = '000000' ]; then
|
||||
echo '7'
|
||||
elif [ "$(getPixel "$filename" $((xoffset+5)) 8)" = '000000' ]; then
|
||||
echo '8'
|
||||
elif [ "$(getPixel "$filename" $((xoffset+6)) 8)" = '000000' ]; then
|
||||
echo '9'
|
||||
elif [ "$(getPixel "$filename" $((xoffset+5)) 6)" = '000000' ]; then
|
||||
echo '3'
|
||||
elif [ "$(getPixel "$filename" $((xoffset+0)) 4)" = '000000' ]; then
|
||||
echo '5'
|
||||
elif [ "$(getPixel "$filename" $((xoffset+1)) 5)" = '000000' ]; then
|
||||
echo '6'
|
||||
else
|
||||
echo '0'
|
||||
fi
|
||||
}
|
||||
|
||||
captcha(){
|
||||
local str
|
||||
str=$(captchaChar "$1" 9)
|
||||
str=$str$(captchaChar "$1" 18)
|
||||
str=$str$(captchaChar "$1" 26)
|
||||
str=$str$(captchaChar "$1" 35)
|
||||
echo "$str"
|
||||
}
|
||||
|
||||
#clean
|
||||
rm /tmp/cnkuai.*
|
||||
#login to cnkuai dns cp
|
||||
curl -c '/tmp/cnkuai.cookiejar' "$urlCaptcha" | gif2rgb > /tmp/cnkuai.rgb || return 1
|
||||
yzm=$(captcha "/tmp/cnkuai.rgb")
|
||||
curl -b '/tmp/cnkuai.cookiejar' -c '/tmp/cnkuai.cookiejar' -H "Content-Type: application/x-www-form-urlencoded" -H "Referer: $urlCp" -d "userid=$URL_USER&password=$URL_PASS&yzm=$yzm&B1=%C8%B7%C8%CF%B5%C7%C2%BD&lx=0&userlx=3" -X POST "$urlLogin" > /dev/null || return 1
|
||||
|
||||
if [ "$use_ipv6" -eq 0 ]; then
|
||||
curl -b '/tmp/cnkuai.cookiejar' -c '/tmp/cnkuai.cookiejar' "$urlDnsA" > /tmp/cnkuai.html || return 1
|
||||
else
|
||||
curl -b '/tmp/cnkuai.cookiejar' -c '/tmp/cnkuai.cookiejar' "$urlDnsAAAA" > /tmp/cnkuai.html || return 1
|
||||
fi
|
||||
local domainline
|
||||
domainline=$(awk "/<td>$domain<\/td>/{ print NR; exit }" /tmp/cnkuai.html)
|
||||
local domainid
|
||||
domainid=$(awk "NR==$((domainline+3))" /tmp/cnkuai.html | sed 's/^.*name=\x27domainid\x27 value="//g' | sed 's/".*$//g')
|
||||
local dnslistid
|
||||
dnslistid=$(awk "NR==$((domainline+3))" /tmp/cnkuai.html | sed 's/^.*name=\x27dnslistid\x27 value="//g' | sed 's/".*$//g')
|
||||
|
||||
local data
|
||||
|
||||
if [ "$use_ipv6" -eq 0 ]; then
|
||||
data="T2=$__IP&T3=120&act=dns_a_edit&domainid=$domainid&dnslistid=$dnslistid&B1=%D0%DE%B8%C4"
|
||||
else
|
||||
data="T2=$__IP&T3=120&act=dns_ipv6_edit&domainid=$domainid&dnslistid=$dnslistid&B1=%D0%DE%B8%C4"
|
||||
fi
|
||||
curl -b '/tmp/cnkuai.cookiejar' -c '/tmp/cnkuai.cookiejar' -H "Content-Type: application/x-www-form-urlencoded" -H "Referer: $urlDnsA" -d "$data" -X POST "$urlDnsSave" > /dev/null || return 1
|
||||
|
||||
return 0
|
Loading…
Reference in a new issue