luci-app-mosdns: local_dns: apply WAN interface all dns addresses

This commit is contained in:
sbwml 2022-08-11 18:16:16 +08:00
parent ea0d472cac
commit e4f5269e68
3 changed files with 14 additions and 11 deletions

View File

@ -31,6 +31,7 @@ inital_conf() {
} }
init_yaml() { init_yaml() {
tmpdir=$(mktemp -d) || exit 1
log_level=$(uci -q get mosdns.mosdns.log_level) log_level=$(uci -q get mosdns.mosdns.log_level)
log_file=$(uci -q get mosdns.mosdns.logfile) log_file=$(uci -q get mosdns.mosdns.logfile)
listen_port=$(uci -q get mosdns.mosdns.listen_port) listen_port=$(uci -q get mosdns.mosdns.listen_port)
@ -38,8 +39,7 @@ init_yaml() {
cache_survival_time=$(uci -q get mosdns.mosdns.cache_survival_time) cache_survival_time=$(uci -q get mosdns.mosdns.cache_survival_time)
minimal_ttl_custom=$(uci -q get mosdns.mosdns.minimal_ttl) minimal_ttl_custom=$(uci -q get mosdns.mosdns.minimal_ttl)
maximum_ttl_custom=$(uci -q get mosdns.mosdns.maximum_ttl) maximum_ttl_custom=$(uci -q get mosdns.mosdns.maximum_ttl)
local_dns1=$(/usr/share/mosdns/mosdns.sh dns 0) local_dns=$(/usr/share/mosdns/mosdns.sh dns | xargs -n1 echo " - addr:")
local_dns2=$(/usr/share/mosdns/mosdns.sh dns 1)
remote_dns1=$(uci -q get mosdns.mosdns.remote_dns1) remote_dns1=$(uci -q get mosdns.mosdns.remote_dns1)
remote_dns2=$(uci -q get mosdns.mosdns.remote_dns2) remote_dns2=$(uci -q get mosdns.mosdns.remote_dns2)
adblock=$(/usr/share/mosdns/mosdns.sh ad) adblock=$(/usr/share/mosdns/mosdns.sh ad)
@ -51,10 +51,13 @@ init_yaml() {
s,cache_survival_time,$cache_survival_time,g; \ s,cache_survival_time,$cache_survival_time,g; \
s,minimal_ttl_custom,$minimal_ttl_custom,g; \ s,minimal_ttl_custom,$minimal_ttl_custom,g; \
s,maximum_ttl_custom,$maximum_ttl_custom,g; \ s,maximum_ttl_custom,$maximum_ttl_custom,g; \
s,local_dns1,$local_dns1,g;s,local_dns2,$local_dns2,g; \
s,remote_dns1,$remote_dns1,g;s,remote_dns2,$remote_dns2,g; \ s,remote_dns1,$remote_dns1,g;s,remote_dns2,$remote_dns2,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 > $(uci -q get mosdns.mosdns.configfile) /usr/share/mosdns/default.yaml > $(uci -q get mosdns.mosdns.configfile)
echo "${local_dns}" > $tmpdir/local_dns.txt
sed -i -e '/- addr: local_dns/{r '$tmpdir/local_dns.txt -e';d}' \
$(uci -q get mosdns.mosdns.configfile)
rm -rf $tmpdir
} }
service_triggers() { service_triggers() {

View File

@ -54,8 +54,7 @@ plugins:
type: fast_forward type: fast_forward
args: args:
upstream: upstream:
- addr: local_dns1 - addr: local_dns
- addr: local_dns2
- tag: "forward_remote" - tag: "forward_remote"
type: fast_forward type: fast_forward

View File

@ -13,12 +13,14 @@ logfile_path() (
interface_dns() ( interface_dns() (
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" -eq 0 ] || [ "$proto" = "static" ]; then if [ "$peerdns" = 0 ] || [ "$proto" = "static" ]; then
ubus call network.interface.wan status | jsonfilter -e "@['dns-server'][$1]" uci -q get network.wan.dns
else else
ubus call network.interface.wan status | jsonfilter -e "@['inactive']['dns-server'][$1]" interface_status=$(ubus call network.interface.wan status)
echo $interface_status | jsonfilter -e "@['dns-server'][0]"
echo $interface_status | jsonfilter -e "@['dns-server'][1]"
fi fi
[ $? -ne 0 ] && echo 119.29.29.29 [ $? -ne 0 ] && echo "119.29.29.29"
) )
ad_block() ( ad_block() (
@ -50,8 +52,7 @@ geodat_update() (
) )
if [ "$1" == "dns" ]; then if [ "$1" == "dns" ]; then
[ -z $2 ] && exit 0 interface_dns
interface_dns $2
elif [ "$1" == "ad" ]; then elif [ "$1" == "ad" ]; then
ad_block ad_block
elif [ "$1" == "geodata" ]; then elif [ "$1" == "geodata" ]; then