From 37d5760db16a5ec3ceb95c7b8b723303b4439ed5 Mon Sep 17 00:00:00 2001 From: zxl hhyccc <45259624+zxlhhyccc@users.noreply.github.com> Date: Sat, 21 Dec 2024 19:50:30 +0800 Subject: [PATCH 1/2] luci-app-ssr-plus: ssrurl.htm: Fix Xray's `trojan` protocol configuration import issue. --- .../luasrc/view/shadowsocksr/ssrurl.htm | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm b/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm index f3d9f15ae72..f4f09e05b23 100644 --- a/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm +++ b/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm @@ -218,7 +218,7 @@ try { var url = new URL("http://" + ssu[1]); } catch(e) { - alert(e) + alert(e); return false; } @@ -230,9 +230,70 @@ document.getElementsByName('cbid.shadowsocksr.' + sid + '.server')[0].value = url.hostname; document.getElementsByName('cbid.shadowsocksr.' + sid + '.server_port')[0].value = url.port || "80"; document.getElementsByName('cbid.shadowsocksr.' + sid + '.password')[0].value = decodeURIComponent(url.username); - document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls')[0].checked = true; - document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls')[0].dispatchEvent(event); - document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls_host')[0].value = url.searchParams.get("sni"); + if (params.get("security") === "tls") { + document.getElementsByName('cbid.shadowsocksr.' + sid + '.' + params.get("security"))[0].checked = true; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.' + params.get("security"))[0].dispatchEvent(event); + + if (params.get("allowInsecure") === "1") { + document.getElementsByName('cbid.shadowsocksr.' + sid + '.insecure')[0].checked = true; // 设置 insecure 为 true + document.getElementsByName('cbid.shadowsocksr.' + sid + '.insecure')[0].dispatchEvent(event); // 触发事件 + } + document.getElementsByName('cbid.shadowsocksr.' + sid + '.fingerprint')[0].value = params.get("fp") || ""; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls_host')[0].value = params.get("sni") || ""; + } + document.getElementsByName('cbid.shadowsocksr.' + sid + '.transport')[0].value = + params.get("type") == "http" ? "h2" : + (["tcp", "raw"].includes(params.get("type")) ? "raw" : + (params.get("type") || "tcp")); + document.getElementsByName('cbid.shadowsocksr.' + sid + '.transport')[0].dispatchEvent(event); + switch (params.get("type")) { + case "ws": + if (params.get("security") !== "tls") { + setElementValue('cbid.shadowsocksr.' + sid + '.ws_host', params.get("host") ? decodeURIComponent(params.get("host")) : ""); + } + setElementValue('cbid.shadowsocksr.' + sid + '.ws_path', params.get("path") ? decodeURIComponent(params.get("path")) : "/"); + break; + case "httpupgrade": + if (params.get("security") !== "tls") { + document.getElementsByName('cbid.shadowsocksr.' + sid + '.httpupgrade_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : ""; + } + document.getElementsByName('cbid.shadowsocksr.' + sid + '.httpupgrade_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : "/"; + break; + case "splithttp": + if (params.get("security") !== "tls") { + document.getElementsByName('cbid.shadowsocksr.' + sid + '.splithttp_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : ""; + } + document.getElementsByName('cbid.shadowsocksr.' + sid + '.splithttp_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : "/"; + break; + case "kcp": + document.getElementsByName('cbid.shadowsocksr.' + sid + '.kcp_guise')[0].value = params.get("headerType") || "none"; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.seed')[0].value = params.get("seed") || ""; + break; + case "http": + /* this is non-standard, bullshit */ + case "h2": + document.getElementsByName('cbid.shadowsocksr.' + sid + '.h2_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : ""; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.h2_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : ""; + break; + case "quic": + document.getElementsByName('cbid.shadowsocksr.' + sid + '.quic_guise')[0].value = params.get("headerType") || "none"; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.quic_security')[0].value = params.get("quicSecurity") || "none"; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.quic_key')[0].value = params.get("key") || ""; + break; + case "grpc": + document.getElementsByName('cbid.shadowsocksr.' + sid + '.serviceName')[0].value = params.get("serviceName") || ""; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.grpc_mode')[0].value = params.get("mode") || "gun"; + break; + case "raw": + case "tcp": + document.getElementsByName('cbid.shadowsocksr.' + sid + '.tcp_guise')[0].value = params.get("headerType") || "none"; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.tcp_guise')[0].dispatchEvent(event); + if (params.get("headerType") === "http") { + document.getElementsByName('cbid.shadowsocksr.' + sid + '.http_host')[0].value = params.get("host") ? decodeURIComponent(params.get("host")) : ""; + document.getElementsByName('cbid.shadowsocksr.' + sid + '.http_path')[0].value = params.get("path") ? decodeURIComponent(params.get("path")) : ""; + } + break; + } s.innerHTML = "<%:Import configuration information successfully.%>"; return false; @@ -306,7 +367,7 @@ var url = new URL("http://" + ssu[1]); var params = url.searchParams; } catch(e) { - alert(e) + alert(e); return false; } // Check if the elements exist before trying to modify them From 0e3f5c18e5489080c7351337871c0437de0314a5 Mon Sep 17 00:00:00 2001 From: zxl hhyccc <45259624+zxlhhyccc@users.noreply.github.com> Date: Sat, 21 Dec 2024 19:54:46 +0800 Subject: [PATCH 2/2] luci-app-ssr-plus: ssrurl.htm: Fix Xray's `trojan` protocol configuration import issue. --- luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm | 1 + 1 file changed, 1 insertion(+) diff --git a/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm b/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm index f4f09e05b23..09576525d40 100644 --- a/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm +++ b/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm @@ -217,6 +217,7 @@ case "trojan": try { var url = new URL("http://" + ssu[1]); + var params = url.searchParams; } catch(e) { alert(e); return false;