From 144f53cb17c16d830f457b3cac0a7aa2cf1785a9 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Sun, 31 Jan 2021 01:11:03 +0800 Subject: [PATCH] luci-app-passwall: sync with upstream source Signed-off-by: CN_SZTL --- .../luasrc/model/cbi/passwall/api/api.lua | 32 +++++++++++++-- .../model/cbi/passwall/client/global.lua | 7 ++++ .../model/cbi/passwall/client/node_list.lua | 22 +++++++++-- .../cbi/passwall/client/node_subscribe.lua | 15 ++++--- .../model/cbi/passwall/server/index.lua | 7 ++++ .../luci-app-passwall/po/zh-cn/passwall.po | 18 +++------ .../root/etc/config/passwall | 11 +++--- .../root/usr/share/passwall/subscribe.lua | 39 ++++++++++--------- 8 files changed, 98 insertions(+), 53 deletions(-) diff --git a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/api/api.lua b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/api/api.lua index 3c04024cbd..c3b673367c 100644 --- a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/api/api.lua +++ b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/api/api.lua @@ -66,11 +66,23 @@ function get_valid_nodes() if e.port and e.address then local address = e.address if datatypes.ipaddr(address) or datatypes.hostname(address) then + local type2 = e.type local address2 = address + if type2 == "Xray" and e.protocol then + local protocol = e.protocol + if protocol == "vmess" then + protocol = "VMess" + elseif protocol == "vless" then + protocol = "VLESS" + else + protocol = protocol:gsub("^%l",string.upper) + end + type2 = type2 .. " " .. protocol + end if datatypes.ip6addr(address) then address2 = "[" .. address .. "]" end - e.remarks_name = "%s:[%s] %s:%s" % {e.type, e.remarks, address2, e.port} + e.remarks_name = "%s:[%s] %s:%s" % {type2, e.remarks, address2, e.port} if e.use_kcp and e.use_kcp == "1" then - e.remarks_name = "%s+%s:[%s] %s" % {e.type, "Kcptun", e.remarks, address2} + e.remarks_name = "%s+%s:[%s] %s" % {type2, "Kcptun", e.remarks, address2} end e.node_type = "normal" nodes[#nodes + 1] = e @@ -87,10 +99,22 @@ function get_full_node_remarks(n) if n.protocol and (n.protocol == "_balancing" or n.protocol == "_shunt") then remarks = "%s:[%s] " % {i18n.translatef(n.type .. n.protocol), n.remarks} else + local type2 = n.type + if n.type == "Xray" and n.protocol then + local protocol = n.protocol + if protocol == "vmess" then + protocol = "VMess" + elseif protocol == "vless" then + protocol = "VLESS" + else + protocol = protocol:gsub("^%l",string.upper) + end + type2 = type2 .. " " .. protocol + end if n.use_kcp and n.use_kcp == "1" then - remarks = "%s+%s:[%s] %s" % {n.type, "Kcptun", n.remarks, n.address} + remarks = "%s+%s:[%s] %s" % {type2, "Kcptun", n.remarks, n.address} else - remarks = "%s:[%s] %s:%s" % {n.type, n.remarks, n.address, n.port} + remarks = "%s:[%s] %s:%s" % {type2, n.remarks, n.address, n.port} end end end diff --git a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua index f0dda34455..a0052c46c1 100644 --- a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua +++ b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/global.lua @@ -114,6 +114,13 @@ if current_node and current_node ~= "" and current_node ~= "nil" then local r = api.get_full_node_remarks(uci:get_all(appname, n[id])) tcp_node.description = tcp_node.description .. remarks .. ":" .. string.format('%s', url, r) .. "
" end + local id = "main_node" + local remarks = translate("Default") .. translate("Preproxy") + if n[id] and n[id] ~= "nil" then + local url = api.url("node_config", n[id]) + local r = api.get_full_node_remarks(uci:get_all(appname, n[id])) + tcp_node.description = tcp_node.description .. remarks .. ":" .. string.format('%s', url, r) .. "
" + end end end end diff --git a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua index 66d700880b..7754028088 100644 --- a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua +++ b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/node_list.lua @@ -65,10 +65,17 @@ if nodes_display:find("compact_display_nodes") then if type == "Xray" then local protocol = m:get(n, "protocol") if protocol == "_balancing" then - type = type .. " 负载均衡" + protocol = "负载均衡" elseif protocol == "_shunt" then - type = type .. " 分流" + protocol = "分流" + elseif protocol == "vmess" then + protocol = "VMess" + elseif protocol == "vless" then + protocol = "VLESS" + else + protocol = protocol:gsub("^%l",string.upper) end + type = type .. " " .. protocol end local address = m:get(n, "address") or "" local port = m:get(n, "port") or "" @@ -108,10 +115,17 @@ else if v == "Xray" then local protocol = m:get(n, "protocol") if protocol == "_balancing" then - result = result .. " 负载均衡" + protocol = "负载均衡" elseif protocol == "_shunt" then - result = result .. " 分流" + protocol = "分流" + elseif protocol == "vmess" then + protocol = "VMess" + elseif protocol == "vless" then + protocol = "VLESS" + else + protocol = protocol:gsub("^%l",string.upper) end + result = result .. " " .. protocol end end return result diff --git a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua index 897490ee5e..df68acd3e5 100644 --- a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua +++ b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/client/node_subscribe.lua @@ -48,15 +48,14 @@ function o.write(e, e) luci.http.redirect(api.url("log")) end -filter_enabled = s:option(Flag, "filter_enabled", translate("Filter keyword switch"), translate("When checked, below options can only be take effect.")) -o.default = 1 -o.rmempty = false +o = s:option(ListValue, "filter_keyword_mode", translate("Filter keyword Mode")) +o:value("0", translate("Close")) +o:value("1", translate("Discard List")) +o:value("2", translate("Keep List")) -filter_keyword = s:option(DynamicList, "filter_keyword", translate("Filter keyword")) - -o = s:option(Flag, "filter_keyword_discarded", translate("Filter keyword discarded"), translate("When checked, the keywords in the list are discarded. Otherwise, it is not discarded.")) -o.default = "1" -o.rmempty = false +o = s:option(DynamicList, "filter_discard_list", translate("Discard List")) + +o = s:option(DynamicList, "filter_keep_list", translate("Keep List")) o = s:option(Flag, "allowInsecure", translate("allowInsecure"), translate("Whether unsafe connections are allowed. When checked, Certificate validation will be skipped.")) o.default = "1" diff --git a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/index.lua b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/index.lua index 6d901135d4..7693fa2dd7 100644 --- a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/index.lua +++ b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/index.lua @@ -48,6 +48,13 @@ e.cfgvalue = function(t, n) if v then if v == "Xray" then local protocol = m:get(n, "protocol") + if protocol == "vmess" then + protocol = "VMess" + elseif protocol == "vless" then + protocol = "VLESS" + else + protocol = protocol:gsub("^%l",string.upper) + end return v .. " -> " .. protocol end return v diff --git a/package/lienol/luci-app-passwall/po/zh-cn/passwall.po b/package/lienol/luci-app-passwall/po/zh-cn/passwall.po index ba5608f870..e769cf903e 100644 --- a/package/lienol/luci-app-passwall/po/zh-cn/passwall.po +++ b/package/lienol/luci-app-passwall/po/zh-cn/passwall.po @@ -820,20 +820,14 @@ msgstr "手动订阅" msgid "Delete All Subscribe Node" msgstr "删除所有订阅节点" -msgid "Filter keyword switch" -msgstr "过滤关键字开关" +msgid "Filter keyword Mode" +msgstr "过滤关键字模式" -msgid "When checked, below options can only be take effect." -msgstr "当勾选时,下面的选项才生效。" +msgid "Discard List" +msgstr "丢弃列表" -msgid "Filter keyword" -msgstr "过滤关键字" - -msgid "Filter keyword discarded" -msgstr "关键字丢弃" - -msgid "When checked, the keywords in the list are discarded. Otherwise, it is not discarded." -msgstr "当勾选时,将丢弃包含列表里的关键字的节点。否则,将保留列表的关键字的节点(反过来)。" +msgid "Keep List" +msgstr "保留列表" msgid "Add" msgstr "添加" diff --git a/package/lienol/luci-app-passwall/root/etc/config/passwall b/package/lienol/luci-app-passwall/root/etc/config/passwall index ea7b6be936..8cbd7a678d 100644 --- a/package/lienol/luci-app-passwall/root/etc/config/passwall +++ b/package/lienol/luci-app-passwall/root/etc/config/passwall @@ -58,13 +58,12 @@ config global_app config global_subscribe option subscribe_proxy '0' option auto_update_subscribe '0' - option filter_enabled '1' - option filter_keyword_discarded '1' option allowInsecure '1' - list filter_keyword '过期时间' - list filter_keyword '剩余流量' - list filter_keyword 'QQ群' - list filter_keyword '官网' + option filter_keyword_mode '1' + list filter_discard_list '过期时间' + list filter_discard_list '剩余流量' + list filter_discard_list 'QQ群' + list filter_discard_list '官网' config auto_switch option testing_time '1' diff --git a/package/lienol/luci-app-passwall/root/usr/share/passwall/subscribe.lua b/package/lienol/luci-app-passwall/root/usr/share/passwall/subscribe.lua index bb463851a4..bc0abbd1c5 100755 --- a/package/lienol/luci-app-passwall/root/usr/share/passwall/subscribe.lua +++ b/package/lienol/luci-app-passwall/root/usr/share/passwall/subscribe.lua @@ -9,6 +9,7 @@ require 'luci.util' require 'luci.jsonc' require 'luci.sys' local api = require "luci.model.cbi.passwall.api.api" +local has_xray = api.is_finded("xray") -- these global functions are accessed all the time by the event handler -- so caching them is worth the effort @@ -211,28 +212,24 @@ do end -- 判断是否过滤节点关键字 -local filter_keyword_enabled = ucic2:get(application, "@global_subscribe[0]", "filter_enabled") -local filter_keyword_table = ucic2:get(application, "@global_subscribe[0]", "filter_keyword") -local filter_keyword_discarded = ucic2:get(application, "@global_subscribe[0]", "filter_keyword_discarded") +local filter_keyword_mode = ucic2:get(application, "@global_subscribe[0]", "filter_keyword_mode") or "0" +local filter_keyword_discard_list = ucic2:get(application, "@global_subscribe[0]", "filter_discard_list") or {} +local filter_keyword_keep_list = ucic2:get(application, "@global_subscribe[0]", "filter_keep_list") or {} local function is_filter_keyword(value) - if filter_keyword_enabled and filter_keyword_enabled == "1" then - if filter_keyword_table then - if filter_keyword_discarded and filter_keyword_discarded == "1" then - for k,v in ipairs(filter_keyword_table) do - if value:find(v) then - return true - end - end - else - local result = true - for k,v in ipairs(filter_keyword_table) do - if value:find(v) then - result = false - end - end - return result + if filter_keyword_mode == "1" then + for k,v in ipairs(filter_keyword_discard_list) do + if value:find(v) then + return true end end + elseif filter_keyword_mode == "2" then + local result = true + for k,v in ipairs(filter_keyword_keep_list) do + if value:find(v) then + result = false + end + end + return result end return false end @@ -436,6 +433,10 @@ local function processData(szType, content, add_mode) content = content:sub(0, idx_sp - 1) end result.type = "Trojan-Plus" + if has_xray then + result.type = 'Xray' + result.protocol = 'trojan' + end result.remarks = UrlDecode(alias) if content:find("@") then local Info = split(content, "@")