From d97655ddffc073053f091ad31c1a41840022d7c4 Mon Sep 17 00:00:00 2001 From: zxlhhyccc Date: Mon, 29 Jun 2026 21:20:32 +0800 Subject: [PATCH] luci-app-ssr-plus: fix parse_realm_uri fun. --- .../usr/share/shadowsocksr/gen_config.lua | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua b/luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua index 66d001d2..f40f2779 100755 --- a/luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua +++ b/luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua @@ -54,12 +54,20 @@ if server.type == "ss-rust" then end local function parse_realm_uri(uri) - if type(uri) ~= "string" then return nil end + uri = trim(uri) + if uri == "" 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 + local scheme = (uri:match("^realm%+http://") and "realm+http") or (uri:match("^realm://") and "realm") + if not scheme then return nil end + uri = uri:gsub("^realm%+http://", ""):gsub("^realm://", "") + local token, server_url, realm_id, query = uri:match("^([^@]+)@([^/]+)/([^?]*)%??(.*)$") + if not token or not server_url or not realm_id then return nil end realm_id = realm_id:gsub("/+$", "") - local address, port = server_url:match("^%[?([^%]]+)%]?:?(%d*)$") + local address, port = server_url:match("^%[([^%]]+)%]:(%d+)$") --ipv6:port + if not address then + address, port = server_url:match("^([^:]+):(%d+)$") --ipv4[domain]:port + end + address = address or server_url:match("^%[([^%]]+)%]$") or server_url port = tonumber(port) or (scheme == "realm+http" and 80 or 443) local realm = { scheme = scheme, @@ -71,9 +79,9 @@ local function parse_realm_uri(uri) } -- 解析 query 中的 stun= 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 + for v in (query or ""):gmatch("[Ss][Tt][Uu][Nn]=([^&]+)") do + stun_servers = stun_servers or {} + stun_servers[#stun_servers + 1] = v end realm.stun_servers = stun_servers return realm