Browse Source

luci-app-ssr-plus: Fix count `nft rules` .

zxl hhyccc 1 week ago
parent
commit
2046a796e7
1 changed files with 9 additions and 1 deletions
  1. 9 1
      luci-app-ssr-plus/root/etc/init.d/shadowsocksr

+ 9 - 1
luci-app-ssr-plus/root/etc/init.d/shadowsocksr

@@ -1483,7 +1483,15 @@ stop() {
 	unlock
 	set_lock
 	/usr/bin/ssr-rules -f
-	local srulecount=$(iptables -L | grep SSR-SERVER-RULE | wc -l)
+	if command -v nft >/dev/null 2>&1; then
+		# nftables / fw4
+		#local srulecount=$(nft list ruleset 2>/dev/null | grep -c 'SSR-SERVER-RULE')
+		#local srulecount=$(nft list chain inet fw4 SSR-SERVER-RULE 2>/dev/null | grep -c 'dport')
+		local srulecount=$(nft list chain inet fw4 SSR-SERVER-RULE | grep -vE '^\s*(chain|{|})' | wc -l)
+	else
+		# iptables / fw3
+		local srulecount=$(iptables -L | grep SSR-SERVER-RULE | wc -l)
+	fi
 	if [ $srulecount -gt 0 ]; then
 		if command -v nft >/dev/null 2>&1; then
 			# nftables / fw4