Skip to content

Commit

Permalink
[luci-app-ssr-plus] Fix mosdns in ssr-monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoliChan committed Nov 7, 2023
1 parent a11a96d commit 3436463
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
43 changes: 23 additions & 20 deletions luci-app-ssr-plus/root/etc/init.d/shadowsocksr
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ tmp_shunt_port="303" #shunt temporary port
tmp_shunt_local_port="304" #shunt socks temporary port
tmp_shunt_dns_port="305" #shunt dns2socks temporary port
tmp_tcp_local_port="306" #tcp socks temporary port
mosdns_config_file=

server_count=0
redir_tcp=0
Expand Down Expand Up @@ -218,70 +219,72 @@ start_dns() {
local mosdns_dnsleak="$(uci_get_by_type global mosdns_dnsleak)"
local netflix_enable="$(uci_get_by_type global netflix_enable)"
if [ "$run_mode" = "router" ] && [ -n "$chinadns_mosdns" ]; then
cp /etc/ssrplus/mosdns-config-chinadns.yaml $TMP_PATH/mosdns-config-chinadns.yaml
mosdns_config_file="$TMP_PATH/mosdns-config-chinadns.yaml"
cp /etc/ssrplus/mosdns-config-chinadns.yaml $mosdns_config_file
tmp=$(for i in $(echo $mosdns_dnsserver | sed "s/,/ /g"); do
dnsserver=${i%:*}
dnsserver=${i##*/}
add_dns_into_ipset $run_mode $dnsserver
yq_ssr '.plugins[4].args.upstreams += [{"addr":"'"${i}"'","enable_pipeline":"true"}]' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins[4].args.upstreams += [{"addr":"'"${i}"'","enable_pipeline":"true"}]' $mosdns_config_file
done)

if [ "$chinadns_mosdns" = "wan" ]; then
wandns=$(ifstatus wan | jsonfilter -e '@["dns-server"]' | sed 's/\[//g; s/\]//g' | sed 's/"//g' | sed 's/ //g' | sed 's/,/ /g')
tmp=$(for i in $(echo $wandns); do
i="udp://$i:53"
yq_ssr '.plugins[5].args.upstreams += [{"addr":"'"${i}"'"}]' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins[5].args.upstreams += [{"addr":"'"${i}"'"}]' $mosdns_config_file
done)
else
tmp=$(for i in $(echo $chinadns_mosdns | sed "s/,/ /g"); do
yq_ssr '.plugins[5].args.upstreams += [{"addr":"'"${i}"'"}]' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins[5].args.upstreams += [{"addr":"'"${i}"'"}]' $mosdns_config_file
done)
fi

if [ "$mosdns_disable_ipv6" == "0" ]; then
yq_ssr '.plugins[10].args[0].exec="$remote_sequence_with_IPv6" | .plugins[12].args[0].exec="$remote_sequence_with_IPv6"' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins[10].args[0].exec="$remote_sequence_with_IPv6" | .plugins[12].args[0].exec="$remote_sequence_with_IPv6"' $mosdns_config_file
else
yq_ssr '.plugins[10].args[0].exec="$remote_sequence_disable_IPv6" | .plugins[12].args[0].exec="$remote_sequence_disable_IPv6"' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins[10].args[0].exec="$remote_sequence_disable_IPv6" | .plugins[12].args[0].exec="$remote_sequence_disable_IPv6"' $mosdns_config_file
fi

if [ "$mosdns_dnsleak" != "0" ]; then
yq_ssr '.plugins[13].args.primary="query_is_remote_ip"' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins[13].args.primary="query_is_remote_ip"' $mosdns_config_file
fi

yq_ssr '.plugins[16].args.listen="0.0.0.0:'${dns_port}'" | .plugins[17].args.listen="0.0.0.0:'${dns_port}'"' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins[16].args.listen="0.0.0.0:'${dns_port}'" | .plugins[17].args.listen="0.0.0.0:'${dns_port}'"' $mosdns_config_file

if [ "$netflix_enable" == 1 ]; then
yq_ssr '.plugins |= (.[:4] + [{"tag": "netflix_domain", "type": "domain_set", "args": {"files": ["/etc/ssrplus/netflix.list"]}}] + .[4:])' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins |= (.[:7] + [{"tag": "forward_netflix", "type": "forward", "args": {"upstreams": [{"addr":"udp://127.0.0.1:'"${tmp_shunt_dns_port}"'"}]}}] + .[7:])' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins |= (.[:11] + [{"tag": "netflix_sequence", "type": "sequence", "args": [{"exec": "$forward_netflix"}]}] + .[11:])' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins |= (.[:14] + [{"tag": "query_is_netflix_domain", "type": "sequence", "args": [{"matches": "qname $netflix_domain", "exec": "$netflix_sequence"}, {"exec": "ipset netflix,inet,24"}]}] + .[14:])' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins[19].args |= (.[:3] + [{"exec": "$query_is_netflix_domain"}, {"exec": "jump has_resp_sequence"}] + .[3:])' $TMP_PATH/mosdns-config-chinadns.yaml
yq_ssr '.plugins |= (.[:4] + [{"tag": "netflix_domain", "type": "domain_set", "args": {"files": ["/etc/ssrplus/netflix.list"]}}] + .[4:])' $mosdns_config_file
yq_ssr '.plugins |= (.[:7] + [{"tag": "forward_netflix", "type": "forward", "args": {"upstreams": [{"addr":"udp://127.0.0.1:'"${tmp_shunt_dns_port}"'"}]}}] + .[7:])' $mosdns_config_file
yq_ssr '.plugins |= (.[:11] + [{"tag": "netflix_sequence", "type": "sequence", "args": [{"exec": "$forward_netflix"}]}] + .[11:])' $mosdns_config_file
yq_ssr '.plugins |= (.[:14] + [{"tag": "query_is_netflix_domain", "type": "sequence", "args": [{"matches": "qname $netflix_domain", "exec": "$netflix_sequence"}, {"exec": "ipset netflix,inet,24"}]}] + .[14:])' $mosdns_config_file
yq_ssr '.plugins[19].args |= (.[:3] + [{"exec": "$query_is_netflix_domain"}, {"exec": "jump has_resp_sequence"}] + .[3:])' $mosdns_config_file
fi

pdnsd_enable_flag=3
ln_start_bin $(first_type mosdns) mosdns start -c $TMP_PATH/mosdns-config-chinadns.yaml
ln_start_bin $(first_type mosdns) mosdns start -c $mosdns_config_file
cat <<-EOF >> "$TMP_DNSMASQ_PATH/chinadns_fixed_server.conf"
no-poll
no-resolv
server=127.0.0.1#$dns_port
EOF
else
cp /etc/ssrplus/mosdns-config.yaml $TMP_PATH/mosdns-config.yaml
mosdns_config_file="$TMP_PATH/mosdns-config.yaml"
cp /etc/ssrplus/mosdns-config.yaml $mosdns_config_file
tmp=$(for i in $(echo $mosdns_dnsserver | sed "s/,/ /g"); do
dnsserver=${i%:*}
dnsserver=${i##*/}
add_dns_into_ipset $run_mode $dnsserver
yq_ssr '.plugins[1].args.upstreams += [{"addr":"'"${i}"'","enable_pipeline":"true"}]' $TMP_PATH/mosdns-config.yaml
yq_ssr '.plugins[1].args.upstreams += [{"addr":"'"${i}"'","enable_pipeline":"true"}]' $mosdns_config_file
done)

if [ "$mosdns_disable_ipv6" == "0" ]; then
yq_ssr '.plugins[4].args.entry="main_sequence_with_IPv6" | .plugins[5].args.entry="main_sequence_with_IPv6"' $TMP_PATH/mosdns-config.yaml
yq_ssr '.plugins[4].args.entry="main_sequence_with_IPv6" | .plugins[5].args.entry="main_sequence_with_IPv6"' $mosdns_config_file
else
yq_ssr '.plugins[4].args.entry="main_sequence_disable_IPv6" | .plugins[5].args.entry="main_sequence_disable_IPv6"' $TMP_PATH/mosdns-config.yaml
yq_ssr '.plugins[4].args.entry="main_sequence_disable_IPv6" | .plugins[5].args.entry="main_sequence_disable_IPv6"' $mosdns_config_file
fi
yq_ssr '.plugins[4].args.listen="0.0.0.0:'${dns_port}'" | .plugins[5].args.listen="0.0.0.0:'${dns_port}'"' $TMP_PATH/mosdns-config.yaml
yq_ssr '.plugins[4].args.listen="0.0.0.0:'${dns_port}'" | .plugins[5].args.listen="0.0.0.0:'${dns_port}'"' $mosdns_config_file
pdnsd_enable_flag=3
ln_start_bin $(first_type mosdns) mosdns start -c $TMP_PATH/mosdns-config.yaml
ln_start_bin $(first_type mosdns) mosdns start -c $mosdns_config_file
fi
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions luci-app-ssr-plus/root/usr/bin/ssr-monitor
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ while [ "1" == "1" ]; do #死循环
logger -t "$NAME" "mosdns tunnel error.restart!"
echolog "mosdns tunnel error.restart!"
dnsserver=$(uci_get_by_type global tunnel_forward 8.8.4.4:53)
kill -9 $(busybox ps -w | grep $TMP_BIN_PATH/mosdns | grep -v grep | awk '{print $1}') >/dev/null 2>&1
ln_start_bin $(first_type mosdns) mosdns start -c /etc/mosdns/config.yaml
kill -9 $(busybox ps -w | grep $TMP_BIN_PATH/mosdns | grep -v grep | grep $mosdns_config_file | awk '{print $1}') >/dev/null 2>&1
ln_start_bin $(first_type mosdns) mosdns start -c $mosdns_config_file
fi
fi
#chinadns-ng
Expand Down

0 comments on commit 3436463

Please sign in to comment.