luci-app-ssr-plus: add snell proxy support with mihomo

This commit is contained in:
coolsnowwolf committed 2026-06-21 14:49:38 +08:00
1 parent e843b4a577
commit da77b44774
6 files changed
+117 -3

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ LUCI_TITLE:=luci-app-ssr-plus
LUCI_PKGARCH:=all
PKG_NAME:=luci-app-ssr-plus
PKG_VERSION:=195
PKG_RELEASE:=3
PKG_RELEASE:=5
PKG_CONFIG_DEPENDS:= \
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \
@@ -417,6 +417,9 @@ end
if is_finded("xray") then
o:value("hysteria2", translate("Hysteria2"))
end
if is_finded("mihomo") then
o:value("snell", translate("Snell"))
end
o:value("socks", translate("Socks"))
o:value("http", translate("HTTP"))
o:depends("type", "v2ray")
@@ -500,6 +503,11 @@ o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", auth_enabl
o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
o:depends({type = "v2ray", v2ray_protocol = "trojan"})
o = s:option(Value, "snell_psk", translate("Snell PSK"))
o.password = true
o.rmempty = true
o:depends({type = "v2ray", v2ray_protocol = "snell"})
o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
for _, v in ipairs(encrypt_methods) do
o:value(v)
@@ -946,6 +954,28 @@ o.rmempty = true
o.default = "5"
o:depends({type = "v2ray", v2ray_protocol = "socks"})
o = s:option(ListValue, "snell_version", translate("Snell Version"))
o:value("1", "v1")
o:value("2", "v2")
o:value("3", "v3")
o:value("4", "v4")
o:value("5", "v5")
o.default = "4"
o.rmempty = true
o:depends({type = "v2ray", v2ray_protocol = "snell"})
o = s:option(ListValue, "snell_obfs", translate("Snell Obfs"))
o:value("", translate("Disable"))
o:value("http", "HTTP")
o:value("tls", "TLS")
o.default = ""
o.rmempty = true
o:depends({type = "v2ray", v2ray_protocol = "snell"})
o = s:option(Value, "snell_obfs_host", translate("Snell Obfs Host"))
o.rmempty = true
o:depends({type = "v2ray", v2ray_protocol = "snell"})
-- 传输协议
o = s:option(ListValue, "transport", translate("Transport"))
o:value("raw", "RAW (TCP)")
@@ -115,6 +115,31 @@ function import_ssr_url(btn, urlname, sid) {
var event = document.createEvent("HTMLEvents");
event.initEvent("change", true, true);
switch (ssu[0]) {
case "snell":
if (has_mihomo !== "true") {
s.innerHTML = "<font style=\'color:red\'><%:No available Mihomo core to import this Snell node.%></font>";
return false;
}
try {
var url = new URL("http://" + ssu[1]);
var params = url.searchParams;
} catch(e) {
alert(e);
return false;
}
document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].value = "v2ray";
document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].dispatchEvent(event);
document.getElementsByName('cbid.shadowsocksr.' + sid + '.v2ray_protocol')[0].value = "snell";
document.getElementsByName('cbid.shadowsocksr.' + sid + '.v2ray_protocol')[0].dispatchEvent(event);
document.getElementsByName('cbid.shadowsocksr.' + sid + '.server')[0].value = normalizeHost(url.hostname);
document.getElementsByName('cbid.shadowsocksr.' + sid + '.server_port')[0].value = url.port;
document.getElementsByName('cbid.shadowsocksr.' + sid + '.snell_psk')[0].value = decodeURIComponent(url.username || params.get("psk") || params.get("password") || "");
document.getElementsByName('cbid.shadowsocksr.' + sid + '.snell_version')[0].value = params.get("version") || params.get("v") || "4";
document.getElementsByName('cbid.shadowsocksr.' + sid + '.snell_obfs')[0].value = params.get("obfs") || params.get("obfs-mode") || params.get("obfs_mode") || "";
document.getElementsByName('cbid.shadowsocksr.' + sid + '.snell_obfs_host')[0].value = params.get("obfs-host") || params.get("obfs_host") || params.get("host") || "";
document.getElementsByName('cbid.shadowsocksr.' + sid + '.alias')[0].value = url.hash ? decodeURIComponent(url.hash.slice(1)) : "";
s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
return false;
case "hysteria2":
case "hy2":
try {
@@ -214,7 +214,7 @@ is_builtin_dns_active() {
ps_list | grep -v "grep" | grep -q "ssr-retcp"
;;
v2ray)
ps_list | grep -v "grep" | grep -q "$TMP_PATH/.*ssr-retcp\\.json"
ps_list | grep -v "grep" | grep -Eq "$TMP_PATH/.*ssr-retcp\\.(json|yaml)"
;;
*)
return 1
@@ -1524,6 +1524,9 @@ start_local() {
[ -n "$probe_instance_key" ] && instance_key="$probe_instance_key"
if start_v2ray_with_mihomo "$LOCAL_SERVER" "$local_port" "$local_port" "$instance_key" "socks" "v2ray-local" "Global_Socks5"; then
:
elif [ "$(uci_get_by_name "$LOCAL_SERVER" v2ray_protocol)" = "snell" ]; then
echolog "Global_Socks5:Snell 需要 Mihomo 内核,且当前 Mihomo 启动失败。"
return 1
elif [ "$_local" == "2" ]; then
gen_config_file $LOCAL_SERVER $type 4 0 $local_port
ln_start_bin $(first_type xray) v2ray run -c $local_config_file
@@ -1868,6 +1871,9 @@ Start_Run() {
v2ray)
if start_v2ray_with_mihomo "$GLOBAL_SERVER" "$tcp_port" "$socks_port" "$GLOBAL_SERVER" "redir" "ssr-retcp" "Main node"; then
:
elif [ "$(uci_get_by_name "$GLOBAL_SERVER" v2ray_protocol)" = "snell" ]; then
echolog "Main node:Snell 需要 Mihomo 内核,且当前 Mihomo 启动失败。"
return 1
else
gen_config_file $GLOBAL_SERVER $type 1 $tcp_port $socks_port
ln_start_bin $(first_type xray) v2ray run -c $tcp_config_file
@@ -884,6 +884,18 @@ local function build_v2ray_mihomo_proxy(sid)
proxy.reserved = parse_wireguard_reserved(sid)
proxy["persistent-keepalive"] = number_or_nil(get_server_field(sid, "keepaliveperiod", ""))
proxy.mtu = number_or_nil(get_server_field(sid, "mtu", ""))
elseif protocol == "snell" then
proxy.type = "snell"
proxy.psk = get_server_field(sid, "snell_psk", "")
proxy.version = number_or_nil(get_server_field(sid, "snell_version", ""))
local obfs_mode = string_or_nil(get_server_field(sid, "snell_obfs", ""))
local obfs_host = string_or_nil(get_server_field(sid, "snell_obfs_host", ""))
if obfs_mode or obfs_host then
proxy["obfs-opts"] = {
mode = obfs_mode,
host = obfs_host
}
end
else
return nil
end
@@ -891,6 +903,9 @@ local function build_v2ray_mihomo_proxy(sid)
if not proxy.server or proxy.server == "" or not proxy.port or proxy.port == 0 then
return nil
end
if proxy.type == "snell" and (not proxy.psk or proxy.psk == "") then
return nil
end
return proxy
end
@@ -761,6 +761,18 @@ local function to_mihomo_proxy(node)
proxy.sni = string_from_value(node.tls_host)
proxy["client-fingerprint"] = string_from_value(node.fingerprint)
proxy["skip-cert-verify"] = bool_from_flag(node.insecure)
elseif node.type == "v2ray" and node.v2ray_protocol == "snell" then
proxy.type = "snell"
proxy.psk = node.snell_psk
proxy.version = tonumber(node.snell_version) or nil
local obfs_mode = string_from_value(node.snell_obfs)
local obfs_host = string_from_value(node.snell_obfs_host)
if obfs_mode or obfs_host then
proxy["obfs-opts"] = {
mode = obfs_mode,
host = obfs_host
}
end
else
return nil
end
@@ -786,6 +798,7 @@ local function can_group_into_mihomo(node)
or node.v2ray_protocol == "trojan"
or node.v2ray_protocol == "hysteria2"
or node.v2ray_protocol == "hy2"
or node.v2ray_protocol == "snell"
) then
return true
end
@@ -933,6 +946,30 @@ local function processData(szType, content, cfgid)
-- 处理 fast open 参数
result.fast_open = params.tfo
end
elseif szType == "snell" then
if not has_mihomo then
log("跳过 Snell 节点:本地未安装 mihomo。")
return nil
end
local url = URL.parse("http://" .. content)
local params = url.query or {}
local raw_alias = url.fragment and UrlDecode(url.fragment) or nil
local psk = url.user and UrlDecode(url.user) or first_nonempty(params, {"psk", "password"})
result.type = "v2ray"
result.v2ray_protocol = "snell"
result.raw_alias = raw_alias
result.alias = raw_alias
result.server = normalize_host(url.host)
result.server_port = url.port
result.snell_psk = psk
result.snell_version = first_nonempty(params, {"version", "v"}) or "4"
result.snell_obfs = first_nonempty(params, {"obfs", "obfs-mode", "obfs_mode"})
result.snell_obfs_host = first_nonempty(params, {"obfs-host", "obfs_host", "host"})
if not result.snell_psk or result.snell_psk == "" then
result.server = nil
end
elseif szType == 'ssr' then
-- 去掉前后空白和#注释
local link = trim(content:gsub("#.*$", ""))
@@ -2307,6 +2344,7 @@ local function is_mihomo_subscribe_node(section)
or section.v2ray_protocol == "trojan"
or section.v2ray_protocol == "hysteria2"
or section.v2ray_protocol == "hy2"
or section.v2ray_protocol == "snell"
) then
return true
end
@@ -2497,7 +2535,7 @@ local execute = function()
if dat[3] then
dat3 = "://" .. dat[3]
end
if dat[1] == 'ss' or dat[1] == 'trojan' or dat[1] == 'tuic' then
if dat[1] == 'ss' or dat[1] == 'trojan' or dat[1] == 'tuic' or dat[1] == 'snell' then
result = processData(dat[1], dat[2] .. dat3)
else
result = processData(dat[1], base64Decode(dat[2]))