mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 12:13:56 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#
|
||||
#-- Copyright (C) 2019 dz <dingzhong110@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI Support for Auto DNS for dnspod
|
||||
LUCI_DEPENDS:= +bash +curl
|
||||
PKG_VERSION:=1.16
|
||||
PKG_RELEASE:=1
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
@@ -0,0 +1,2 @@
|
||||
#luci-app-dnspod
|
||||
随意写的,只保证正常解析
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
|
||||
#
|
||||
#-- Copyright (C) 2019 dz <dingzhong110@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
]]--
|
||||
module("luci.controller.dnspod", package.seeall)
|
||||
|
||||
function index()
|
||||
entry({"admin", "network", "dnspod"}, cbi("dnspod"), _("动态DNSPOD"), 59)
|
||||
end
|
||||
Executable
+147
@@ -0,0 +1,147 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
|
||||
#
|
||||
#-- Copyright (C) 2019 dz <dingzhong110@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
]]--
|
||||
|
||||
require("luci.sys")
|
||||
|
||||
if luci.sys.call("ps -w | grep ddnspod |grep -v grep >/dev/null") == 0 then
|
||||
m = Map("dnspod", translate("动态DNSPOD"), "%s - %s" %{translate("DDNSPOD"), translate("<strong><font color=\"green\">Running</font></strong>")})
|
||||
else
|
||||
m = Map("dnspod", translate("动态DNSPOD"), "%s - %s" %{translate("DDNSPOD"), translate("<strong><font color=\"red\">Not Running</font></strong>")})
|
||||
end
|
||||
|
||||
------------------------------------------------------------
|
||||
s = m:section(TypedSection, "base_arg", translate("基本设置"))
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
enable = s:option(Flag, "enabled", translate("Enable"), translate("Enable or disable server"))
|
||||
enable.default = 0
|
||||
enable.rmempty = false
|
||||
|
||||
o = s:option(Value,"time",translate("Inspection Time"),translate("域名检查间隔时间,单位秒"))
|
||||
o.default = 667
|
||||
o.rmempty=false
|
||||
|
||||
o = s:option(Button,"delete",translate("删除全部域名记录"))
|
||||
o.inputstyle = "reset"
|
||||
o.write = function()
|
||||
luci.sys.call("cat /dev/null > /usr/share/dnspod/last.ip")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin", "services", "dnspod"))
|
||||
end
|
||||
|
||||
------------------------------------------------------------
|
||||
s = m:section(TypedSection, "ip_last", translate("ip获取设置"))
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
o = s:option(ListValue, "IPtype", translate("ip获取途径"))
|
||||
o:value("1", translate("网络获取一"))
|
||||
o:value("2", translate("网络获取二"))
|
||||
o:value("3", translate("网络获取三"))
|
||||
o:value("4", translate("网络获取四"))
|
||||
o:value("5", translate("本地获取"))
|
||||
o.default = 1
|
||||
|
||||
o = s:option(Value, "iface", translate("选择接口"))
|
||||
o:value("wan2", translate("WAN2"))
|
||||
o:value("wan", translate("WAN"))
|
||||
o:value("lan", translate("LAN"))
|
||||
o.default = "wan"
|
||||
o:depends("IPtype", "5")
|
||||
|
||||
o = s:option(Value, "ipv4linenumber", translate("ipv4选择"))
|
||||
o:value("1p", translate("第一行"))
|
||||
o:value("2p", translate("第二行"))
|
||||
o:value("3p", translate("第三行"))
|
||||
o:value("4p", translate("第四行"))
|
||||
o:value("5p", translate("第五行"))
|
||||
o:value("6p", translate("第六行"))
|
||||
o.default = "1p"
|
||||
o:depends("IPtype", "5")
|
||||
|
||||
o = s:option(Value, "ipv6iface", translate("ipv6选择接口"))
|
||||
o:value("wan2", translate("WAN2"))
|
||||
o:value("wan", translate("WAN"))
|
||||
o:value("lan", translate("LAN"))
|
||||
o.default = "lan"
|
||||
o:depends("IPtype", "5")
|
||||
|
||||
o = s:option(Value, "ipv6linenumber", translate("ipv6选择"))
|
||||
o:value("1p", translate("第一行"))
|
||||
o:value("2p", translate("第二行"))
|
||||
o:value("3p", translate("第三行"))
|
||||
o:value("4p", translate("第四行"))
|
||||
o:value("5p", translate("第五行"))
|
||||
o:value("6p", translate("第六行"))
|
||||
o.default = "2p"
|
||||
o:depends("IPtype", "5")
|
||||
|
||||
------------------------------------------------------------
|
||||
s = m:section(TypedSection, "login_mode", translate("账号设置"))
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
o = s:option(ListValue, "mode", translate("解析模式"))
|
||||
o:value("login", translate("账号解析"))
|
||||
o:value("token", translate("token解析"))
|
||||
|
||||
email = s:option(Value, "login_email", translate("登录邮箱"),"登录DNSPOD的用户名")
|
||||
email:depends("mode", "login")
|
||||
pass = s:option(Value, "login_password", translate("登录密码"),"登录DNSPOD的密码")
|
||||
pass.password=true
|
||||
pass:depends("mode", "login")
|
||||
|
||||
token = s:option(Value, "artoken", translate("ID,TOKEN"))
|
||||
token:depends("mode", "token")
|
||||
|
||||
-----------------------------------------------------------
|
||||
|
||||
s = m:section(TypedSection, "domain_name", translate("域名"))
|
||||
s.template = "cbi/tblsection"
|
||||
s.anonymous = true
|
||||
s.addremove = true
|
||||
s.sortable = true
|
||||
|
||||
record_type = s:option(ListValue, "record_type", translate("记录类型"),"A,AAAA")
|
||||
record_type:value("A", translate("A"))
|
||||
record_type:value("AAAA", translate("AAAA"))
|
||||
|
||||
sub = s:option(Value, "sub_domain", translate("子域名"),"想要解析的子域名,例如:www")
|
||||
|
||||
main = s:option(Value, "main_domain", translate("主域名"),"想要解析的主域名,例如:baidu.com")
|
||||
|
||||
comment = s:option(Value, "comment", translate("Comment"))
|
||||
|
||||
-------------------------------------------------------
|
||||
s=m:section(TypedSection,"base",translate("Update Log"))
|
||||
s.anonymous=true
|
||||
local a="/var/log/ddnspod.log"
|
||||
tvlog=s:option(TextValue,"sylogtext")
|
||||
tvlog.rows=16
|
||||
tvlog.readonly="readonly"
|
||||
tvlog.wrap="off"
|
||||
|
||||
function tvlog.cfgvalue(s,s)
|
||||
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(s,s,s)
|
||||
end
|
||||
|
||||
local apply = luci.http.formvalue("cbi.apply")
|
||||
if apply then
|
||||
io.popen("/etc/init.d/dnspod restart &")
|
||||
end
|
||||
|
||||
return m
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
msgid "Enable or disable server"
|
||||
msgstr "启用或禁用服务"
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
zh-cn
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
|
||||
config base_arg 'base_arg'
|
||||
option enabled '0'
|
||||
option time '667'
|
||||
|
||||
config domain_name
|
||||
option record_type 'AAAA'
|
||||
option sub_domain 'ipv6'
|
||||
option main_domain '12345.xyz'
|
||||
|
||||
config domain_name
|
||||
option record_type 'A'
|
||||
option sub_domain 'www'
|
||||
option main_domain '12345.xyz'
|
||||
|
||||
config ip_last
|
||||
option ip_all '2'
|
||||
option IPtype '1'
|
||||
|
||||
config login_mode
|
||||
option mode 'token'
|
||||
option artoken '12424,532453245345b2301e22bca69b1f06ef55'
|
||||
|
||||
config base
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "$ACTION" = ifup ] || exit 0
|
||||
|
||||
enable=$(uci get dnspod.base_arg.enabled 2>/dev/null)
|
||||
if [ $enable -eq 1 ]; then
|
||||
sleep 30
|
||||
/etc/init.d/dnspod restart
|
||||
fi
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
START=80
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
logfile="/var/log/ddnspod.log"
|
||||
|
||||
uci_get_by_name() {
|
||||
local ret=$(uci get dnspod.$1.$2 2>/dev/null)
|
||||
echo ${ret:=$3}
|
||||
}
|
||||
|
||||
start(){
|
||||
enable=$(uci get dnspod.base_arg.enabled 2>/dev/null)
|
||||
if [ $enable -eq 1 ]; then
|
||||
sleeptime=$(uci get dnspod.base_arg.time 2>/dev/null)
|
||||
icount=`ps -w | grep ddnspod.sh |grep -v grep| wc -l`
|
||||
if [ $icount = 1 ] ;then
|
||||
kill -9 $(ps | grep ddnspod.sh | grep -v "grep" | awk '{print $1}') >/dev/null 2>&1
|
||||
# cat /dev/null > /var/log/ddnspod.log
|
||||
cat /dev/null > /var/log/ddnspod1.log
|
||||
cat /dev/null > /usr/share/dnspod/dns.conf
|
||||
fi
|
||||
local login_email=$(uci get dnspod.@login_mode[0].login_email 2>/dev/null)
|
||||
local login_password=$(uci get dnspod.@login_mode[0].login_password 2>/dev/null)
|
||||
local artoken=$(uci get dnspod.@login_mode[0].artoken 2>/dev/null)
|
||||
rm -f /usr/share/dnspod/dns.conf
|
||||
|
||||
cat >>/usr/share/dnspod/dns.conf <<EOF
|
||||
# For security reasons, it is recommended that you use token-based auth instead
|
||||
arMail="$login_email"
|
||||
arPass="$login_password"
|
||||
|
||||
# Combine your token ID and token together as follows
|
||||
arToken="$artoken"
|
||||
|
||||
# Place each domain you want to check as follows
|
||||
# you can have multiple arDdnsCheck blocks
|
||||
EOF
|
||||
|
||||
for arDdnsCheck in $(uci -X show dnspod | grep domain_name | awk -F'[.=]' '{print $2}'); do
|
||||
local main_domain=$(uci_get_by_name $arDdnsCheck main_domain)
|
||||
local sub_domain=$(uci_get_by_name $arDdnsCheck sub_domain)
|
||||
local record_type=$(uci_get_by_name $arDdnsCheck record_type)
|
||||
|
||||
cat >>/usr/share/dnspod/dns.conf <<EOF
|
||||
arDdnsCheck "$main_domain" "$sub_domain" "$record_type"
|
||||
EOF
|
||||
|
||||
done
|
||||
sleep 2
|
||||
bash /usr/share/dnspod/ddnspod.sh >> /var/log/ddnspod1.log 2>&1 &
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") >>>>>>>>正在运行:检查更新DNS记录间隔时间为${sleeptime}秒<<<<<<<<" >> ${logfile}
|
||||
|
||||
#nohup /usr/share/dnspod/ddnspod.sh > /var/log/ddnspod.log 2>&1 &
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
enable=$(uci get dnspod.base_arg.enabled 2>/dev/null)
|
||||
if [ $enable -ne 1 ]; then
|
||||
kill -9 $(ps | grep ddnspod.sh | grep -v "grep" | awk '{print $1}') >/dev/null 2>&1
|
||||
kill $(ps -w | grep ddnspod |grep -v grep) >/dev/null 2>&1
|
||||
# cat /dev/null > /var/log/ddnspod1.log
|
||||
cat /dev/null > /usr/share/dnspod/dns.conf
|
||||
cat /dev/null > /var/log/ddnspod.log && echo "$(date "+%Y-%m-%d %H:%M:%S") >>>>>>>>停止运行:DNS记录以保存<<<<<<<<" >> ${logfile}
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
[ ! -f "/usr/share/ucitrack/luci-app-dnspod.json" ] && {
|
||||
cat > /usr/share/ucitrack/luci-app-dnspod.json << EEOF
|
||||
{
|
||||
"config": "dnspod",
|
||||
"init": "dnspod"
|
||||
}
|
||||
EEOF
|
||||
}
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@dnspod[-1]
|
||||
add ucitrack dnspod
|
||||
set ucitrack.@dnspod[-1].init=dnspod
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
|
||||
/etc/init.d/dnspod stop
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
||||
+357
@@ -0,0 +1,357 @@
|
||||
#!/bin/bash
|
||||
|
||||
#################################################
|
||||
# AnripDdns v5.08
|
||||
# Dynamic DNS using DNSPod API
|
||||
# Original by anrip<mail@anrip.com>, http://www.anrip.com/ddnspod
|
||||
# Edited by ProfFan
|
||||
# Edited by dz
|
||||
#################################################
|
||||
enable=1
|
||||
sleeptime=667
|
||||
ip_mode=2
|
||||
WanIp=""
|
||||
LastIpFile=/usr/share/dnspod/last.ip
|
||||
logfile="/var/log/ddnspod.log"
|
||||
logfile1="/var/log/ddnspod1.log"
|
||||
sleeptime=$(uci get dnspod.base_arg.time 2>/dev/null)
|
||||
enable=$(uci get dnspod.base_arg.enabled 2>/dev/null)
|
||||
IPtype=$(uci get dnspod.@ip_last[0].IPtype 2>/dev/null)
|
||||
iface=$(uci get dnspod.@ip_last[0].iface 2>/dev/null)
|
||||
ipv6iface=$(uci get dnspod.@ip_last[0].ipv6iface 2>/dev/null)
|
||||
ipv4linenumber=$(uci get dnspod.@ip_last[0].ipv4linenumber 2>/dev/null)
|
||||
ipv6linenumber=$(uci get dnspod.@ip_last[0].ipv6linenumber 2>/dev/null)
|
||||
|
||||
clean_log(){
|
||||
logrow=$(grep -c "" ${logfile})
|
||||
if [ $logrow -ge 3000 ];then
|
||||
cat /dev/null > ${logfile}
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") Log条数超限,清空处理!" >> ${logfile}
|
||||
fi
|
||||
|
||||
logrow1=$(grep -c "" ${logfile1})
|
||||
if [ $logrow1 -ge 300 ];then
|
||||
cat /dev/null > ${logfile1}
|
||||
echo "Log条数超限,清空处理!" >> ${logfile1}
|
||||
fi
|
||||
}
|
||||
|
||||
while [ "$enable" = "1" ];
|
||||
do
|
||||
|
||||
clean_log
|
||||
|
||||
function getPublicIp() {
|
||||
record_type=$record_type
|
||||
if [ $record_type = 'AAAA' ]; then
|
||||
case $IPtype in
|
||||
'1')
|
||||
WanIp=`curl -6 -s 'https://api.myip.com' | grep ip |sed 's/.*ip":"\([^"]*\)".*/\1/g'`
|
||||
echo $WanIp
|
||||
;;
|
||||
'2')
|
||||
WanIp=`curl -6 -s 'http://ip-api.com/json/?fields=query' | grep query |sed 's/.*query":"\([^"]*\)".*/\1/g'`
|
||||
echo $WanIp
|
||||
;;
|
||||
'3')
|
||||
WanIp=`curl -6 -s 'https://ipapi.co/ip/'`
|
||||
echo $WanIp
|
||||
;;
|
||||
'4')
|
||||
WanIp=`curl -6 -s 'https://ifconfig.co'`
|
||||
echo $WanIp
|
||||
;;
|
||||
'5')
|
||||
WanIp=`ubus call network.interface.$ipv6iface status | grep '"address"' | grep -oE '([a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){0,7}::[a-f0-9]{0,4}(:[a-f0-9]{1,4}){0,7})' | sed -n ''$ipv6linenumber''`
|
||||
echo $WanIp
|
||||
;;
|
||||
'6')
|
||||
WanIp=`curl -6 -s 'https://ip6.seeip.org'`
|
||||
echo $WanIp
|
||||
;;
|
||||
esac
|
||||
|
||||
else
|
||||
|
||||
case $IPtype in
|
||||
'1')
|
||||
WanIp=`curl -4 -s 'https://api.myip.com' | grep ip |sed 's/.*ip":"\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)".*/\1/g'`
|
||||
echo $WanIp
|
||||
;;
|
||||
'2')
|
||||
WanIp=`curl -4 -s 'http://ip-api.com/json/?fields=query' | grep query |sed 's/.*query":"\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)".*/\1/g'`
|
||||
echo $WanIp
|
||||
;;
|
||||
'3')
|
||||
WanIp=`curl -4 -s 'https://ipapi.co/ip/'`
|
||||
echo $WanIp
|
||||
;;
|
||||
'4')
|
||||
WanIp=`curl -4 -s 'https://ifconfig.co'`
|
||||
echo $WanIp
|
||||
;;
|
||||
'5')
|
||||
WanIp=`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}' | sed -n ''$ipv4linenumber''`
|
||||
echo $WanIp
|
||||
;;
|
||||
'6')
|
||||
WanIp=`curl -4 -s 'https://ip4.seeip.org'`
|
||||
echo $WanIp
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
||||
|
||||
|
||||
}
|
||||
|
||||
# OS Detection
|
||||
case $(uname) in
|
||||
'Linux')
|
||||
echo "Linux"
|
||||
arIpAddress() {
|
||||
# local extip
|
||||
# extip=$(ip -o -4 addr list | grep -Ev '\s(docker|lo)' | awk '{print $4}' | cut -d/ -f1 | grep -Ev '(^127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.1[6-9]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.2[0-9]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.3[0-1]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^192\.168\.[0-9]{1,3}\.[0-9]{1,3}$)')
|
||||
# if [ "x${extip}" = "x" ]; then
|
||||
# extip=$(ip -o -4 addr list | grep -Ev '\s(docker|lo)' | awk '{print $4}' | cut -d/ -f1 )
|
||||
# fi
|
||||
# echo $extip
|
||||
|
||||
if [ "x${WanIp}" = "x" ]; then
|
||||
WanIp=$(getPublicIp)
|
||||
fi
|
||||
|
||||
if [ "x${WanIp}" = "x" ]; then
|
||||
IPtype="1"
|
||||
WanIp=$(getPublicIp)
|
||||
fi
|
||||
|
||||
if [ "x${WanIp}" = "x" ]; then
|
||||
IPtype="2"
|
||||
WanIp=$(getPublicIp)
|
||||
fi
|
||||
|
||||
if [ "x${WanIp}" = "x" ]; then
|
||||
IPtype="3"
|
||||
WanIp=$(getPublicIp)
|
||||
fi
|
||||
|
||||
if [ "x${WanIp}" = "x" ]; then
|
||||
IPtype="4"
|
||||
WanIp=$(getPublicIp)
|
||||
fi
|
||||
|
||||
if [ "x${WanIp}" = "x" ]; then
|
||||
IPtype="6"
|
||||
WanIp=$(getPublicIp)
|
||||
fi
|
||||
|
||||
|
||||
echo $WanIp
|
||||
}
|
||||
;;
|
||||
'FreeBSD')
|
||||
echo 'FreeBSD'
|
||||
exit 100
|
||||
;;
|
||||
'WindowsNT')
|
||||
echo "Windows"
|
||||
exit 100
|
||||
;;
|
||||
'Darwin')
|
||||
echo "Mac"
|
||||
arIpAddress() {
|
||||
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'
|
||||
}
|
||||
;;
|
||||
'SunOS')
|
||||
echo 'Solaris'
|
||||
exit 100
|
||||
;;
|
||||
'AIX')
|
||||
echo 'AIX'
|
||||
exit 100
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
# Get script dir
|
||||
# See: http://stackoverflow.com/a/29835459/4449544
|
||||
rreadlink() ( # Execute the function in a *subshell* to localize variables and the effect of `cd`.
|
||||
|
||||
target=$1 fname= targetDir= CDPATH=
|
||||
|
||||
# Try to make the execution environment as predictable as possible:
|
||||
# All commands below are invoked via `command`, so we must make sure that `command`
|
||||
# itself is not redefined as an alias or shell function.
|
||||
# (Note that command is too inconsistent across shells, so we don't use it.)
|
||||
# `command` is a *builtin* in bash, dash, ksh, zsh, and some platforms do not even have
|
||||
# an external utility version of it (e.g, Ubuntu).
|
||||
# `command` bypasses aliases and shell functions and also finds builtins
|
||||
# in bash, dash, and ksh. In zsh, option POSIX_BUILTINS must be turned on for that
|
||||
# to happen.
|
||||
{ \unalias command; \unset -f command; } >/dev/null 2>&1
|
||||
[ -n "$ZSH_VERSION" ] && options[POSIX_BUILTINS]=on # make zsh find *builtins* with `command` too.
|
||||
|
||||
while :; do # Resolve potential symlinks until the ultimate target is found.
|
||||
[ -L "$target" ] || [ -e "$target" ] || { command printf '%s\n' "ERROR: '$target' does not exist." >&2; return 1; }
|
||||
command cd "$(command dirname -- "$target")" # Change to target dir; necessary for correct resolution of target path.
|
||||
fname=$(command basename -- "$target") # Extract filename.
|
||||
[ "$fname" = '/' ] && fname='' # !! curiously, `basename /` returns '/'
|
||||
if [ -L "$fname" ]; then
|
||||
# Extract [next] target path, which may be defined
|
||||
# *relative* to the symlink's own directory.
|
||||
# Note: We parse `ls -l` output to find the symlink target
|
||||
# which is the only POSIX-compliant, albeit somewhat fragile, way.
|
||||
target=$(command ls -l "$fname")
|
||||
target=${target#* -> }
|
||||
continue # Resolve [next] symlink target.
|
||||
fi
|
||||
break # Ultimate target reached.
|
||||
done
|
||||
targetDir=$(command pwd -P) # Get canonical dir. path
|
||||
# Output the ultimate target's canonical path.
|
||||
# Note that we manually resolve paths ending in /. and /.. to make sure we have a normalized path.
|
||||
if [ "$fname" = '.' ]; then
|
||||
command printf '%s\n' "${targetDir%/}"
|
||||
elif [ "$fname" = '..' ]; then
|
||||
# Caveat: something like /var/.. will resolve to /private (assuming /var@ -> /private/var), i.e. the '..' is applied
|
||||
# AFTER canonicalization.
|
||||
command printf '%s\n' "$(command dirname -- "${targetDir}")"
|
||||
else
|
||||
command printf '%s\n' "${targetDir%/}/$fname"
|
||||
fi
|
||||
)
|
||||
|
||||
DIR=$(dirname -- "$(rreadlink "$0")")
|
||||
|
||||
# Global Variables:
|
||||
|
||||
# Token-based Authentication
|
||||
arToken=""
|
||||
# Account-based Authentication
|
||||
arMail=""
|
||||
arPass=""
|
||||
|
||||
# Load config
|
||||
|
||||
#. $DIR/dns.conf
|
||||
|
||||
# Get Domain IP
|
||||
# arg: domain
|
||||
arNslookup() {
|
||||
#wget --quiet --output-document=- $inter$1
|
||||
if [ ! -f $LastIpFile ]; then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
cat $LastIpFile | grep $1 | awk '{print $2}'
|
||||
}
|
||||
|
||||
# Get data
|
||||
# arg: type data
|
||||
arApiPost() {
|
||||
local inter="https://dnsapi.cn/${1:?'Info.Version'}"
|
||||
if [ "x${arToken}" = "x" ]; then # undefine token
|
||||
local param="login_email=${arMail}&login_password=${arPass}&format=json&${2}"
|
||||
else
|
||||
local param="login_token=${arToken}&format=json&${2}"
|
||||
fi
|
||||
curl -s -k -X POST $inter -d $param
|
||||
}
|
||||
|
||||
# Update
|
||||
# arg: main domain sub domain
|
||||
arDdnsUpdate() {
|
||||
local domainID recordID recordRS recordCD myIP
|
||||
# Get domain ID
|
||||
domainID=$(arApiPost "Domain.Info" "domain=${1}")
|
||||
domainID=$(echo $domainID | sed 's/.*"id":"\([0-9]*\)".*/\1/')
|
||||
|
||||
# Update IP
|
||||
arIpAddress
|
||||
myIP=$(arIpAddress)
|
||||
|
||||
if echo $myIP|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$">/dev/null; then
|
||||
post_type="Record.Ddns"
|
||||
record_types="A"
|
||||
else
|
||||
post_type="Record.Modify"
|
||||
record_types="AAAA"
|
||||
fi
|
||||
|
||||
# Get Record ID
|
||||
recordID=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${2}&record_type=${record_types}&record_line=%e9%bb%98%e8%ae%a4")
|
||||
recordID=$(echo $recordID | sed 's/.*"id":"\([0-9]*\)".*/\1/')
|
||||
|
||||
recordRS=$(arApiPost "$post_type" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=${record_types}&value=${myIP}&record_line=%e9%bb%98%e8%ae%a4")
|
||||
recordCD=$(echo $recordRS | sed 's/.*{"code":"\([0-9]*\)".*/\1/')
|
||||
|
||||
# Output IP
|
||||
if [ "$recordCD" = "1" ]; then
|
||||
echo $recordRS | sed 's/.*,"value":"\([^"]*\)".*/\1/'
|
||||
return 1
|
||||
fi
|
||||
# Echo error message
|
||||
echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/'
|
||||
|
||||
}
|
||||
|
||||
# DDNS Check
|
||||
# Arg: Main Sub
|
||||
arDdnsCheck() {
|
||||
record_type=${3}
|
||||
#arIpAddress
|
||||
|
||||
local postRS
|
||||
local hostIP=$(arIpAddress)
|
||||
local lastIP=$(arNslookup "${3}-${2}.${1}")
|
||||
echo "domain name: ${2}.${1}"
|
||||
echo "hostIP: ${3} ${hostIP}"
|
||||
echo "lastIP: ${3} ${lastIP}"
|
||||
if [ "$lastIP" != "$hostIP" ]; then
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") 域名: ${2}.${1} 记录类型: ${3}" >> ${logfile}
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") 当前IP: ${hostIP}" >> ${logfile}
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") 记录IP: ${lastIP}" >> ${logfile}
|
||||
echo "--- Update last.ip"
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") 更新域名记录" >> ${logfile}
|
||||
if [ -f $LastIpFile ]
|
||||
then
|
||||
grep -v "${3}-${2}.${1}" $LastIpFile > $LastIpFile.bak
|
||||
fi
|
||||
echo "${3}-${2}.${1} ${hostIP}" >> $LastIpFile.bak
|
||||
mv $LastIpFile.bak $LastIpFile
|
||||
|
||||
echo "--- Update dns zone"
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") 更新DNS日志" >> ${logfile}
|
||||
postRS=$(arDdnsUpdate $1 $2)
|
||||
echo "postRS: ${postRS}"
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") 输出记录: ${postRS}" >> ${logfile}
|
||||
sleep 2
|
||||
echo "$(date "+%Y-%m-%d %H:%M:%S") >>>>>>>>正在运行:检查更新DNS记录间隔时间为${sleeptime}秒<<<<<<<<" >> ${logfile}
|
||||
if [ $? -ne 1 ]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# DDNS
|
||||
#echo ${#domains[@]}
|
||||
#for index in ${!domains[@]}; do
|
||||
# echo "${domains[index]} ${subdomains[index]}"
|
||||
# arDdnsCheck "${domains[index]}" "${subdomains[index]}"
|
||||
#done
|
||||
|
||||
date
|
||||
. $DIR/dns.conf
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "+++++++++++++++++++++++++++"
|
||||
|
||||
sleep ${sleeptime}
|
||||
continue
|
||||
done
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# For security reasons, it is recommended that you use token-based auth instead
|
||||
# arMail=""
|
||||
# arPass=""
|
||||
|
||||
# Combine your token ID and token together as follows
|
||||
arToken="6541626156242"
|
||||
|
||||
# Place each domain you want to check as follows
|
||||
# you can have multiple arDdnsCheck blocks
|
||||
arDdnsCheck "1" "11"
|
||||
arDdnsCheck "2" "22"
|
||||
arDdnsCheck "3" "33"
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-dnspod": {
|
||||
"description": "Grant UCI access for luci-app-dnspod",
|
||||
"read": {
|
||||
"uci": [ "dnspod" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "dnspod" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"config": "dnspod",
|
||||
"init": "dnspod"
|
||||
}
|
||||
Reference in new issue
Block a user