Comparison

mod_firewall/conditions.lib.lua @ 2128:21bc4d7cddae

mod_firewall: Add support for throttling based on user-defined properties (experimental)
author Matthew Wild <mwild1@gmail.com>
date Fri, 18 Mar 2016 09:47:52 +0000
parent 2127:59023dffbdd4
child 2342:6848297cf40a
comparison
equal deleted inserted replaced
2127:59023dffbdd4 2128:21bc4d7cddae
180 table.insert(conditions, "("..table.concat(clause, " "..op.." ")..")"); 180 table.insert(conditions, "("..table.concat(clause, " "..op.." ")..")");
181 end 181 end
182 return table.concat(conditions, " or "), { "time:hour,min" }; 182 return table.concat(conditions, " or "), { "time:hour,min" };
183 end 183 end
184 184
185 function condition_handlers.LIMIT(name) 185 function condition_handlers.LIMIT(spec)
186 return ("not throttle_%s:poll(1)"):format(name), { "throttle:"..name }; 186 local name, param = spec:match("^(%w+) on (.+)$");
187
188 if not name then
189 name = spec:match("^%w+$");
190 if not name then
191 error("Unable to parse LIMIT specification");
192 end
193 else
194 param = meta(("%q"):format(param));
195 end
196
197 if not param then
198 return ("not global_throttle_%s:poll(1)"):format(name), { "globalthrottle:"..name };
199 end
200 return ("not multi_throttle_%s:poll_on(%s, 1)"):format(name, param), { "multithrottle:"..name };
187 end 201 end
188 202
189 function condition_handlers.ORIGIN_MARKED(name_and_time) 203 function condition_handlers.ORIGIN_MARKED(name_and_time)
190 local name, time = name_and_time:match("^%s*([%w_]+)%s+%(([^)]+)s%)%s*$"); 204 local name, time = name_and_time:match("^%s*([%w_]+)%s+%(([^)]+)s%)%s*$");
191 if not name then 205 if not name then