fixed regular expression in live nameserver parsing function
Skyweave Test, Lint, and Deploy Ritual / Test and Lint Code (push) Successful in 28s
Skyweave Test, Lint, and Deploy Ritual / Deploy to Roof Unit (push) Successful in 18s

This commit is contained in:
wes
2025-06-29 10:45:42 -04:00
parent 3fd7a9bcbc
commit 7d43a3d488
+10 -7
View File
@@ -162,29 +162,32 @@ function utils.get_live_interface_info(interface_name)
return nil
end
-- Moved from original main script
function utils.get_live_dns_servers_from_resolv(logical_interface_name)
local dns_servers = {}
local search_domains = {}
-- Ensure logical_interface_name is somewhat safe before using in string matching,
-- though it's typically from internal config.
if not logical_interface_name or not logical_interface_name:match("^[a-zA-Z0-9_%-]+$") then
return dns_servers, search_domains -- Invalid interface name format
return dns_servers, search_domains
end
local file = io.open("/tmp/resolv.conf.auto", "r")
if not file then return dns_servers, search_domains end
local in_target_section = false
local section_start_pattern_str = "# Interface " .. logical_interface_name
-- It looks for the logical_interface_name followed by an optional underscore and digits (e.g., "_4"),
-- and then the end of the line. This prevents "wan" from incorrectly matching "wan_lte_".
local section_start_pattern = "^%s*# Interface%s+" .. logical_interface_name .. "(_%d+)?%s*$"
for line in file:lines() do
if not in_target_section then
if line:match("^%s*" .. section_start_pattern_str:gsub("%%", "%%%%") .. "%s*$") then -- Escape % for string pattern
-- We now use the more precise pattern to find our starting point.
if line:match(section_start_pattern) then
in_target_section = true
end
else
if line:match("^%s*# Interface ") and not line:match("^%s*" .. section_start_pattern_str:gsub("%%", "%%%%") .. "%s*$") then
-- The end-of-section logic is now also hardened. We break if we find a new
-- "# Interface" line that does NOT match our precise pattern.
if line:match("^%s*# Interface") and not line:match(section_start_pattern) then
break
end