Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 78 additions & 75 deletions luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local m, s, o
local sid = arg[1]
local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid")
local xray_version = nil
local xray_version_val = 0

-- 确保正确判断程序是否存在
local function is_finded(e)
Expand All @@ -25,16 +26,28 @@ end

-- 获取 Xray 版本号
if is_finded("xray") then
local version = luci.sys.exec("xray version 2>&1")
if version and version ~= "" then
xray_version = version:match("Xray%s+([%d%.]+)")
end
local version = luci.sys.exec("xray version 2>&1")
if version and version ~= "" then
xray_version = version:match("Xray%s+([%d%.]+)")
end
end

-- 将 Xray 版本号转换为数字
if xray_version and xray_version ~= "" then
local major, minor, patch =
xray_version:match("(%d+)%.?(%d*)%.?(%d*)")

major = tonumber(major) or 0
minor = tonumber(minor) or 0
patch = tonumber(patch) or 0

xray_version_val = major * 10000 + minor * 100 + patch
end

-- 默认的保存并应用行为
local function apply_redirect(m)
local tmp_uci_file = "/etc/config/" .. "shadowsocksr" .. "_redirect"
if m.redirect and m.redirect ~= "" then
local tmp_uci_file = "/etc/config/" .. "shadowsocksr" .. "_redirect"
if m.redirect and m.redirect ~= "" then
if nixio.fs.access(tmp_uci_file) then
local redirect
for line in io.lines(tmp_uci_file) do
Expand All @@ -54,9 +67,9 @@ local function apply_redirect(m)
uci:set("shadowsocksr" .. "_redirect", "@redirect[0]", "url", redirect)
end
end
else
else
luci.sys.call("/bin/rm -f " .. tmp_uci_file)
end
end
end

local has_xray = is_finded("xray")
Expand Down Expand Up @@ -199,35 +212,35 @@ o.description = translate("The configured type also applies to the core specifie
-- 设置默认 Xray 或 Hysteria2 核心
-- 动态添加选项
if has_xray then
o:value("xray", translate("Xray"))
o:value("xray", translate("Xray"))
end
if has_hysteria2 then
o:value("hysteria2", translate("Hysteria2"))
o:value("hysteria2", translate("Hysteria2"))
end
-- 设置默认值
if xray_hy2_type == "xray" then
o.default = "xray"
o.default = "xray"
elseif xray_hy2_type == "hysteria2" then
o.default = "hysteria2"
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
-- 更新 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
-- 更新当前 section 的 xray_hy2_type
ListValue.write(self, section, value)
end

o = s:option(ListValue, "type", translate("Server Node Type"))
Expand Down Expand Up @@ -281,36 +294,36 @@ o.description = translate("Selection ShadowSocks Node Use Version.")
-- 设置默认 Shadowsocks 版本
-- 动态添加选项
if has_ss_rust then
o:value("ss-rust", translate("ShadowSocks-rust Version"))
o:value("ss-rust", translate("ShadowSocks-rust Version"))
end
if has_ss_libev then
o:value("ss-libev", translate("ShadowSocks-libev Version"))
o:value("ss-libev", translate("ShadowSocks-libev Version"))
end
-- 设置默认值
if ss_type == "ss-rust" then
o.default = "ss-rust"
o.default = "ss-rust"
elseif ss_type == "ss-libev" then
o.default = "ss-libev"
o.default = "ss-libev"
end
o:depends("type", "ss")
o.write = function(self, section, value)
-- 更新 Shadowsocks 节点的 has_ss_type
uci:foreach("shadowsocksr", "servers", function(s)
local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型
if node_type == "ss" then -- 仅修改 Shadowsocks 节点
local old_value = uci:get("shadowsocksr", s[".name"], "has_ss_type")
if old_value ~= value then
uci:set("shadowsocksr", s[".name"], "has_ss_type", 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
ListValue.write(self, section, value)
-- 更新 Shadowsocks 节点的 has_ss_type
uci:foreach("shadowsocksr", "servers", function(s)
local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型
if node_type == "ss" then -- 仅修改 Shadowsocks 节点
local old_value = uci:get("shadowsocksr", s[".name"], "has_ss_type")
if old_value ~= value then
uci:set("shadowsocksr", s[".name"], "has_ss_type", 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
ListValue.write(self, section, value)
end

o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol"))
Expand Down Expand Up @@ -1279,39 +1292,29 @@ o:depends("type", "hysteria2")
o:depends("type", "trojan")
o:depends("type", "tuic")
o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
-- Xray 的26.1.31 以下版本使用
if xray_version and xray_version ~= "" then
-- 提取所有数字部分,允许版本号有1到3个部分,不足部分补0
local major, minor, patch =
xray_version:match("(%d+)%.?(%d*)%.?(%d*)")
-- 将字符串转换为数字,空字符串转为0
major = tonumber(major) or 0
minor = tonumber(minor) or 0
patch = tonumber(patch) or 0
-- 如果版本低于 26.1.31
if (major * 10000 + minor * 100 + patch) < 260131 then
o:depends("tls", true)
o:depends({ type = "v2ray", v2ray_protocol = "vless", reality = true })
end
-- Xray 版本判断
if xray_version_val < 260131 then
-- Xray 版本小于 26.1.31
o:depends("tls", true)
o:depends({ type = "v2ray", v2ray_protocol = "vless", reality = true })
else
-- Xray 版本大于等于 26.1.31
-- [[ Xray TLS pinSHA256 ]] --
o = s:option(Value, "tls_CertSha", translate("TLS Chain Fingerprint (SHA256)"), translate("Once set, connects only when the server’s chain fingerprint matches."))
o.rmempty = true
o:depends({type = "v2ray", tls = true})

-- [[ Xray TLS verify leaf certificate name ]] --
o = s:option(Value, "tls_CertByName", translate("TLS Certificate Name (CertName)"), translate("TLS is used to verify the leaf certificate name."))
o.rmempty = true
o:depends({type = "v2ray", tls = true})
end

-- [[ Hysteria2 TLS pinSHA256 ]] --
o = s:option(Value, "pinsha256", translate("Certificate fingerprint"))
o:depends("type", "hysteria2")
o.rmempty = true

-- [[ Xray TLS pinSHA256 ]] --
o = s:option(Value, "chain_fingerprint", translate("TLS Chain Fingerprint (SHA256)"), translate("Once set, connects only when the server’s chain fingerprint matches."))
o.rmempty = true
o:depends({type = "v2ray", tls = true})
o:depends({type = "v2ray", reality = true})

-- [[ Xray TLS verify leaf certificate name ]] --
o = s:option(Value, "verify_name", translate("TLS Certificate Name (CertName)"), translate("TLS is used to verify the leaf certificate name."))
o.rmempty = true
o:depends({type = "v2ray", tls = true})
o:depends({type = "v2ray", reality = true})

-- [[ Mux.Cool ]] --
o = s:option(Flag, "mux", translate("Mux"), translate("Enable Mux.Cool"))
o.rmempty = false
Expand Down
110 changes: 55 additions & 55 deletions luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local server_count = 0

-- 确保正确判断程序是否存在
local function is_finded(e)
return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= ""
return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= ""
end

local has_xray = is_finded("xray")
Expand All @@ -21,19 +21,19 @@ local has_hysteria2 = is_finded("hysteria")
local hy2_type_list = {}

if has_xray then
table.insert(hy2_type_list, { id = "xray", name = translate("Xray") })
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") })
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
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")
Expand All @@ -42,19 +42,19 @@ local has_ss_libev = is_finded("ss-redir") or is_finded("ss-local")
local ss_type_list = {}

if has_ss_rust then
table.insert(ss_type_list, { id = "ss-rust", name = translate("ShadowSocks-rust Version") })
table.insert(ss_type_list, { id = "ss-rust", name = translate("ShadowSocks-rust Version") })
end
if has_ss_libev then
table.insert(ss_type_list, { id = "ss-libev", name = translate("ShadowSocks-libev Version") })
table.insert(ss_type_list, { id = "ss-libev", name = translate("ShadowSocks-libev Version") })
end

-- 如果用户没有手动设置,则自动选择
if not ss_type or ss_type == "" then
if has_ss_rust then
ss_type = "ss-rust"
elseif has_ss_libev then
ss_type = "ss-libev"
end
if has_ss_rust then
ss_type = "ss-rust"
elseif has_ss_libev then
ss_type = "ss-libev"
end
end

uci:foreach("shadowsocksr", "servers", function(s)
Expand Down Expand Up @@ -94,58 +94,58 @@ o:depends("auto_update", "1")

o = s:option(ListValue, "auto_update_min_time", translate("Regular update (Min)"))
for i = 0, 59 do
o:value(i, i .. ":00")
o:value(i, i .. ":00")
end
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("<b><span style='color:red;'>%s</span></b>", translatef("%s Node Use Type", "Hysteria2")))
o = s:option(ListValue, "xray_hy2_type", string.format("<b><span style='color:red;'>%s</span></b>", 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
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("<b><span style='color:red;'>%s</span></b>", 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 显示完整名称
end
o.default = ss_type -- 设置默认值
o.write = function(self, section, value)
-- 更新 Shadowsocks 节点的 has_ss_type
uci:foreach("shadowsocksr", "servers", function(s)
local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型
if node_type == "ss" then -- 仅修改 Shadowsocks 节点
local old_value = uci:get("shadowsocksr", s[".name"], "has_ss_type")
if old_value ~= value then
uci:set("shadowsocksr", s[".name"], "has_ss_type", value)
end
end
end)
-- 更新当前 section 的 ss_type
ListValue.write(self, section, value)
end
o = s:option(ListValue, "ss_type", string.format("<b><span style='color:red;'>%s</span></b>", 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 显示完整名称
end
o.default = ss_type -- 设置默认值
o.write = function(self, section, value)
-- 更新 Shadowsocks 节点的 has_ss_type
uci:foreach("shadowsocksr", "servers", function(s)
local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型
if node_type == "ss" then -- 仅修改 Shadowsocks 节点
local old_value = uci:get("shadowsocksr", s[".name"], "has_ss_type")
if old_value ~= value then
uci:set("shadowsocksr", s[".name"], "has_ss_type", value)
end
end
end)
-- 更新当前 section 的 ss_type
ListValue.write(self, section, value)
end
end

o = s:option(DynamicList, "subscribe_url", translate("Subscribe URL"))
Expand Down
Loading