From d84dec809a1f8942d3aa2d1150ad0ccacade77a0 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:29:07 +0800 Subject: [PATCH] luci: import link prefer use sing-box --- .../passwall/node_list/link_share_man.htm | 72 +++++++++++++++---- 1 file changed, 60 insertions(+), 12 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 4c19f26fc..3f31d88df 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 @@ -1,6 +1,7 @@ <%+cbi/valueheader%> <% local api = require "luci.passwall.api" +local has_singbox = api.finded_com("singbox") local has_v2ray = api.finded_com("v2ray") local has_xray = api.finded_com("xray") -%> @@ -149,6 +150,8 @@ local has_xray = api.finded_com("xray") protocol = "hysteria" } else if (v_type === "V2ray" || v_type === "Xray") { dom_prefix = "xray_" + } else if (v_type === "sing-box") { + dom_prefix = "singbox_" } var _address = "" if (dom_prefix && dom_prefix != null) { @@ -236,7 +239,7 @@ local has_xray = api.finded_com("xray") "&protoparam=" + b64encsafe(v_protocol_param.value) + "&remarks=" + b64encutf8safe(v_alias.value); url = b64encsafe(ssr_str); - } else if ((v_type === "V2ray" || v_type === "Xray") && opt.get(dom_prefix + "protocol").value === "vmess") { + } else if ((v_type === "sing-box" || v_type === "V2ray" || v_type === "Xray") && opt.get(dom_prefix + "protocol").value === "vmess") { protocol = "vmess"; var info = {}; info.v = "2"; @@ -281,7 +284,7 @@ local has_xray = api.finded_com("xray") info.sni = opt.get(dom_prefix + "tls_serverName").value; } url = b64EncodeUnicode(JSON.stringify(info)); - } else if ((v_type === "V2ray" || v_type === "Xray") && opt.get(dom_prefix + "protocol").value === "vless") { + } else if ((v_type === "sing-box" || v_type === "V2ray" || v_type === "Xray") && opt.get(dom_prefix + "protocol").value === "vless") { protocol = "vless"; var v_password = opt.get(dom_prefix + "uuid"); var v_port = opt.get(dom_prefix + "port"); @@ -404,7 +407,7 @@ local has_xray = api.finded_com("xray") params = params.substring(1); } url += params; - } else if (((v_type === "V2ray" || v_type === "Xray") && opt.get(dom_prefix + "protocol").value === "trojan")) { + } else if (((v_type === "sing-box" || v_type === "V2ray" || v_type === "Xray") && opt.get(dom_prefix + "protocol").value === "trojan")) { protocol = "trojan"; var v_password = opt.get(dom_prefix + "password"); var v_port = opt.get(dom_prefix + "port"); @@ -629,7 +632,6 @@ local has_xray = api.finded_com("xray") opt.set('remarks', b64decutf8safe(rem)); } if (ssu[0] === "ss") { - dom_prefix = "ss_" var url0 = "", param = ""; var sipIndex = ssu[1].indexOf("@"); var ploc = ssu[1].indexOf("#"); @@ -660,10 +662,27 @@ local has_xray = api.finded_com("xray") password = userInfo.substr(userInfoSplitIndex + 1); } if (["2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305"].includes(method)) { + <% if has_singbox then %> + opt.set('type', "sing-box"); + dom_prefix = "singbox_" + <% elseif has_xray then %> + opt.set('type', "Xray"); + dom_prefix = "xray_" + <% else %> opt.set('type', "SS-Rust"); dom_prefix = "ssrust_" + <% end %> } else { + <% if has_singbox then %> + opt.set('type', "sing-box"); + dom_prefix = "singbox_" + <% elseif has_xray then %> + opt.set('type', "Xray"); + dom_prefix = "xray_" + <% else %> opt.set('type', "SS"); + dom_prefix = "ss_" + <% end %> } opt.set(dom_prefix + 'address', server); opt.set(dom_prefix + 'port', port); @@ -677,9 +696,18 @@ local has_xray = api.finded_com("xray") opt.set('remarks', decodeURI(param)); } } else { + <% if has_singbox then %> + opt.set('type', "sing-box"); + dom_prefix = "singbox_" + <% elseif has_xray then %> + opt.set('type', "Xray"); + dom_prefix = "xray_" + <% else %> + opt.set('type', "SS"); + dom_prefix = "ss_" + <% end %> var sstr = b64decsafe(url0); var team = sstr.split('@'); - opt.set('type', "SS"); var part1 = team[0].split(':'); var part2 = team[1].split(':'); opt.set(dom_prefix + 'address', part2[0]); @@ -694,7 +722,16 @@ local has_xray = api.finded_com("xray") } } if (ssu[0] === "trojan" || ssu[0] === "trojan-plus") { + <% if has_singbox then %> + opt.set('type', "sing-box"); + dom_prefix = "singbox_" + <% elseif has_xray then %> + opt.set('type', "Xray"); + dom_prefix = "xray_" + <% else %> + opt.set('type', "Trojan-Plus"); dom_prefix = "trojan_plus_" + <% end %> var m = parseNodeUrl(ssrurl); var password = m.passwd; if (password === "") { @@ -715,7 +752,6 @@ local has_xray = api.finded_com("xray") if (queryParam.mux || queryParam.ws || queryParam.h2 || queryParam.ss || queryParam.plugin) { ssu[0] = "trojan-go" } - opt.set('type', "Trojan-Plus"); opt.set(dom_prefix + 'address', m.hostname); opt.set(dom_prefix + 'port', m.port || "443"); opt.set(dom_prefix + 'password', decodeURIComponent(password)); @@ -801,13 +837,17 @@ local has_xray = api.finded_com("xray") } } if (ssu[0] === "vmess") { - dom_prefix = "xray_" var sstr = b64DecodeUnicode(ssu[1]); var ploc = sstr.indexOf("/?"); - <% if has_v2ray then %> + <% if has_singbox then %> + opt.set('type', "sing-box"); + dom_prefix = "singbox_" + <% elseif has_v2ray then %> opt.set('type', "V2ray"); + dom_prefix = "xray_" <% elseif has_xray then %> opt.set('type', "Xray"); + dom_prefix = "xray_" <% end %> opt.set(dom_prefix + 'protocol', "vmess"); var url0, param = ""; @@ -854,11 +894,15 @@ local has_xray = api.finded_com("xray") } } if (ssu[0] === "vless") { - dom_prefix = "xray_" - <% if has_xray then %> + <% if has_singbox then %> + opt.set('type', "sing-box"); + dom_prefix = "singbox_" + <% elseif has_xray then %> opt.set('type', "Xray"); + dom_prefix = "xray_" <% elseif has_v2ray then %> opt.set('type', "V2ray"); + dom_prefix = "xray_" <% end %> opt.set(dom_prefix + 'protocol', "vless"); var m = parseNodeUrl(ssrurl); @@ -1003,8 +1047,13 @@ local has_xray = api.finded_com("xray") } } if (ssu[0] === "hysteria") { + <% if has_singbox then %> + opt.set('type', "sing-box"); + dom_prefix = "singbox_" + <% else %> + opt.set('type', "Hysteria"); dom_prefix = "hysteria_" - var stype = "Hysteria"; + <% end %> var m = parseNodeUrl(ssrurl); var queryParam = {}; if (m.search.length > 1) { @@ -1017,7 +1066,6 @@ local has_xray = api.finded_com("xray") queryParam[decodeURIComponent(params[0])] = decodeURIComponent(params[1] || ''); } } - opt.set('type', stype); opt.set(dom_prefix + 'address', m.hostname); opt.set(dom_prefix + 'port', m.port || "443"); opt.set(dom_prefix + 'protocol', queryParam.protocol);