From 882094b858a579fdf7feff31aaa7284f32d8fa90 Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Tue, 7 Apr 2020 01:22:52 +0800 Subject: [PATCH] luci-app-passwall: sync with upstream source --- package/lienol/luci-app-passwall/Makefile | 4 +- .../model/cbi/passwall/node_subscribe.lua | 7 +- .../luci-app-passwall/po/zh-cn/passwall.po | 7 +- .../root/etc/config/passwall | 1 + .../root/usr/share/passwall/app.sh | 2 +- .../root/usr/share/passwall/config.default | 1 + .../root/usr/share/passwall/subscribe.lua | 334 +++++++++++++----- 7 files changed, 269 insertions(+), 87 deletions(-) diff --git a/package/lienol/luci-app-passwall/Makefile b/package/lienol/luci-app-passwall/Makefile index a4cb2f20d1..f1d103d714 100644 --- a/package/lienol/luci-app-passwall/Makefile +++ b/package/lienol/luci-app-passwall/Makefile @@ -7,8 +7,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-passwall PKG_VERSION:=3.6 -PKG_RELEASE:=33 -PKG_DATE:=20200403 +PKG_RELEASE:=36 +PKG_DATE:=20200406 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) diff --git a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/node_subscribe.lua b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/node_subscribe.lua index f4512f4307..3c741018a1 100644 --- a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/node_subscribe.lua +++ b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/node_subscribe.lua @@ -52,8 +52,11 @@ function o.write(e, e) "log")) end -filter_keyword = s:option(DynamicList, "filter_keyword", translate("Filter keyword"), - translate("When subscribing, the keywords in the list are discarded.")) +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 s = m:section(TypedSection, "subscribe_list", "", "" .. translate( 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 a82dc6afcc..099f9d6fa9 100644 --- a/package/lienol/luci-app-passwall/po/zh-cn/passwall.po +++ b/package/lienol/luci-app-passwall/po/zh-cn/passwall.po @@ -628,8 +628,11 @@ msgstr "删除所有订阅节点" msgid "Filter keyword" msgstr "过滤关键字" -msgid "When subscribing, the keywords in the list are discarded." -msgstr "订阅时,将丢弃包含列表里的关键字的节点。" +msgid "Filter keyword discarded" +msgstr "关键字丢弃" + +msgid "When checked, the keywords in the list are discarded. Otherwise, it is not discarded." +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 9e7753a6df..bd66e15053 100644 --- a/package/lienol/luci-app-passwall/root/etc/config/passwall +++ b/package/lienol/luci-app-passwall/root/etc/config/passwall @@ -60,6 +60,7 @@ config global_app config global_subscribe option subscribe_proxy '0' option auto_update_subscribe '0' + option filter_keyword_discarded '1' list filter_keyword '过期时间' list filter_keyword '剩余流量' list filter_keyword 'QQ群' diff --git a/package/lienol/luci-app-passwall/root/usr/share/passwall/app.sh b/package/lienol/luci-app-passwall/root/usr/share/passwall/app.sh index 148f8c78e3..727e19bf5b 100755 --- a/package/lienol/luci-app-passwall/root/usr/share/passwall/app.sh +++ b/package/lienol/luci-app-passwall/root/usr/share/passwall/app.sh @@ -607,7 +607,7 @@ start_dns() { [ -f "$RULES_PATH/chnlist" ] && cp -a $RULES_PATH/chnlist $TMP_PATH/chnlist [ -f "$TMP_PATH/chnlist" ] && { [ -f "$RULES_PATH/whitelist_host" -a -s "$RULES_PATH/whitelist_host" ] && cat $RULES_PATH/whitelist_host >> $TMP_PATH/chnlist - local chnlist_param="-m $TMP_PATH/chnlist -M" + local chnlist_param="-m $TMP_PATH/chnlist -M -f" } up_trust_chinadns_ng_dns=$(config_t_get global up_trust_chinadns_ng_dns "pdnsd") diff --git a/package/lienol/luci-app-passwall/root/usr/share/passwall/config.default b/package/lienol/luci-app-passwall/root/usr/share/passwall/config.default index 551dd64096..7465aa60f1 100644 --- a/package/lienol/luci-app-passwall/root/usr/share/passwall/config.default +++ b/package/lienol/luci-app-passwall/root/usr/share/passwall/config.default @@ -60,6 +60,7 @@ config global_app config global_subscribe option subscribe_proxy '0' option auto_update_subscribe '0' + option filter_keyword_discarded '1' list filter_keyword '过期时间' list filter_keyword '剩余流量' list filter_keyword 'QQ群' 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 360a5db7b2..c83b062563 100644 --- a/package/lienol/luci-app-passwall/root/usr/share/passwall/subscribe.lua +++ b/package/lienol/luci-app-passwall/root/usr/share/passwall/subscribe.lua @@ -47,52 +47,193 @@ do local node_num = ucic2:get(application, "@global_other[0]", protocol .. "_node_num") or 1 for i = 1, node_num, 1 do local name = string.upper(protocol) - local option = protocol .. "_node" .. i local szType = "@global[0]" - local json = { + local option = protocol .. "_node" .. i + + local node = ucic2:get(application, szType, option) + local currentNode + if node then + currentNode = ucic2:get_all(application, node) + end + CONFIG[#CONFIG + 1] = { + log = true, remarks = name .. "节点" .. i, - type = szType, - option = option, + node = node, + currentNode = currentNode, set = function(server) ucic2:set(application, szType, option, server) end } - CONFIG[name .. "_NODE" .. i] = json end end import_config("tcp") import_config("udp") import_config("socks5") - for k, v in pairs(CONFIG) do - local currentNode - if v.get then - currentNode = v.get() - else - local cfgid = ucic2:get(application, v.type, v.option) - if cfgid then - currentNode = ucic2:get_all(application, cfgid) + local tcp_node1_table = ucic2:get(application, "@auto_switch[0]", "tcp_node1") + if tcp_node1_table then + local nodes = {} + local new_nodes = {} + for k,v in ipairs(tcp_node1_table) do + local node = v + local currentNode + if node then + currentNode = ucic2:get_all(application, node) end + nodes[#nodes + 1] = { + log = false, + node = node, + currentNode = currentNode, + remarks = node, + set = function(server) + for kk, vv in pairs(CONFIG) do + if (vv.remarks == "自动切换TCP_1节点列表") then + table.insert(vv.new_nodes, server) + end + end + end + } end - if currentNode then - CONFIG[k].currentNode = currentNode + CONFIG[#CONFIG + 1] = { + remarks = "自动切换TCP_1节点列表", + nodes = nodes, + new_nodes = new_nodes, + set = function() + for kk, vv in pairs(CONFIG) do + if (vv.remarks == "自动切换TCP_1节点列表") then + log("刷新自动切换列表") + ucic2:set_list(application, "@auto_switch[0]", "tcp_node1", vv.new_nodes) + end + end + end + } + end + + ucic2:foreach(application, uciType, function(node) + if node.type == 'V2ray_shunt' then + local node_id = node[".name"] + local youtube_node_id = node.youtube_node + local netflix_node_id = node.netflix_node + local default_node_id = node.default_node + + local youtube_node + local netflix_node + local default_node + if youtube_node_id then + youtube_node = ucic2:get_all(application, youtube_node_id) + end + if netflix_node_id then + netflix_node = ucic2:get_all(application, netflix_node_id) + end + if default_node_id then + default_node = ucic2:get_all(application, default_node_id) + end + CONFIG[#CONFIG + 1] = { + log = false, + currentNode = youtube_node, + remarks = "V2ray分流youtube节点", + set = function(server) + ucic2:set(application, node_id, "youtube_node", server) + end + } + CONFIG[#CONFIG + 1] = { + log = false, + currentNode = netflix_node, + remarks = "V2ray分流Netflix节点", + set = function(server) + ucic2:set(application, node_id, "netflix_node", server) + end + } + CONFIG[#CONFIG + 1] = { + log = false, + currentNode = default_node, + remarks = "V2ray分流默认节点", + set = function(server) + ucic2:set(application, node_id, "default_node", server) + end + } + elseif node.type == 'V2ray_balancing' then + local node_id = node[".name"] + local nodes = {} + local new_nodes = {} + for k, v in pairs(node.v2ray_balancing_node) do + local node = v + local currentNode + if node then + currentNode = ucic2:get_all(application, node) + end + nodes[#nodes + 1] = { + log = false, + node = node, + currentNode = currentNode, + remarks = node, + set = function(server) + for kk, vv in pairs(CONFIG) do + if (vv.remarks == "V2ray负载均衡节点列表" .. node_id) then + table.insert(vv.new_nodes, server) + end + end + end + } + end + CONFIG[#CONFIG + 1] = { + remarks = "V2ray负载均衡节点列表" .. node_id, + nodes = nodes, + new_nodes = new_nodes, + set = function() + for kk, vv in pairs(CONFIG) do + if (vv.remarks == "V2ray负载均衡节点列表" .. node_id) then + log("刷新V2ray负载均衡节点列表") + ucic2:foreach(application, uciType, function(node2) + if node2[".name"] == node[".name"] then + local index = node2[".index"] + ucic2:set_list(application, "@nodes[" .. index .. "]", "v2ray_balancing_node", vv.new_nodes) + end + end) + end + end + end + } + end + end) + + for k, v in pairs(CONFIG) do + if v.nodes and type(v.nodes) == "table" then + for kk, vv in pairs(v.nodes) do + if vv.currentNode == nil then + CONFIG[k].nodes[kk] = nil + end + end else - CONFIG[k] = nil + if v.currentNode == nil then + CONFIG[k] = nil + end end end end -- 判断是否过滤节点关键字 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 function is_filter_keyword(value) if filter_keyword_table then - for k,v in ipairs(filter_keyword_table) do - if value:find(v) then - return true + 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 end end - return false + return false end -- 分割字符串 @@ -370,77 +511,90 @@ end local function select_node(nodes, config) local server - -- 特别优先级 V2ray分流 + 备注 - if config.currentNode.type == 'V2ray_shunt' then - for id, node in pairs(nodes) do - if node.remarks == config.currentNode.remarks then - log('选择【' .. config.remarks .. '】V2ray分流匹配节点:' .. node.remarks) - server = id - break - end - end - end - -- 特别优先级 V2ray负载均衡 + 备注 - if config.currentNode.type == 'V2ray_balancing' then - for id, node in pairs(nodes) do - if node.remarks == config.currentNode.remarks then - log('选择【' .. config.remarks .. '】V2ray负载均衡匹配节点:' .. node.remarks) - server = id - break - end - end - end - -- 第一优先级 IP + 端口 - if not server then - for id, node in pairs(nodes) do - if node.address and node.port then - if node.address .. ':' .. node.port == config.currentNode.address .. ':' .. config.currentNode.port then - log('选择【' .. config.remarks .. '】第一匹配节点:' .. node.remarks) - server = id - break - end - end - end - end - -- 第二优先级 IP - if not server then - for id, node in pairs(nodes) do - if node.address then - if node.address == config.currentNode.address then - log('选择【' .. config.remarks .. '】第二匹配节点:' .. node.remarks) - server = id - break - end - end - end - end - -- 第三优先级备注 - if not server then - for id, node in pairs(nodes) do - if node.remarks then + if config.currentNode then + -- 特别优先级 V2ray分流 + 备注 + if config.currentNode.type == 'V2ray_shunt' then + for id, node in pairs(nodes) do if node.remarks == config.currentNode.remarks then - log('选择【' .. config.remarks .. '】第三匹配节点:' .. node.remarks) + log('选择【' .. config.remarks .. '】V2ray分流匹配节点:' .. node.remarks) server = id break end end end - end - -- 第四 cfgid - if not server then - for id, node in pairs(nodes) do - if id == config.currentNode['.name'] then - log('选择【' .. config.remarks .. '】第四匹配节点:' .. node.remarks) - server = id - break + -- 特别优先级 V2ray负载均衡 + 备注 + if config.currentNode.type == 'V2ray_balancing' then + for id, node in pairs(nodes) do + if node.remarks == config.currentNode.remarks then + log('选择【' .. config.remarks .. '】V2ray负载均衡匹配节点:' .. node.remarks) + server = id + break + end + end + end + -- 第一优先级 IP + 端口 + if not server then + for id, node in pairs(nodes) do + if node.address and node.port then + if node.address .. ':' .. node.port == config.currentNode.address .. ':' .. config.currentNode.port then + if config.log == nil or config.log == true then + log('选择【' .. config.remarks .. '】第一匹配节点:' .. node.remarks) + end + server = id + break + end + end + end + end + -- 第二优先级 IP + if not server then + for id, node in pairs(nodes) do + if node.address then + if node.address == config.currentNode.address then + if config.log == nil or config.log == true then + log('选择【' .. config.remarks .. '】第二匹配节点:' .. node.remarks) + end + server = id + break + end + end + end + end + -- 第三优先级备注 + if not server then + for id, node in pairs(nodes) do + if node.remarks then + if node.remarks == config.currentNode.remarks then + if config.log == nil or config.log == true then + log('选择【' .. config.remarks .. '】第三匹配节点:' .. node.remarks) + end + server = id + break + end + end + end + end + -- 第四 cfgid + if not server then + for id, node in pairs(nodes) do + if id == config.currentNode['.name'] then + if config.log == nil or config.log == true then + log('选择【' .. config.remarks .. '】第四匹配节点:' .. node.remarks) + end + server = id + break + end end end end -- 还不行 随便找一个 if not server then - server = ucic2:get(application, '@' .. uciType .. '[0]') + server = ucic2:get_all(application, '@' .. uciType .. '[0]') if server then - log('无法找到最匹配的节点,当前已更换为' .. ucic2:get_all(application, server).remarks) + if config.log == nil or config.log == true then + log('【' .. config.remarks .. '】' .. '无法找到最匹配的节点,当前已更换为:' .. server.remarks) + end + server = server[".name"] end end if server then @@ -479,8 +633,28 @@ local function update_node(manual) end end) for _, config in pairs(CONFIG) do - select_node(nodes, config) + if config.nodes and type(config.nodes) == "table" then + for kk, vv in pairs(config.nodes) do + select_node(nodes, vv) + end + config.set() + else + select_node(nodes, config) + end end + + --[[ + for k, v in pairs(CONFIG) do + if type(v.new_nodes) == "table" and #v.new_nodes > 0 then + for kk, vv in pairs(v.new_nodes) do + print(vv) + end + else + print(v.new_nodes) + end + end + ]]-- + ucic2:commit(application) luci.sys.call("/etc/init.d/" .. application .. " restart > /dev/null 2>&1 &") -- 不加&的话日志会出现的更早 end