From e5ca4ee15d48227962e3b53a6cdd4ab8a196524f Mon Sep 17 00:00:00 2001 From: actions Date: Mon, 29 Jan 2024 03:30:11 +0800 Subject: [PATCH] luci-app-passwall2: sync upstream --- luci-app-passwall2/Makefile | 2 +- .../luasrc/controller/passwall2.lua | 7 +- .../model/cbi/passwall2/client/acl_config.lua | 8 + .../model/cbi/passwall2/client/haproxy.lua | 4 +- .../model/cbi/passwall2/client/node_list.lua | 41 +++- .../model/cbi/passwall2/client/other.lua | 8 + .../model/cbi/passwall2/client/type/ray.lua | 2 +- .../cbi/passwall2/client/type/sing-box.lua | 2 +- .../model/cbi/passwall2/server/type/ray.lua | 2 +- luci-app-passwall2/luasrc/passwall2/api.lua | 4 +- .../passwall2/node_list/link_add_node.htm | 2 + .../passwall2/node_list/link_share_man.htm | 103 ++++----- .../view/passwall2/node_list/node_list.htm | 207 +++++++----------- luci-app-passwall2/po/zh-cn/passwall2.po | 24 +- .../root/usr/share/passwall2/0_default_config | 3 +- 15 files changed, 207 insertions(+), 212 deletions(-) diff --git a/luci-app-passwall2/Makefile b/luci-app-passwall2/Makefile index 3d19ccbca..5756f07f6 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.24-1 +PKG_VERSION:=1.25-1 PKG_RELEASE:= PKG_CONFIG_DEPENDS:= \ diff --git a/luci-app-passwall2/luasrc/controller/passwall2.lua b/luci-app-passwall2/luasrc/controller/passwall2.lua index 2ccc17ce7..d70acd54e 100644 --- a/luci-app-passwall2/luasrc/controller/passwall2.lua +++ b/luci-app-passwall2/luasrc/controller/passwall2.lua @@ -226,16 +226,15 @@ function ping_node() local index = luci.http.formvalue("index") local address = luci.http.formvalue("address") local port = luci.http.formvalue("port") + local type = luci.http.formvalue("type") or "icmp" local e = {} e.index = index - local nodes_ping = ucic:get(appname, "@global_other[0]", "nodes_ping") or "" - if nodes_ping:find("tcping") and luci.sys.exec("echo -n $(command -v tcping)") ~= "" then + if type == "tcping" and luci.sys.exec("echo -n $(command -v tcping)") ~= "" then if api.is_ipv6(address) then address = api.get_ipv6_only(address) end e.ping = luci.sys.exec(string.format("echo -n $(tcping -q -c 1 -i 1 -t 2 -p %s %s 2>&1 | grep -o 'time=[0-9]*' | awk -F '=' '{print $2}') 2>/dev/null", port, address)) - end - if e.ping == nil or tonumber(e.ping) == 0 then + else e.ping = luci.sys.exec("echo -n $(ping -c 1 -W 1 %q 2>&1 | grep -o 'time=[0-9]*' | awk -F '=' '{print $2}') 2>/dev/null" % address) end luci.http.prepare_content("application/json") diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua index e6b3c9798..d605ce27f 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua @@ -2,6 +2,10 @@ local api = require "luci.passwall2.api" local appname = api.appname local sys = api.sys +local port_validate = function(self, value, t) + return value:gsub("-", ":") +end + m = Map(appname) api.set_apply_on_parse(m) @@ -157,6 +161,7 @@ o.default = "default" o:value("disable", translate("No patterns are used")) o:value("default", translate("Default")) o:value("1:65535", translate("All")) +o.validate = port_validate ---- UDP No Redir Ports o = s:option(Value, "udp_no_redir_ports", translate("UDP No Redir Ports"), @@ -167,6 +172,7 @@ o.default = "default" o:value("disable", translate("No patterns are used")) o:value("default", translate("Default")) o:value("1:65535", translate("All")) +o.validate = port_validate ---- TCP Redir Ports o = s:option(Value, "tcp_redir_ports", translate("TCP Redir Ports")) @@ -175,12 +181,14 @@ o:value("default", translate("Default")) o:value("1:65535", translate("All")) o:value("22,25,53,143,465,587,853,993,995,80,443", translate("Common Use")) o:value("80,443", "80,443") +o.validate = port_validate ---- UDP Redir Ports o = s:option(Value, "udp_redir_ports", translate("UDP Redir Ports")) o.default = "default" o:value("default", translate("Default")) o:value("1:65535", translate("All")) +o.validate = port_validate node = s:option(ListValue, "node", "" .. translate("Node") .. "") node.default = "default" diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua index ad5082d62..65192afdb 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/haproxy.lua @@ -50,7 +50,7 @@ o:depends("balancing_enable", true) o = s:option(ListValue, "health_check_type", translate("Health Check Type")) o.default = "passwall_logic" o:value("tcp", "TCP") -o:value("passwall_logic", translate("Availability test") .. string.format("(passwall %s)", translate("Inner implement"))) +o:value("passwall_logic", translate("URL Test") .. string.format("(passwall %s)", translate("Inner implement"))) o:depends("balancing_enable", true) ---- Health Check Inter @@ -61,7 +61,7 @@ o:depends("balancing_enable", true) o = s:option(DummyValue, "health_check_tips", " ") o.rawhtml = true o.cfgvalue = function(t, n) - return string.format('%s', translate("When the availability test is used, the load balancing node will be converted into a Socks node. when node list set customizing, must be a Socks node, otherwise the health check will be invalid.")) + return string.format('%s', translate("When the URL test is used, the load balancing node will be converted into a Socks node. when node list set customizing, must be a Socks node, otherwise the health check will be invalid.")) end o:depends("health_check_type", "passwall_logic") diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_list.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_list.lua index 9dab90f17..647dd28b8 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_list.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/node_list.lua @@ -10,15 +10,19 @@ api.set_apply_on_parse(m) s = m:section(TypedSection, "global_other") s.anonymous = true -o = s:option(MultiValue, "nodes_ping", " ") -o:value("auto_ping", translate("Auto Ping"), translate("This will automatically ping the node for latency")) -o:value("tcping", translate("Tcping"), translate("This will use tcping replace ping detection of node")) -o:value("info", translate("Show server address and port"), translate("Show server address and port")) +o = s:option(ListValue, "auto_detection_time", translate("Automatic detection delay")) +o:value("0", translate("Close")) +o:value("icmp", "Ping") +o:value("tcping", "TCP Ping") + +o = s:option(Flag, "show_node_info", translate("Show server address and port")) +o.default = "0" -- [[ Add the node via the link ]]-- s:append(Template(appname .. "/node_list/link_add_node")) -local nodes_ping = m:get("@global_other[0]", "nodes_ping") or "" +local auto_detection_time = m:get("@global_other[0]", "auto_detection_time") or "0" +local show_node_info = m:get("@global_other[0]", "show_node_info") or "0" -- [[ Node List ]]-- s = m:section(TypedSection, "nodes") @@ -103,7 +107,7 @@ o.cfgvalue = function(t, n) local port = m:get(n, "port") or "" str = str .. translate(type) .. ":" .. remarks if address ~= "" and port ~= "" then - if nodes_ping:find("info") then + if show_node_info == "1" then if datatypes.ip6addr(address) then str = str .. string.format("([%s]:%s)", address, port) else @@ -117,23 +121,38 @@ o.cfgvalue = function(t, n) end ---- Ping -o = s:option(DummyValue, "ping") +o = s:option(DummyValue, "ping", "Ping") o.width = "8%" o.rawhtml = true o.cfgvalue = function(t, n) local result = "---" - if not nodes_ping:find("auto_ping") then - result = string.format('Ping', n) + if auto_detection_time ~= "icmp" then + result = string.format('%s', n, translate("Test")) else result = string.format('---', n) end return result end -o = s:option(DummyValue, "_url_test") +---- TCP Ping +o = s:option(DummyValue, "tcping", "TCPing") +o.width = "8%" o.rawhtml = true o.cfgvalue = function(t, n) - return string.format('%s', n, translate("Test")) + else + result = string.format('---', n) + end + return result +end + +o = s:option(DummyValue, "_url_test", translate("URL Test")) +o.width = "8%" +o.rawhtml = true +o.cfgvalue = function(t, n) + return string.format('%s', n, translate("Test")) end m:append(Template(appname .. "/node_list/node_list")) 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 359abf652..275380518 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/other.lua @@ -7,6 +7,10 @@ local has_xray = api.finded_com("xray") local has_fw3 = api.is_finded("fw3") local has_fw4 = api.is_finded("fw4") +local port_validate = function(self, value, t) + return value:gsub("-", ":") +end + m = Map(appname) api.set_apply_on_parse(m) @@ -63,6 +67,7 @@ o = s:option(Value, "tcp_no_redir_ports", translate("TCP No Redir Ports")) o.default = "disable" o:value("disable", translate("No patterns are used")) o:value("1:65535", translate("All")) +o.validate = port_validate ---- UDP No Redir Ports o = s:option(Value, "udp_no_redir_ports", translate("UDP No Redir Ports"), @@ -72,6 +77,7 @@ o = s:option(Value, "udp_no_redir_ports", translate("UDP No Redir Ports"), o.default = "disable" o:value("disable", translate("No patterns are used")) o:value("1:65535", translate("All")) +o.validate = port_validate ---- TCP Redir Ports o = s:option(Value, "tcp_redir_ports", translate("TCP Redir Ports")) @@ -79,11 +85,13 @@ o.default = "22,25,53,143,465,587,853,993,995,80,443" o:value("1:65535", translate("All")) o:value("22,25,53,143,465,587,853,993,995,80,443", translate("Common Use")) o:value("80,443", translate("Only Web")) +o.validate = port_validate ---- UDP Redir Ports o = s:option(Value, "udp_redir_ports", translate("UDP Redir Ports")) o.default = "1:65535" o:value("1:65535", translate("All")) +o.validate = port_validate ---- Use nftables o = s:option(ListValue, "use_nft", translate("Firewall tools")) diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/ray.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/ray.lua index 27abc9a71..19c239a5a 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/ray.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/ray.lua @@ -41,7 +41,7 @@ o:value("trojan", translate("Trojan")) o:value("wireguard", translate("WireGuard")) o:value("_balancing", translate("Balancing")) o:value("_shunt", translate("Shunt")) -o:value("_iface", translate("Custom Interface") .. " (Only Support Xray)") +o:value("_iface", translate("Custom Interface")) o = s:option(Value, option_name("iface"), translate("Interface")) o.default = "eth1" diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/sing-box.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/sing-box.lua index 662a6c49c..cf8a0a4c1 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/sing-box.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/sing-box.lua @@ -58,7 +58,7 @@ if singbox_tags:find("with_quic") then o:value("hysteria2", "Hysteria2") end o:value("_shunt", translate("Shunt")) -o:value("_iface", translate("Custom Interface") .. " (Only Support Xray)") +o:value("_iface", translate("Custom Interface")) o = s:option(Value, option_name("iface"), translate("Interface")) o.default = "eth1" diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua index 033b01227..825132369 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/ray.lua @@ -345,7 +345,7 @@ o = s:option(ListValue, option_name("outbound_node"), translate("outbound node") o:value("nil", translate("Close")) o:value("_socks", translate("Custom Socks")) o:value("_http", translate("Custom HTTP")) -o:value("_iface", translate("Custom Interface") .. " (Only Support Xray)") +o:value("_iface", translate("Custom Interface")) for k, v in pairs(nodes_table) do o:value(v.id, v.remarks) end o.default = "nil" diff --git a/luci-app-passwall2/luasrc/passwall2/api.lua b/luci-app-passwall2/luasrc/passwall2/api.lua index 6d0afe6e6..5f0da5c3d 100644 --- a/luci-app-passwall2/luasrc/passwall2/api.lua +++ b/luci-app-passwall2/luasrc/passwall2/api.lua @@ -292,7 +292,7 @@ function get_domain_from_url(url) end function get_valid_nodes() - local nodes_ping = uci_get_type("global_other", "nodes_ping") or "" + local show_node_info = uci_get_type("global_other", "show_node_info") or "0" local nodes = {} uci:foreach(appname, "nodes", function(e) e.id = e[".name"] @@ -319,7 +319,7 @@ function get_valid_nodes() end if is_ipv6(address) then address = get_ipv6_full(address) end e["remark"] = "%s:[%s]" % {type, e.remarks} - if nodes_ping:find("info") then + if show_node_info == "1" then e["remark"] = "%s:[%s] %s:%s" % {type, e.remarks, address, e.port} end e.node_type = "normal" diff --git a/luci-app-passwall2/luasrc/view/passwall2/node_list/link_add_node.htm b/luci-app-passwall2/luasrc/view/passwall2/node_list/link_add_node.htm index c981748bd..6a1bec7e7 100644 --- a/luci-app-passwall2/luasrc/view/passwall2/node_list/link_add_node.htm +++ b/luci-app-passwall2/luasrc/view/passwall2/node_list/link_add_node.htm @@ -103,6 +103,8 @@ local api = require "luci.passwall2.api" + +
\ No newline at end of file diff --git a/luci-app-passwall2/luasrc/view/passwall2/node_list/link_share_man.htm b/luci-app-passwall2/luasrc/view/passwall2/node_list/link_share_man.htm index 341ec9697..e6e8b51c2 100644 --- a/luci-app-passwall2/luasrc/view/passwall2/node_list/link_share_man.htm +++ b/luci-app-passwall2/luasrc/view/passwall2/node_list/link_share_man.htm @@ -162,9 +162,10 @@ local api = require "luci.passwall2.api" } } var url = null; - if (v_type === "SS") { + if (v_type === "SS" || v_type === "SS-Rust" || ((v_type === "sing-box" || v_type === "Xray") && opt.get(dom_prefix + "protocol").value === "shadowsocks")) { + protocol = "ss" var v_port = opt.get(dom_prefix + "port"); - var v_method = opt.get(dom_prefix + "method"); + var v_method = opt.get(dom_prefix + "method") || opt.get(dom_prefix + "ss_method"); var v_password = opt.get(dom_prefix + "password"); url = b64encsafe(v_method.value + ":" + v_password.value) + "@" + @@ -172,43 +173,19 @@ local api = require "luci.passwall2.api" v_port.value + "/?"; var params = ""; - var v_plugin = opt.get(dom_prefix + "plugin").value; - if (v_plugin && v_plugin != "none") { - if (v_plugin == "simple-obfs" || v_plugin == "obfs-local") { - v_plugin = "obfs-local"; + var v_plugin_dom = opt.get(dom_prefix + "plugin"); + if (v_plugin_dom) { + var v_plugin = v_plugin_dom.value; + if (v_plugin && v_plugin != "none") { + if (v_plugin == "simple-obfs" || v_plugin == "obfs-local") { + v_plugin = "obfs-local"; + } + var v_plugin_opts = opt.get(dom_prefix + "plugin_opts").value; + if (v_plugin_opts && v_plugin_opts != "") { + v_plugin += ";" + v_plugin_opts; + } + params += "&plugin=" + encodeURIComponent(v_plugin); } - var v_plugin_opts = opt.get(dom_prefix + "plugin_opts").value; - if (v_plugin_opts && v_plugin_opts != "") { - v_plugin += ";" + v_plugin_opts; - } - params += "&plugin=" + encodeURIComponent(v_plugin); - } - params += "&group=" - params += "#" + encodeURIComponent(v_alias.value); - if (params[0] == "&") { - params = params.substring(1); - } - url += params; - } else if (v_type === "SS-Rust") { - var v_port = opt.get(dom_prefix + "port"); - var v_method = opt.get(dom_prefix + "method"); - var v_password = opt.get(dom_prefix + "password"); - - url = btoa(v_method.value + ":" + v_password.value) + "@" + - _address + ":" + - v_port.value + "/?"; - - var params = ""; - var v_plugin = opt.get(dom_prefix + "plugin").value; - if (v_plugin && v_plugin != "none") { - if (v_plugin == "simple-obfs" || v_plugin == "obfs-local") { - v_plugin = "obfs-local"; - } - var v_plugin_opts = opt.get(dom_prefix + "plugin_opts").value; - if (v_plugin_opts && v_plugin_opts != "") { - v_plugin += ";" + v_plugin_opts; - } - params += "&plugin=" + encodeURIComponent(v_plugin); } params += "&group=" params += "#" + encodeURIComponent(v_alias.value); @@ -600,11 +577,22 @@ local api = require "luci.passwall2.api" method = userInfo.substr(0, userInfoSplitIndex); password = userInfo.substr(userInfoSplitIndex + 1); } - if (["2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305"].includes(method)) { - opt.set('type', "SS-Rust"); - dom_prefix = "ssrust_" + if (has_singbox) { + dom_prefix = "singbox_" + opt.set('type', "sing-box"); + opt.set(dom_prefix + 'protocol', "shadowsocks"); + } else if (has_xray) { + dom_prefix = "xray_" + opt.set('type', "Xray"); + opt.set(dom_prefix + 'protocol', "shadowsocks"); } else { - opt.set('type', "SS"); + if (["2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305"].includes(method)) { + dom_prefix = "ssrust_" + opt.set('type', "SS-Rust"); + } else { + dom_prefix = "ss_" + opt.set('type', "SS"); + } } opt.set(dom_prefix + 'address', server); opt.set(dom_prefix + 'port', port); @@ -620,9 +608,22 @@ local api = require "luci.passwall2.api" } else { var sstr = b64decsafe(url0); var team = sstr.split('@'); - opt.set('type', "SS"); var part1 = team[0].split(':'); var part2 = team[1].split(':'); + + if (has_singbox) { + dom_prefix = "singbox_" + opt.set('type', "sing-box"); + opt.set(dom_prefix + 'protocol', "shadowsocks"); + } else if (has_xray) { + dom_prefix = "xray_" + opt.set('type', "Xray"); + opt.set(dom_prefix + 'protocol', "shadowsocks"); + } else { + dom_prefix = "ss_" + opt.set('type', "SS"); + } + opt.set(dom_prefix + 'address', part2[0]); opt.set(dom_prefix + 'port', part2[1]); opt.set(dom_prefix + 'password', part1[1]); @@ -653,17 +654,17 @@ local api = require "luci.passwall2.api" } } if (has_singbox) { - opt.set('type', "sing-box"); dom_prefix = "singbox_" + opt.set('type', "sing-box"); } else if (has_xray) { - opt.set('type', "Xray"); dom_prefix = "xray_" + opt.set('type', "Xray"); } opt.set(dom_prefix + 'protocol', "trojan"); opt.set(dom_prefix + 'address', m.hostname); opt.set(dom_prefix + 'port', m.port || "443"); opt.set(dom_prefix + 'password', decodeURIComponent(password)); - opt.set(dom_prefix + 'tls', true); + opt.set(dom_prefix + 'tls', queryParam.tls === "1"); opt.set(dom_prefix + 'tls_serverName', queryParam.peer || queryParam.sni || ''); opt.set(dom_prefix + 'tls_allowInsecure', queryParam.allowinsecure === '1'); opt.set(dom_prefix + 'mux', queryParam.mux === '1'); @@ -675,12 +676,12 @@ local api = require "luci.passwall2.api" var sstr = b64DecodeUnicode(ssu[1]); var ploc = sstr.indexOf("/?"); if (has_singbox) { - opt.set('type', "sing-box"); dom_prefix = "singbox_" + opt.set('type', "sing-box"); } if (has_xray) { - opt.set('type', "Xray"); dom_prefix = "xray_" + opt.set('type', "Xray"); } opt.set(dom_prefix + 'protocol', "vmess"); var url0, param = ""; @@ -728,12 +729,12 @@ local api = require "luci.passwall2.api" } if (ssu[0] === "vless") { if (has_singbox) { - opt.set('type', "sing-box"); dom_prefix = "singbox_" + opt.set('type', "sing-box"); } if (has_xray) { - opt.set('type', "Xray"); dom_prefix = "xray_" + opt.set('type', "Xray"); } opt.set(dom_prefix + 'protocol', "vless"); var m = parseNodeUrl(ssrurl); @@ -897,8 +898,8 @@ local api = require "luci.passwall2.api" } } if (has_singbox) { - opt.set('type', "sing-box"); dom_prefix = "singbox_" + opt.set('type', "sing-box"); opt.set(dom_prefix + 'protocol', "hysteria2"); opt.set(dom_prefix + 'hysteria2_auth_password', decodeURIComponent(password)); if (queryParam["obfs-password"]) { diff --git a/luci-app-passwall2/luasrc/view/passwall2/node_list/node_list.htm b/luci-app-passwall2/luasrc/view/passwall2/node_list/node_list.htm index acc7fd1a2..5f222ecfe 100644 --- a/luci-app-passwall2/luasrc/view/passwall2/node_list/node_list.htm +++ b/luci-app-passwall2/luasrc/view/passwall2/node_list/node_list.htm @@ -53,6 +53,7 @@ table td, .table .td {