Comparison

mod_firewall/mod_firewall.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 2126:b0d711cd3da5
child 2130:9239893a2400
comparison
equal deleted inserted replaced
2127:59023dffbdd4 2128:21bc4d7cddae
106 table.insert(defs, ("local current_%s = current_date_time.%s;"):format(field, field)); 106 table.insert(defs, ("local current_%s = current_date_time.%s;"):format(field, field));
107 end 107 end
108 return table.concat(defs, " "); 108 return table.concat(defs, " ");
109 end, depends = { "date_time" }; }; 109 end, depends = { "date_time" }; };
110 timestamp = { global_code = [[local get_time = require "socket".gettime]]; local_code = [[local current_timestamp = get_time()]]; }; 110 timestamp = { global_code = [[local get_time = require "socket".gettime]]; local_code = [[local current_timestamp = get_time()]]; };
111 throttle = { 111 globalthrottle = {
112 global_code = function (throttle) 112 global_code = function (throttle)
113 assert(idsafe(throttle), "Invalid rate limit name: "..throttle); 113 assert(idsafe(throttle), "Invalid rate limit name: "..throttle);
114 assert(active_definitions.RATE[throttle], "Unknown rate limit: "..throttle); 114 assert(active_definitions.RATE[throttle], "Unknown rate limit: "..throttle);
115 return ("local throttle_%s = rates.%s;"):format(throttle, throttle); 115 return ("local global_throttle_%s = rates.%s:single();"):format(throttle, throttle);
116 end;
117 };
118 multithrottle = {
119 global_code = function (throttle)
120 assert(idsafe(throttle), "Invalid rate limit name: "..throttle);
121 assert(active_definitions.RATE[throttle], "Unknown rate limit: "..throttle);
122 return ("local multi_throttle_%s = rates.%s:multi();"):format(throttle, throttle);
116 end; 123 end;
117 }; 124 };
118 }; 125 };
119 126
120 local function include_dep(dependency, code) 127 local function include_dep(dependency, code)