revert luci-app-aliddns

This commit is contained in:
coolsnowwolf 2018-04-09 17:57:16 +08:00
parent 4b914ed236
commit 63824c55db
8 changed files with 240 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI for Aliddns
LUCI_DEPENDS:=+wget +openssl-util
LUCI_PKGARCH:=all
PKG_VERSION:=1.0
PKG_RELEASE:=1
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,4 @@
module("luci.controller.aliddns",package.seeall)
function index()
entry({"admin","services","aliddns"},cbi("aliddns"),_("Aliddns Client"),101)
end

View File

@ -0,0 +1,52 @@
local a=require"luci.sys"
local e=luci.model.uci.cursor()
local e=require"nixio.fs"
require("luci.sys")
local t,e,o
local m,s
t=Map("aliddns",translate("阿里DDNS客户端"),translate("基于阿里云解析的私人DDNS解决方案"))
e=t:section(TypedSection,"base")
e.anonymous=true
e:tab("basic", translate("设置"))
enable=e:taboption("basic",Flag,"enable",translate("开启"),translate("开启或关闭aliddns动态域名"))
enable.rmempty=false
token=e:taboption("basic",Value,"app_key",translate("APP KEY"))
email=e:taboption("basic",Value,"app_secret",translate("APP SECRET"))
iface=e:taboption("basic",ListValue,"interface",translate("选择外网接口"),translate("限定要动态aliddns的外网接口如pppoe-wan"))
iface:value("",translate("选择要动态更新的外网接口"))
for t,e in ipairs(a.net.devices())do
if e~="lo"then iface:value(e)end
end
iface.rmempty=false
main=e:taboption("basic",Value,"main_domain",translate("主域名"),"想要解析的主域名,例如:baidu.com")
main.rmempty=false
sub=e:taboption("basic",Value,"sub_domain",translate("子域名"),"想要解析的子域名,例如:test hehe")
sub.rmempty=false
time=e:taboption("basic",Value,"time",translate("检查时间"),"域名检查时间单位分钟范围1-59")
time.rmempty=false
e:tab("log", translate("更新记录"))
--e=t:section(TypedSection,"base",translate("更新记录"))
e.anonymous=true
local a="/var/log/aliddns.log"
tvlog=e:taboption("log",TextValue,"sylogtext")
tvlog.rows=14
tvlog.readonly="readonly"
tvlog.wrap="off"
function tvlog.cfgvalue(e,e)
sylogtext=""
if a and nixio.fs.access(a)then
sylogtext=luci.sys.exec("tail -n 100 %s"%a)
end
return sylogtext
end
tvlog.write=function(e,e,e)
end
local e=luci.http.formvalue("cbi.apply")
if e then
io.popen("/etc/init.d/aliddns restart")
end
return t

View File

@ -0,0 +1,4 @@
msgid "Aliddns Client"
msgstr "阿里DDNS客户端"

View File

@ -0,0 +1,10 @@
config base 'base'
option time '30'
option enable '0'
option app_key '1'
option app_secret '1'
option interface 'br-lan'
option main_domain '1.com'
option sub_domain '2'

View File

@ -0,0 +1,18 @@
#!/bin/sh /etc/rc.common
START=80
restart()
{
/usr/sbin/aliddns
}
start()
{
/usr/sbin/aliddns
}
stop()
{
/usr/sbin/aliddns
}

View File

@ -0,0 +1,5 @@
#!/bin/sh
rm -f /tmp/luci-indexcache
exit 0

View File

@ -0,0 +1,128 @@
#!/bin/sh
aliddns_ak=`uci get aliddns.base.app_key 2>/dev/null`
aliddns_sk=`uci get aliddns.base.app_secret 2>/dev/null`
aliddns_record_id=`uci get aliddns.base.record_id 2>/dev/null`
time=`uci get aliddns.base.time 2>/dev/null`
aliddns_enable=`uci get aliddns.base.enable`
aliddns_domain=`uci get aliddns.base.main_domain 2>/dev/null`
aliddns_name=`uci get aliddns.base.sub_domain 2>/dev/null`
interface=`uci get aliddns.base.interface 2>/dev/null`
DATE=$(date +'%Y-%m-%d %H:%M:%S')
timestamp=`date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ"`
ip=$(ifconfig $interface 2> /dev/null | grep 'inet addr' | awk '{print $2}' | cut -d: -f2 2>/dev/null)
check_aliddns() {
#ip=`wget -qO- http://whatismyip.akamai.com/ 2>/dev/null`
#current_ip=`nslookup $aliddns_name.$aliddns_domain | grep "Address 1"|tail -n1|cut -d' ' -f3 2>/dev/null`
current_ip=`echo $query_result | sed 's/.*,"Value":"\([0-9\.]*\)",.*/\1/'`
echo "$DATE 当前路由IP: ${ip}" >> /var/log/aliddns.log
echo "$DATE 远程解析IP: ${current_ip}" >> /var/log/aliddns.log
if [ "$ip" = "$current_ip" ]
then
echo "$DATE IP未改变无需更新" >> /var/log/aliddns.log
exit 0
else
echo "$DATE 更新中..." >> /var/log/aliddns.log
fi
}
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))
wget -qO- "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=$(urlencode "$aliddns_name").$aliddns_domain&Timestamp=$timestamp"
}
update_record() {
send_request "UpdateDomainRecord" "RR=$(urlencode "$aliddns_name")&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=$(urlencode "$aliddns_name")&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&Timestamp=$timestamp&Type=A&Value=$ip"
}
go_record() {
if [ "$aliddns_record_id" = "" ]
then
aliddns_record_id=`echo $query_result | get_recordid`
fi
if [ "$aliddns_record_id" = "" ]
then
aliddns_record_id=`add_record | get_recordid`
echo "$DATE 添加 record $aliddns_record_id" >> /var/log/aliddns.log
else
update_record $aliddns_record_id
echo "$DATE 更新 record $aliddns_record_id" >> /var/log/aliddns.log
fi
# save to file
if [ "$aliddns_record_id" = "" ]; then
# failed
echo "$DATE : 更新出错,请检查设置!" >> /var/log/aliddns.log
exit 0
else
uci set aliddns.base.record_id=$aliddns_record_id
uci commit
echo "$DATE : 更新成功!($ip)" >> /var/log/aliddns.log
fi
}
#将执行脚本写入crontab定时运行
add_aliddns_cru(){
wirtecron=$(cat /etc/crontabs/root | grep "$time * * * *" | grep aliddns)
if [ -z "$wirtecron" ];then
sed -i '/aliddns/d' /etc/crontabs/root >/dev/null 2>&1
echo "*/$time * * * * /usr/sbin/aliddns" >> /etc/crontabs/root
fi
}
#清除过多记录
clean_log(){
logrow=$(grep -c "" /var/log/aliddns.log)
if [ $logrow -ge 15 ];then
cat /dev/null > /var/log/aliddns.log
echo "$DATE Log条数超限清空处理" >> /var/log/aliddns.log
fi
}
#停止服务
stop_aliddns(){
#停掉cru里的任务
sed -i '/aliddns/d' /etc/crontabs/root >/dev/null 2>&1
}
if [ "$aliddns_enable" != "1" ]; then
stop_aliddns
echo "$DATE : aliddns没有开启" >> /var/log/aliddns.log
else
clean_log
query_result=$(query_recordid)
check_aliddns
go_record
add_aliddns_cru
fi