luci: import link prefer use sing-box

This commit is contained in:
xiaorouji 2023-09-06 16:29:07 +08:00 committed by sbwml
parent 3cbdd15b50
commit d84dec809a

View File

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