luci: improve hy2 port hopping

This commit is contained in:
lwb1978 2025-04-09 10:03:28 +08:00 committed by xiaorouji
parent e1d21555c2
commit fa4439262b
7 changed files with 13 additions and 15 deletions

View File

@ -26,7 +26,8 @@ o = s:option(Value, _n("address"), translate("Address (Support Domain Name)"))
o = s:option(Value, _n("port"), translate("Port")) o = s:option(Value, _n("port"), translate("Port"))
o.datatype = "port" o.datatype = "port"
o = s:option(Value, _n("hop"), translate("Additional ports for hysteria hop")) o = s:option(Value, _n("hop"), translate("Port hopping range"))
o.description = translate("Format as 1000:2000 or 1000-2000 Multiple groups are separated by commas (,).")
o.rewrite_option = o.option o.rewrite_option = o.option
o = s:option(Value, _n("obfs"), translate("Obfs Password")) o = s:option(Value, _n("obfs"), translate("Obfs Password"))

View File

@ -404,8 +404,8 @@ if singbox_tags:find("with_quic") then
end end
if singbox_tags:find("with_quic") then if singbox_tags:find("with_quic") then
o = s:option(Value, _n("hysteria2_ports"), translate("Port hopping range")) o = s:option(Value, _n("hysteria2_hop"), translate("Port hopping range"))
o.description = translate("Format as 1000:2000 Multiple groups are separated by commas (,).") o.description = translate("Format as 1000:2000 or 1000-2000 Multiple groups are separated by commas (,).")
o:depends({ [_n("protocol")] = "hysteria2" }) o:depends({ [_n("protocol")] = "hysteria2" })
o = s:option(Value, _n("hysteria2_up_mbps"), translate("Max upload Mbps")) o = s:option(Value, _n("hysteria2_up_mbps"), translate("Max upload Mbps"))

View File

@ -54,7 +54,7 @@ function gen_config(var)
local server = server_host .. ":" .. server_port local server = server_host .. ":" .. server_port
if (node.hysteria2_hop) then if (node.hysteria2_hop) then
server = server .. "," .. node.hysteria2_hop server = server .. "," .. string.gsub(node.hysteria2_hop, ":", "-")
end end
local config = { local config = {

View File

@ -350,8 +350,9 @@ function gen_outbound(flag, node, tag, proxy_table)
if node.protocol == "hysteria2" then if node.protocol == "hysteria2" then
local server_ports = {} local server_ports = {}
if node.hysteria2_ports then if node.hysteria2_hop then
for range in node.hysteria2_ports:gmatch("([^,]+)") do node.hysteria2_hop = string.gsub(node.hysteria2_hop, "-", ":")
for range in node.hysteria2_hop:gmatch("([^,]+)") do
if range:match("^%d+:%d+$") then if range:match("^%d+:%d+$") then
table.insert(server_ports, range) table.insert(server_ports, range)
end end

View File

@ -511,7 +511,7 @@ local hysteria2_type = map:get("@global_subscribe[0]", "hysteria2_type") or "sin
params += opt.query("obfs", dom_prefix + "hysteria2_obfs_type"); params += opt.query("obfs", dom_prefix + "hysteria2_obfs_type");
params += opt.query("obfs-password", dom_prefix + "hysteria2_obfs_password"); params += opt.query("obfs-password", dom_prefix + "hysteria2_obfs_password");
} }
params += opt.query("mport", dom_prefix + "hysteria2_ports"); params += opt.query("mport", dom_prefix + "hysteria2_hop");
} }
params = params.replace(/^&/, ""); params = params.replace(/^&/, "");
url = url =
@ -1300,7 +1300,7 @@ local hysteria2_type = map:get("@global_subscribe[0]", "hysteria2_type") or "sin
opt.set(dom_prefix + 'hysteria2_obfs_type', "salamander"); opt.set(dom_prefix + 'hysteria2_obfs_type', "salamander");
opt.set(dom_prefix + 'hysteria2_obfs_password', queryParam["obfs-password"]); opt.set(dom_prefix + 'hysteria2_obfs_password', queryParam["obfs-password"]);
} }
opt.set(dom_prefix + 'hysteria2_ports', queryParam.mport || ""); opt.set(dom_prefix + 'hysteria2_hop', queryParam.mport || "");
} else if (has_hysteria2) { } else if (has_hysteria2) {
opt.set('type', "Hysteria2"); opt.set('type', "Hysteria2");
dom_prefix = "hysteria2_" dom_prefix = "hysteria2_"

View File

@ -1492,9 +1492,6 @@ msgstr "空闲超时 "
msgid "Hop Interval" msgid "Hop Interval"
msgstr "端口跳跃时间 " msgstr "端口跳跃时间 "
msgid "Additional ports for hysteria hop"
msgstr "端口跳跃额外端口"
msgid "HeartbeatPeriod(second)" msgid "HeartbeatPeriod(second)"
msgstr "心跳周期(单位:秒)" msgstr "心跳周期(单位:秒)"
@ -1690,5 +1687,5 @@ msgstr "当选择的出站发生变化时中断现有连接。"
msgid "Port hopping range" msgid "Port hopping range"
msgstr "端口跳跃范围" msgstr "端口跳跃范围"
msgid "Format as 1000:2000 Multiple groups are separated by commas (,)." msgid "Format as 1000:2000 or 1000-2000 Multiple groups are separated by commas (,)."
msgstr "格式为1000:2000 多组时用逗号(,)隔开。" msgstr "格式为1000:2000 或 1000-2000 多组时用逗号(,)隔开。"

View File

@ -1222,6 +1222,7 @@ local function processData(szType, content, add_mode, add_from)
result.tls_allowInsecure = allowInsecure_default and "1" or "0" result.tls_allowInsecure = allowInsecure_default and "1" or "0"
end end
result.hysteria2_tls_pinSHA256 = params.pinSHA256 result.hysteria2_tls_pinSHA256 = params.pinSHA256
result.hysteria2_hop = params.mport
if hysteria2_type_default == "sing-box" and has_singbox then if hysteria2_type_default == "sing-box" and has_singbox then
result.type = 'sing-box' result.type = 'sing-box'
@ -1230,13 +1231,11 @@ local function processData(szType, content, add_mode, add_from)
result.hysteria2_obfs_type = "salamander" result.hysteria2_obfs_type = "salamander"
result.hysteria2_obfs_password = params["obfs-password"] result.hysteria2_obfs_password = params["obfs-password"]
end end
result.hysteria2_ports = params.mport
elseif has_hysteria2 then elseif has_hysteria2 then
result.type = "Hysteria2" result.type = "Hysteria2"
if params["obfs-password"] then if params["obfs-password"] then
result.hysteria2_obfs = params["obfs-password"] result.hysteria2_obfs = params["obfs-password"]
end end
result.hysteria2_hop = params.mport
end end
elseif szType == 'tuic' then elseif szType == 'tuic' then
local alias = "" local alias = ""