From 9e10215c674f23ad380b861509006ba0effc04d7 Mon Sep 17 00:00:00 2001 From: actions Date: Sat, 10 Aug 2024 00:00:07 +0800 Subject: [PATCH] luci-app-passwall: sync upstream last commit: https://github.com/xiaorouji/openwrt-passwall/commit/dd01852d42639842b0f0f14b2fba215bde9a7123 --- .../passwall/node_list/link_share_man.htm | 61 ++++++++++- .../root/usr/share/passwall/subscribe.lua | 102 +++++++++++++++--- 2 files changed, 146 insertions(+), 17 deletions(-) diff --git a/luci-app-passwall/luasrc/view/passwall/node_list/link_share_man.htm b/luci-app-passwall/luasrc/view/passwall/node_list/link_share_man.htm index f6a209a00..523f65324 100644 --- a/luci-app-passwall/luasrc/view/passwall/node_list/link_share_man.htm +++ b/luci-app-passwall/luasrc/view/passwall/node_list/link_share_man.htm @@ -354,9 +354,37 @@ local api = require "luci.passwall.api" var params = ""; if (opt.get(dom_prefix + "tls").checked) { params += opt.query("sni", dom_prefix + "tls_serverName"); - params += "&tls=1" + params += "&security=tls" params += opt.query("allowinsecure", dom_prefix + "tls_allowInsecure"); } + // 获取transport参数并设置type + var transport = opt.get(dom_prefix + "transport").value || ""; + switch (transport.toLowerCase()) { + case 'tcp': + params += "&type=tcp"; + break; + case 'ws': + params += "&type=ws"; + break; + case 'kcp': + params += "&type=kcp"; + break; + case 'mkcp': + params += "&type=kcp"; + break; + case 'http': + params += "&type=http"; + break; + case 'h2': + params += "&type=h2"; + break; + case 'grpc': + params += "&type=grpc"; + break; + default: + // 默认不添加type参数 + break; + } params += "#" + encodeURI(v_alias.value); if (params[0] == "&") { params = params.substring(1); @@ -679,7 +707,7 @@ local api = require "luci.passwall.api" var queryParams = query[1]; var queryArray = queryParams.split('&'); var params; - for (i = 0; i < queryArray.length; i++) { + for (var i = 0; i < queryArray.length; i++) { params = queryArray[i].split('='); queryParam[decodeURIComponent(params[0]).toLowerCase()] = decodeURIComponent(params[1] || ''); } @@ -687,9 +715,36 @@ local api = require "luci.passwall.api" 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', queryParam.tls === "1"); + opt.set(dom_prefix + 'tls', queryParam.security === "tls" ? "1" : "0"); opt.set(dom_prefix + 'tls_serverName', queryParam.peer || queryParam.sni || ''); opt.set(dom_prefix + 'tls_allowInsecure', queryParam.allowinsecure === '1'); + // 根据type参数设置transport + var transportType = queryParam.type || ""; + switch (transportType.toLowerCase()) { + case 'tcp': + opt.set(dom_prefix + 'transport', 'tcp'); + break; + case 'ws': + opt.set(dom_prefix + 'transport', 'ws'); + break; + case 'kcp': + opt.set(dom_prefix + 'transport', 'mkcp'); + break; + case 'mkcp': + opt.set(dom_prefix + 'transport', 'mkcp'); + break; + case 'http': + opt.set(dom_prefix + 'transport', 'http'); + break; + case 'h2': + opt.set(dom_prefix + 'transport', 'h2'); + break; + case 'grpc': + opt.set(dom_prefix + 'transport', 'grpc'); + break; + default: + opt.set(dom_prefix + 'transport', ''); // 默认清空transport + } if (m.hash) { opt.set('remarks', decodeURI(m.hash.substr(1))); } diff --git a/luci-app-passwall/root/usr/share/passwall/subscribe.lua b/luci-app-passwall/root/usr/share/passwall/subscribe.lua index be9888d8a..8b1ad16ec 100755 --- a/luci-app-passwall/root/usr/share/passwall/subscribe.lua +++ b/luci-app-passwall/root/usr/share/passwall/subscribe.lua @@ -618,6 +618,14 @@ local function processData(szType, content, add_mode, add_from) end end elseif szType == "trojan" then + if trojan_type_default == "trojan-plus" and has_trojan_plus then + result.type = "Trojan-Plus" + elseif trojan_type_default == "sing-box" and has_singbox then + result.type = 'sing-box' + elseif trojan_type_default == "xray" and has_xray then + result.type = 'Xray' + end + result.protocol = 'trojan' local alias = "" if content:find("#") then local idx_sp = content:find("#") @@ -625,7 +633,6 @@ local function processData(szType, content, add_mode, add_from) content = content:sub(0, idx_sp - 1) end result.remarks = UrlDecode(alias) - result.type = "Trojan-Plus" if content:find("@") then local Info = split(content, "@") result.password = UrlDecode(Info[1]) @@ -658,8 +665,10 @@ local function processData(szType, content, add_mode, add_from) if params.peer then peer = params.peer end sni = params.sni and params.sni or "" result.port = port + result.tls = '1' result.tls_serverName = peer and peer or sni + if params.allowinsecure then if params.allowinsecure == "1" or params.allowinsecure == "0" then result.tls_allowInsecure = params.allowinsecure @@ -670,16 +679,75 @@ local function processData(szType, content, add_mode, add_from) else result.tls_allowInsecure = allowInsecure_default and "1" or "0" end + + if not params.type then + params.type = "tcp" + end + params.type = string.lower(params.type) + result.transport = params.type + if params.type == 'ws' then + result.ws_host = params.host + result.ws_path = params.path + if result.type == "sing-box" and params.path then + local ws_path_dat = split(params.path, "?") + local ws_path = ws_path_dat[1] + local ws_path_params = {} + for _, v in pairs(split(ws_path_dat[2], '&')) do + local t = split(v, '=') + ws_path_params[t[1]] = t[2] + end + if ws_path_params.ed and tonumber(ws_path_params.ed) then + result.ws_path = ws_path + result.ws_enableEarlyData = "1" + result.ws_maxEarlyData = tonumber(ws_path_params.ed) + result.ws_earlyDataHeaderName = "Sec-WebSocket-Protocol" + end + end + end + if params.type == 'h2' or params.type == 'http' then + if result.type == "sing-box" then + result.transport = "http" + result.http_host = params.host + result.http_path = params.path + elseif result.type == "xray" then + result.transport = "h2" + result.h2_host = params.host + result.h2_path = params.path + end + end + if params.type == 'tcp' then + result.tcp_guise = params.headerType or "none" + result.tcp_guise_http_host = params.host + result.tcp_guise_http_path = params.path + end + if params.type == 'kcp' or params.type == 'mkcp' then + result.transport = "mkcp" + result.mkcp_guise = params.headerType or "none" + result.mkcp_mtu = 1350 + result.mkcp_tti = 50 + result.mkcp_uplinkCapacity = 5 + result.mkcp_downlinkCapacity = 20 + result.mkcp_readBufferSize = 2 + result.mkcp_writeBufferSize = 2 + result.mkcp_seed = params.seed + end + if params.type == 'quic' then + result.quic_guise = params.headerType or "none" + result.quic_key = params.key + result.quic_security = params.quicSecurity or "none" + end + if params.type == 'grpc' then + if params.path then result.grpc_serviceName = params.path end + if params.serviceName then result.grpc_serviceName = params.serviceName end + result.grpc_mode = params.mode + end + + result.encryption = params.encryption or "none" + + result.flow = params.flow or nil + end - if trojan_type_default == "trojan-plus" and has_trojan_plus then - result.type = "Trojan-Plus" - elseif trojan_type_default == "sing-box" and has_singbox then - result.type = 'sing-box' - result.protocol = 'trojan' - elseif trojan_type_default == "xray" and has_xray then - result.type = 'Xray' - result.protocol = 'trojan' - end + elseif szType == "ssd" then result.type = "SS" result.address = content.server @@ -762,9 +830,15 @@ local function processData(szType, content, add_mode, add_from) end end if params.type == 'h2' or params.type == 'http' then - params.type = "h2" - result.h2_host = params.host - result.h2_path = params.path + if result.type == "sing-box" then + result.transport = "http" + result.http_host = params.host + result.http_path = params.path + elseif result.type == "xray" then + result.transport = "h2" + result.h2_host = params.host + result.h2_path = params.path + end end if params.type == 'tcp' then result.tcp_guise = params.headerType or "none" @@ -772,7 +846,7 @@ local function processData(szType, content, add_mode, add_from) result.tcp_guise_http_path = params.path end if params.type == 'kcp' or params.type == 'mkcp' then - params.type = "mkcp" + result.transport = "mkcp" result.mkcp_guise = params.headerType or "none" result.mkcp_mtu = 1350 result.mkcp_tti = 50