diff --git a/luci-app-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index 44bf97cb..fc7f6772 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -1606,27 +1606,23 @@ end function parse_realm_uri(uri) if type(uri) ~= "string" then return nil end - -- realm://token@server/realm_id?query - local token, server_url, realm_id, query = trim(uri):match("^realm://([^@]+)@([^/]+)/([^?]*)%??(.*)$") - if not token or not server_url or not realm_id then return nil end + -- realm[+http]://token@server/realm_id?query + local scheme, token, server_url, realm_id, query = trim(uri):match("^(realm%+http|realm)://([^@]+)@([^/]+)/([^?]*)%??(.*)$") + if not scheme or not token or not server_url or not realm_id then return nil end realm_id = realm_id:gsub("/+$", "") local realm = { + scheme = scheme, token = token, server_url = server_url, realm_id = realm_id } -- 解析 query 中的 stun= - if query and query ~= "" then - local stun_servers = {} - for key, value in query:gmatch("([^&=?]+)=([^&]+)") do - if key == "stun" and value ~= "" then - stun_servers[#stun_servers + 1] = value - end - end - if #stun_servers > 0 then - realm.stun_servers = stun_servers - end + local stun_servers + for value in (query or ""):gmatch("[?&]?[Ss][Tt][Uu][Nn]=([^&]+)") do + if not stun_servers then stun_servers = {} end + stun_servers[#stun_servers + 1] = value end + realm.stun_servers = stun_servers return realm end diff --git a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua index 89049692..b8497914 100644 --- a/luci-app-passwall/luasrc/passwall/util_hysteria2.lua +++ b/luci-app-passwall/luasrc/passwall/util_hysteria2.lua @@ -67,7 +67,8 @@ function gen_config(var) server_host = api.get_ipv6_full(server_host) end - local server = server_host .. ":" .. ((server_port or "") .. "," .. (node.hysteria2_hop or "")):gsub("^[%s,]+", ""):gsub("[%s,]+$", ""):gsub(":", "-") + local port_hop = ((server_port or "") .. "," .. (node.hysteria2_hop or "")):gsub("^[%s,]+", ""):gsub("[%s,]+$", ""):gsub(":", "-") + local server = server_host .. ":" .. (port_hop ~= "" and port_hop or "443") local config = { server = (function() diff --git a/luci-app-passwall/luasrc/passwall/util_sing-box.lua b/luci-app-passwall/luasrc/passwall/util_sing-box.lua index ad76c2a9..9b6747b3 100644 --- a/luci-app-passwall/luasrc/passwall/util_sing-box.lua +++ b/luci-app-passwall/luasrc/passwall/util_sing-box.lua @@ -583,8 +583,9 @@ function gen_outbound(flag, node, tag, proxy_table) result.server_port = nil local realm = api.parse_realm_uri(node.hysteria2_realm_url) if realm then - realm.server_url = realm.server_url and "https://" .. realm.server_url or nil + realm.server_url = (realm.scheme == "realm+http" and "http://" or "https://") .. realm.server_url realm.stun_servers = realm.stun_servers or node.hysteria2_realm_stun + realm.scheme = nil return realm end return nil @@ -929,8 +930,9 @@ function gen_config_server(node) realm = node.hysteria2_realms and (function() local realm = api.parse_realm_uri(node.hysteria2_realm_url) if realm then - realm.server_url = realm.server_url and "https://" .. realm.server_url or nil + realm.server_url = (realm.scheme == "realm+http" and "http://" or "https://") .. realm.server_url realm.stun_servers = realm.stun_servers or node.hysteria2_realm_stun + realm.scheme = nil realm.stun_domain_resolver = "direct" return realm end diff --git a/luci-app-passwall/luasrc/passwall/util_xray.lua b/luci-app-passwall/luasrc/passwall/util_xray.lua index b7602396..85b5e794 100644 --- a/luci-app-passwall/luasrc/passwall/util_xray.lua +++ b/luci-app-passwall/luasrc/passwall/util_xray.lua @@ -294,9 +294,7 @@ function gen_outbound(flag, node, tag, proxy_table) local realm = api.parse_realm_uri(node.hysteria2_realm_url) local url, stun if realm then - if realm.token and realm.server_url and realm.realm_id then - url = "realm://" .. realm.token .. "@" .. realm.server_url .. "/" .. realm.realm_id - end + url = realm.scheme .. "://" .. realm.token .. "@" .. realm.server_url .. "/" .. realm.realm_id stun = realm.stun_servers or node.hysteria2_realm_stun end local r = { @@ -754,9 +752,7 @@ function gen_config_server(node) local realm = api.parse_realm_uri(node.hysteria2_realm_url) local url, stun if realm then - if realm.token and realm.server_url and realm.realm_id then - url = "realm://" .. realm.token .. "@" .. realm.server_url .. "/" .. realm.realm_id - end + url = realm.scheme .. "://" .. realm.token .. "@" .. realm.server_url .. "/" .. realm.realm_id stun = realm.stun_servers or node.hysteria2_realm_stun end local r = {