From 37f5311fe076fc875757d5afba679468407777a9 Mon Sep 17 00:00:00 2001 From: action Date: Sat, 16 May 2026 21:11:54 +0800 Subject: [PATCH] update 2026-05-16 21:11:54 --- .../cbi/passwall/client/type/hysteria2.lua | 17 ++++++++++++ .../cbi/passwall/server/type/hysteria2.lua | 14 ++++++++++ .../luasrc/passwall/util_hysteria2.lua | 26 ++++++++++++++++--- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/hysteria2.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/hysteria2.lua index 314010f1..4152cd61 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/hysteria2.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/hysteria2.lua @@ -24,19 +24,36 @@ o = s:option(ListValue, _n("protocol"), translate("Protocol")) o:value("udp", "UDP") o = s:option(Value, _n("address"), translate("Address (Support Domain Name)")) +o:depends({ [_n("realms")] = false }) o = s:option(Value, _n("port"), translate("Port")) o.datatype = "port" +o:depends({ [_n("realms")] = false }) 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:depends({ [_n("realms")] = false }) o = s:option(Value, _n("hop_interval"), translate("Hop Interval(second)"), translate("Supports a fixed value or a random range (e.g., 30, 5-30), minimum 5.")) o.datatype = "or(uinteger,portrange)" o.placeholder = "30" o.default = "30" o.rewrite_option = o.option +o:depends({ [_n("realms")] = false }) + +o = s:option(Flag, _n("realms"), translate("Realms")) +o.default = "0" +o.rewrite_option = o.option + +o = s:option(Value, _n("realm_url"), translate("Realm URL"), translate("Example:") .. "realm://public@realm.hy2.io/your-realm-name") +o.rewrite_option = o.option +o:depends({ [_n("realms")] = "1" }) + +o = s:option(DynamicList, _n("realm_stun"), translate("Realm STUN")) +o.default = { "stun.sip.us:3478", "stun.nextcloud.com:3478", "global.stun.twilio.com:3478" } +o.rewrite_option = o.option +o:depends({ [_n("realms")] = "1" }) o = s:option(Value, _n("auth_password"), translate("Auth Password")) o.password = true diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua index 5fbf3707..89135cd6 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/hysteria2.lua @@ -26,6 +26,20 @@ o = s:option(Value, _n("port"), translate("Listen Port")) o.datatype = "port" o:depends({ [_n("custom")] = false }) +o = s:option(Flag, _n("realms"), translate("Realms")) +o.default = "0" +o.rewrite_option = o.option +o:depends({ [_n("custom")] = false }) + +o = s:option(Value, _n("realm_url"), translate("Realm URL"), translate("Example:") .. "realm://public@realm.hy2.io/your-realm-name") +o.rewrite_option = o.option +o:depends({ [_n("realms")] = "1" }) + +o = s:option(DynamicList, _n("realm_stun"), translate("Realm STUN")) +o.default = { "stun.sip.us:3478", "stun.nextcloud.com:3478", "global.stun.twilio.com:3478" } +o.rewrite_option = o.option +o:depends({ [_n("realms")] = "1" }) + o = s:option(Value, _n("auth_password"), translate("Auth Password")) o.password = true o.rewrite_option = o.option diff --git a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua index 957908aa..e2ca3a55 100644 --- a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua +++ b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua @@ -5,7 +5,16 @@ local jsonc = api.jsonc function gen_config_server(node) local config = { - listen = ":" .. node.port, + listen = (function() + if node.hysteria2_realms and node.hysteria2_realm_url then + local url = node.hysteria2_realm_url:gsub("/+$", "") + if node.port then + url = url .. (url:find("?") and "&lport=" or "?lport=") .. node.port + end + return url + end + return ":" .. (node.port or "0") + end)(), tls = { cert = node.tls_certificateFile, key = node.tls_keyFile, @@ -26,6 +35,9 @@ function gen_config_server(node) } or nil, ignoreClientBandwidth = (node.hysteria2_ignoreClientBandwidth == "1") and true or false, disableUDP = (node.hysteria2_udp == "0") and true or false, + realm = (node.hysteria2_realms and node.hysteria2_realm_stun) and { + stunServers = node.hysteria2_realm_stun + } or nil } return config end @@ -49,7 +61,7 @@ function gen_config(var) local local_http_password = var["local_http_password"] local tcp_proxy_way = var["tcp_proxy_way"] local server_host = var["server_host"] or (node.address or ""):lower() - local server_port = var["server_port"] or node.port + local server_port = var["server_port"] or (node.port or "443") if api.is_ipv6(server_host) then server_host = api.get_ipv6_full(server_host) @@ -61,7 +73,15 @@ function gen_config(var) end local config = { - server = server, + server = (function() + if node.hysteria2_realms and node.hysteria2_realm_url then + return node.hysteria2_realm_url:gsub("/+$", "") + end + return server + end)(), + realm = (node.hysteria2_realms and node.hysteria2_realm_stun) and { + stunServers = node.hysteria2_realm_stun + } or nil, transport = { type = "udp", udp = node.hysteria2_hop and (function()