From fe2caaab18ff1299412b297b9b2166481c3f2064 Mon Sep 17 00:00:00 2001 From: sbwml <984419930@qq.com> Date: Sun, 4 Dec 2022 15:50:08 +0800 Subject: [PATCH] luci-app-mosdns: add local DNS settings * make up for the defect that Dnsmasq does not support DoH / DoT protocols --- .../luasrc/model/cbi/mosdns/basic.lua | 41 +++++++++++++++++-- luci-app-mosdns/po/zh-cn/mosdns.po | 19 ++++++++- luci-app-mosdns/root/etc/config/mosdns | 1 + luci-app-mosdns/root/etc/init.d/mosdns | 5 +++ .../root/usr/share/mosdns/default.yaml | 5 ++- .../root/usr/share/mosdns/mosdns.sh | 20 +++++---- 6 files changed, 77 insertions(+), 14 deletions(-) diff --git a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua index e730414..80fda23 100644 --- a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua +++ b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua @@ -34,6 +34,44 @@ logfile.placeholder = "/tmp/mosdns.log" logfile.default = "/tmp/mosdns.log" logfile:depends( "configfile", "/etc/mosdns/config.yaml") +redirect = s:option(Flag, "redirect", translate("DNS Forward"), translate("Forward Dnsmasq Domain Name resolution requests to MosDNS")) +redirect.default = true + +custom_local_dns = s:option(Flag, "custom_local_dns", translate("Local DNS"), translate("Follow WAN interface DNS if not enabled")) +custom_local_dns:depends( "configfile", "/etc/mosdns/config.yaml") +custom_local_dns.default = false + +custom_local_dns = s:option(DynamicList, "local_dns", translate("Upstream DNS servers")) +custom_local_dns:value("119.29.29.29", "119.29.29.29 (DNSPod Primary)") +custom_local_dns:value("119.28.28.28", "119.28.28.28 (DNSPod Secondary)") +custom_local_dns:value("223.5.5.5", "223.5.5.5 (AliDNS Primary)") +custom_local_dns:value("223.6.6.6", "223.6.6.6 (AliDNS Secondary)") +custom_local_dns:value("114.114.114.114", "114.114.114.114 (114DNS Primary)") +custom_local_dns:value("114.114.115.115", "114.114.115.115 (114DNS Secondary)") +custom_local_dns:value("180.76.76.76", "180.76.76.76 (Baidu DNS)") +custom_local_dns:depends("custom_local_dns", "1") + +custom_local_dns = s:option(ListValue, "bootstrap_dns1", translate("Bootstrap DNS servers")) +custom_local_dns:value("119.29.29.29", "119.29.29.29 (DNSPod Primary)") +custom_local_dns:value("119.28.28.28", "119.28.28.28 (DNSPod Secondary)") +custom_local_dns:value("223.5.5.5", "223.5.5.5 (AliDNS Primary)") +custom_local_dns:value("223.6.6.6", "223.6.6.6 (AliDNS Secondary)") +custom_local_dns:value("114.114.114.114", "114.114.114.114 (114DNS Primary)") +custom_local_dns:value("114.114.115.115", "114.114.115.115 (114DNS Secondary)") +custom_local_dns:value("180.76.76.76", "180.76.76.76 (Baidu DNS)") +custom_local_dns.default = "119.29.29.29" +custom_local_dns:depends("custom_local_dns", "1") +custom_local_dns = s:option(ListValue, "bootstrap_dns2", " ", translate("Bootstrap DNS servers are used to resolve IP addresses of the DoH/DoT resolvers you specify as upstreams")) +custom_local_dns:value("119.29.29.29", "119.29.29.29 (DNSPod Primary)") +custom_local_dns:value("119.28.28.28", "119.28.28.28 (DNSPod Secondary)") +custom_local_dns:value("223.5.5.5", "223.5.5.5 (AliDNS Primary)") +custom_local_dns:value("223.6.6.6", "223.6.6.6 (AliDNS Secondary)") +custom_local_dns:value("114.114.114.114", "114.114.114.114 (114DNS Primary)") +custom_local_dns:value("114.114.115.115", "114.114.115.115 (114DNS Secondary)") +custom_local_dns:value("180.76.76.76", "180.76.76.76 (Baidu DNS)") +custom_local_dns.default = "223.5.5.5" +custom_local_dns:depends("custom_local_dns", "1") + remote_dns = s:option(DynamicList, "remote_dns", translate("Remote DNS")) remote_dns:value("tls://1.1.1.1", "1.1.1.1 (CloudFlare DNS)") remote_dns:value("tls://1.0.0.1", "1.0.0.1 (CloudFlare DNS)") @@ -72,9 +110,6 @@ maximum_ttl.datatype = "and(uinteger,min(0))" maximum_ttl.default = "0" maximum_ttl:depends( "configfile", "/etc/mosdns/config.yaml") -redirect = s:option(Flag, "redirect", translate("Enable DNS Forward"), translate("Forward Dnsmasq Domain Name resolution requests to MosDNS")) -redirect.default = true - adblock = s:option(Flag, "adblock", translate("Enable DNS ADblock")) adblock:depends( "configfile", "/etc/mosdns/config.yaml") adblock.default = false diff --git a/luci-app-mosdns/po/zh-cn/mosdns.po b/luci-app-mosdns/po/zh-cn/mosdns.po index f091dca..2c1ece7 100644 --- a/luci-app-mosdns/po/zh-cn/mosdns.po +++ b/luci-app-mosdns/po/zh-cn/mosdns.po @@ -22,8 +22,8 @@ msgstr "监听端口" msgid "Log Level" msgstr "日志等级" -msgid "Enable DNS Forward" -msgstr "启用 DNS 转发" +msgid "DNS Forward" +msgstr "DNS 转发" msgid "Forward Dnsmasq Domain Name resolution requests to MosDNS" msgstr "将 Dnsmasq 域名解析请求转发到 MosDNS 服务器" @@ -109,6 +109,21 @@ msgstr "自定义" msgid "Log File" msgstr "日志文件" +msgid "Local DNS" +msgstr "本地 DNS" + +msgid "Follow WAN interface DNS if not enabled" +msgstr "不启用则遵循 WAN 接口 DNS" + +msgid "Upstream DNS servers" +msgstr "上游 DNS 服务器" + +msgid "Bootstrap DNS servers" +msgstr "Bootstrap DNS 服务器" + +msgid "Bootstrap DNS servers are used to resolve IP addresses of the DoH/DoT resolvers you specify as upstreams" +msgstr "Bootstrap DNS 服务器用于解析所指定为上游的 DoH / DoT 解析器的 IP 地址" + msgid "Remote DNS" msgstr "远程 DNS" diff --git a/luci-app-mosdns/root/etc/config/mosdns b/luci-app-mosdns/root/etc/config/mosdns index 81e922c..e488e5c 100644 --- a/luci-app-mosdns/root/etc/config/mosdns +++ b/luci-app-mosdns/root/etc/config/mosdns @@ -14,6 +14,7 @@ config mosdns 'config' option cache_survival_time '259200' option minimal_ttl '0' option maximum_ttl '0' + option custom_local_dns '0' option enable_pipeline '0' list remote_dns 'tls://8.8.8.8' list remote_dns 'tls://1.1.1.1' diff --git a/luci-app-mosdns/root/etc/init.d/mosdns b/luci-app-mosdns/root/etc/init.d/mosdns index 08b4cbd..0d53e29 100755 --- a/luci-app-mosdns/root/etc/init.d/mosdns +++ b/luci-app-mosdns/root/etc/init.d/mosdns @@ -41,6 +41,9 @@ get_config() { config_get minimal_ttl_custom $1 minimal_ttl 0 config_get redirect $1 redirect 0 config_get remote_dns $1 remote_dns "tls://8.8.8.8 tls://1.1.1.1" + config_get custom_local_dns $1 custom_local_dns 0 + config_get bootstrap_dns1 $1 bootstrap_dns1 "119.29.29.29" + config_get bootstrap_dns2 $1 bootstrap_dns2 "223.5.5.5" } init_yaml() { @@ -56,6 +59,8 @@ init_yaml() { s,maximum_ttl_custom,$maximum_ttl_custom,g; \ s,adblock,$adblock,g;s,remote_dns_pipeline,$enable_pipeline,g" \ /usr/share/mosdns/default.yaml > $CONF + [ "$custom_local_dns" -eq 0 ] && sed -i "/bootstrap/d" $CONF || \ + sed -i "s,bootstrap_dns1,$bootstrap_dns1,g;s,bootstrap_dns2,$bootstrap_dns2,g" $CONF echo "${local_dns}" > $tmpdir/local_dns.txt echo "${remote_dns}" > $tmpdir/remote_dns.txt sed -i -e '/- addr: local_dns/{r '$tmpdir/local_dns.txt -e';d};/- addr: remote_dns/{r '$tmpdir/remote_dns.txt -e';d}' \ diff --git a/luci-app-mosdns/root/usr/share/mosdns/default.yaml b/luci-app-mosdns/root/usr/share/mosdns/default.yaml index 88012de..0de10da 100644 --- a/luci-app-mosdns/root/usr/share/mosdns/default.yaml +++ b/luci-app-mosdns/root/usr/share/mosdns/default.yaml @@ -55,10 +55,13 @@ plugins: maximum_ttl: maximum_ttl_custom - tag: "forward_local" - type: fast_forward + type: forward args: upstream: - addr: local_dns + bootstrap: + - "bootstrap_dns1" + - "bootstrap_dns2" - tag: "forward_remote" type: fast_forward diff --git a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh index eca1a11..7aef37b 100755 --- a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh +++ b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh @@ -11,16 +11,20 @@ logfile_path() ( ) interface_dns() ( - peerdns=$(uci -q get network.wan.peerdns) - proto=$(uci -q get network.wan.proto) - if [ "$peerdns" = 0 ] || [ "$proto" = "static" ]; then - uci -q get network.wan.dns + if [ "$(uci -q get mosdns.config.custom_local_dns)" -eq 1 ]; then + uci -q get mosdns.config.local_dns else - interface_status=$(ubus call network.interface.wan status) - echo $interface_status | jsonfilter -e "@['dns-server'][0]" - echo $interface_status | jsonfilter -e "@['dns-server'][1]" + peerdns=$(uci -q get network.wan.peerdns) + proto=$(uci -q get network.wan.proto) + if [ "$peerdns" = 0 ] || [ "$proto" = "static" ]; then + uci -q get network.wan.dns + else + interface_status=$(ubus call network.interface.wan status) + echo $interface_status | jsonfilter -e "@['dns-server'][0]" + echo $interface_status | jsonfilter -e "@['dns-server'][1]" + fi + [ $? -ne 0 ] && echo "119.29.29.29" fi - [ $? -ne 0 ] && echo "119.29.29.29" ) ad_block() (