From a1e6216966bfa90b7c45aef8dbe1e8c008db791b Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Wed, 9 Oct 2024 13:42:35 +0800 Subject: [PATCH] luci-app-mosdns: bump version --- applications/luci-app-mosdns/Makefile | 6 +- .../luasrc/controller/mosdns.lua | 2 +- .../luasrc/model/cbi/mosdns/basic.lua | 83 ++- .../luasrc/model/cbi/mosdns/rule_list.lua | 12 + .../luasrc/model/cbi/mosdns/update.lua | 2 +- .../luci-app-mosdns/po/zh-cn/mosdns.po | 34 +- applications/luci-app-mosdns/po/zh_Hans | 1 + .../luci-app-mosdns/root/etc/config/mosdns | 9 +- .../luci-app-mosdns/root/etc/init.d/mosdns | 703 +++++++++++++++--- .../root/etc/mosdns/rule/streaming.txt | 0 .../root/usr/share/mosdns/default.yaml | 259 ------- .../root/usr/share/mosdns/mosdns.sh | 35 +- 12 files changed, 736 insertions(+), 410 deletions(-) create mode 120000 applications/luci-app-mosdns/po/zh_Hans create mode 100644 applications/luci-app-mosdns/root/etc/mosdns/rule/streaming.txt delete mode 100644 applications/luci-app-mosdns/root/usr/share/mosdns/default.yaml diff --git a/applications/luci-app-mosdns/Makefile b/applications/luci-app-mosdns/Makefile index 4777fbf7..ffb05b56 100644 --- a/applications/luci-app-mosdns/Makefile +++ b/applications/luci-app-mosdns/Makefile @@ -1,8 +1,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-mosdns -PKG_VERSION:=1.5.18 -PKG_RELEASE:=1 +PKG_VERSION:=1.5.23 +PKG_RELEASE:=3 LUCI_TITLE:=LuCI Support for mosdns LUCI_PKGARCH:=all @@ -15,6 +15,6 @@ define Package/$(PKG_NAME)/conffiles /etc/mosdns/rule endef -include ../../luci.mk +include $(TOPDIR)/feeds/luci/luci.mk # call BuildPackage - OpenWrt buildroot signature diff --git a/applications/luci-app-mosdns/luasrc/controller/mosdns.lua b/applications/luci-app-mosdns/luasrc/controller/mosdns.lua index 60840fbb..a45b78a7 100644 --- a/applications/luci-app-mosdns/luasrc/controller/mosdns.lua +++ b/applications/luci-app-mosdns/luasrc/controller/mosdns.lua @@ -25,7 +25,7 @@ end function act_status() local e = {} - e.running = sys.call("pgrep -f mosdns >/dev/null") == 0 + e.running = sys.call("pgrep -f /usr/bin/mosdns >/dev/null") == 0 http.prepare_content("application/json") http.write_json(e) end diff --git a/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua b/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua index 4af0903e..dcd8f487 100644 --- a/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua +++ b/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua @@ -22,14 +22,14 @@ o = s:taboption("basic", Flag, "enabled", translate("Enabled")) o.rmempty = false o = s:taboption("basic", ListValue, "configfile", translate("Config File")) -o:value("/etc/mosdns/config.yaml", translate("Default Config")) +o:value("/var/etc/mosdns.json", translate("Default Config")) o:value("/etc/mosdns/config_custom.yaml", translate("Custom Config")) -o.default = "/etc/mosdns/config.yaml" +o.default = "/var/etc/mosdns.json" o = s:taboption("basic", Value, "listen_port", translate("Listen port")) o.datatype = "and(port,min(1))" o.default = 5335 -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("basic", ListValue, "log_level", translate("Log Level")) o:value("debug", translate("Debug")) @@ -37,22 +37,22 @@ o:value("info", translate("Info")) o:value("warn", translate("Warning")) o:value("error", translate("Error")) o.default = "info" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") -o = s:taboption("basic", Value, "logfile", translate("Log File")) +o = s:taboption("basic", Value, "log_file", translate("Log File")) o.placeholder = "/var/log/mosdns.log" o.default = "/var/log/mosdns.log" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("basic", Flag, "redirect", translate("DNS Forward"), translate("Forward Dnsmasq Domain Name resolution requests to MosDNS")) o.default = true -o = s:taboption("basic", Flag, "prefer_ipv4", translate("Remote DNS prefer IPv4"), translate("IPv4 is preferred for remote DNS resolution of dual-stack addresses, and is not affected when the destination is IPv6 only")) -o:depends( "configfile", "/etc/mosdns/config.yaml") +o = s:taboption("basic", Flag, "prefer_ipv4", translate("Remote DNS prefer IPv4"), translate("IPv4 is preferred for Remote / Streaming Media DNS resolution of dual-stack addresses, and is not affected when the destination is IPv6 only")) +o:depends( "configfile", "/var/etc/mosdns.json") o.default = true o = s:taboption("basic", Flag, "custom_local_dns", translate("Custom China DNS"), translate("Follow WAN interface DNS if not enabled")) -o:depends( "configfile", "/etc/mosdns/config.yaml") +o:depends( "configfile", "/var/etc/mosdns.json") o.default = false o = s:taboption("basic", Flag, "apple_optimization", translate("Apple domains optimization"), translate("For Apple domains equipped with Chinese mainland CDN, always responsive to Chinese CDN IP addresses")) @@ -83,7 +83,23 @@ o:value("tls://9.9.9.9", translate("Quad9 Public DNS (9.9.9.9)")) o:value("tls://149.112.112.112", translate("Quad9 Public DNS (149.112.112.112)")) o:value("tls://208.67.222.222", translate("Cisco Public DNS (208.67.222.222)")) o:value("tls://208.67.220.220", translate("Cisco Public DNS (208.67.220.220)")) -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") + +o = s:taboption("basic", Flag, "custom_stream_media_dns", translate("Custom Stream Media DNS"), translate("Netflix, Disney+, Hulu and streaming media rules list will use this DNS")) +o:depends( "configfile", "/var/etc/mosdns.json") +o.default = false + +o = s:taboption("basic", DynamicList, "stream_media_dns", translate("Streaming Media DNS server")) +o:value("tls://1.1.1.1", translate("CloudFlare Public DNS (1.1.1.1)")) +o:value("tls://1.0.0.1", translate("CloudFlare Public DNS (1.0.0.1)")) +o:value("tls://8.8.8.8", translate("Google Public DNS (8.8.8.8)")) +o:value("tls://8.8.4.4", translate("Google Public DNS (8.8.4.4)")) +o:value("tls://9.9.9.9", translate("Quad9 Public DNS (9.9.9.9)")) +o:value("tls://149.112.112.112", translate("Quad9 Public DNS (149.112.112.112)")) +o:value("tls://208.67.222.222", translate("Cisco Public DNS (208.67.222.222)")) +o:value("tls://208.67.220.220", translate("Cisco Public DNS (208.67.220.220)")) +o.default = "tls://8.8.8.8" +o:depends("custom_stream_media_dns", "1") o = s:taboption("basic", ListValue, "bootstrap_dns", translate("Bootstrap DNS servers"), translate("Bootstrap DNS servers are used to resolve IP addresses of the DoH/DoT resolvers you specify as upstreams")) o:value("119.29.29.29", translate("Tencent Public DNS (119.29.29.29)")) @@ -96,58 +112,63 @@ o:value("180.76.76.76", translate("Baidu Public DNS (180.76.76.76)")) o:value("8.8.8.8", translate("Google Public DNS (8.8.8.8)")) o:value("1.1.1.1", translate("CloudFlare Public DNS (1.1.1.1)")) o.default = "119.29.29.29" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") s:tab("advanced", translate("Advanced Options")) o = s:taboption("advanced", Value, "concurrent", translate("Concurrent"), translate("DNS query request concurrency, The number of upstream DNS servers that are allowed to initiate requests at the same time")) o.datatype = "and(uinteger,min(1),max(3))" o.default = "2" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("advanced", Value, "idle_timeout", translate("Idle Timeout"), translate("DoH/TCP/DoT Connection Multiplexing idle timeout (default 30 seconds)")) o.datatype = "and(uinteger,min(1))" o.default = "30" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("advanced", Flag, "enable_pipeline", translate("TCP/DoT Connection Multiplexing"), translate("Enable TCP/DoT RFC 7766 new Query Pipelining connection multiplexing mode")) o.rmempty = false o.default = false -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("advanced", Flag, "insecure_skip_verify", translate("Disable TLS Certificate"), translate("Disable TLS Servers certificate validation, Can be useful if system CA certificate expires or the system time is out of order")) o.rmempty = false o.default = false -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("advanced", Flag, "enable_ecs_remote", translate("Enable EDNS client subnet")) o.rmempty = false o.default = false -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") -o = s:taboption("advanced", Value, "remote_ecs_ip", translate("IP Address"), translate("Please provide the IP address you use when accessing foreign websites. This IP subnet (0/24) will be used as the ECS address for Remote DNS requests") .. '
' .. translate("This feature is typically used when using a self-built DNS server as an Remote DNS upstream (requires support from the upstream server)")) +o = s:taboption("advanced", Value, "remote_ecs_ip", translate("IP Address"), translate("Please provide the IP address you use when accessing foreign websites. This IP subnet (0/24) will be used as the ECS address for Remote / Streaming Media DNS requests") .. '
' .. translate("This feature is typically used when using a self-built DNS server as an Remote / Streaming Media DNS upstream (requires support from the upstream server)")) o.datatype = "ipaddr" o:depends("enable_ecs_remote", "1") o = s:taboption("advanced", Flag, "dns_leak", translate("Prevent DNS Leaks"), translate("Enable this option fallback policy forces forwarding to remote DNS")) o.rmempty = false o.default = false -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") -o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size"), translate("DNS cache size (in piece). To disable caching, please set to 0.")) +o = s:taboption("advanced", Flag, "cache", translate("Enable DNS Cache")) +o.rmempty = false +o.default = false +o:depends("configfile", "/var/etc/mosdns.json") + +o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size"), translate("DNS cache size (in piece).")) o.datatype = "and(uinteger,min(0))" o.default = "8000" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("cache", "1") -o = s:taboption("advanced", Value, "cache_survival_time", translate("Lazy Cache TTL"), translate("Lazy cache survival time (in second). To disable Lazy Cache, please set to 0.")) +o = s:taboption("advanced", Value, "lazy_cache_ttl", translate("Lazy Cache TTL"), translate("Lazy cache survival time (in second). To disable Lazy Cache, please set to 0.")) o.datatype = "and(uinteger,min(0))" o.default = "86400" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("cache", "1") o = s:taboption("advanced", Flag, "dump_file", translate("Cache Dump"), translate("Save the cache locally and reload the cache dump on the next startup")) o.rmempty = false o.default = false -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("cache", "1") o = s:taboption("advanced", Value, "dump_interval", translate("Auto Save Cache Interval")) o.datatype = "and(uinteger,min(0))" @@ -157,15 +178,15 @@ o:depends("dump_file", "1") o = s:taboption("advanced", Value, "minimal_ttl", translate("Minimum TTL"), translate("Modify the Minimum TTL value (seconds) for DNS answer results, 0 indicating no modification")) o.datatype = "and(uinteger,min(0),max(604800))" o.default = "0" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("advanced", Value, "maximum_ttl", translate("Maximum TTL"), translate("Modify the Maximum TTL value (seconds) for DNS answer results, 0 indicating no modification")) o.datatype = "and(uinteger,min(0),max(604800))" o.default = "0" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("advanced", Flag, "adblock", translate("Enable DNS ADblock")) -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o.default = false o = s:taboption("advanced", DynamicList, "ad_source", translate("ADblock Source"), translate("When using custom rule sources, please use rule types supported by MosDNS (domain lists).") .. '
' .. translate("Support for local files, such as: file:///var/mosdns/example.txt")) @@ -201,17 +222,17 @@ s:tab("cloudflare", translate("Cloudflare Options")) o = s:taboption("cloudflare", Flag, "cloudflare", translate("Enabled"), translate("Match the parsing result with the Cloudflare IP ranges, and when there is a successful match, use the 'Custom IP' as the parsing result (experimental feature)")) o.rmempty = false o.default = false -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("cloudflare", DynamicList, "cloudflare_ip", translate("Custom IP")) o.datatype = "ipaddr" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("cloudflare", TextValue, "cloudflare_cidr", translate("Cloudflare IP Ranges")) o.description = translate("IPv4 CIDR:") .. [[https://www.cloudflare.com/ips-v4]] .. '
' .. translate("IPv6 CIDR:") .. [[https://www.cloudflare.com/ips-v6]] o.template = "cbi/tvalue" o.rows = 15 -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") function o.cfgvalue(self, section) return fs.readfile("/etc/mosdns/rule/cloudflare-cidr.txt") end @@ -225,12 +246,12 @@ s:tab("api", translate("API Options")) o = s:taboption("api", Value, "listen_port_api", translate("API Listen port")) o.datatype = "and(port,min(1))" o.default = 9091 -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") o = s:taboption("api", Button, "flush_cache", translate("Flush Cache"), translate("Flushing Cache will clear any IP addresses or DNS records from MosDNS cache")) o.rawhtml = true o.template = "mosdns/mosdns_flush_cache" -o:depends("configfile", "/etc/mosdns/config.yaml") +o:depends("configfile", "/var/etc/mosdns.json") s:tab("geodata", translate("GeoData Export")) diff --git a/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/rule_list.lua b/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/rule_list.lua index 1d6554e2..d41957be 100644 --- a/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/rule_list.lua +++ b/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/rule_list.lua @@ -7,6 +7,7 @@ local hosts_list_file = "/etc/mosdns/rule/hosts.txt" local redirect_list_file = "/etc/mosdns/rule/redirect.txt" local local_ptr_file = "/etc/mosdns/rule/local-ptr.txt" local ddns_list_file = "/etc/mosdns/rule/ddnslist.txt" +local streaming_media_list_file = "/etc/mosdns/rule/streaming.txt" m = Map("mosdns") @@ -20,6 +21,7 @@ s:tab("ddns_list", translate("DDNS Lists")) s:tab("hosts_list", translate("Hosts")) s:tab("redirect_list", translate("Redirect")) s:tab("local_ptr_list", translate("Block PTR")) +s:tab("streaming_media_list", translate("Streaming Media")) o = s:taboption("white_list", TextValue, "whitelist", "", "" .. translate("These domain names allow DNS resolution with the highest priority. Please input the domain names of websites, every line can input only one website domain. For example: hm.baidu.com.") .. "" .. "" .. translate("
The list of rules only apply to 'Default Config' profiles.") .. "
") o.rows = 15 @@ -91,6 +93,16 @@ o.validate = function(self, value) return value end +o = s:taboption("streaming_media_list", TextValue, "streaming_media", "", "" .. translate("These domains are always resolved using Streaming Media DNS. Please input the domain names of websites, every line can input only one website domain. For example: netflix.com.") .. "" .. "" .. translate("
The list of rules only apply to 'Default Config' profiles.") .. "
") +o.rows = 15 +o.wrap = "off" +o.cfgvalue = function(self, section) return nixio.fs.readfile(streaming_media_list_file) or "" end +o.write = function(self, section, value) nixio.fs.writefile(streaming_media_list_file, value:gsub("\r\n", "\n")) end +o.remove = function(self, section, value) nixio.fs.writefile(streaming_media_list_file, "") end +o.validate = function(self, value) + return value +end + local apply = luci.http.formvalue("cbi.apply") if apply then luci.sys.exec("/etc/init.d/mosdns reload") diff --git a/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/update.lua b/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/update.lua index 79ce65df..bcc14145 100644 --- a/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/update.lua +++ b/applications/luci-app-mosdns/luasrc/model/cbi/mosdns/update.lua @@ -25,7 +25,7 @@ end default = 3 o = s:option(Value, "github_proxy", translate("GitHub Proxy"), translate("Update data files with GitHub Proxy, leave blank to disable proxy downloads.")) -o:value("https://gh-proxy.com", translate("https://gh-proxy.com")) +o:value("https://hub.gitmirror.com", translate("https://hub.gitmirror.com")) o:value("https://ghps.cc", translate("https://ghps.cc")) o.rmempty = true o.default = "" diff --git a/applications/luci-app-mosdns/po/zh-cn/mosdns.po b/applications/luci-app-mosdns/po/zh-cn/mosdns.po index 07859801..d6040540 100644 --- a/applications/luci-app-mosdns/po/zh-cn/mosdns.po +++ b/applications/luci-app-mosdns/po/zh-cn/mosdns.po @@ -163,8 +163,8 @@ msgstr "日志文件" msgid "Remote DNS prefer IPv4" msgstr "远程 DNS 首选 IPv4" -msgid "IPv4 is preferred for remote DNS resolution of dual-stack addresses, and is not affected when the destination is IPv6 only" -msgstr "远程 DNS 解析双栈地址时首选 IPv4,目标仅 IPv6 时不受影响" +msgid "IPv4 is preferred for Remote / Streaming Media DNS resolution of dual-stack addresses, and is not affected when the destination is IPv6 only" +msgstr "远程 / 流媒体 DNS 解析双栈地址时首选 IPv4,目标仅 IPv6 时不受影响" msgid "Custom China DNS" msgstr "自定义国内 DNS" @@ -280,11 +280,11 @@ msgstr "启用 EDNS 客户端子网" msgid "IP Address" msgstr "IP 地址" -msgid "Please provide the IP address you use when accessing foreign websites. This IP subnet (0/24) will be used as the ECS address for Remote DNS requests" -msgstr "请提供您在访问国外网站时使用的 IP 地址,这个 IP 子网(0/24)将用作远程 DNS 请求的 ECS 地址" +msgid "Please provide the IP address you use when accessing foreign websites. This IP subnet (0/24) will be used as the ECS address for Remote / Streaming Media DNS requests" +msgstr "请提供您在访问国外网站时使用的 IP 地址,这个 IP 子网(0/24)将用作 远程 / 流媒体 DNS 请求的 ECS 地址" -msgid "This feature is typically used when using a self-built DNS server as an Remote DNS upstream (requires support from the upstream server)" -msgstr "此功能通常在使用自建 DNS 服务器作为 远程 DNS 上游时使用(需要上游服务器的支持)" +msgid "This feature is typically used when using a self-built DNS server as an Remote / Streaming Media DNS upstream (requires support from the upstream server)" +msgstr "此功能通常在使用自建 DNS 服务器作为 远程 / 流媒体 DNS 上游时使用(需要上游服务器的支持)" msgid "Prevent DNS Leaks" msgstr "防止 DNS 泄漏" @@ -292,11 +292,14 @@ msgstr "防止 DNS 泄漏" msgid "Enable this option fallback policy forces forwarding to remote DNS" msgstr "启用此选项 fallback 策略会强制转发到远程 DNS" +msgid "Enable DNS Cache" +msgstr "启用 DNS 缓存" + msgid "DNS Cache Size" msgstr "DNS 缓存大小" -msgid "DNS cache size (in piece). To disable caching, please set to 0." -msgstr "DNS 缓存大小(单位:条),要禁用缓存,请设置为 0" +msgid "DNS cache size (in piece)." +msgstr "DNS 缓存大小(单位:条)" msgid "Lazy Cache TTL" msgstr "乐观缓存 TTL" @@ -396,3 +399,18 @@ msgstr "输入需要导出的 GeoIP.dat 类别条目,允许添加多个标签" msgid "Export directory: /var/mosdns" msgstr "导出目录:/var/mosdns" + +msgid "Custom Stream Media DNS" +msgstr "自定义流媒体 DNS" + +msgid "Streaming Media DNS server" +msgstr "流媒体 DNS 服务器" + +msgid "Netflix, Disney+, Hulu and streaming media rules list will use this DNS" +msgstr "自定义 Netflix、Disney+、Hulu 以及 “流媒体” 规则列表的 DNS 服务器" + +msgid "Streaming Media" +msgstr "流媒体" + +msgid "These domains are always resolved using Streaming Media DNS. Please input the domain names of websites, every line can input only one website domain. For example: netflix.com." +msgstr "启用 “自定义流媒体 DNS” 时,加入的域名始终使用 “流媒体 DNS 服务器” 进行解析(每个域名一行,支持域名匹配规则)" diff --git a/applications/luci-app-mosdns/po/zh_Hans b/applications/luci-app-mosdns/po/zh_Hans new file mode 120000 index 00000000..41451e4a --- /dev/null +++ b/applications/luci-app-mosdns/po/zh_Hans @@ -0,0 +1 @@ +zh-cn \ No newline at end of file diff --git a/applications/luci-app-mosdns/root/etc/config/mosdns b/applications/luci-app-mosdns/root/etc/config/mosdns index 8d3408cc..11e2e843 100644 --- a/applications/luci-app-mosdns/root/etc/config/mosdns +++ b/applications/luci-app-mosdns/root/etc/config/mosdns @@ -8,12 +8,10 @@ config mosdns 'config' option redirect '1' option prefer_ipv4 '1' option adblock '0' - option configfile '/etc/mosdns/config.yaml' + option configfile '/var/etc/mosdns.json' option log_level 'info' - option logfile '/var/log/mosdns.log' - option cache_size '8000' - option cache_survival_time '86400' - option dump_file '0' + option log_file '/var/log/mosdns.log' + option cache '0' option concurrent '1' option idle_timeout '30' option minimal_ttl '0' @@ -24,6 +22,7 @@ config mosdns 'config' option dns_leak '0' option cloudflare '0' option listen_port_api '9091' + option custom_stream_media_dns '0' option bootstrap_dns '119.29.29.29' list remote_dns 'tls://8.8.8.8' list remote_dns 'tls://1.1.1.1' diff --git a/applications/luci-app-mosdns/root/etc/init.d/mosdns b/applications/luci-app-mosdns/root/etc/init.d/mosdns index 5f785b83..387d8b74 100755 --- a/applications/luci-app-mosdns/root/etc/init.d/mosdns +++ b/applications/luci-app-mosdns/root/etc/init.d/mosdns @@ -1,8 +1,7 @@ #!/bin/sh /etc/rc.common # # Copyright (C) 2020-2022, IrineSistiana -# -# Copyright (C) 2023, sbwml +# Copyright (C) 2023-2024, sbwml # # This file is part of mosdns. # @@ -20,7 +19,7 @@ # along with this program. If not, see . # -START=51 +START=75 USE_PROCD=1 PROG=/usr/bin/mosdns @@ -28,15 +27,15 @@ CONF=$(uci -q get mosdns.config.configfile) CRON_FILE=/etc/crontabs/root DUMP_FILE=/etc/mosdns/cache.dump DUMP_FILE_DEFAULT=/usr/share/mosdns/cache.dump -DEFAULT_CONF=/usr/share/mosdns/default.yaml MOSDNS_SCRIPT=/usr/share/mosdns/mosdns.sh get_config() { config_get enabled $1 enabled 0 config_get adblock $1 adblock 0 config_get ad_source $1 ad_source "" + config_get cache $1 cache 0 config_get cache_size $1 cache_size 8000 - config_get cache_survival_time $1 cache_survival_time 86400 + config_get lazy_cache_ttl $1 lazy_cache_ttl 86400 config_get dump_file $1 dump_file 0 config_get dump_interval $1 dump_interval 3600 config_get enable_pipeline $1 enable_pipeline 0 @@ -44,15 +43,17 @@ get_config() { config_get geo_update_day_time $1 geo_update_day_time 2 config_get geo_update_week_time $1 geo_update_week_time "*" config_get listen_port $1 listen_port 5335 - config_get log_file $1 logfile "/var/log/mosdns.log" + config_get log_file $1 log_file "/var/log/mosdns.log" config_get log_level $1 log_level "info" - config_get maximum_ttl_custom $1 maximum_ttl 0 - config_get minimal_ttl_custom $1 minimal_ttl 0 + config_get minimal_ttl $1 minimal_ttl 0 + config_get maximum_ttl $1 maximum_ttl 0 config_get redirect $1 redirect 0 config_get prefer_ipv4 $1 prefer_ipv4 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 apple_optimization $1 apple_optimization 0 + config_get custom_stream_media_dns $1 custom_stream_media_dns 0 + config_get stream_media_dns $1 stream_media_dns "tls://8.8.8.8" config_get bootstrap_dns $1 bootstrap_dns "119.29.29.29" config_get listen_port_api $1 listen_port_api 9091 config_get concurrent $1 concurrent 1 @@ -62,84 +63,619 @@ get_config() { config_get remote_ecs_ip $1 remote_ecs_ip "110.34.181.1" config_get dns_leak $1 dns_leak 0 config_get cloudflare $1 cloudflare 0 + config_get cloudflare_ip $1 cloudflare_ip "" } -init_yaml() { - TMPDIR=$(mktemp -d) || exit 1 - [ $enable_pipeline -eq 1 ] && enable_pipeline=true || enable_pipeline=false - [ $insecure_skip_verify -eq 1 ] && insecure_skip_verify=true || insecure_skip_verify=false - # China DNS - if [ "$custom_local_dns" -eq 1 ]; then - local_dns=$($MOSDNS_SCRIPT dns | awk -v s=' ' '{ - for(i=1; i<=NF; i++) { - if ($i ~ /^h3:\/\//) { - printf "%s- addr: \"%s\"\n%s bootstrap: '${bootstrap_dns}'\n%s enable_pipeline: '${enable_pipeline}'\n%s insecure_skip_verify: '${insecure_skip_verify}'\n%s idle_timeout: '${idle_timeout}'\n%s enable_http3: true\n",s,$i,s,s,s,s,s - } else { - printf "%s- addr: \"%s\"\n%s bootstrap: '${bootstrap_dns}'\n%s enable_pipeline: '${enable_pipeline}'\n%s insecure_skip_verify: '${insecure_skip_verify}'\n%s idle_timeout: '${idle_timeout}'\n",s,$i,s,s,s,s - } - } - }') - else - local_dns=$($MOSDNS_SCRIPT dns | awk '{for(i=1;i<=NF;i++)printf "%s- addr: \"%s\"\n",s,$i,s}' s=' ') - fi - # Remote DNS - remote_dns=$(echo $remote_dns | awk -v s=' ' '{ - for(i=1; i<=NF; i++) { - if ($i ~ /^h3:\/\//) { - printf "%s- addr: \"%s\"\n%s bootstrap: '${bootstrap_dns}'\n%s enable_pipeline: '${enable_pipeline}'\n%s insecure_skip_verify: '${insecure_skip_verify}'\n%s idle_timeout: '${idle_timeout}'\n%s enable_http3: true\n",s,$i,s,s,s,s,s - } else { - printf "%s- addr: \"%s\"\n%s bootstrap: '${bootstrap_dns}'\n%s enable_pipeline: '${enable_pipeline}'\n%s insecure_skip_verify: '${insecure_skip_verify}'\n%s idle_timeout: '${idle_timeout}'\n",s,$i,s,s,s,s - } - } - }') - # Write parameters - sed "s,log_level,$log_level,g;s,log_file,$log_file,g; \ - s,listen_port,$listen_port,g;s,cache_size,$cache_size,g; \ - s,cache_survival_time,$cache_survival_time,g; \ - s,minimal_ttl_custom,$minimal_ttl_custom,g; \ - s,maximum_ttl_custom,$maximum_ttl_custom,g; \ - s,concurrent_num,$concurrent,g;s,api_port,$listen_port_api,g; \ - s,remote_dns_pipeline,$enable_pipeline,g" $DEFAULT_CONF > $CONF - # Apple optimization - [ "$apple_optimization" != 1 ] && sed -i '/- exec: \$query_is_apple_domain/,+1d' $CONF - # Adlist +generate_config() { + # jshn shell library + . /usr/share/libubox/jshn.sh + # json data + json_init + # log + json_add_object 'log' + json_add_string "level" "$log_level" + json_add_string "file" "$log_file" + json_close_object + # api + json_add_object 'api' + json_add_string "http" "0.0.0.0:$listen_port_api" + json_close_object + # include + json_add_array "include" + json_close_array + # plugins + json_add_array "plugins" + # plugin: geosite_cn + json_add_object + json_add_string "tag" "geosite_cn" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/var/mosdns/geosite_cn.txt" + json_close_array + json_close_object + json_close_object + # plugin: geoip_cn + json_add_object + json_add_string "tag" "geoip_cn" + json_add_string "type" "ip_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/var/mosdns/geoip_cn.txt" + json_close_array + json_close_object + json_close_object + # plugin: geosite_apple + json_add_object + json_add_string "tag" "geosite_apple" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/var/mosdns/geosite_apple.txt" + json_close_array + json_close_object + json_close_object + # plugin: geosite_no_cn + json_add_object + json_add_string "tag" "geosite_no_cn" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/var/mosdns/geosite_geolocation-!cn.txt" + json_close_array + json_close_object + json_close_object + # plugin: whitelist + json_add_object + json_add_string "tag" "whitelist" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/etc/mosdns/rule/whitelist.txt" + json_close_array + json_close_object + json_close_object + # plugin: blocklist + json_add_object + json_add_string "tag" "blocklist" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/etc/mosdns/rule/blocklist.txt" + json_close_array + json_close_object + json_close_object + # plugin: greylist + json_add_object + json_add_string "tag" "greylist" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/etc/mosdns/rule/greylist.txt" + json_close_array + json_close_object + json_close_object + # plugin: ddnslist + json_add_object + json_add_string "tag" "ddnslist" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/etc/mosdns/rule/ddnslist.txt" + json_close_array + json_close_object + json_close_object + # plugin: hosts + json_add_object + json_add_string "tag" "hosts" + json_add_string "type" "hosts" + json_add_object "args" + json_add_array "files" + json_add_string "" "/etc/mosdns/rule/hosts.txt" + json_close_array + json_close_object + json_close_object + # plugin: redirect + json_add_object + json_add_string "tag" "redirect" + json_add_string "type" "redirect" + json_add_object "args" + json_add_array "files" + json_add_string "" "/etc/mosdns/rule/redirect.txt" + json_close_array + json_close_object + json_close_object + # plugin: adlist + json_add_object + json_add_string "tag" "adlist" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" adlist=$($MOSDNS_SCRIPT adlist) - echo "${adlist}" > $TMPDIR/adlist_files.txt - sed -i -e '/ADBLOCK_LIST/{r '$TMPDIR/adlist_files.txt -e';d}' $CONF - # DNS - 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}' $CONF - # Convert HTTP/3 prefix format - sed -i 's/h3:\/\//https:\/\//g' $CONF - # Prefer IPv4 - [ $prefer_ipv4 -ne 1 ] && sed -i "/prefer_ipv4/d" $CONF - # Cache dump - [ "$dump_file" -eq 1 ] && sed -i "/lazy_cache_ttl/a\ dump_file: $DUMP_FILE\n dump_interval: $dump_interval" $CONF + for list in $adlist; do + json_add_string "" "$list" + done + json_close_array + json_close_object + json_close_object + # plugin: local_ptr + json_add_object + json_add_string "tag" "local_ptr" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/etc/mosdns/rule/local-ptr.txt" + json_close_array + json_close_object + json_close_object + # plugin: stream_media + json_add_object + json_add_string "tag" "stream_media" + json_add_string "type" "domain_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/var/mosdns/geosite_disney.txt" + json_add_string "" "/var/mosdns/geosite_netflix.txt" + json_add_string "" "/var/mosdns/geosite_hulu.txt" + json_add_string "" "/etc/mosdns/rule/streaming.txt" + json_close_array + json_close_object + json_close_object + # plugin: cloudflare_cidr + json_add_object + json_add_string "tag" "cloudflare_cidr" + json_add_string "type" "ip_set" + json_add_object "args" + json_add_array "files" + json_add_string "" "/etc/mosdns/rule/cloudflare-cidr.txt" + json_close_array + json_close_object + json_close_object + # plugin: lazy_cache + [ "$cache" -eq 1 ] && { + json_add_object + json_add_string "tag" "lazy_cache" + json_add_string "type" "cache" + json_add_object "args" + json_add_int "size" "$cache_size" + json_add_int "lazy_cache_ttl" "$lazy_cache_ttl" + [ "$dump_file" -eq 1 ] && { + json_add_string "dump_file" "/etc/mosdns/cache.dump" + json_add_int "dump_interval" "$dump_interval" + } + json_close_object + json_close_object + } + # plugin: forward_xinfeng_udp + json_add_object + json_add_string "tag" "forward_xinfeng_udp" + json_add_string "type" "forward" + json_add_object "args" + json_add_int "concurrent" 2 + json_add_array "upstreams" + json_add_object + json_add_string "addr" "114.114.114.114" + json_close_object + json_add_object + json_add_string "addr" "114.114.115.115" + json_close_object + json_close_array + json_close_object + json_close_object + # plugin: forward_local + json_add_object + json_add_string "tag" "forward_local" + json_add_string "type" "forward" + json_add_object "args" + json_add_int "concurrent" "$concurrent" + json_add_array "upstreams" + local_dns=$($MOSDNS_SCRIPT dns) + for addr in $local_dns; do + enable_http3=0 + if echo "$addr" | grep -q "^h3://"; then + enable_http3=1 + addr=$(echo $addr | sed 's/h3:\/\//https:\/\//g') + fi + json_add_object + json_add_string "addr" "$addr" + json_add_string "bootstrap" "$bootstrap_dns" + json_add_boolean "enable_pipeline" "$enable_pipeline" + json_add_boolean "insecure_skip_verify" "$insecure_skip_verify" + json_add_int "idle_timeout" "$idle_timeout" + [ "$enable_http3" -eq 1 ] && json_add_boolean "enable_http3" "1" + json_close_object + done + json_close_array + json_close_object + json_close_object + # plugin: forward_remote + json_add_object + json_add_string "tag" "forward_remote" + json_add_string "type" "forward" + json_add_object "args" + json_add_int "concurrent" "$concurrent" + json_add_array "upstreams" + for addr in $remote_dns; do + enable_http3=0 + if echo "$addr" | grep -q "^h3://"; then + enable_http3=1 + addr=$(echo $addr | sed 's/h3:\/\//https:\/\//g') + fi + json_add_object + json_add_string "addr" "$addr" + json_add_string "bootstrap" "$bootstrap_dns" + json_add_boolean "enable_pipeline" "$enable_pipeline" + json_add_boolean "insecure_skip_verify" "$insecure_skip_verify" + json_add_int "idle_timeout" "$idle_timeout" + [ "$enable_http3" -eq 1 ] && json_add_boolean "enable_http3" "1" + json_close_object + done + json_close_array + json_close_object + json_close_object + # plugin: forward_remote_upstream + json_add_object + json_add_string "tag" "forward_remote_upstream" + json_add_string "type" "sequence" + json_add_array "args" + [ "$prefer_ipv4" -eq 1 ] && { + json_add_object + json_add_string "exec" "prefer_ipv4" + json_close_object + } + [ "$enable_ecs_remote" -eq 1 ] && { + json_add_object + json_add_string "exec" "ecs $remote_ecs_ip" + json_close_object + } + json_add_object + json_add_string "exec" "\$forward_remote" + json_close_object + json_close_array + json_close_object + # plugin: forward_stream_media + json_add_object + json_add_string "tag" "forward_stream_media" + json_add_string "type" "forward" + json_add_object "args" + json_add_int "concurrent" "$concurrent" + json_add_array "upstreams" + for addr in $stream_media_dns; do + enable_http3=0 + if echo "$addr" | grep -q "^h3://"; then + enable_http3=1 + addr=$(echo $addr | sed 's/h3:\/\//https:\/\//g') + fi + json_add_object + json_add_string "addr" "$addr" + json_add_string "bootstrap" "$bootstrap_dns" + json_add_boolean "enable_pipeline" "$enable_pipeline" + json_add_boolean "insecure_skip_verify" "$insecure_skip_verify" + json_add_int "idle_timeout" "$idle_timeout" + [ "$enable_http3" -eq 1 ] && json_add_boolean "enable_http3" "1" + json_close_object + done + json_close_array + json_close_object + json_close_object + # plugin: forward_stream_media_upstream + json_add_object + json_add_string "tag" "forward_stream_media_upstream" + json_add_string "type" "sequence" + json_add_array "args" + [ "$prefer_ipv4" -eq 1 ] && { + json_add_object + json_add_string "exec" "prefer_ipv4" + json_close_object + } + [ "$enable_ecs_remote" -eq 1 ] && { + json_add_object + json_add_string "exec" "ecs $remote_ecs_ip" + json_close_object + } + json_add_object + json_add_string "exec" "\$forward_stream_media" + json_close_object + json_close_array + json_close_object + # plugin: modify_ttl + json_add_object + json_add_string "tag" "modify_ttl" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "exec" "ttl $minimal_ttl-$maximum_ttl" + json_close_object + json_close_array + json_close_object + # plugin: modify_ddns_ttl + json_add_object + json_add_string "tag" "modify_ddns_ttl" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "exec" "ttl 5-5" + json_close_object + json_close_array + json_close_object + # plugin: has_resp_sequence + json_add_object + json_add_string "tag" "has_resp_sequence" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "qname \$ddnslist" + json_add_string "exec" "\$modify_ddns_ttl" + json_close_object + json_add_object + json_add_string "matches" "!qname \$ddnslist" + json_add_string "exec" "\$modify_ttl" + json_close_object + [ "$cloudflare" -eq 1 ] && { + json_add_object + json_add_string "matches" "resp_ip \$cloudflare_cidr" + json_add_string "exec" "black_hole $cloudflare_ip" + json_close_object + } + json_add_object + json_add_string "matches" "has_resp" + json_add_string "exec" "accept" + json_close_object + json_close_array + json_close_object + # plugin: query_is_non_local_ip + json_add_object + json_add_string "tag" "query_is_non_local_ip" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "exec" "\$forward_local" + json_close_object + json_add_object + json_add_string "matches" "!resp_ip \$geoip_cn" + json_add_string "exec" "drop_resp" + json_close_object + json_close_array + json_close_object + # plugin: fallback + json_add_object + json_add_string "tag" "fallback" + json_add_string "type" "fallback" + json_add_object "args" + [ "$dns_leak" -eq 1 ] && json_add_string "primary" "forward_remote_upstream" || json_add_string "primary" "query_is_non_local_ip" + json_add_string "secondary" "forward_remote_upstream" + json_add_int "threshold" 500 + json_add_boolean "always_standby" 1 + json_close_object + json_close_object + # plugin: apple_domain_fallback + json_add_object + json_add_string "tag" "apple_domain_fallback" + json_add_string "type" "fallback" + json_add_object "args" + json_add_string "primary" "query_is_non_local_ip" + json_add_string "secondary" "forward_xinfeng_udp" + json_add_int "threshold" 100 + json_add_boolean "always_standby" 1 + json_close_object + json_close_object + # plugin: query_is_apple_domain + json_add_object + json_add_string "tag" "query_is_apple_domain" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "!qname \$geosite_apple" + json_add_string "exec" "return" + json_close_object + json_add_object + json_add_string "exec" "\$apple_domain_fallback" + json_close_object + json_close_array + json_close_object + # plugin: query_is_ddns_domain + json_add_object + json_add_string "tag" "query_is_ddns_domain" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "qname \$ddnslist" + json_add_string "exec" "\$forward_local" + json_close_object + json_close_array + json_close_object + # plugin: query_is_local_domain + json_add_object + json_add_string "tag" "query_is_local_domain" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "qname \$geosite_cn" + json_add_string "exec" "\$forward_local" + json_close_object + json_close_array + json_close_object + # plugin: query_is_no_local_domain + json_add_object + json_add_string "tag" "query_is_no_local_domain" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "qname \$geosite_no_cn" + json_add_string "exec" "\$forward_remote_upstream" + json_close_object + json_close_array + json_close_object + # plugin: query_is_whitelist_domain + json_add_object + json_add_string "tag" "query_is_whitelist_domain" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "qname \$whitelist" + json_add_string "exec" "\$forward_local" + json_close_object + json_close_array + json_close_object + # plugin: query_is_greylist_domain + json_add_object + json_add_string "tag" "query_is_greylist_domain" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "qname \$greylist" + json_add_string "exec" "\$forward_remote_upstream" + json_close_object + json_close_array + json_close_object + # plugin: query_is_reject_domain + json_add_object + json_add_string "tag" "query_is_reject_domain" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "qname \$blocklist" + json_add_string "exec" "reject 3" + json_close_object + json_add_object + json_add_string "matches" "qname \$adlist" + json_add_string "exec" "reject 3" + json_close_object + json_add_object + json_add_array "matches" + json_add_string "" "qtype 12" + json_add_string "" "qname \$local_ptr" + json_close_array + json_add_string "exec" "reject 3" + json_close_object + json_add_object + json_add_string "matches" "qtype 65" + json_add_string "exec" "reject 3" + json_close_object + json_close_array + json_close_object + # plugin: query_is_stream_media_domain + json_add_object + json_add_string "tag" "query_is_stream_media_domain" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "matches" "qname \$stream_media" + json_add_string "exec" "\$forward_stream_media_upstream" + json_close_object + json_close_array + json_close_object + # plugin: main_sequence + json_add_object + json_add_string "tag" "main_sequence" + json_add_string "type" "sequence" + json_add_array "args" + json_add_object + json_add_string "exec" "\$hosts" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + [ "$cache" -eq 1 ] && { + json_add_object + json_add_array "matches" + json_add_string "" "!qname \$ddnslist" + json_add_string "" "!qname \$blocklist" + json_add_string "" "!qname \$adlist" + json_add_string "" "!qname \$local_ptr" + json_close_array + json_add_string "exec" "\$lazy_cache" + json_close_object + } + json_add_object + json_add_string "exec" "\$redirect" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + json_add_object + [ "$apple_optimization" -eq 1 ] && { + json_add_string "exec" "\$query_is_apple_domain" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + json_add_object + } + json_add_string "exec" "\$query_is_ddns_domain" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + json_add_object + json_add_string "exec" "\$query_is_whitelist_domain" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + json_add_object + json_add_string "exec" "\$query_is_reject_domain" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + json_add_object + json_add_string "exec" "\$query_is_greylist_domain" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + [ "$custom_stream_media_dns" -eq 1 ] && { + json_add_object + json_add_string "exec" "\$query_is_stream_media_domain" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + } + json_add_object + json_add_string "exec" "\$query_is_local_domain" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + json_add_object + json_add_string "exec" "\$query_is_no_local_domain" + json_close_object + json_add_object + json_add_string "exec" "jump has_resp_sequence" + json_close_object + json_add_object + json_add_string "exec" "\$fallback" + json_close_object + json_close_array + json_close_object + # plugin: udp_server + json_add_object + json_add_string "tag" "udp_server" + json_add_string "type" "udp_server" + json_add_object "args" + json_add_string "entry" "main_sequence" + json_add_string "listen" ":$listen_port" + json_close_object + json_close_object + # plugin: tcp_server + json_add_object + json_add_string "tag" "tcp_server" + json_add_string "type" "tcp_server" + json_add_object "args" + json_add_string "entry" "main_sequence" + json_add_string "listen" ":$listen_port" + json_close_object + json_close_object + # close plugins array + json_close_array + # print json + json_dump > /var/etc/mosdns.json + + # init dump_file [ "$dump_file" -eq 1 ] && [ ! -f $DUMP_FILE ] && cp -a $DUMP_FILE_DEFAULT $DUMP_FILE [ "$dump_file" -eq 0 ] && \cp -a $DUMP_FILE_DEFAULT $DUMP_FILE - # ECS - if [ "$enable_ecs_remote" -eq 1 ]; then - sed -i "s,ecs_remote,ecs\ $remote_ecs_ip,g" $CONF - else - sed -i "/ecs_remote/d;" $CONF - fi - # DNS Leak - if [ $dns_leak -eq 1 ]; then - sed -i "s/primary: UNDEFINED/primary: forward_remote_upstream/g" $CONF - else - sed -i "s/primary: UNDEFINED/primary: query_is_non_local_ip/g" $CONF - fi - # Cloudflare IP - if [ $cloudflare -eq 1 ]; then - cloudflare_ip=$(sh $MOSDNS_SCRIPT cloudflare) - sed -i "s/CLOUDFLARE_IP/$cloudflare_ip/g" $CONF - else - sed -i '/\$cloudflare_cidr\|CLOUDFLARE_IP/d' $CONF - fi - # disable lazy_cache plugin when cache_size is 0 - [ $cache_size -eq 0 ] && sed -i -E ':l;N;/exec: \$lazy_cache/s/(\n[^\n]*){6}$//;bl' $CONF - rm -rf $TMPDIR } service_triggers() { @@ -155,7 +691,7 @@ restore_setting() { } redirect_setting() { - if [ "${CONF}" = "/etc/mosdns/config.yaml" ]; then + if [ "${CONF}" = "/var/etc/mosdns.json" ]; then sed -i "/list server/d" /etc/config/dhcp uci add_list dhcp.@dnsmasq[0].server="127.0.0.1#$listen_port" uci set dhcp.@dnsmasq[0].rebind_protection='0' @@ -203,13 +739,14 @@ start_service() { config_foreach get_config "mosdns" [ $enabled -ne 1 ] && return 1 delcron ; setcron - [ "${CONF}" = "/etc/mosdns/config.yaml" ] && init_yaml :> $($MOSDNS_SCRIPT logfile) if [ "${log_level}" = "error" ] || [ "${log_level}" = "warn" ]; then v2dat_dump > /dev/null 2>&1 else v2dat_dump >> $($MOSDNS_SCRIPT logfile) 2>&1 fi + [ "${CONF}" = "/var/etc/mosdns.json" ] && generate_config + procd_open_instance mosdns procd_set_param env QUIC_GO_DISABLE_RECEIVE_BUFFER_WARNING=true procd_set_param command $PROG start diff --git a/applications/luci-app-mosdns/root/etc/mosdns/rule/streaming.txt b/applications/luci-app-mosdns/root/etc/mosdns/rule/streaming.txt new file mode 100644 index 00000000..e69de29b diff --git a/applications/luci-app-mosdns/root/usr/share/mosdns/default.yaml b/applications/luci-app-mosdns/root/usr/share/mosdns/default.yaml deleted file mode 100644 index a684438d..00000000 --- a/applications/luci-app-mosdns/root/usr/share/mosdns/default.yaml +++ /dev/null @@ -1,259 +0,0 @@ -log: - level: log_level - file: "log_file" - -api: - http: "0.0.0.0:api_port" - -include: [] - -plugins: - - tag: geosite_cn - type: domain_set - args: - files: - - "/var/mosdns/geosite_cn.txt" - - - tag: geoip_cn - type: ip_set - args: - files: - - "/var/mosdns/geoip_cn.txt" - - - tag: geosite_apple - type: domain_set - args: - files: - - "/var/mosdns/geosite_apple.txt" - - - tag: geosite_no_cn - type: domain_set - args: - files: - - "/var/mosdns/geosite_geolocation-!cn.txt" - - - tag: whitelist - type: domain_set - args: - files: - - "/etc/mosdns/rule/whitelist.txt" - - - tag: blocklist - type: domain_set - args: - files: - - "/etc/mosdns/rule/blocklist.txt" - - - tag: greylist - type: domain_set - args: - files: - - "/etc/mosdns/rule/greylist.txt" - - - tag: ddnslist - type: domain_set - args: - files: - - "/etc/mosdns/rule/ddnslist.txt" - - - tag: hosts - type: hosts - args: - files: - - "/etc/mosdns/rule/hosts.txt" - - - tag: redirect - type: redirect - args: - files: - - "/etc/mosdns/rule/redirect.txt" - - - tag: adlist - type: domain_set - args: - files: - ADBLOCK_LIST - - - tag: local_ptr - type: domain_set - args: - files: - - "/etc/mosdns/rule/local-ptr.txt" - - - tag: cloudflare_cidr - type: ip_set - args: - files: - - "/etc/mosdns/rule/cloudflare-cidr.txt" - - - tag: lazy_cache - type: cache - args: - size: cache_size - lazy_cache_ttl: cache_survival_time - - - tag: forward_xinfeng_udp - type: forward - args: - concurrent: 2 - upstreams: - - addr: "114.114.114.114" - - addr: "114.114.115.115" - - - tag: forward_local - type: forward - args: - concurrent: concurrent_num - upstreams: - - addr: local_dns - - - tag: forward_remote - type: forward - args: - concurrent: concurrent_num - upstreams: - - addr: remote_dns - - - tag: forward_remote_upstream - type: sequence - args: - - exec: prefer_ipv4 - - exec: ecs_remote - - exec: $forward_remote - - - tag: modify_ttl - type: sequence - args: - - exec: ttl minimal_ttl_custom-maximum_ttl_custom - - - tag: modify_ddns_ttl - type: sequence - args: - - exec: ttl 5-5 - - - tag: has_resp_sequence - type: sequence - args: - - matches: qname $ddnslist - exec: $modify_ddns_ttl - - matches: "!qname $ddnslist" - exec: $modify_ttl - - matches: "resp_ip $cloudflare_cidr" - exec: black_hole CLOUDFLARE_IP - - matches: has_resp - exec: accept - - - tag: query_is_non_local_ip - type: sequence - args: - - exec: $forward_local - - matches: "!resp_ip $geoip_cn" - exec: drop_resp - - - tag: fallback - type: fallback - args: - primary: UNDEFINED - secondary: forward_remote_upstream - threshold: 500 - always_standby: true - - - tag: apple_domain_fallback - type: fallback - args: - primary: query_is_non_local_ip - secondary: forward_xinfeng_udp - threshold: 100 - always_standby: true - - - tag: query_is_apple_domain - type: sequence - args: - - matches: "!qname $geosite_apple" - exec: return - - exec: $apple_domain_fallback - - - tag: query_is_ddns_domain - type: sequence - args: - - matches: qname $ddnslist - exec: $forward_local - - - tag: query_is_local_domain - type: sequence - args: - - matches: qname $geosite_cn - exec: $forward_local - - - tag: query_is_no_local_domain - type: sequence - args: - - matches: qname $geosite_no_cn - exec: $forward_remote_upstream - - - tag: query_is_whitelist_domain - type: sequence - args: - - matches: qname $whitelist - exec: $forward_local - - - tag: query_is_greylist_domain - type: sequence - args: - - matches: qname $greylist - exec: $forward_remote_upstream - - - tag: query_is_reject_domain - type: sequence - args: - - matches: qname $blocklist - exec: reject 3 - - matches: qname $adlist - exec: reject 3 - - matches: - - qtype 12 - - qname $local_ptr - exec: reject 3 - - matches: qtype 65 - exec: reject 3 - - - tag: main_sequence - type: sequence - args: - - exec: $hosts - - exec: jump has_resp_sequence - - matches: - - "!qname $ddnslist" - - "!qname $blocklist" - - "!qname $adlist" - - "!qname $local_ptr" - exec: $lazy_cache - - exec: $redirect - - exec: jump has_resp_sequence - - exec: $query_is_apple_domain - - exec: jump has_resp_sequence - - exec: $query_is_ddns_domain - - exec: jump has_resp_sequence - - exec: $query_is_whitelist_domain - - exec: jump has_resp_sequence - - exec: $query_is_reject_domain - - exec: jump has_resp_sequence - - exec: $query_is_greylist_domain - - exec: jump has_resp_sequence - - exec: $query_is_local_domain - - exec: jump has_resp_sequence - - exec: $query_is_no_local_domain - - exec: jump has_resp_sequence - - exec: $fallback - - - tag: udp_server - type: udp_server - args: - entry: main_sequence - listen: ":listen_port" - - - tag: tcp_server - type: tcp_server - args: - entry: main_sequence - listen: ":listen_port" diff --git a/applications/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh b/applications/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh index 4e6a5ebe..32eaf55c 100755 --- a/applications/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh +++ b/applications/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh @@ -4,8 +4,8 @@ script_action=${1} logfile_path() ( configfile=$(uci -q get mosdns.config.configfile) - if [ "$configfile" = "/etc/mosdns/config.yaml" ]; then - uci -q get mosdns.config.logfile + if [ "$configfile" = "/var/etc/mosdns.json" ]; then + uci -q get mosdns.config.log_file else [ ! -f /etc/mosdns/config_custom.yaml ] && exit 1 awk '/^log:/{f=1;next}f==1{if($0~/file:/){print;exit}if($0~/^[^ ]/)exit}' /etc/mosdns/config_custom.yaml | grep -Eo "/[^'\"]+" @@ -37,18 +37,18 @@ get_adlist() ( for url in $ad_source; do if [ $(echo $url) = 'geosite.dat' ]; then - echo " - \"/var/mosdns/geosite_category-ads-all.txt\"" + echo "/var/mosdns/geosite_category-ads-all.txt" elif echo "$url" | grep -Eq "^file://" ; then - echo " - \"$(echo "$url" | sed 's/file:\/\///')\"" + echo "$url" | sed 's/file:\/\///' else - echo " - \"/etc/mosdns/rule/adlist/$(basename $url)\"" + echo "/etc/mosdns/rule/adlist/$(basename $url)" [ ! -f "/etc/mosdns/rule/adlist/$(basename $url)" ] && touch /etc/mosdns/rule/adlist/$(basename $url) fi done else rm -rf /etc/mosdns/rule/adlist /etc/mosdns/rule/.ad_source - touch /var/disable-ads.txt - echo " - \"/var/disable-ads.txt\"" + touch /var/mosdns/disable-ads.txt + echo "/var/mosdns/disable-ads.txt" fi ) @@ -56,8 +56,6 @@ adlist_update() { [ "$(uci -q get mosdns.config.adblock)" != 1 ] && return 0 lock_file=/var/lock/mosdns_ad_update.lock ad_source=$(uci -q get mosdns.config.ad_source) - AD_TMPDIR=$(mktemp -d) || exit 1 - mirror="" : > /etc/mosdns/rule/.ad_source if [ -f "$lock_file" ]; then has_update=0 @@ -65,6 +63,7 @@ adlist_update() { else : > $lock_file fi + AD_TMPDIR=$(mktemp -d) || exit 1 has_update=0 for url in $ad_source; do @@ -74,6 +73,8 @@ adlist_update() { filename=$(basename $url) if echo "$url" | grep -Eq "^https://raw.githubusercontent.com" ; then [ -n "$(uci -q get mosdns.config.github_proxy)" ] && mirror="$(uci -q get mosdns.config.github_proxy)/" + else + mirror="" fi echo -e "\e[1;32mDownloading $mirror$url\e[0m" curl --connect-timeout 5 -m 90 --ipv4 -kfSLo "$AD_TMPDIR/$filename" "$mirror$url" @@ -81,7 +82,7 @@ adlist_update() { done if [ $? -ne 0 ]; then echo -e "\e[1;31mRules download failed.\e[0m" - rm -rf "$AD_TMPDIR" + rm -rf "$AD_TMPDIR" "$lock_file" exit 1 else [ $has_update -eq 1 ] && { @@ -90,7 +91,7 @@ adlist_update() { \cp $AD_TMPDIR/* /etc/mosdns/rule/adlist } fi - rm -rf "$AD_TMPDIR" $lock_file + rm -rf "$AD_TMPDIR" "$lock_file" } geodat_update() ( @@ -142,13 +143,16 @@ v2dat_dump() { adblock=$(uci -q get mosdns.config.adblock) ad_source=$(uci -q get mosdns.config.ad_source) configfile=$(uci -q get mosdns.config.configfile) + streaming_media=$(uci -q get mosdns.config.custom_stream_media_dns) mkdir -p /var/mosdns rm -f /var/mosdns/geo*.txt - if [ "$configfile" = "/etc/mosdns/config.yaml" ]; then + if [ "$configfile" = "/var/etc/mosdns.json" ]; then # default config v2dat unpack geoip -o /var/mosdns -f cn $v2dat_dir/geoip.dat v2dat unpack geosite -o /var/mosdns -f cn -f apple -f 'geolocation-!cn' $v2dat_dir/geosite.dat [ "$adblock" -eq 1 ] && [ $(echo $ad_source | grep -c geosite.dat) -ge '1' ] && v2dat unpack geosite -o /var/mosdns -f category-ads-all $v2dat_dir/geosite.dat + [ "$streaming_media" -eq 1 ] && v2dat unpack geosite -o /var/mosdns -f netflix -f disney -f hulu $v2dat_dir/geosite.dat || \ + touch /var/mosdns/geosite_disney.txt ; touch /var/mosdns/geosite_netflix.txt ; touch /var/mosdns/geosite_hulu.txt else # custom config v2dat unpack geoip -o /var/mosdns -f cn $v2dat_dir/geoip.dat @@ -160,10 +164,6 @@ v2dat_dump() { fi } -cloudflare_ip() { - uci -q get mosdns.config.cloudflare_ip -} - case $script_action in "dns") interface_dns @@ -186,9 +186,6 @@ case $script_action in "v2dat_dump") v2dat_dump ;; - "cloudflare") - cloudflare_ip - ;; "version") mosdns version ;;