luci-app-mosdns: add local DNS settings

* make up for the defect that Dnsmasq does not support DoH / DoT protocols
This commit is contained in:
sbwml 2022-12-04 15:50:08 +08:00
parent 6f677a8f9d
commit fe2caaab18
6 changed files with 77 additions and 14 deletions

View File

@ -34,6 +34,44 @@ logfile.placeholder = "/tmp/mosdns.log"
logfile.default = "/tmp/mosdns.log" logfile.default = "/tmp/mosdns.log"
logfile:depends( "configfile", "/etc/mosdns/config.yaml") 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 = 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.1.1.1", "1.1.1.1 (CloudFlare DNS)")
remote_dns:value("tls://1.0.0.1", "1.0.0.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.default = "0"
maximum_ttl:depends( "configfile", "/etc/mosdns/config.yaml") 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 = s:option(Flag, "adblock", translate("Enable DNS ADblock"))
adblock:depends( "configfile", "/etc/mosdns/config.yaml") adblock:depends( "configfile", "/etc/mosdns/config.yaml")
adblock.default = false adblock.default = false

View File

@ -22,8 +22,8 @@ msgstr "监听端口"
msgid "Log Level" msgid "Log Level"
msgstr "日志等级" msgstr "日志等级"
msgid "Enable DNS Forward" msgid "DNS Forward"
msgstr "启用 DNS 转发" msgstr "DNS 转发"
msgid "Forward Dnsmasq Domain Name resolution requests to MosDNS" msgid "Forward Dnsmasq Domain Name resolution requests to MosDNS"
msgstr "将 Dnsmasq 域名解析请求转发到 MosDNS 服务器" msgstr "将 Dnsmasq 域名解析请求转发到 MosDNS 服务器"
@ -109,6 +109,21 @@ msgstr "自定义"
msgid "Log File" msgid "Log File"
msgstr "日志文件" 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" msgid "Remote DNS"
msgstr "远程 DNS" msgstr "远程 DNS"

View File

@ -14,6 +14,7 @@ config mosdns 'config'
option cache_survival_time '259200' option cache_survival_time '259200'
option minimal_ttl '0' option minimal_ttl '0'
option maximum_ttl '0' option maximum_ttl '0'
option custom_local_dns '0'
option enable_pipeline '0' option enable_pipeline '0'
list remote_dns 'tls://8.8.8.8' list remote_dns 'tls://8.8.8.8'
list remote_dns 'tls://1.1.1.1' list remote_dns 'tls://1.1.1.1'

View File

@ -41,6 +41,9 @@ get_config() {
config_get minimal_ttl_custom $1 minimal_ttl 0 config_get minimal_ttl_custom $1 minimal_ttl 0
config_get redirect $1 redirect 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 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() { init_yaml() {
@ -56,6 +59,8 @@ init_yaml() {
s,maximum_ttl_custom,$maximum_ttl_custom,g; \ s,maximum_ttl_custom,$maximum_ttl_custom,g; \
s,adblock,$adblock,g;s,remote_dns_pipeline,$enable_pipeline,g" \ s,adblock,$adblock,g;s,remote_dns_pipeline,$enable_pipeline,g" \
/usr/share/mosdns/default.yaml > $CONF /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 "${local_dns}" > $tmpdir/local_dns.txt
echo "${remote_dns}" > $tmpdir/remote_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}' \ sed -i -e '/- addr: local_dns/{r '$tmpdir/local_dns.txt -e';d};/- addr: remote_dns/{r '$tmpdir/remote_dns.txt -e';d}' \

View File

@ -55,10 +55,13 @@ plugins:
maximum_ttl: maximum_ttl_custom maximum_ttl: maximum_ttl_custom
- tag: "forward_local" - tag: "forward_local"
type: fast_forward type: forward
args: args:
upstream: upstream:
- addr: local_dns - addr: local_dns
bootstrap:
- "bootstrap_dns1"
- "bootstrap_dns2"
- tag: "forward_remote" - tag: "forward_remote"
type: fast_forward type: fast_forward

View File

@ -11,6 +11,9 @@ logfile_path() (
) )
interface_dns() ( interface_dns() (
if [ "$(uci -q get mosdns.config.custom_local_dns)" -eq 1 ]; then
uci -q get mosdns.config.local_dns
else
peerdns=$(uci -q get network.wan.peerdns) peerdns=$(uci -q get network.wan.peerdns)
proto=$(uci -q get network.wan.proto) proto=$(uci -q get network.wan.proto)
if [ "$peerdns" = 0 ] || [ "$proto" = "static" ]; then if [ "$peerdns" = 0 ] || [ "$proto" = "static" ]; then
@ -21,6 +24,7 @@ interface_dns() (
echo $interface_status | jsonfilter -e "@['dns-server'][1]" echo $interface_status | jsonfilter -e "@['dns-server'][1]"
fi fi
[ $? -ne 0 ] && echo "119.29.29.29" [ $? -ne 0 ] && echo "119.29.29.29"
fi
) )
ad_block() ( ad_block() (