From 463d8995053f963819a8b4718e46c9fd7dc237b1 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:36:47 +0800 Subject: [PATCH] luci: optimization --- .../luasrc/controller/passwall.lua | 7 +- .../model/cbi/passwall/client/acl_config.lua | 10 + .../model/cbi/passwall/client/haproxy.lua | 4 +- .../model/cbi/passwall/client/node_list.lua | 41 +++- .../model/cbi/passwall/client/other.lua | 10 + .../model/cbi/passwall/client/type/ray.lua | 2 +- .../cbi/passwall/client/type/sing-box.lua | 2 +- .../model/cbi/passwall/server/type/ray.lua | 2 +- luci-app-passwall/luasrc/passwall/api.lua | 4 +- .../view/passwall/node_list/link_add_node.htm | 12 +- .../view/passwall/node_list/node_list.htm | 212 ++++++++---------- luci-app-passwall/po/zh-cn/passwall.po | 34 ++- .../root/usr/share/passwall/0_default_config | 3 +- 13 files changed, 171 insertions(+), 172 deletions(-) diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index 369bfd556..2283d95c3 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -246,16 +246,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-passwall/luasrc/model/cbi/passwall/client/acl_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/acl_config.lua index 200da9788..607ce2401 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/acl_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/acl_config.lua @@ -5,6 +5,10 @@ local has_singbox = api.finded_com("singbox") local has_xray = api.finded_com("xray") local has_chnlist = api.fs.access("/usr/share/passwall/rules/chnlist") +local port_validate = function(self, value, t) + return value:gsub("-", ":") +end + m = Map(appname) local nodes_table = {} @@ -141,6 +145,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")) @@ -148,12 +153,14 @@ 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 Proxy Drop Ports o = s:option(Value, "tcp_proxy_drop_ports", translate("TCP Proxy Drop Ports")) o.default = "default" o:value("disable", translate("No patterns are used")) o:value("default", translate("Default")) +o.validate = port_validate ---- UDP Proxy Drop Ports o = s:option(Value, "udp_proxy_drop_ports", translate("UDP Proxy Drop Ports")) @@ -161,6 +168,7 @@ o.default = "default" o:value("disable", translate("No patterns are used")) o:value("default", translate("Default")) o:value("80,443", translate("QUIC")) +o.validate = port_validate ---- TCP Redir Ports o = s:option(Value, "tcp_redir_ports", translate("TCP Redir Ports")) @@ -170,6 +178,7 @@ o:value("1:65535", translate("All")) o:value("80,443", "80,443") o:value("80:65535", "80 " .. translate("or more")) o:value("1:443", "443 " .. translate("or less")) +o.validate = port_validate ---- UDP Redir Ports o = s:option(Value, "udp_redir_ports", translate("UDP Redir Ports")) @@ -177,6 +186,7 @@ o.default = "default" o:value("default", translate("Default")) o:value("1:65535", translate("All")) o:value("53", "53") +o.validate = port_validate ---- TCP Proxy Mode tcp_proxy_mode = s:option(ListValue, "tcp_proxy_mode", "TCP " .. translate("Proxy Mode")) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua index 416fbd53a..f64f0260d 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/haproxy.lua @@ -49,7 +49,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 @@ -60,7 +60,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-passwall/luasrc/model/cbi/passwall/client/node_list.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua index be71197e4..052c6c8d2 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua @@ -9,15 +9,19 @@ m = Map(appname) 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") @@ -113,7 +117,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 @@ -127,23 +131,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-passwall/luasrc/model/cbi/passwall/client/other.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/other.lua index 2c42d58a8..07aba526c 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/other.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/other.lua @@ -6,6 +6,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) -- [[ Delay Settings ]]-- @@ -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,17 +77,20 @@ 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 Proxy Drop Ports o = s:option(Value, "tcp_proxy_drop_ports", translate("TCP Proxy Drop Ports")) o.default = "disable" o:value("disable", translate("No patterns are used")) +o.validate = port_validate ---- UDP Proxy Drop Ports o = s:option(Value, "udp_proxy_drop_ports", translate("UDP Proxy Drop Ports")) o.default = "443" o:value("disable", translate("No patterns are used")) o:value("443", translate("QUIC")) +o.validate = port_validate ---- TCP Redir Ports o = s:option(Value, "tcp_redir_ports", translate("TCP Redir Ports")) @@ -90,12 +98,14 @@ 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:value("53", "DNS") +o.validate = port_validate ---- Use nftables o = s:option(ListValue, "use_nft", translate("Firewall tools")) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/ray.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/ray.lua index 66a739208..45dc8f9b2 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/ray.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/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-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua index a9aaf2ced..b0ffffc16 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/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-passwall/luasrc/model/cbi/passwall/server/type/ray.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/ray.lua index c8ea16d6d..69a459b06 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/ray.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/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-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index f84f50497..89ea3b76a 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -307,7 +307,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"] @@ -334,7 +334,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-passwall/luasrc/view/passwall/node_list/link_add_node.htm b/luci-app-passwall/luasrc/view/passwall/node_list/link_add_node.htm index cbc43216c..575f20568 100644 --- a/luci-app-passwall/luasrc/view/passwall/node_list/link_add_node.htm +++ b/luci-app-passwall/luasrc/view/passwall/node_list/link_add_node.htm @@ -48,9 +48,8 @@ local api = require "luci.passwall.api" function add_node() { var nodes_link = document.getElementById("nodes_link").value; if (nodes_link.trim() != "") { - var supports = "ss ssr vmess vless trojan trojan-go hysteria"; - var itype = nodes_link.split('://')[0]; - if (itype.trim() != "" && supports.indexOf(itype) >= 0) { + var s = nodes_link.split('://'); + if (s.length > 1) { ajax_add_node(nodes_link); } else { @@ -81,9 +80,10 @@ local api = require "luci.passwall.api" diff --git a/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm b/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm index 9d2ebb00c..874b92345 100644 --- a/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm +++ b/luci-app-passwall/luasrc/view/passwall/node_list/node_list.htm @@ -36,6 +36,8 @@ table td, .table .td {