comparison mod_firewall/conditions.lib.lua @ 6509:f61564e11d3b

various: Adjust for loop variables becoming constants in Lua 5.5
author Kim Alvefur <zash@zash.se>
date Tue, 07 Apr 2026 14:30:31 +0200
parents b15601203d0d
children d4da95d6d977
comparison
equal deleted inserted replaced
6508:3044e14fcaa0 6509:f61564e11d3b
171 return ("group_contains(%q, bare_to)"):format(group_name), { "group_contains", "bare_to" }; 171 return ("group_contains(%q, bare_to)"):format(group_name), { "group_contains", "bare_to" };
172 end 172 end
173 173
174 function condition_handlers.CROSSING_GROUPS(group_names) 174 function condition_handlers.CROSSING_GROUPS(group_names)
175 local code = {}; 175 local code = {};
176 for group_name in group_names:gmatch("([^, ][^,]+)") do 176 for wgroup_name in group_names:gmatch("([^, ][^,]+)") do
177 group_name = group_name:match("^%s*(.-)%s*$"); -- Trim leading/trailing whitespace 177 local group_name = wgroup_name:match("^%s*(.-)%s*$"); -- Trim leading/trailing whitespace
178 -- Just check that's it is crossing from outside group to inside group 178 -- Just check that's it is crossing from outside group to inside group
179 table.insert(code, ("(group_contains(%q, bare_to) and group_contains(%q, bare_from))"):format(group_name, group_name)) 179 table.insert(code, ("(group_contains(%q, bare_to) and group_contains(%q, bare_from))"):format(group_name, group_name))
180 end 180 end
181 return "not "..table.concat(code, " or "), { "group_contains", "bare_to", "bare_from" }; 181 return "not "..table.concat(code, " or "), { "group_contains", "bare_to", "bare_from" };
182 end 182 end
252 return "("..table.concat(conditions, ") or (")..")", { "time:day" }; 252 return "("..table.concat(conditions, ") or (")..")", { "time:day" };
253 end 253 end
254 254
255 function condition_handlers.TIME(ranges) 255 function condition_handlers.TIME(ranges)
256 local conditions = {}; 256 local conditions = {};
257 for range in ranges:gmatch("([^,]+)") do 257 for rawrange in ranges:gmatch("([^,]+)") do
258 local clause = {}; 258 local clause = {};
259 range = range:lower() 259 local range = rawrange:lower()
260 :gsub("(%d+):?(%d*) *am", function (h, m) return tostring(tonumber(h)%12)..":"..(tonumber(m) or "00"); end) 260 :gsub("(%d+):?(%d*) *am", function (h, m) return tostring(tonumber(h)%12)..":"..(tonumber(m) or "00"); end)
261 :gsub("(%d+):?(%d*) *pm", function (h, m) return tostring(tonumber(h)%12+12)..":"..(tonumber(m) or "00"); end); 261 :gsub("(%d+):?(%d*) *pm", function (h, m) return tostring(tonumber(h)%12+12)..":"..(tonumber(m) or "00"); end);
262 local start_hour, start_minute = range:match("(%d+):(%d+) *%-"); 262 local start_hour, start_minute = range:match("(%d+):(%d+) *%-");
263 local end_hour, end_minute = range:match("%- *(%d+):(%d+)"); 263 local end_hour, end_minute = range:match("%- *(%d+):(%d+)");
264 local op = tonumber(start_hour) > tonumber(end_hour) and " or " or " and "; 264 local op = tonumber(start_hour) > tonumber(end_hour) and " or " or " and ";