Skip to content

Commit bf72025

Browse files
author
zxlhhyccc
committed
luci-app-ssr-plus: Do not generate gfw list when mode is not gfw.
1 parent 1997773 commit bf72025

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

luci-app-ssr-plus/root/usr/share/shadowsocksr/gfw2ipset.sh

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ if command -v nft >/dev/null 2>&1; then
77
fi
88

99
netflix() {
10-
if [ -f "$TMP_DNSMASQ_PATH/gfw_list.conf" ] && [ -s /etc/ssrplus/netflix.list ]; then
10+
local port="$1"
11+
if [ "$run_mode" = "gfw" ] && [ -f "$TMP_DNSMASQ_PATH/gfw_list.conf" ] && [ -s /etc/ssrplus/netflix.list ]; then
1112
grep -vE '^\s*#|^\s*$' /etc/ssrplus/netflix.list > /tmp/ssrplus_netflix.list.clean
1213
if [ -s /tmp/ssrplus_netflix.list.clean ]; then
1314
grep -v -F -f /tmp/ssrplus_netflix.list.clean "$TMP_DNSMASQ_PATH/gfw_list.conf" > "$TMP_DNSMASQ_PATH/gfw_list.conf.tmp"
@@ -21,24 +22,45 @@ netflix() {
2122
fi
2223
if [ "$nft_support" = "1" ]; then
2324
# 移除 ipset
24-
cat /etc/ssrplus/netflix.list | sed '/^$/d' | sed '/#/d' | sed "/.*/s/.*/server=\/&\/127.0.0.1#$1\nnftset=\/&\/inet#ss_spec#netflix/" >$TMP_DNSMASQ_PATH/netflix_forward.conf
25+
cat /etc/ssrplus/netflix.list | sed '/^$/d' | sed '/#/d' | sed "/.*/s/.*/server=\/&\/127.0.0.1#$port\nnftset=\/&\/inet#ss_spec#netflix/" >$TMP_DNSMASQ_PATH/netflix_forward.conf
2526
else
26-
cat /etc/ssrplus/netflix.list | sed '/^$/d' | sed '/#/d' | sed "/.*/s/.*/server=\/&\/127.0.0.1#$1\nipset=\/&\/netflix/" >$TMP_DNSMASQ_PATH/netflix_forward.conf
27+
cat /etc/ssrplus/netflix.list | sed '/^$/d' | sed '/#/d' | sed "/.*/s/.*/server=\/&\/127.0.0.1#$port\nipset=\/&\/netflix/" >$TMP_DNSMASQ_PATH/netflix_forward.conf
2728
fi
2829
}
2930
mkdir -p $TMP_DNSMASQ_PATH
30-
if [ "$(uci_get_by_type global run_mode router)" == "oversea" ]; then
31+
32+
run_mode=$(uci_get_by_type global run_mode router)
33+
34+
if [ "$run_mode" = "oversea" ]; then
3135
cp -rf /etc/ssrplus/oversea_list.conf $TMP_DNSMASQ_PATH/
32-
else
36+
elif [ "$run_mode" = "gfw" ]; then
3337
cp -rf /etc/ssrplus/gfw_list.conf $TMP_DNSMASQ_PATH/
3438
cp -rf /etc/ssrplus/gfw_base.conf $TMP_DNSMASQ_PATH/
35-
fi
3639

37-
if [ "$nft_support" = "1" ]; then
38-
# 移除 ipset 指令
39-
for conf_file in gfw_base.conf gfw_list.conf; do
40-
if [ -f "$TMP_DNSMASQ_PATH/$conf_file" ]; then
41-
sed -i 's|ipset=/\([^/]*\)/\([^[:space:]]*\)|nftset=/\1/inet#ss_spec#\2|g' "$TMP_DNSMASQ_PATH/$conf_file"
40+
if [ "$nft_support" = "1" ]; then
41+
# 移除 ipset
42+
for conf_file in gfw_base.conf gfw_list.conf; do
43+
if [ -f "$TMP_DNSMASQ_PATH/$conf_file" ]; then
44+
sed -i 's|ipset=/\([^/]*\)/\([^[:space:]]*\)|nftset=/\1/inet#ss_spec#\2|g' "$TMP_DNSMASQ_PATH/$conf_file"
45+
fi
46+
done
47+
fi
48+
49+
# 仅在 gfw 模式下才需要从 gfw 列表中移除黑名单/白名单/拒绝列表的域名
50+
# 此处使用 for 方式读取 防止 /etc/ssrplus/ 目录下的 black.list white.list deny.list 等2个或多个文件一行中存在空格 比如:# abc.com 而丢失:server
51+
# Optimize: Batch filter using grep
52+
for list_file in /etc/ssrplus/black.list /etc/ssrplus/white.list /etc/ssrplus/deny.list; do
53+
if [ -s "$list_file" ]; then
54+
grep -vE '^\s*#|^\s*$' "$list_file" > "${list_file}.clean"
55+
if [ -s "${list_file}.clean" ]; then
56+
for target_file in "$TMP_DNSMASQ_PATH/gfw_list.conf" "$TMP_DNSMASQ_PATH/gfw_base.conf"; do
57+
if [ -f "$target_file" ]; then
58+
grep -v -F -f "${list_file}.clean" "$target_file" > "${target_file}.tmp"
59+
mv "${target_file}.tmp" "$target_file"
60+
fi
61+
done
62+
fi
63+
rm -f "${list_file}.clean"
4264
fi
4365
done
4466
fi
@@ -62,23 +84,6 @@ $(uci_get_by_type global global_server nil) | $switch_server | same)
6284
;;
6385
esac
6486

65-
# 此处使用while方式读取 防止 /etc/ssrplus/ 目录下的 black.list white.list deny.list 等2个或多个文件一行中存在空格 比如:# abc.com 而丢失:server
66-
# Optimize: Batch filter using grep
67-
for list_file in /etc/ssrplus/black.list /etc/ssrplus/white.list /etc/ssrplus/deny.list; do
68-
if [ -s "$list_file" ]; then
69-
grep -vE '^\s*#|^\s*$' "$list_file" > "${list_file}.clean"
70-
if [ -s "${list_file}.clean" ]; then
71-
for target_file in "$TMP_DNSMASQ_PATH/gfw_list.conf" "$TMP_DNSMASQ_PATH/gfw_base.conf"; do
72-
if [ -f "$target_file" ]; then
73-
grep -v -F -f "${list_file}.clean" "$target_file" > "${target_file}.tmp"
74-
mv "${target_file}.tmp" "$target_file"
75-
fi
76-
done
77-
fi
78-
rm -f "${list_file}.clean"
79-
fi
80-
done
81-
8287
# 此处直接使用 cat 因为有 sed '/#/d' 删除了 数据
8388
if [ "$nft_support" = "1" ]; then
8489
cat /etc/ssrplus/black.list | sed '/^$/d' | sed '/#/d' | sed "/.*/s/.*/server=\/&\/127.0.0.1#$dns_port\nnftset=\/&\/inet#ss_spec#blacklist/" >$TMP_DNSMASQ_PATH/blacklist_forward.conf

0 commit comments

Comments
 (0)