diff --git a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua index 29b8ebd..380bae3 100644 --- a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua +++ b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua @@ -119,6 +119,11 @@ o.rmempty = false o.default = false o:depends("configfile", "/etc/mosdns/config.yaml") +o = s:taboption("advanced", Flag, "enable_ecs_remote", translate("Enable EDNS client subnet"), translate("Add the EDNS Client Subnet option (ECS) to Remote DNS") .. '
' .. translate("MosDNS will auto identify the IP address subnet segment of your remote connection (.0/24)") .. '
' .. translate("If your remote access network changes, May need restart MosDNS to update the ECS request address")) +o.rmempty = false +o.default = false +o:depends("configfile", "/etc/mosdns/config.yaml") + o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size")) o.datatype = "and(uinteger,min(0))" o.default = "20000" diff --git a/luci-app-mosdns/po/zh-cn/mosdns.po b/luci-app-mosdns/po/zh-cn/mosdns.po index a740022..ffbf944 100644 --- a/luci-app-mosdns/po/zh-cn/mosdns.po +++ b/luci-app-mosdns/po/zh-cn/mosdns.po @@ -176,11 +176,23 @@ msgid "Disable TLS Servers certificate validation, Can be useful if system CA ce msgstr "禁用 TLS 服务器证书验证,当系统 CA 证书过期或系统时间错乱时,本选项可能会有用" msgid "Enable HTTP/3" -msgstr "启用 HTTP3" +msgstr "启用 HTTP/3" msgid "Enable DoH HTTP/3 protocol support for remote DNS, Upstream DNS server support is required (Experimental)" msgstr "为远程 DNS 启用 DoH HTTP/3 协议支持,需要上游 DNS 服务器支持(实验性,谨慎启用该功能)" +msgid "Enable EDNS client subnet" +msgstr "启用 EDNS 客户端子网" + +msgid "Add the EDNS Client Subnet option (ECS) to Remote DNS" +msgstr "在远程 DNS 请求中加入 EDNS 客户端子网(即 ECS)选项(需要上游 DNS 服务器支持)" + +msgid "MosDNS will auto identify the IP address subnet segment of your remote connection (.0/24)" +msgstr "MosDNS 将会自动获取您访问远程连接时使用的 IP 子网段(.0/24)" + +msgid "If your remote access network changes, May need restart MosDNS to update the ECS request address" +msgstr "如果您的远程访问网络发生改变时可能需要重启 MosDNS 以更新 ECS 请求地址" + msgid "DNS Cache Size" msgstr "DNS 缓存大小(条)" diff --git a/luci-app-mosdns/root/etc/init.d/mosdns b/luci-app-mosdns/root/etc/init.d/mosdns index 1dfc1ee..cc2b44f 100755 --- a/luci-app-mosdns/root/etc/init.d/mosdns +++ b/luci-app-mosdns/root/etc/init.d/mosdns @@ -60,6 +60,7 @@ get_config() { config_get insecure_skip_verify $1 insecure_skip_verify 0 config_get idle_timeout $1 idle_timeout 30 config_get enable_http3 $1 enable_http3 0 + config_get enable_ecs_remote $1 enable_ecs_remote 0 } init_yaml() { @@ -87,6 +88,12 @@ init_yaml() { [ "$dump_file" -eq 1 ] && sed -i "/lazy_cache_ttl/a\ dump_file: $DUMP_FILE\n dump_interval: $dump_interval" $CONF [ "$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 + if [ "$enable_ecs_remote" -eq 1 ]; then + ecs_remote=$(sh /usr/share/mosdns/mosdns.sh ecs_remote) + sed -i "s,ecs_remote,$ecs_remote,g" $CONF + else + sed -i "/ecs_remote/d;" $CONF + fi rm -rf $TMPDIR } diff --git a/luci-app-mosdns/root/usr/share/mosdns/default.yaml b/luci-app-mosdns/root/usr/share/mosdns/default.yaml index ee7ef2d..f1cf76b 100644 --- a/luci-app-mosdns/root/usr/share/mosdns/default.yaml +++ b/luci-app-mosdns/root/usr/share/mosdns/default.yaml @@ -108,6 +108,7 @@ plugins: type: sequence args: - exec: prefer_ipv4 + - exec: ecs_remote - exec: $forward_remote - tag: has_resp_sequence diff --git a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh index 8b35883..9fd6fd3 100755 --- a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh +++ b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh @@ -84,6 +84,16 @@ restart_service() { /etc/init.d/mosdns restart } +ecs_local() { + ipaddr=$(curl -s -4 --connect-timeout 2 -H "Host:ip.3322.org" 118.184.169.32) || ipaddr=119.29.0.0 + echo "ecs ${ipaddr%.*}.0/24" +} + +ecs_remote() { + ipaddr=$(curl -s -4 --connect-timeout 2 -H "Host:icanhazip.com" 104.18.114.97) || ipaddr=103.103.65.0 + echo "ecs ${ipaddr%.*}.0/24" +} + case $script_action in "dns") interface_dns @@ -100,6 +110,12 @@ case $script_action in "adlist_update") adlist_update && restart_service ;; + "ecs_local") + ecs_local + ;; + "ecs_remote") + ecs_remote + ;; "version") mosdns version ;;