diff --git a/doc/lucky1.png b/doc/lucky1.png new file mode 100644 index 00000000..a5b41b6e Binary files /dev/null and b/doc/lucky1.png differ diff --git a/doc/lucky2.png b/doc/lucky2.png new file mode 100644 index 00000000..ba4c026f Binary files /dev/null and b/doc/lucky2.png differ diff --git a/doc/lucky3.png b/doc/lucky3.png new file mode 100644 index 00000000..6fa7982f Binary files /dev/null and b/doc/lucky3.png differ diff --git a/doc/taskplan1.png b/doc/taskplan1.png deleted file mode 100644 index 1f8db7be..00000000 Binary files a/doc/taskplan1.png and /dev/null differ diff --git a/doc/taskplan2.png b/doc/taskplan2.png deleted file mode 100644 index edb45d6d..00000000 Binary files a/doc/taskplan2.png and /dev/null differ diff --git a/doc/taskplan3.png b/doc/taskplan3.png deleted file mode 100644 index d4794702..00000000 Binary files a/doc/taskplan3.png and /dev/null differ diff --git a/doc/view.png b/doc/view.png deleted file mode 100644 index 169e112f..00000000 Binary files a/doc/view.png and /dev/null differ diff --git a/doc/view2.png b/doc/view2.png deleted file mode 100644 index 9058c632..00000000 Binary files a/doc/view2.png and /dev/null differ diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index 2814d151..aebf24b4 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -346,8 +346,12 @@ function index_status() has_tproxy = (mods:find("TPROXY") or mods:find("nft_tproxy")) and "1" or "0" api.set_cache_var("HAS_TPROXY", has_tproxy) end - e["tcp_status"] = luci.sys.call("/bin/busybox top -bn1 | grep -v 'grep' | grep '%s/bin/' | grep 'default' | grep 'global' >/dev/null" % api.TMP_PATH) == 0 - if has_tproxy == "1" then + local tcp_redir = api.get_cache_var("DEFAULT_TCP_REDIR") + local udp_redir = api.get_cache_var("DEFAULT_UDP_REDIR") + if tcp_redir == "1" then + e["tcp_status"] = luci.sys.call("/bin/busybox top -bn1 | grep -v 'grep' | grep '%s/bin/' | grep 'default' | grep 'global' >/dev/null" % api.TMP_PATH) == 0 + end + if has_tproxy == "1" and udp_redir == "1" then e["udp_status"] = luci.sys.call("/bin/busybox top -bn1 | grep -v -E 'grep|naive' | grep '%s/bin/' | grep 'default' | grep 'global' >/dev/null" % api.TMP_PATH) == 0 end end @@ -962,7 +966,7 @@ function geo_view() return end local function get_rules(str, type) - local rules_id = {} + local rules = {} uci_foreach("shunt_rules", function(s) local list if type == "geoip" then list = s.ip_list else list = s.domain_list end @@ -971,14 +975,18 @@ function geo_view() local prefix, main = line:match("^(.-):(.*)") if not main then main = line end if type == "geoip" and (api.datatypes.ipaddr(str) or api.datatypes.ip6addr(str)) then - if main:find(str, 1, true) then rules_id[#rules_id + 1] = s[".name"] end + if main:find(str, 1, true) then + table.insert(rules, {id = s[".name"], group = s.group or i18n.translate("default")}) + end else - if main == str then rules_id[#rules_id + 1] = s[".name"] end + if main == str then + table.insert(rules, {id = s[".name"], group = s.group or i18n.translate("default")}) + end end end end end) - return rules_id + return rules end local geo_dir = (uci_get("@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") local geosite_path = geo_dir .. "/geosite.dat" @@ -999,11 +1007,17 @@ function geo_view() for line in geo_string:gmatch("([^\n]+)") do lines[#lines + 1] = geo_type .. ":" .. line for _, r in ipairs(get_rules(line, geo_type) or {}) do - if not seen[r] then seen[r] = true; rules[#rules + 1] = r end + if not seen[r.id] then + seen[r.id] = true + rules[#rules + 1] = string.format("[%s]%s", r.group, r.id) + end end end for _, r in ipairs(get_rules(value, geo_type) or {}) do - if not seen[r] then seen[r] = true; rules[#rules + 1] = r end + if not seen[r.id] then + seen[r.id] = true + rules[#rules + 1] = string.format("[%s]%s", r.group, r.id) + end end geo_string = table.concat(lines, "\n") if #rules > 0 then diff --git a/luci-app-passwall/root/usr/share/passwall/iptables.sh b/luci-app-passwall/root/usr/share/passwall/iptables.sh index 57e3e7a6..1fcaf98e 100755 --- a/luci-app-passwall/root/usr/share/passwall/iptables.sh +++ b/luci-app-passwall/root/usr/share/passwall/iptables.sh @@ -325,7 +325,7 @@ load_acl() { continue fi msg="【$remarks】,${msg}" - + ipt_tmp=$ipt_n [ -n "${is_tproxy}" ] && ipt_tmp=$ipt_m @@ -340,7 +340,7 @@ load_acl() { echolog " - ${msg}不代理所有 TCP 端口" fi } - + [ "$udp_no_redir_ports" != "disable" ] && { if ! has_1_65535 "$udp_no_redir_ports"; then [ "$_ipv4" != "1" ] && add_port_rules "$ip6t_m -A PSW $(comment "$remarks") ${_ipt_source} -p udp" $udp_no_redir_ports "-j RETURN" 2>/dev/null @@ -352,7 +352,7 @@ load_acl() { echolog " - ${msg}不代理所有 UDP 端口" fi } - + local dns_redirect [ $(config_n_get @global[0] dns_redirect "1") = "1" ] && dns_redirect=53 if ([ -n "$tcp_port" ] && [ -n "${tcp_proxy_mode}" ]) || ([ -n "$udp_port" ] && [ -n "${udp_proxy_mode}" ]); then @@ -463,7 +463,7 @@ load_acl() { $ip6t_m -A PSW $(comment "$remarks") ${_ipt_source} -m mark --mark 88 -j ACCEPT 2>/dev/null } } - + [ -n "$tcp_port" ] && { if [ -n "${tcp_proxy_mode}" ]; then msg2="${msg}代理 TCP 使用节点[$node_remark]" @@ -475,7 +475,7 @@ load_acl() { msg2="${msg2}(REDIRECT:${tcp_port})" ipt_j="$(REDIRECT $tcp_port)" fi - + [ "$accept_icmp" = "1" ] && { [ "${use_fakedns}" = "1" ] && $ipt_n -A PSW $(comment "$remarks") -p icmp ${_ipt_source} -d $FAKE_IP $(REDIRECT) [ "${use_proxy_list}" = "1" ] && $ipt_n -A PSW $(comment "$remarks") -p icmp ${_ipt_source} $(dst $black_set_name) $(REDIRECT) @@ -484,7 +484,7 @@ load_acl() { [ "${use_shunt_node}" = "1" ] && $ipt_n -A PSW $(comment "$remarks") -p icmp ${_ipt_source} $(dst $shunt_set_name) $(REDIRECT) [ "${tcp_proxy_mode}" != "disable" ] && $ipt_n -A PSW $(comment "$remarks") -p icmp ${_ipt_source} $(REDIRECT) } - + [ "$accept_icmpv6" = "1" ] && [ "$PROXY_IPV6" = "1" ] && [ "$_ipv4" != "1" ] && { [ "${use_fakedns}" = "1" ] && $ip6t_n -A PSW $(comment "$remarks") -p ipv6-icmp ${_ipt_source} -d $FAKE_IP_6 $(REDIRECT) 2>/dev/null [ "${use_proxy_list}" = "1" ] && $ip6t_n -A PSW $(comment "$remarks") -p ipv6-icmp ${_ipt_source} $(dst $black6_set_name) $(REDIRECT) 2>/dev/null @@ -555,11 +555,13 @@ load_acl() { unset tcp_port udp_port node_remark _acl_list use_shunt_node dns_redirect use_fakedns done } - + [ "$ENABLED_DEFAULT_ACL" = 1 ] && [ "$CLIENT_PROXY" = 1 ] && { msg="【默认】," local ipt_tmp=$ipt_n [ -n "${is_tproxy}" ] && ipt_tmp=$ipt_m + local DEFAULT_TCP_REDIR=1 + local DEFAULT_UDP_REDIR=1 [ "$TCP_NO_REDIR_PORTS" != "disable" ] && { add_port_rules "$ip6t_m -A PSW $(comment "默认") -p tcp" $TCP_NO_REDIR_PORTS "-j RETURN" @@ -568,10 +570,11 @@ load_acl() { echolog " - ${msg}不代理 TCP 端口[${TCP_NO_REDIR_PORTS}]" else unset TCP_PROXY_MODE + DEFAULT_TCP_REDIR=0 echolog " - ${msg}不代理所有 TCP 端口" fi } - + [ "$UDP_NO_REDIR_PORTS" != "disable" ] && { add_port_rules "$ip6t_m -A PSW $(comment "默认") -p udp" $UDP_NO_REDIR_PORTS "-j RETURN" add_port_rules "$ipt_m -A PSW $(comment "默认") -p udp" $UDP_NO_REDIR_PORTS "-j RETURN" @@ -579,10 +582,11 @@ load_acl() { echolog " - ${msg}不代理 UDP 端口[${UDP_NO_REDIR_PORTS}]" else unset UDP_PROXY_MODE + DEFAULT_UDP_REDIR=0 echolog " - ${msg}不代理所有 UDP 端口" fi } - + local DNS_REDIRECT [ $(config_n_get @global[0] dns_redirect "1") = "1" ] && DNS_REDIRECT=53 if [ -n "$NODE" ] && ([ -n "${TCP_PROXY_MODE}" ] || [ -n "${UDP_PROXY_MODE}" ]); then @@ -590,7 +594,7 @@ load_acl() { else [ -n "${DIRECT_DNSMASQ_PORT}" ] && DNS_REDIRECT=${DIRECT_DNSMASQ_PORT} fi - + if [ -n "${DNS_REDIRECT}" ]; then $ipt_m -A PSW $(comment "默认") -p udp --dport 53 -j RETURN $ip6t_m -A PSW $(comment "默认") -p udp --dport 53 -j RETURN 2>/dev/null @@ -609,7 +613,7 @@ load_acl() { [ "${USE_BLOCK_LIST}" = "1" ] && $ip6t_m -A PSW $(comment "默认") $(dst $IPSET_BLOCK6) -j MARK --set-mark 88 2>/dev/null [ "${USE_DIRECT_LIST}" = "1" ] && $ip6t_m -A PSW $(comment "默认") $(dst $IPSET_WHITE6) -j RETURN 2>/dev/null } - + [ "$TCP_PROXY_DROP_PORTS" != "disable" ] && { [ "$PROXY_IPV6" = "1" ] && { [ "${USE_FAKEDNS}" = "1" ] && add_port_rules "$ip6t_m -A PSW $(comment "默认") -p tcp" $TCP_PROXY_DROP_PORTS "-d $FAKE_IP_6 -j MARK --set-mark 88" @@ -626,8 +630,11 @@ load_acl() { [ "${USE_SHUNT_NODE}" = "1" ] && add_port_rules "$ipt_m -A PSW $(comment "默认") -p tcp" $TCP_PROXY_DROP_PORTS $(dst $IPSET_SHUNT) "-j MARK --set-mark 88" [ "${TCP_PROXY_MODE}" != "disable" ] && add_port_rules "$ipt_m -A PSW $(comment "默认") -p tcp" $TCP_PROXY_DROP_PORTS "-j MARK --set-mark 88" echolog " - ${msg}屏蔽代理 TCP 端口[${TCP_PROXY_DROP_PORTS}]" + if has_1_65535 "$TCP_PROXY_DROP_PORTS"; then + DEFAULT_TCP_REDIR=0 + fi } - + [ "$UDP_PROXY_DROP_PORTS" != "disable" ] && { [ "$PROXY_IPV6" = "1" ] && { [ "${USE_FAKEDNS}" = "1" ] && add_port_rules "$ip6t_m -A PSW $(comment "默认") -p udp" $UDP_PROXY_DROP_PORTS "-d $FAKE_IP_6 -j MARK --set-mark 88" @@ -644,6 +651,9 @@ load_acl() { [ "${USE_SHUNT_NODE}" = "1" ] && add_port_rules "$ipt_m -A PSW $(comment "默认") -p udp" $UDP_PROXY_DROP_PORTS "$(dst $IPSET_SHUNT) -j MARK --set-mark 88" [ "${UDP_PROXY_MODE}" != "disable" ] && add_port_rules "$ipt_m -A PSW $(comment "默认") -p udp" $UDP_PROXY_DROP_PORTS "-j MARK --set-mark 88" echolog " - ${msg}屏蔽代理 UDP 端口[${UDP_PROXY_DROP_PORTS}]" + if has_1_65535 "$UDP_PROXY_DROP_PORTS"; then + DEFAULT_UDP_REDIR=0 + fi } $ipt_m -A PSW $(comment "默认") -m mark --mark 88 -j ACCEPT 2>/dev/null @@ -652,6 +662,9 @@ load_acl() { } } + set_cache_var "DEFAULT_TCP_REDIR" "$DEFAULT_TCP_REDIR" + set_cache_var "DEFAULT_UDP_REDIR" "$DEFAULT_UDP_REDIR" + # 加载TCP默认代理模式 if [ -n "${TCP_PROXY_MODE}" ]; then [ -n "$NODE" ] && { @@ -667,7 +680,7 @@ load_acl() { msg2="${msg2}(REDIRECT:${REDIR_PORT})" ipt_j="$(REDIRECT $REDIR_PORT)" fi - + [ "$accept_icmp" = "1" ] && { [ "${USE_FAKEDNS}" = "1" ] && $ipt_n -A PSW $(comment "默认") -p icmp -d $FAKE_IP $(REDIRECT) [ "${USE_PROXY_LIST}" = "1" ] && $ipt_n -A PSW $(comment "默认") -p icmp $(dst $IPSET_BLACK) $(REDIRECT) @@ -676,7 +689,7 @@ load_acl() { [ "${USE_SHUNT_NODE}" = "1" ] && $ipt_n -A PSW $(comment "默认") -p icmp $(dst $IPSET_SHUNT) $(REDIRECT) [ "${TCP_PROXY_MODE}" != "disable" ] && $ipt_n -A PSW $(comment "默认") -p icmp $(REDIRECT) } - + [ "$accept_icmpv6" = "1" ] && [ "$PROXY_IPV6" = "1" ] && { [ "${USE_FAKEDNS}" = "1" ] && $ip6t_n -A PSW $(comment "默认") -p ipv6-icmp -d $FAKE_IP_6 $(REDIRECT) [ "${USE_PROXY_LIST}" = "1" ] && $ip6t_n -A PSW $(comment "默认") -p ipv6-icmp $(dst $IPSET_BLACK6) $(REDIRECT) diff --git a/luci-app-passwall/root/usr/share/passwall/nftables.sh b/luci-app-passwall/root/usr/share/passwall/nftables.sh index ff9f7171..3ccb3c3c 100755 --- a/luci-app-passwall/root/usr/share/passwall/nftables.sh +++ b/luci-app-passwall/root/usr/share/passwall/nftables.sh @@ -381,7 +381,7 @@ load_acl() { continue fi msg="【$remarks】,${msg}" - + [ "$tcp_no_redir_ports" != "disable" ] && { if ! has_1_65535 "$tcp_no_redir_ports"; then nft "add rule $NFTABLE_NAME $nft_prerouting_chain ${_ipt_source} ip protocol tcp $(factor $tcp_no_redir_ports "tcp dport") counter return comment \"$remarks\"" @@ -393,7 +393,7 @@ load_acl() { echolog " - ${msg}不代理所有 TCP 端口" fi } - + [ "$udp_no_redir_ports" != "disable" ] && { if ! has_1_65535 "$udp_no_redir_ports"; then nft "add rule $NFTABLE_NAME PSW_MANGLE ip protocol udp ${_ipt_source} $(factor $udp_no_redir_ports "udp dport") counter return comment \"$remarks\"" @@ -484,7 +484,7 @@ load_acl() { [ "${use_block_list}" = "1" ] && nft_rule_dual "PSW_MANGLE_V6" "${_ipt_source} ip6 daddr" "$NFTSET_BLOCK6" "counter reject comment \"$remarks\"" [ "${use_direct_list}" = "1" ] && nft_rule_dual "PSW_MANGLE_V6" "${_ipt_source} ip6 daddr" "$NFTSET_WHITE6" "counter return comment \"$remarks\"" } - + [ "$tcp_proxy_drop_ports" != "disable" ] && { [ "$PROXY_IPV6" = "1" ] && [ "$_ipv4" != "1" ] && { [ "${use_fakedns}" = "1" ] && nft "add rule $NFTABLE_NAME PSW_MANGLE_V6 meta l4proto tcp ${_ipt_source} $(factor $tcp_proxy_drop_ports "tcp dport") ip6 daddr $FAKE_IP_6 counter reject comment \"$remarks\"" 2>/dev/null @@ -502,7 +502,7 @@ load_acl() { [ "${tcp_proxy_mode}" != "disable" ] && nft "add rule $NFTABLE_NAME $nft_prerouting_chain ip protocol tcp ${_ipt_source} $(factor $tcp_proxy_drop_ports "tcp dport") counter reject comment \"$remarks\"" echolog " - ${msg}屏蔽代理 TCP 端口[${tcp_proxy_drop_ports}]" } - + [ "$udp_proxy_drop_ports" != "disable" ] && { [ "$PROXY_IPV6" = "1" ] && [ "$_ipv4" != "1" ] && { [ "${use_fakedns}" = "1" ] && nft "add rule $NFTABLE_NAME PSW_MANGLE_V6 meta l4proto udp ${_ipt_source} $(factor $udp_proxy_drop_ports "udp dport") ip6 daddr $FAKE_IP_6 counter reject comment \"$remarks\"" 2>/dev/null @@ -534,7 +534,7 @@ load_acl() { nft_chain="PSW_NAT" nft_j="$(REDIRECT $tcp_port)" fi - + [ "$accept_icmp" = "1" ] && { [ "${use_direct_list}" = "1" ] && nft_rule_dual "PSW_ICMP_REDIRECT" "ip protocol icmp ${_ipt_source} ip daddr" "$NFTSET_WHITE" "counter return comment \"$remarks\"" [ "${use_fakedns}" = "1" ] && nft "add rule $NFTABLE_NAME PSW_ICMP_REDIRECT ip protocol icmp ${_ipt_source} ip daddr $FAKE_IP $(REDIRECT) comment \"$remarks\"" @@ -620,6 +620,8 @@ load_acl() { } [ "$ENABLED_DEFAULT_ACL" = 1 ] && [ "$CLIENT_PROXY" = 1 ] && { + local DEFAULT_TCP_REDIR=1 + local DEFAULT_UDP_REDIR=1 msg="【默认】," [ "$TCP_NO_REDIR_PORTS" != "disable" ] && { nft "add rule $NFTABLE_NAME $nft_prerouting_chain ip protocol tcp $(factor $TCP_NO_REDIR_PORTS "tcp dport") counter return comment \"默认\"" @@ -628,6 +630,7 @@ load_acl() { echolog " - ${msg}不代理 TCP 端口[${TCP_NO_REDIR_PORTS}]" else unset TCP_PROXY_MODE + DEFAULT_TCP_REDIR=0 echolog " - ${msg}不代理所有 TCP 端口" fi } @@ -639,6 +642,7 @@ load_acl() { echolog " - ${msg}不代理 UDP 端口[${UDP_NO_REDIR_PORTS}]" else unset UDP_PROXY_MODE + DEFAULT_UDP_REDIR=0 echolog " - ${msg}不代理所有 UDP 端口" fi } @@ -689,6 +693,9 @@ load_acl() { [ "${USE_SHUNT_NODE}" = "1" ] && nft_rule_dual "$nft_prerouting_chain" "ip protocol tcp $(factor $TCP_PROXY_DROP_PORTS "tcp dport") ip daddr" "$NFTSET_SHUNT" "counter reject comment \"默认\"" [ "${TCP_PROXY_MODE}" != "disable" ] && nft "add rule $NFTABLE_NAME $nft_prerouting_chain ip protocol tcp $(factor $TCP_PROXY_DROP_PORTS "tcp dport") counter reject comment \"默认\"" echolog " - ${msg}屏蔽代理 TCP 端口[${TCP_PROXY_DROP_PORTS}]" + if has_1_65535 "$TCP_PROXY_DROP_PORTS"; then + DEFAULT_TCP_REDIR=0 + fi } [ "$UDP_PROXY_DROP_PORTS" != "disable" ] && { @@ -707,9 +714,15 @@ load_acl() { [ "${USE_SHUNT_NODE}" = "1" ] && nft_rule_dual "PSW_MANGLE" "ip protocol udp $(factor $UDP_PROXY_DROP_PORTS "udp dport") ip daddr" "$NFTSET_SHUNT" "counter reject comment \"默认\"" [ "${UDP_PROXY_MODE}" != "disable" ] && nft "add rule $NFTABLE_NAME PSW_MANGLE ip protocol udp $(factor $UDP_PROXY_DROP_PORTS "udp dport") counter reject comment \"默认\"" echolog " - ${msg}屏蔽代理 UDP 端口[${UDP_PROXY_DROP_PORTS}]" + if has_1_65535 "$UDP_PROXY_DROP_PORTS"; then + DEFAULT_UDP_REDIR=0 + fi } } + set_cache_var "DEFAULT_TCP_REDIR" "$DEFAULT_TCP_REDIR" + set_cache_var "DEFAULT_UDP_REDIR" "$DEFAULT_UDP_REDIR" + # 加载TCP默认代理模式 if [ -n "${TCP_PROXY_MODE}" ]; then [ -n "$NODE" ] && { @@ -727,7 +740,7 @@ load_acl() { nft_chain="PSW_NAT" nft_j="$(REDIRECT $REDIR_PORT)" fi - + [ "$accept_icmp" = "1" ] && { [ "${USE_DIRECT_LIST}" = "1" ] && nft_rule_dual "PSW_ICMP_REDIRECT" "ip daddr" "$NFTSET_WHITE" "counter return comment \"默认\"" [ "${USE_FAKEDNS}" = "1" ] && nft "add rule $NFTABLE_NAME PSW_ICMP_REDIRECT ip protocol icmp ip daddr $FAKE_IP $(REDIRECT) comment \"默认\""