Skip to content

Commit

Permalink
fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
honwen committed Dec 5, 2017
1 parent 0b86c7f commit 1d94a6d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-aliddns
PKG_VERSION:=0.1.3
PKG_VERSION:=0.2.0
PKG_RELEASE:=1

PKG_LICENSE:=MIT
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# luci-app-aliddns
OpenWrt LuCI for AliDDNS (based on DDNSC)
LEDE/OpenWrt LuCI for AliDDNS
===

简介
Expand Down Expand Up @@ -41,20 +41,21 @@ OpenWrt LuCI for AliDDNS (based on DDNSC)
---

软件包的配置文件路径: `/etc/config/aliddns`
此文件为 UCI 配置文件, 配置方式可参考 [Wiki -> Use-UCI-system][Use-UCI-system][OpenWrt Wiki][uci]
此文件为 UCI 配置文件, 配置方式可参考 [Wiki][uci]

编译
---

OpenWrt[SDK][openwrt-sdk] 编译
LEDE[SDK][lede-sdk] 编译
```bash
# 解压下载好的 SDK
tar xjf OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
cd OpenWrt-SDK-ar71xx-*
tar axvf lede-sdk-17.01.*-ar71xx-generic_gcc-5.4.0_musl-1.1.16.Linux-x86_64.tar.xz
cd lede-sdk-17.01.*-ar71xx-*
# Clone 项目
mkdir -p package/feeds
git clone https://github.com/chenhw2/luci-app-aliddns.git package/feeds/luci-app-aliddns
# 编译 po2lmo (如果有po2lmo可跳过)
pushd package/feeds/luci-app-chenhw2/tools/po2lmo
pushd package/feeds/luci-app-aliddns/tools/po2lmo
make && sudo make install
popd
# 选择要编译的包 LuCI -> 3. Applications
Expand All @@ -63,6 +64,5 @@ make menuconfig
make package/feeds/luci-app-aliddns/compile V=s
```

[openwrt-sdk]: https://wiki.openwrt.org/doc/howto/obtain.firmware.sdk
[Use-UCI-system]: https://github.com/shadowsocks/luci-app-shadowsocks/wiki/Use-UCI-system
[uci]: https://wiki.openwrt.org/doc/uci
[lede-sdk]: https://lede-project.org/docs/guide-developer/compile_packages_for_lede_with_the_sdk
[uci]: https://lede-project.org/docs/user-guide/introduction_to_lede_configuration
12 changes: 6 additions & 6 deletions files/luci/i18n/aliddns.zh-cn.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ msgstr "启用"
msgid "Base"
msgstr "基本设置"

msgid "WAN Interface"
msgstr "外网接口"
msgid "WAN-IP Source"
msgstr "WAN-IP来源"

msgid "Select WAN Interface"
msgstr "选择外网接口"
msgid "Select WAN-IP Source"
msgstr "选择WAN-IP来源"

msgid "Select the Interface for AliDDNS, like eth0/pppoe-wan"
msgstr "动态域名的外网接口,如eth0/pppoe-wan"
msgid "Select the WAN-IP Source for AliDDNS, like wan/internet"
msgstr "动态域名的IP来源,如wan/internet"

msgid "Main Domain"
msgstr "主域名"
Expand Down
11 changes: 5 additions & 6 deletions files/luci/model/cbi/aliddns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ enable.rmempty=false
token=e:option(Value,"app_key",translate("Access Key ID"))
email=e:option(Value,"app_secret",translate("Access Key Secret"))

iface=e:option(ListValue,"interface",translate("WAN Interface"),translate("Select the Interface for AliDDNS, like eth0/pppoe-wan"))
iface:value("",translate("Select WAN Interface"))
for t,e in ipairs(a.net.devices())do
if e~="lo" and e~="br-lan"and e~="sit0"then iface:value(e)end
end
iface=e:option(ListValue,"interface",translate("WAN-IP Source"),translate("Select the WAN-IP Source for AliDDNS, like wan/internet"))
iface:value("",translate("Select WAN-IP Source"))
iface:value("internet")
iface:value("wan")

iface.rmempty=false
main=e:option(Value,"main_domain",translate("Main Domain"),translate("For example: test.github.com -> github.com"))
Expand All @@ -39,7 +38,7 @@ tvlog.wrap="off"

function tvlog.cfgvalue(e,e)
sylogtext=""
if a and nixio.fs.access(a)then
if a and nixio.fs.access(a) then
sylogtext=luci.sys.exec("tail -n 100 %s"%a)
end
return sylogtext
Expand Down
60 changes: 42 additions & 18 deletions files/root/usr/sbin/aliddns
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
#/bin/sh
#!/bin/sh

NAME=aliddns
log_file=/var/log/$NAME.log

uci_get_by_name() {
local ret=$(uci get $NAME.$1.$2 2>/dev/null)
echo ${ret:=$3}
}

ak_id=$(uci_get_by_name base app_key)
ak_sec=$(uci_get_by_name base app_secret)
rrid=$(uci_get_by_name base record_id)
main_dm=$(uci_get_by_name base main_domain)
sub_dm=$(uci_get_by_name base sub_domain)
iface=$(uci_get_by_name base interface)

DATE=$(date +'%Y-%m-%d %H:%M:%S')
timestamp=$(date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ")

# ip=$(curl -sSL 'http://whatismyip.akamai.com')
ip=$(ifconfig $iface 2>/dev/null | sed -n 's/.*inet addr:\([0-9.]*\) .*/\1/p')
log_file=/var/log/aliddns.log
intelnetip() {
tmp_ip=`curl -sL --connect-timeout 3 ns1.dnspod.net:6666`
if [ "Z$tmp_ip" == "Z" ]; then
tmp_ip=`curl -sL --connect-timeout 3 members.3322.org/dyndns/getip`
fi
if [ "Z$tmp_ip" == "Z" ]; then
tmp_ip=`curl -sL --connect-timeout 3 14.215.150.17:6666`
fi
if [ "Z$tmp_ip" == "Z" ]; then
tmp_ip=`curl -sL --connect-timeout 3 whatismyip.akamai.com`
fi
echo -n $tmp_ip
}

resolve2ip() {
# resolve2ip domain<string>
domain=$1
tmp_ip=`nslookup $domain ns1.alidns.com 2>/dev/null | sed -n 's/Address 1: \([0-9.]*\)/\1/p' | sed -n '2p'`
tmp_ip=`nslookup $domain ns1.alidns.com 2>/dev/null | sed '/^Server/d; /#53$/d' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | tail -n1`
if [ "Z$tmp_ip" == "Z" ]; then
tmp_ip=`nslookup $domain ns2.alidns.com 2>/dev/null | sed '/^Server/d; /#53$/d' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | tail -n1`
fi
if [ "Z$tmp_ip" == "Z" ]; then
tmp_ip=`nslookup $domain ns2.alidns.com 2>/dev/null | sed -n 's/Address 1: \([0-9.]*\)/\1/p' | sed -n '2p'`
tmp_ip=`nslookup $domain 114.114.115.115 2>/dev/null | sed '/^Server/d; /#53$/d' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | tail -n1`
fi
if [ "Z$tmp_ip" == "Z" ]; then
tmp_ip=`nslookup $domain 114.114.115.115 2>/dev/null | sed -n 's/Address 1: \([0-9.]*\)/\1/p' | sed -n '2p'`
tmp_ip=`curl -sL --connect-timeout 3 "119.29.29.29/d?dn=$domain"`
fi
echo -n $tmp_ip
}

check_aliddns() {
echo "$DATE WAN-IP: ${ip}"
if [ "Z$ip" == "Z" ]; then
echo "$DATE ERROR, cant get WAN-IP..."
return 0
fi
current_ip=$(resolve2ip "$sub_dm.$main_dm")
if [ "Z$current_ip" == "Z" ]; then
rrid='' # NO Resolve IP Means new Record_ID
Expand Down Expand Up @@ -66,7 +74,7 @@ send_request() {
# send_request action<string> args<string>
local args="AccessKeyId=$ak_id&Action=$1&Format=json&$2&Version=2015-01-09"
local hash=$(urlencode $(echo -n "GET&%2F&$(urlencode $args)" | openssl dgst -sha1 -hmac "$ak_sec&" -binary | openssl base64))
curl -sSL "http://alidns.aliyuncs.com/?$args&Signature=$hash"
curl -sSL --connect-timeout 5 "http://alidns.aliyuncs.com/?$args&Signature=$hash"
}

get_recordid() {
Expand Down Expand Up @@ -117,5 +125,21 @@ clean_log() {
[ -x /usr/bin/openssl -a -x /usr/bin/curl -a -x /bin/sed ] ||
( echo "Need [ openssl + curl + sed ]" && exit 1 )

ak_id=$(uci_get_by_name base app_key)
ak_sec=$(uci_get_by_name base app_secret)
rrid=$(uci_get_by_name base record_id)
main_dm=$(uci_get_by_name base main_domain)
sub_dm=$(uci_get_by_name base sub_domain)

iface=$(uci_get_by_name base interface)
if [ "Z$iface" == "Zinternet" -o "Z$iface" == "Z" ]; then
ip=$(intelnetip)
else
ip=$(ubus call network.interface.$iface status | grep '"address"' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
fi

DATE=$(date +'%Y-%m-%d %H:%M:%S')
timestamp=$(date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ")

clean_log
check_aliddns || do_ddns_record

0 comments on commit 1d94a6d

Please sign in to comment.