Merge Lean's source

This commit is contained in:
CN_SZTL 2020-02-22 16:07:38 +08:00
parent 9937361a53
commit 99b30dcf94
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
7 changed files with 1 additions and 245 deletions

View File

@ -1,13 +0,0 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-dnspod
PKG_VERSION=1.0
PKG_RELEASE:=1
LUCI_TITLE:=Auto DNS for dnspod
LUCI_DEPENDS:=+curl +libcurl
LUCI_PKGARCH:=all
LUCI_DESCRIPTION=auto get pub ip,dnspod ddns,must include curl with ssl
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -1,5 +0,0 @@
module("luci.controller.dnspod", package.seeall)
function index()
entry({"admin", "network", "dnspod"}, cbi("dnspod"), _("动态DNSPOD"), 100)
end

View File

@ -1,32 +0,0 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
]]--
require("luci.sys")
m = Map("dnspod", translate("动态DNSPOD"), translate("配置动态DNSPOD"))
s = m:section(TypedSection, "base_arg", "")
s.addremove = false
s.anonymous = true
email = s:option(Value, "login_token", translate("DNSPOD Token"), "格式: ID,Token")
main = s:option(Value, "main_domain", translate("主域名"), "想要解析的主域名,例如:baidu.com")
sub = s:option(Value, "sub_domain", translate("子域名"), "想要解析的子域名,只允许填写一个。如果想解析*子域名,请填写 \\*")
wait = s:option(Value, "wait_second", translate("更新周期(s)"), "请填写数字默认为300s")
command = s:option(Value, "command_to_get_ip", translate("外网ip获取命令"), "默认为 curl -s whatismyip.akamai.com")
local apply = luci.http.formvalue("cbi.apply")
if apply then
io.popen("/etc/init.d/dnspod restart &")
end
return m

View File

@ -1,7 +0,0 @@
config base_arg "base_arg"
option main_domain ''
option sub_domain ''
option login_token ''
option wait_second ''
option command_to_get_ip 'curl -s whatismyip.akamai.com'

View File

@ -1,18 +0,0 @@
#!/bin/sh /etc/rc.common
START=80
start()
{
/usr/sbin/dnspod.sh --svc &
}
stop()
{
ps | grep dnspod.sh | grep -v 'grep' | awk '{print $1}' | xargs kill
}
run_reboot()
{
stop
start
}

View File

@ -1,169 +0,0 @@
#!/bin/bash
#written by Michael Qu
#greennyreborn@gmail.com
#dnspod api token
token=`uci get dnspod.base_arg.login_token`
#域名
domain=`uci get dnspod.base_arg.main_domain 2>/dev/null`
#需要更新的子域名,只允许一个
#由于*linux会被脚本解析为当前目录下的所有文件所以请填写\*
# sub_domain='\*'
sub_domain=`uci get dnspod.base_arg.sub_domain 2>/dev/null`
if [ $sub_domain = "\*" ]; then
sub_domain="*"
fi
#check for changed ip every 300 seconds
wait=300
wait_second=`uci get dnspod.base_arg.wait_second 2>/dev/null`
if [[ $wait_second =~ ^[1-9][0-9]*$ ]]; then
wait=$wait_second
fi
#外网ip获取命令
command=`uci get dnspod.base_arg.command_to_get_ip 2>/dev/null`
if [ -z "$command" ]; then
command='curl -s whatismyip.akamai.com'
fi
#检查curl是否安装
curl_status=`which curl 2>/dev/null`
[ -n "$curl_status" ] || { echo "curl is not installed";exit 3; }
os=$(uname -a | egrep -io 'openwrt' | tr [A-Z] [a-z])
API_url="https://dnsapi.cn"
LOG_FILE="/tmp/dnspod.log"
MAX_LOG_SIZE=`expr 1 * 1024 * 1024` # 默认最大限制1M
PROGRAM=$(basename $0)
format='json'
lang='en'
record_type='A'
common_options="login_token=$token&format=${format}&lang=${lang}"
is_svc=0
last_modified_ip=
getFileSize() {
local file=$1
wc -c $file | awk '{print $1}'
}
clearLog() {
local file_size=$(getFileSize $LOG_FILE)
if [ $file_size -gt $MAX_LOG_SIZE ]; then
echo "" > $LOG_FILE
printMsg "Log file [$LOG_FILE], size: [$file_size bytes]."
printMsg "Exceeds max log size [$MAX_LOG_SIZE]. Clear the log."
fi
}
printMsg() {
local time=$(date "+%Y-%m-%d %H:%M:%S")
local msg="$1"
if [ $is_svc -eq 1 ]; then
echo "$time: $msg" >> $LOG_FILE
# logger -t ${PROGRAM} "${msg}"
else
echo "$time: $msg"
fi
}
getIp() {
# curl -s http://checkip.dyndns.com | sed -n 's/.*: \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/p'
eval $command
}
execAPI() {
local action="$1"
local extra_options="$2"
eval "curl -k -X POST \"${API_url}/${action}\" -d \"${common_options}&${extra_options}\""
}
getRecordList() {
local extra_options="domain=$domain"
echo $(execAPI "Record.List" "$extra_options")
exit
}
updateRecord() {
local ip=$1
local record_list=`getRecordList`
local old_ip=`jsonfilter -s "$record_list" -e "@.records[@.name='$sub_domain'].value"`
local id=`jsonfilter -s "$record_list" -e "@.records[@.name='$sub_domain'].id"`
printMsg "Change record: $sub_domain.$domain from $old_ip to $ip"
local extra_options="domain=$domain&record_id=$id&value=$ip&record_type=A&record_line_id=0&sub_domain=$sub_domain"
local response=$(execAPI "Record.Modify" "$extra_options")
local code=`jsonfilter -s "$response" -e "@.status.code"`
if [ "$code" == "1" ]; then
last_modified_ip=$ip
fi
local message=`jsonfilter -s "$response" -e "@.status.message"`
printMsg "response: $message"
}
checkip() {
local wan_ip=$1
printMsg "old ip: [$last_modified_ip], new ip: [$wan_ip]"
if [ "$wan_ip" != "$last_modified_ip" ]; then
return 8
else
return 3
fi
}
execSvc() {
local ip
#check that whether the network is ok
while [ 1 ];do
ip=$(getIp)
if [ -n "$ip" ]; then
printMsg "WAN IP: ${ip}"
break;
else
printMsg "Can't get wan ip"
sleep 30
fi
done
while [ 1 ];do
clearLog
ip=$(getIp)
checkip $ip
if [ $? -eq 8 ]; then
updateRecord $ip
#updateTunnelBroker
fi
sleep $wait
done
}
execUpdate() {
local ip=`getIp`
printMsg "WAN IP: ${ip}"
updateRecord $ip
}
case $1 in
--svc)
is_svc=1;
clearLog;
printMsg "Start in Service mode, check in every $wait seconds";
printMsg "domain: ${domain}, sub_domain: ${sub_domain}";
printMsg "Use command: [$command] to get wan ip";
execSvc;;
*)
is_svc=0;
printMsg "Start update record, domain: ${domain}, sub_domain: ${sub_domain}";
printMsg "Use command: [$command] to get wan ip";
execUpdate;;
esac

View File

@ -47,7 +47,7 @@ msgid "Server Address"
msgstr "服务器地址"
msgid "Server Port"
msgstr "服务器端口"
msgstr "端口"
msgid "Local Port"
msgstr "本地端口"