From f1c401ae97e043e980f16f9ffd6d8b5623f42aeb Mon Sep 17 00:00:00 2001 From: actions Date: Sat, 6 Jan 2024 11:00:14 +0800 Subject: [PATCH] luci-app-passwall2: sync upstream --- luci-app-passwall2/Makefile | 2 +- .../model/cbi/passwall2/client/other.lua | 14 +++++ .../cbi/passwall2/client/shunt_rules.lua | 4 ++ luci-app-passwall2/luasrc/passwall2/api.lua | 23 +++++++ .../luasrc/passwall2/util_sing-box.lua | 61 +++++++++++++------ .../luasrc/passwall2/util_xray.lua | 32 ++++++++-- luci-app-passwall2/po/zh-cn/passwall2.po | 12 ++++ .../root/usr/share/passwall2/subscribe.lua | 23 +------ 8 files changed, 124 insertions(+), 47 deletions(-) diff --git a/luci-app-passwall2/Makefile b/luci-app-passwall2/Makefile index 79b607356..5a28d90d2 100644 --- a/luci-app-passwall2/Makefile +++ b/luci-app-passwall2/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-passwall2 -PKG_VERSION:=1.21-4 +PKG_VERSION:=1.22-1 PKG_RELEASE:= PKG_CONFIG_DEPENDS:= \ diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua index fc2d37388..359abf652 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua @@ -185,6 +185,20 @@ if has_singbox then o.default = "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db" o:value("https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db") o.rmempty = false + + o = s:option(Button, "_remove_resource", translate("Remove resource files")) + o.description = translate("Sing-Box will automatically download resource files when starting, you can use this feature achieve upgrade resource files.") + o.inputstyle = "remove" + function o.write(self, section, value) + local geoip_path = s.fields["geoip_path"] and s.fields["geoip_path"]:formvalue(section) or nil + if geoip_path then + os.remove(geoip_path) + end + local geosite_path = s.fields["geosite_path"] and s.fields["geosite_path"]:formvalue(section) or nil + if geosite_path then + os.remove(geosite_path) + end + end end return m diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/shunt_rules.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/shunt_rules.lua index 3a998a05d..7c1cef804 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/shunt_rules.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/shunt_rules.lua @@ -19,6 +19,10 @@ protocol:value("http") protocol:value("tls") protocol:value("bittorrent") +o = s:option(MultiValue, "inbound", translate("Inbound Tag")) +o:value("tproxy", translate("Transparent proxy")) +o:value("socks", "Socks") + network = s:option(ListValue, "network", translate("Network")) network:value("tcp,udp", "TCP UDP") network:value("tcp", "TCP") diff --git a/luci-app-passwall2/luasrc/passwall2/api.lua b/luci-app-passwall2/luasrc/passwall2/api.lua index b9a6f11d1..6d0afe6e6 100644 --- a/luci-app-passwall2/luasrc/passwall2/api.lua +++ b/luci-app-passwall2/luasrc/passwall2/api.lua @@ -106,6 +106,29 @@ function trim(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end +-- 分割字符串 +function split(full, sep) + if full then + full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0 + local off, result = 1, {} + while true do + local nStart, nEnd = full:find(sep, off) + if not nEnd then + local res = string.sub(full, off, string.len(full)) + if #res > 0 then -- 过滤掉 \0 + table.insert(result, res) + end + break + else + table.insert(result, string.sub(full, off, nStart - 1)) + off = nEnd + 1 + end + end + return result + end + return {} +end + function is_exist(table, value) for index, k in ipairs(table) do if k == value then diff --git a/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua b/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua index 64602abc1..0a5943c90 100644 --- a/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua +++ b/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua @@ -129,19 +129,6 @@ function gen_outbound(flag, node, tag, proxy_table) } end - local mux = nil - if node.mux == "1" then - mux = { - enabled = true, - padding = (node.mux_padding == "1") and true or false, - brutal = { - enabled = (node.tcpbrutal == "1") and true or false, - up_mbps = tonumber(node.tcpbrutal_up_mbps) or 10, - down_mbps = tonumber(node.tcpbrutal_down_mbps) or 50, - }, - } - end - local v2ray_transport = nil if node.transport == "http" then @@ -429,6 +416,19 @@ function gen_config_server(node) } end + local mux = nil + if node.mux == "1" then + mux = { + enabled = true, + padding = (node.mux_padding == "1") and true or false, + brutal = { + enabled = (node.tcpbrutal == "1") and true or false, + up_mbps = tonumber(node.tcpbrutal_up_mbps) or 10, + down_mbps = tonumber(node.tcpbrutal_down_mbps) or 50, + }, + } + end + local v2ray_transport = nil if node.transport == "http" then @@ -1051,8 +1051,29 @@ function gen_config(var) table.insert(protocols, w) end) end + + local inboundTag = nil + if e["inbound"] and e["inbound"] ~= "" then + inboundTag = {} + if e["inbound"]:find("tproxy") then + if redir_port then + if tcp_proxy_way == "tproxy" then + table.insert(inboundTag, "tproxy") + else + table.insert(inboundTag, "redirect_tcp") + table.insert(inboundTag, "tproxy_udp") + end + end + end + if e["inbound"]:find("socks") then + if local_socks_port then + table.insert(inboundTag, "socks-in") + end + end + end local rule = { + inbound = inboundTag, outbound = outboundTag, invert = false, --匹配反选 protocol = protocols @@ -1352,6 +1373,7 @@ function gen_config(var) } if value.outboundTag ~= "block" and value.outboundTag ~= "direct" then dns_rule.server = "remote" + dns_rule.rewrite_ttl = 30 if value.outboundTag ~= "default" and remote_server.address and remote_server.detour ~= "direct" then local remote_dns_server = api.clone(remote_server) remote_dns_server.tag = value.outboundTag @@ -1403,11 +1425,14 @@ function gen_config(var) end if direct_nftset then string.gsub(direct_nftset, '[^' .. "," .. ']+', function(w) - local s = string.reverse(w) - local _, i = string.find(s, "#") - local m = string.len(s) - i + 1 - local n = w:sub(m + 1) - sys.call("nft flush set inet fw4 " .. n .. " 2>/dev/null") + local split = api.split(w, "#") + if #split > 3 then + local ip_type = split[1] + local family = split[2] + local table_name = split[3] + local set_name = split[4] + sys.call(string.format("nft flush set %s %s %s 2>/dev/null", family, table_name, set_name)) + end end) end end diff --git a/luci-app-passwall2/luasrc/passwall2/util_xray.lua b/luci-app-passwall2/luasrc/passwall2/util_xray.lua index ee491edb9..19860434a 100644 --- a/luci-app-passwall2/luasrc/passwall2/util_xray.lua +++ b/luci-app-passwall2/luasrc/passwall2/util_xray.lua @@ -554,6 +554,7 @@ function gen_config(var) if local_socks_port then local inbound = { + tag = "socks-in", listen = local_socks_address, port = tonumber(local_socks_port), protocol = "socks", @@ -874,6 +875,21 @@ function gen_config(var) table.insert(protocols, w) end) end + local inboundTag = nil + if e["inbound"] and e["inbound"] ~= "" then + inboundTag = {} + if e["inbound"]:find("tproxy") then + if redir_port then + table.insert(inboundTag, "tcp_redir") + table.insert(inboundTag, "udp_redir") + end + end + if e["inbound"]:find("socks") then + if local_socks_port then + table.insert(inboundTag, "socks-in") + end + end + end local domains = nil if e.domain_list then domains = {} @@ -912,6 +928,7 @@ function gen_config(var) local rule = { _flag = e.remarks, type = "field", + inboundTag = inboundTag, outboundTag = outboundTag, balancerTag = balancerTag, network = e["network"] or "tcp,udp", @@ -1244,11 +1261,14 @@ function gen_config(var) end if direct_nftset then string.gsub(direct_nftset, '[^' .. "," .. ']+', function(w) - local s = string.reverse(w) - local _, i = string.find(s, "#") - local m = string.len(s) - i + 1 - local n = w:sub(m + 1) - sys.call("nft flush set inet fw4 " .. n .. " 2>/dev/null") + local split = api.split(w, "#") + if #split > 3 then + local ip_type = split[1] + local family = split[2] + local table_name = split[3] + local set_name = split[4] + sys.call(string.format("nft flush set %s %s %s 2>/dev/null", family, table_name, set_name)) + end end) end end @@ -1607,7 +1627,7 @@ function gen_dns_config(var) tag = "dns-in", settings = { address = other_type_dns_server or "1.1.1.1", - port = 53, + port = other_type_dns_port or 53, network = "tcp,udp" } }) diff --git a/luci-app-passwall2/po/zh-cn/passwall2.po b/luci-app-passwall2/po/zh-cn/passwall2.po index 256b890a0..c8a18d36d 100644 --- a/luci-app-passwall2/po/zh-cn/passwall2.po +++ b/luci-app-passwall2/po/zh-cn/passwall2.po @@ -955,6 +955,12 @@ msgstr "配置路由etc/hosts文件,如果你不知道自己在做什么,请 msgid "These had been joined ip addresses will be block. Please input the ip address or ip address segment, every line can input only one ip address." msgstr "加入的IP段将屏蔽。可输入IP地址或地址段,每个地址段一行。" +msgid "Inbound Tag" +msgstr "入站标签" + +msgid "Transparent proxy" +msgstr "透明代理" + msgid "Not valid domain name, please re-enter!" msgstr "不是有效域名,请重新输入!" @@ -1414,6 +1420,12 @@ msgstr "端口跳跃时间 " msgid "Additional ports for hysteria hop" msgstr "端口跳跃额外端口" +msgid "Remove resource files" +msgstr "删除资源文件" + +msgid "Sing-Box will automatically download resource files when starting, you can use this feature achieve upgrade resource files." +msgstr "Sing-Box 会在启动时自动下载资源文件,您可以使用此功能实现升级资源文件。" + msgid "Override the connection destination address" msgstr "覆盖连接目标地址" diff --git a/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua b/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua index 1ff6325f2..3444e6111 100755 --- a/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua +++ b/luci-app-passwall2/root/usr/share/passwall2/subscribe.lua @@ -16,6 +16,7 @@ local datatypes = require "luci.cbi.datatypes" -- so caching them is worth the effort local tinsert = table.insert local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub +local split = api.split local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify local base64Decode = api.base64Decode local uci = luci.model.uci.cursor() @@ -309,28 +310,6 @@ do end end --- 分割字符串 -local function split(full, sep) - if full then - full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0 - local off, result = 1, {} - while true do - local nStart, nEnd = full:find(sep, off) - if not nEnd then - local res = ssub(full, off, slen(full)) - if #res > 0 then -- 过滤掉 \0 - tinsert(result, res) - end - break - else - tinsert(result, ssub(full, off, nStart - 1)) - off = nEnd + 1 - end - end - return result - end - return {} -end -- urlencode -- local function get_urlencode(c) return sformat("%%%02X", sbyte(c)) end