Skip to content

Commit c9f2048

Browse files
committed
luci: optimize import/subscribe logic and support udp/tfo params
1 parent c626cc3 commit c9f2048

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

luci-app-passwall/luasrc/view/passwall/node_config/link_share_man.htm

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@
243243
}
244244

245245
var params = "";
246+
247+
opt.get(dom_prefix + "tcp_fast_open")?.checked && (params += "&tfo=1");
248+
246249
var v_plugin_dom = opt.get(dom_prefix + "plugin");
247250
if (v_plugin_dom) {
248251
var v_plugin = v_plugin_dom.value;
@@ -322,6 +325,8 @@
322325
params += opt.query("ech", dom_prefix + "ech_config");
323326
}
324327

328+
opt.get(dom_prefix + "uot")?.checked && (params += "&udp=1");
329+
325330
if (opt.get(dom_prefix + "shadowtls")?.checked) {
326331
let st_plugin_str = "";
327332
let st_version = opt.get(dom_prefix + "shadowtls_version")?.value;
@@ -418,6 +423,9 @@
418423
info.tls = "tls";
419424
info.sni = opt.get(dom_prefix + "tls_serverName").value;
420425
}
426+
427+
opt.get(dom_prefix + "tcp_fast_open")?.checked && (info.tfo = "1");
428+
421429
url = b64EncodeUnicode(JSON.stringify(info));
422430
} else if ((v_type === "sing-box" || v_type === "Xray") && opt.get(dom_prefix + "protocol").value === "vless") {
423431
protocol = "vless";
@@ -502,6 +510,8 @@
502510
params += opt.query("ech", dom_prefix + "ech_config");
503511
}
504512

513+
opt.get(dom_prefix + "tcp_fast_open")?.checked && (params += "&tfo=1");
514+
505515
params += "#" + encodeURI(v_alias.value);
506516
if (params[0] == "&") {
507517
params = params.substring(1);
@@ -567,6 +577,9 @@
567577
params += opt.query("vcn", dom_prefix + "tls_CertByName");
568578
params += opt.query("ech", dom_prefix + "ech_config");
569579
}
580+
581+
opt.get(dom_prefix + "tcp_fast_open")?.checked && (params += "&tfo=1");
582+
570583
params += "#" + encodeURI(v_alias.value);
571584
if (params[0] == "&") {
572585
params = params.substring(1);
@@ -944,11 +957,14 @@
944957
pluginOpts = pluginParams.join(";");
945958
}
946959

947-
if (has_xray && ((ss_type !== "xray" && ss_type !== "sing-box" && queryParam.type) || ss_type == "xray" || queryParam.type == "xhttp")) {
960+
const needUpgrade = ss_type !== "Xray" && ss_type !== "sing-box" &&
961+
queryParam.type && queryParam.type !== "tcp" &&
962+
queryParam.headerType && queryParam.headerType !== "none";
963+
if (has_xray && (ss_type == "xray" || needUpgrade || queryParam.type === "xhttp")) {
948964
dom_prefix = "xray_"
949965
opt.set('type', "Xray");
950966
opt.set(dom_prefix + 'protocol', "shadowsocks");
951-
} else if (has_singbox && ((ss_type !== "xray" && ss_type !== "sing-box" && queryParam.type) || ss_type == "sing-box")) {
967+
} else if (has_singbox && (ss_type == "sing-box" || needUpgrade)) {
952968
dom_prefix = "singbox_"
953969
opt.set('type', "sing-box");
954970
opt.set(dom_prefix + 'protocol', "shadowsocks");
@@ -977,6 +993,7 @@
977993
opt.set(dom_prefix + 'password', password || "");
978994
opt.set(dom_prefix + 'method', method || "");
979995
opt.set(dom_prefix + 'ss_method', method || "");
996+
opt.set(dom_prefix + 'tcp_fast_open', queryParam.tfo);
980997
if (plugin && plugin != "none") {
981998
plugin = (plugin === "simple-obfs") ? "obfs-local" : plugin;
982999
opt.set(dom_prefix + 'plugin_enabled', true);
@@ -1114,6 +1131,8 @@
11141131
opt.set(dom_prefix + 'use_xhttp_extra', !!queryParam.extra);
11151132
opt.set(dom_prefix + 'xhttp_extra', queryParam.extra || "");
11161133
}
1134+
1135+
opt.set(dom_prefix + 'uot', queryParam.udp);
11171136

11181137
if (queryParam["shadow-tls"]) {
11191138
//解析SS Shadow-TLS 插件参数
@@ -1273,6 +1292,8 @@
12731292
opt.set(dom_prefix + 'tls_allowInsecure', false);
12741293
}
12751294

1295+
opt.set(dom_prefix + 'tcp_fast_open', queryParam.tfo);
1296+
12761297
if (m.hash) {
12771298
opt.set('remarks', decodeURIComponent(m.hash.substr(1)));
12781299
}
@@ -1367,6 +1388,8 @@
13671388
} else if (ssm.net === "grpc") {
13681389
opt.set(dom_prefix + 'grpc_serviceName', ssm.path);
13691390
}
1391+
1392+
opt.set(dom_prefix + 'tcp_fast_open', ssm.tfo);
13701393
}
13711394
if (ssu[0] === "vless") {
13721395
if (vless_type == "sing-box" && has_singbox) {
@@ -1518,6 +1541,8 @@
15181541
opt.set(dom_prefix + 'httpupgrade_path', queryParam.path || "");
15191542
}
15201543

1544+
opt.set(dom_prefix + 'tcp_fast_open', queryParam.tfo);
1545+
15211546
if (m.hash) {
15221547
opt.set('remarks', decodeURIComponent(m.hash.substr(1)));
15231548
}
@@ -1697,12 +1722,14 @@
16971722
}
16981723

16991724
document.addEventListener("DOMContentLoaded", function () {
1700-
const fromUrlCache = JSON.parse(sessionStorage.getItem("fromUrl"));
1701-
if (fromUrlCache && fromUrlCache.savetime && (Date.now() - fromUrlCache.timestamp) < fromUrlCache.savetime) {
1702-
fromUrl(null, fromUrlCache.urlname, fromUrlCache.sid, fromUrlCache)
1703-
} else {
1704-
sessionStorage.removeItem("fromUrl");
1705-
}
1725+
setTimeout(function () {
1726+
const fromUrlCache = JSON.parse(sessionStorage.getItem("fromUrl"));
1727+
if (fromUrlCache && fromUrlCache.savetime && (Date.now() - fromUrlCache.timestamp) < fromUrlCache.savetime) {
1728+
fromUrl(null, fromUrlCache.urlname, fromUrlCache.sid, fromUrlCache)
1729+
} else {
1730+
sessionStorage.removeItem("fromUrl");
1731+
}
1732+
}, 500);
17061733
})
17071734

17081735
//]]></script>

luci-app-passwall/root/usr/share/passwall/subscribe.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ local function processData(szType, content, add_mode, group)
620620
result.tls = "0"
621621
end
622622

623+
result.tcp_fast_open = info.tfo
624+
623625
if result.type == "sing-box" and (result.transport == "mkcp" or result.transport == "xhttp") then
624626
log("跳过节点:" .. result.remarks ..",因Sing-Box不支持" .. szType .. "协议的" .. result.transport .. "传输方式,需更换Xray。")
625627
return nil
@@ -723,13 +725,17 @@ local function processData(szType, content, add_mode, group)
723725

724726
result.method = method
725727
result.password = password
728+
result.tcp_fast_open = params.tfo
726729

727-
if has_xray and (result.type ~= 'Xray' and result.type ~= 'sing-box' and params.type) then
728-
result.type = 'Xray'
729-
result.protocol = 'shadowsocks'
730-
elseif has_singbox and (result.type ~= 'Xray' and result.type ~= 'sing-box' and params.type) then
731-
result.type = 'sing-box'
732-
result.protocol = 'shadowsocks'
730+
local need_upgrade = (result.type ~= "Xray" and result.type ~= "sing-box")
731+
and (params.type and params.type ~= "tcp")
732+
and (params.headerType and params.headerType ~= "none")
733+
if has_xray and (need_upgrade or params.type == "xhttp") then
734+
result.type = "Xray"
735+
result.protocol = "shadowsocks"
736+
elseif has_singbox and need_upgrade then
737+
result.type = "sing-box"
738+
result.protocol = "shadowsocks"
733739
end
734740

735741
if result.plugin then
@@ -892,7 +898,8 @@ local function processData(szType, content, add_mode, group)
892898
else
893899
result.tls_allowInsecure = allowInsecure_default and "1" or "0"
894900
end
895-
else
901+
result.uot = params.udp
902+
elseif (params.type ~= "tcp" and params.type ~= "raw") and (params.headerType and params.headerType ~= "none") then
896903
result.error_msg = "请更换Xray或Sing-Box来支持SS更多的传输方式."
897904
end
898905
end
@@ -1091,6 +1098,7 @@ local function processData(szType, content, add_mode, group)
10911098
end
10921099

10931100
result.alpn = params.alpn
1101+
result.tcp_fast_open = params.tfo
10941102

10951103
if result.type == "sing-box" and (result.transport == "mkcp" or result.transport == "xhttp") then
10961104
log("跳过节点:" .. result.remarks ..",因Sing-Box不支持" .. szType .. "协议的" .. result.transport .. "传输方式,需更换Xray。")
@@ -1281,6 +1289,8 @@ local function processData(szType, content, add_mode, group)
12811289
result.tls_allowInsecure = allowInsecure_default and "1" or "0"
12821290
end
12831291

1292+
result.tcp_fast_open = params.tfo
1293+
12841294
if result.type == "sing-box" and (result.transport == "mkcp" or result.transport == "xhttp") then
12851295
log("跳过节点:" .. result.remarks ..",因Sing-Box不支持" .. szType .. "协议的" .. result.transport .. "传输方式,需更换Xray。")
12861296
return nil

0 commit comments

Comments
 (0)