luci-app-mosdns: customize the remote DNS ecs address

* In poor network conditions, obtaining an IP address through curl may fail and cause MOSDNS to fail to start, so replace it with manual filling.

Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
sbwml 2023-10-23 16:36:16 +08:00
parent 329756b8e3
commit 8a427120b7
4 changed files with 13 additions and 16 deletions

View File

@ -121,11 +121,15 @@ o.rmempty = false
o.default = false o.default = false
o:depends("configfile", "/etc/mosdns/config.yaml") 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") .. '<br />' .. translate("MosDNS will auto identify the IP address subnet segment of your remote connection (0/24)") .. '<br />' .. translate("If your remote access network changes, May need restart MosDNS to update the ECS request address")) o = s:taboption("advanced", Flag, "enable_ecs_remote", translate("Enable EDNS client subnet"))
o.rmempty = false o.rmempty = false
o.default = false o.default = false
o:depends("configfile", "/etc/mosdns/config.yaml") o:depends("configfile", "/etc/mosdns/config.yaml")
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") .. '<br />' .. 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.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 = 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.rmempty = false
o.default = false o.default = false

View File

@ -271,14 +271,14 @@ msgstr "禁用 TLS 服务器证书验证,当系统 CA 证书过期或系统时
msgid "Enable EDNS client subnet" msgid "Enable EDNS client subnet"
msgstr "启用 EDNS 客户端子网" msgstr "启用 EDNS 客户端子网"
msgid "Add the EDNS Client Subnet option (ECS) to Remote DNS" msgid "IP Address"
msgstr "在远程 DNS 请求中加入 EDNS 客户端子网(即 ECS选项需要上游 DNS 服务器支持)" msgstr "IP 地址"
msgid "MosDNS will auto identify the IP address subnet segment of your remote connection (0/24)" 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 "MosDNS 将会自动获取您访问远程连接时使用的 IP 子网段0/24" msgstr "请提供您在访问国外网站时使用的 IP 地址,这个 IP 子网0/24将用作远程 DNS 请求的 ECS 地址"
msgid "If your remote access network changes, May need restart MosDNS to update the ECS request address" 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 "如果您的远程访问网络发生改变时可能需要重启 MosDNS 以更新 ECS 请求地址" msgstr "此功能通常在使用自建 DNS 服务器作为 远程 DNS 上游时使用(需要上游服务器的支持)"
msgid "Prevent DNS Leaks" msgid "Prevent DNS Leaks"
msgstr "防止 DNS 泄漏" msgstr "防止 DNS 泄漏"

View File

@ -59,6 +59,7 @@ get_config() {
config_get insecure_skip_verify $1 insecure_skip_verify 0 config_get insecure_skip_verify $1 insecure_skip_verify 0
config_get idle_timeout $1 idle_timeout 30 config_get idle_timeout $1 idle_timeout 30
config_get enable_ecs_remote $1 enable_ecs_remote 0 config_get enable_ecs_remote $1 enable_ecs_remote 0
config_get remote_ecs_ip $1 remote_ecs_ip "110.34.181.1"
config_get dns_leak $1 dns_leak 0 config_get dns_leak $1 dns_leak 0
config_get cloudflare $1 cloudflare 0 config_get cloudflare $1 cloudflare 0
} }
@ -117,7 +118,7 @@ init_yaml() {
[ "$dump_file" -eq 0 ] && \cp -a $DUMP_FILE_DEFAULT $DUMP_FILE [ "$dump_file" -eq 0 ] && \cp -a $DUMP_FILE_DEFAULT $DUMP_FILE
# ECS # ECS
if [ "$enable_ecs_remote" -eq 1 ]; then if [ "$enable_ecs_remote" -eq 1 ]; then
ecs_remote=$(sh $MOSDNS_SCRIPT ecs_remote) ecs_remote=$(echo "ecs ${remote_ecs_ip%.*}.0/24")
sed -i "s,ecs_remote,$ecs_remote,g" $CONF sed -i "s,ecs_remote,$ecs_remote,g" $CONF
else else
sed -i "/ecs_remote/d;" $CONF sed -i "/ecs_remote/d;" $CONF

View File

@ -127,11 +127,6 @@ restart_service() {
/etc/init.d/mosdns restart /etc/init.d/mosdns restart
} }
ecs_remote() {
ipaddr=$(curl -s --user-agent "curl/8.2.1" --connect-timeout 3 -H "Host:v4.ident.me" 49.12.234.183) || ipaddr=110.34.181.1
echo "ecs ${ipaddr%.*}.0/24"
}
flush_cache() { flush_cache() {
curl -s 127.0.0.1:$(uci -q get mosdns.config.listen_port_api)/plugins/lazy_cache/flush || exit 1 curl -s 127.0.0.1:$(uci -q get mosdns.config.listen_port_api)/plugins/lazy_cache/flush || exit 1
} }
@ -180,9 +175,6 @@ case $script_action in
"adlist_update") "adlist_update")
adlist_update && [ "$has_update" -eq 1 ] && restart_service adlist_update && [ "$has_update" -eq 1 ] && restart_service
;; ;;
"ecs_remote")
ecs_remote
;;
"flush") "flush")
flush_cache flush_cache
;; ;;