|
@@ -3,34 +3,32 @@
|
|
|
-- This file is part of the luci-app-ssr-plus subscribe.lua
|
|
|
-- @author William Chan <[email protected]>
|
|
|
------------------------------------------------
|
|
|
-require 'nixio'
|
|
|
-require 'luci.util'
|
|
|
-require 'luci.jsonc'
|
|
|
-require 'luci.sys'
|
|
|
-require 'uci'
|
|
|
+require "luci.model.uci"
|
|
|
+require "nixio"
|
|
|
+require "luci.util"
|
|
|
+require "luci.sys"
|
|
|
+require "luci.jsonc"
|
|
|
-- these global functions are accessed all the time by the event handler
|
|
|
-- so caching them is worth the effort
|
|
|
-local luci = luci
|
|
|
local tinsert = table.insert
|
|
|
local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub
|
|
|
local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
|
|
|
local b64decode = nixio.bin.b64decode
|
|
|
local cache = {}
|
|
|
-local nodeResult = setmetatable({}, { __index = cache }) -- update result
|
|
|
+local nodeResult = setmetatable({}, { __index = cache }) -- update result
|
|
|
local name = 'shadowsocksr'
|
|
|
local uciType = 'servers'
|
|
|
local ucic = luci.model.uci.cursor()
|
|
|
local proxy = ucic:get_first(name, 'server_subscribe', 'proxy', '0')
|
|
|
local switch = ucic:get_first(name, 'server_subscribe', 'switch', '1')
|
|
|
local subscribe_url = ucic:get_first(name, 'server_subscribe', 'subscribe_url', {})
|
|
|
-local filter_words = ucic:get_first(name, 'server_subscribe', 'filter_words', 'QQ群')
|
|
|
-
|
|
|
+local filter_words = ucic:get_first(name, 'server_subscribe', 'filter_words', '过期时间/剩余流量')
|
|
|
local log = function(...)
|
|
|
print(os.date("%Y-%m-%d %H:%M:%S ") .. table.concat({ ... }, " "))
|
|
|
end
|
|
|
-- 分割字符串
|
|
|
local function split(full, sep)
|
|
|
- full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0
|
|
|
+ full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0
|
|
|
local off, result = 1, {}
|
|
|
while true do
|
|
|
local nStart, nEnd = full:find(sep, off)
|
|
@@ -74,7 +72,7 @@ local function trim(text)
|
|
|
end
|
|
|
-- md5
|
|
|
local function md5(content)
|
|
|
- local stdout = luci.sys.exec('echo \"' .. urlEncode(content) .. '\" | md5sum | cut -d \" \" -f1')
|
|
|
+ local stdout = luci.sys.exec('echo \"' .. urlEncode(content) .. '\" | md5sum | cut -d \" \" -f1')
|
|
|
-- assert(nixio.errno() == 0)
|
|
|
return trim(stdout)
|
|
|
end
|
|
@@ -119,7 +117,7 @@ local function processData(szType, content)
|
|
|
result.protocol_param = base64Decode(params.protoparam)
|
|
|
local group = base64Decode(params.group)
|
|
|
if group then
|
|
|
- result.alias = "[" .. group .. "] "
|
|
|
+ result.alias = "[" .. group .. "] "
|
|
|
end
|
|
|
result.alias = result.alias .. base64Decode(params.remarks)
|
|
|
elseif szType == 'vmess' then
|
|
@@ -131,7 +129,6 @@ local function processData(szType, content)
|
|
|
result.alter_id = info.aid
|
|
|
result.vmess_id = info.id
|
|
|
result.alias = info.ps
|
|
|
- result.insecure = 1
|
|
|
-- result.mux = 1
|
|
|
-- result.concurrency = 8
|
|
|
if info.net == 'ws' then
|
|
@@ -143,6 +140,9 @@ local function processData(szType, content)
|
|
|
result.h2_path = info.path
|
|
|
end
|
|
|
if info.net == 'tcp' then
|
|
|
+ if info.type and info.type ~= "http" then
|
|
|
+ info.type = "none"
|
|
|
+ end
|
|
|
result.tcp_guise = info.type
|
|
|
result.http_host = info.host
|
|
|
result.http_path = info.path
|
|
@@ -167,6 +167,7 @@ local function processData(szType, content)
|
|
|
if info.tls == "tls" or info.tls == "1" then
|
|
|
result.tls = "1"
|
|
|
result.tls_host = info.host
|
|
|
+ result.insecure = 1
|
|
|
else
|
|
|
result.tls = "0"
|
|
|
end
|
|
@@ -244,12 +245,10 @@ local function processData(szType, content)
|
|
|
local t = split(v, '=')
|
|
|
params[t[1]] = t[2]
|
|
|
end
|
|
|
-
|
|
|
if params.peer then
|
|
|
-- 未指定peer(sni)默认使用remote addr
|
|
|
result.tls_host = params.peer
|
|
|
end
|
|
|
-
|
|
|
if params.allowInsecure == "1" then
|
|
|
result.insecure = "1"
|
|
|
else
|
|
@@ -280,15 +279,15 @@ local function wget(url)
|
|
|
end
|
|
|
|
|
|
local function check_filer(result)
|
|
|
- do
|
|
|
- local filter_word = split(filter_words, "/")
|
|
|
- for i, v in pairs(filter_word) do
|
|
|
- if result.alias:find(v) then
|
|
|
- log('订阅节点关键字过滤:“' .. v ..'” ,该节点被丢弃')
|
|
|
- return true
|
|
|
- end
|
|
|
- end
|
|
|
- end
|
|
|
+ do
|
|
|
+ local filter_word = split(filter_words, "/")
|
|
|
+ for i, v in pairs(filter_word) do
|
|
|
+ if result.alias:find(v) then
|
|
|
+ log('订阅节点关键字过滤:“' .. v ..'” ,该节点被丢弃')
|
|
|
+ return true
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
local execute = function()
|
|
@@ -313,10 +312,10 @@ local execute = function()
|
|
|
nodes = base64Decode(raw:sub(nEnd + 1, #raw))
|
|
|
nodes = jsonParse(nodes)
|
|
|
local extra = {
|
|
|
- airport = nodes.airport,
|
|
|
- port = nodes.port,
|
|
|
- encryption = nodes.encryption,
|
|
|
- password = nodes.password
|
|
|
+ airport = nodes.airport,
|
|
|
+ port = nodes.port,
|
|
|
+ encryption = nodes.encryption,
|
|
|
+ password = nodes.password
|
|
|
}
|
|
|
local servers = {}
|
|
|
-- SS里面包着 干脆直接这样
|
|
@@ -349,10 +348,11 @@ local execute = function()
|
|
|
-- log(result)
|
|
|
if result then
|
|
|
if
|
|
|
- not result.server or
|
|
|
- check_filer(result) or
|
|
|
- result.server:match("[^0-9a-zA-Z%-%.%s]") -- 中文做地址的 也没有人拿中文域名搞,就算中文域也有Puny Code SB 机场
|
|
|
- then
|
|
|
+ not result.server or
|
|
|
+ not result.server_port or
|
|
|
+ check_filer(result) or
|
|
|
+ result.server:match("[^0-9a-zA-Z%-%.%s]") -- 中文做地址的 也没有人拿中文域名搞,就算中文域也有Puny Code SB 机场
|
|
|
+ then
|
|
|
log('丢弃无效节点: ' .. result.type ..' 节点, ' .. result.alias)
|
|
|
else
|
|
|
log('成功解析: ' .. result.type ..' 节点, ' .. result.alias)
|
|
@@ -385,7 +385,7 @@ local execute = function()
|
|
|
local dat = nodeResult[old.grouphashkey][old.hashkey]
|
|
|
ucic:tset(name, old['.name'], dat)
|
|
|
-- 标记一下
|
|
|
- setmetatable(nodeResult[old.grouphashkey][old.hashkey], { __index = { _ignore = true } })
|
|
|
+ setmetatable(nodeResult[old.grouphashkey][old.hashkey], { __index = { _ignore = true } })
|
|
|
end
|
|
|
else
|
|
|
if not old.alias then
|