luci-app-mosdns: Add dns redirect support for "custom configuration"

This commit is contained in:
sbwml 2022-07-12 04:54:30 +08:00
parent ad77fbee68
commit b783834358
2 changed files with 15 additions and 17 deletions

View File

@ -77,7 +77,6 @@ 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 = s:option(Flag, "redirect", translate("Enable DNS Forward"), translate("Forward Dnsmasq Domain Name resolution requests to MosDNS"))
redirect:depends( "configfile", "/etc/mosdns/config.yaml")
redirect.default = true redirect.default = true
adblock = s:option(Flag, "adblock", translate("Enable DNS ADblock")) adblock = s:option(Flag, "adblock", translate("Enable DNS ADblock"))

View File

@ -42,14 +42,20 @@ restore_setting() {
} }
redirect_setting() { redirect_setting() {
redirect=$(uci -q get mosdns.mosdns.redirect) if [ "${CONF}" = "/etc/mosdns/config.yaml" ]; then
if [ "$redirect" -eq 1 ]; then
sed -i "/list server/d" /etc/config/dhcp sed -i "/list server/d" /etc/config/dhcp
uci add_list dhcp.@dnsmasq[0].server="127.0.0.1#$(uci -q get mosdns.mosdns.listen_port)" uci add_list dhcp.@dnsmasq[0].server="127.0.0.1#$(uci -q get mosdns.mosdns.listen_port)"
uci set dhcp.@dnsmasq[0].rebind_protection='0' uci set dhcp.@dnsmasq[0].rebind_protection='0'
uci set dhcp.@dnsmasq[0].noresolv="1" uci set dhcp.@dnsmasq[0].noresolv="1"
uci set dhcp.@dnsmasq[0].cachesize='0' uci set dhcp.@dnsmasq[0].cachesize='0'
uci commit dhcp uci commit dhcp
else
sed -i "/list server/d" /etc/config/dhcp
uci add_list dhcp.@dnsmasq[0].server="127.0.0.1#$(cat /etc/mosdns/config_custom.yaml | grep -A 4 listeners | grep addr | head -n1 | sed 's/[^0-9]//g')"
uci set dhcp.@dnsmasq[0].rebind_protection='0'
uci set dhcp.@dnsmasq[0].noresolv="1"
uci set dhcp.@dnsmasq[0].cachesize='0'
uci commit dhcp
fi fi
} }
@ -90,22 +96,15 @@ start_service() {
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_close_instance mosdns procd_close_instance mosdns
configfile=$(uci -q get mosdns.mosdns.configfile) restore_setting
if [ "${configfile}" = "/etc/mosdns/config.yaml" ]; then [ "$(uci -q get mosdns.mosdns.redirect)" -eq 1 ] && redirect_setting
restore_setting reload_others
redirect_setting
reload_others
fi
} }
stop_service() { stop_service() {
pgrep -f /usr/bin/mosdns | xargs kill -9 pgrep -f /usr/bin/mosdns | xargs kill -9 >/dev/null 2>&1
configfile=$(uci -q get mosdns.mosdns.configfile) config_load "mosdns"
if [ "${configfile}" = "/etc/mosdns/config.yaml" ]; then [ "$(uci -q get mosdns.mosdns.enabled)" = "0" ] && restore_setting
config_load "mosdns" reload_others
enabled=$(uci -q get mosdns.mosdns.enabled)
[ "${enabled}" = "0" ] && restore_setting
reload_others
fi
delcron delcron
} }