mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-06-11 10:42:04 +08:00
dnspod support customized command to get wan ip (#1705)
fix dnspod clear log bug
This commit is contained in:
parent
6e2f8766af
commit
d354ed7a32
@ -24,6 +24,12 @@ if [[ $wait_second =~ ^[1-9][0-9]*$ ]]; then
|
|||||||
wait=$wait_second
|
wait=$wait_second
|
||||||
fi
|
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是否安装
|
||||||
curl_status=`which curl 2>/dev/null`
|
curl_status=`which curl 2>/dev/null`
|
||||||
[ -n "$curl_status" ] || { echo "curl is not installed";exit 3; }
|
[ -n "$curl_status" ] || { echo "curl is not installed";exit 3; }
|
||||||
@ -32,7 +38,7 @@ os=$(uname -a | egrep -io 'openwrt' | tr [A-Z] [a-z])
|
|||||||
|
|
||||||
API_url="https://dnsapi.cn"
|
API_url="https://dnsapi.cn"
|
||||||
LOG_FILE="/tmp/dnspod.log"
|
LOG_FILE="/tmp/dnspod.log"
|
||||||
MAX_LOG_SIZE=1*1024*1024
|
MAX_LOG_SIZE=`expr 1 * 1024 * 1024` # 默认最大限制1M
|
||||||
PROGRAM=$(basename $0)
|
PROGRAM=$(basename $0)
|
||||||
|
|
||||||
format='json'
|
format='json'
|
||||||
@ -45,15 +51,16 @@ last_modified_ip=
|
|||||||
|
|
||||||
getFileSize() {
|
getFileSize() {
|
||||||
local file=$1
|
local file=$1
|
||||||
wc -c $file
|
wc -c $file | awk '{print $1}'
|
||||||
}
|
}
|
||||||
|
|
||||||
clearLog() {
|
clearLog() {
|
||||||
local file_size=$(getFileSize $LOG_FILE)
|
local file_size=$(getFileSize $LOG_FILE)
|
||||||
if [ $file_size -gt $MAX_LOG_SIZE ]; then
|
if [ $file_size -gt $MAX_LOG_SIZE ]; then
|
||||||
echo "" > $LOG_FILE
|
echo "" > $LOG_FILE
|
||||||
|
printMsg "Log file [$LOG_FILE], size: [$file_size bytes]."
|
||||||
|
printMsg "Exceeds max log size [$MAX_LOG_SIZE]. Clear the log."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printMsg() {
|
printMsg() {
|
||||||
@ -69,7 +76,7 @@ printMsg() {
|
|||||||
|
|
||||||
getIp() {
|
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'
|
# 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'
|
||||||
curl -s whatismyip.akamai.com
|
eval $command
|
||||||
}
|
}
|
||||||
|
|
||||||
execAPI() {
|
execAPI() {
|
||||||
@ -142,6 +149,7 @@ execSvc() {
|
|||||||
|
|
||||||
execUpdate() {
|
execUpdate() {
|
||||||
local ip=`getIp`
|
local ip=`getIp`
|
||||||
|
printMsg "WAN IP: ${ip}"
|
||||||
updateRecord $ip
|
updateRecord $ip
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,9 +159,11 @@ case $1 in
|
|||||||
clearLog;
|
clearLog;
|
||||||
printMsg "Start in Service mode, check in every $wait seconds";
|
printMsg "Start in Service mode, check in every $wait seconds";
|
||||||
printMsg "domain: ${domain}, sub_domain: ${sub_domain}";
|
printMsg "domain: ${domain}, sub_domain: ${sub_domain}";
|
||||||
|
printMsg "Use command: [$command] to get wan ip";
|
||||||
execSvc;;
|
execSvc;;
|
||||||
*)
|
*)
|
||||||
is_svc=0;
|
is_svc=0;
|
||||||
printMsg "Start update record, domain: ${domain}, sub_domain: ${sub_domain}";
|
printMsg "Start update record, domain: ${domain}, sub_domain: ${sub_domain}";
|
||||||
|
printMsg "Use command: [$command] to get wan ip";
|
||||||
execUpdate;;
|
execUpdate;;
|
||||||
esac
|
esac
|
||||||
|
@ -3,4 +3,5 @@ config base_arg "base_arg"
|
|||||||
option sub_domain ''
|
option sub_domain ''
|
||||||
option login_token ''
|
option login_token ''
|
||||||
option wait_second ''
|
option wait_second ''
|
||||||
|
option command_to_get_ip 'curl -s whatismyip.akamai.com'
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ email = s:option(Value, "login_token", translate("DNSPOD Token"), "格式: ID,To
|
|||||||
main = s:option(Value, "main_domain", translate("主域名"), "想要解析的主域名,例如:baidu.com")
|
main = s:option(Value, "main_domain", translate("主域名"), "想要解析的主域名,例如:baidu.com")
|
||||||
sub = s:option(Value, "sub_domain", translate("子域名"), "想要解析的子域名,只允许填写一个。如果想解析*子域名,请填写 \\*")
|
sub = s:option(Value, "sub_domain", translate("子域名"), "想要解析的子域名,只允许填写一个。如果想解析*子域名,请填写 \\*")
|
||||||
wait = s:option(Value, "wait_second", translate("更新周期(s)"), "请填写数字,默认为300s")
|
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")
|
local apply = luci.http.formvalue("cbi.apply")
|
||||||
if apply then
|
if apply then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user