From b50cc11affeb71684255ed7236f1c54e87eb8636 Mon Sep 17 00:00:00 2001 From: zxlhhyccc Date: Wed, 21 Jan 2026 22:37:10 +0800 Subject: [PATCH] luci-app-ssr-plus: Add Xray Hysteria2 protocol configuration import and subscribe. --- .../model/cbi/shadowsocksr/client-config.lua | 51 +- .../luasrc/model/cbi/shadowsocksr/servers.lua | 51 +- .../luasrc/view/shadowsocksr/ssrurl.htm | 35 +- luci-app-ssr-plus/po/templates/ssr-plus.pot | 720 ++++++++--------- luci-app-ssr-plus/po/zh_Hans/ssr-plus.po | 723 +++++++++--------- .../root/etc/uci-defaults/luci-ssr-plus | 8 + .../share/shadowsocksr/shadowsocksr.config | 2 + .../root/usr/share/shadowsocksr/subscribe.lua | 54 +- 8 files changed, 907 insertions(+), 737 deletions(-) diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua index d4789e3d..b05e9662 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua @@ -141,6 +141,12 @@ local function set_apply_on_parse(map) end end +local has_xray = is_finded("xray") +local has_hysteria2 = is_finded("hysteria") + +-- 读取当前存储的 xray_hy2_type +local xray_hy2_type = uci:get_first("shadowsocksr", "server_subscribe", "xray_hy2_type") + local has_ss_rust = is_finded("sslocal") or is_finded("ssserver") local has_ss_libev = is_finded("ss-redir") or is_finded("ss-local") @@ -269,6 +275,43 @@ o.rawhtml = true o.template = "shadowsocksr/ssrurl" o.value = sid +-- 新增一个选择框,用于选择 Xray 或 Hysteria2 核心 +o = s:option(ListValue, "xray_hy2_type", string.format("%s", translatef("%s Node Use Type", "Hysteria2"))) +o.description = translate("The configured type also applies to the core specified when manually importing nodes.") +-- 设置默认 Xray 或 Hysteria2 核心 +-- 动态添加选项 +if has_xray then + o:value("xray", translate("Xray")) +end +if has_hysteria2 then + o:value("hysteria2", translate("Hysteria2")) +end +-- 设置默认值 +if xray_hy2_type == "xray" then + o.default = "xray" +elseif xray_hy2_type == "hysteria2" then + o.default = "hysteria2" +end +o.write = function(self, section, value) + -- 更新 Hysteria 节点的 xray_hy2_type + uci:foreach("shadowsocksr", "servers", function(s) + local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型 + if node_type == "hysteria2" then -- 仅修改 Hysteria 节点 + local old_value = uci:get("shadowsocksr", s[".name"], "xray_hy2_type") + if old_value ~= value then + uci:set("shadowsocksr", s[".name"], "xray_hy2_type", value) + end + end + end) + -- 更新 server_subscribe 的 xray_hy2_type + local old_value = uci:get("shadowsocksr", "server_subscribe", "xray_hy2_type") + if old_value ~= value then + uci:set("shadowsocksr", "@server_subscribe[0]", "xray_hy2_type", value) + end + -- 更新当前 section 的 xray_hy2_type + ListValue.write(self, section, value) +end + o = s:option(ListValue, "type", translate("Server Node Type")) if is_finded("xray") or is_finded("v2ray") then o:value("v2ray", translate("V2Ray/XRay")) @@ -315,7 +358,7 @@ o:depends("type", "tun") o.description = translate("Redirect traffic to this network interface") -- 新增一个选择框,用于选择 Shadowsocks 版本 -o = s:option(ListValue, "has_ss_type", string.format("%s", translate("ShadowSocks Node Use Version"))) +o = s:option(ListValue, "has_ss_type", string.format("%s", translatef("%s Node Use Version", "ShadowSocks"))) o.description = translate("Selection ShadowSocks Node Use Version.") -- 设置默认 Shadowsocks 版本 -- 动态添加选项 @@ -343,15 +386,13 @@ o.write = function(self, section, value) end end end) - -- 更新 server_subscribe 的 ss_type local old_value = uci:get("shadowsocksr", "server_subscribe", "ss_type") if old_value ~= value then uci:set("shadowsocksr", "@server_subscribe[0]", "ss_type", value) end - -- 更新当前 section 的 has_ss_type - Value.write(self, section, value) + ListValue.write(self, section, value) end o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol")) @@ -363,7 +404,7 @@ if is_finded("xray") then o:value("wireguard", translate("WireGuard")) end if is_finded("xray") then - o:value("hysteria2", translate("hysteria2")) + o:value("hysteria2", translate("Hysteria2")) end o:value("socks", translate("Socks")) o:value("http", translate("HTTP")) diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua index bc464d57..5303655a 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua @@ -39,6 +39,27 @@ local function optimize_cbi_ui() ]]) end +local has_xray = is_finded("xray") +local has_hysteria2 = is_finded("hysteria") + +local hy2_type_list = {} + +if has_xray then + table.insert(hy2_type_list, { id = "xray", name = translate("Xray") }) +end +if has_hysteria2 then + table.insert(hy2_type_list, { id = "hysteria2", name = translate("Hysteria2") }) +end + +-- 如果用户没有手动设置,则自动选择 +if not xray_hy2_type or xray_hy2_type == "" then + if has_hysteria2 then + xray_hy2_type = "hysteria2" + elseif has_xray then + xray_hy2_type = "xray" + end +end + local has_ss_rust = is_finded("sslocal") or is_finded("ssserver") local has_ss_libev = is_finded("ss-redir") or is_finded("ss-local") @@ -52,7 +73,7 @@ if has_ss_libev then end -- 如果用户没有手动设置,则自动选择 -if ss_type == "" then +if not ss_type or ss_type == "" then if has_ss_rust then ss_type = "ss-rust" elseif has_ss_libev then @@ -103,9 +124,33 @@ o.default = 30 o.rmempty = true o:depends("auto_update", "1") +-- 确保 hy2_type_list 不为空 +if #hy2_type_list > 0 then + o = s:option(ListValue, "xray_hy2_type", string.format("%s", translatef("%s Node Use Type", "Hysteria2"))) + o.description = translate("The configured type also applies to the core specified when manually importing nodes.") + for _, v in ipairs(hy2_type_list) do + o:value(v.id, v.name) -- 存储 "Xray" / "Hysteria2",但 UI 显示完整名称 + end + o.default = xray_hy2_type -- 设置默认值 + o.write = function(self, section, value) + -- 更新 Hysteria 节点的 xray_hy2_type + uci:foreach("shadowsocksr", "servers", function(s) + local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型 + if node_type == "hysteria2" then -- 仅修改 Hysteria 节点 + local old_value = uci:get("shadowsocksr", s[".name"], "xray_hy2_type") + if old_value ~= value then + uci:set("shadowsocksr", s[".name"], "xray_hy2_type", value) + end + end + end) + -- 更新当前 section 的 xray_hy2_type + ListValue.write(self, section, value) + end +end + -- 确保 ss_type_list 不为空 if #ss_type_list > 0 then - o = s:option(ListValue, "ss_type", string.format("%s", translate("ShadowSocks Node Use Version"))) + o = s:option(ListValue, "ss_type", string.format("%s", translatef("%s Node Use Version", "ShadowSocks"))) o.description = translate("Selection ShadowSocks Node Use Version.") for _, v in ipairs(ss_type_list) do o:value(v.id, v.name) -- 存储 "ss-libev" / "ss-rust",但 UI 显示完整名称 @@ -123,7 +168,7 @@ if #ss_type_list > 0 then end end) -- 更新当前 section 的 ss_type - Value.write(self, section, value) + ListValue.write(self, section, value) end end diff --git a/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm b/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm index 1758b6fd..b1365614 100644 --- a/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm +++ b/luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm @@ -2,10 +2,12 @@ <% local map = self.map local ss_type = map:get("@server_subscribe[0]", "ss_type") +local xray_hy2_type = map:get("@server_subscribe[0]", "xray_hy2_type") -%>