summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-05-30 10:17:43 +0200
committerPeter Kozak <spag@golwen.net>2013-05-30 10:17:43 +0200
commitf1260d478acae4a5fc34d7231530a6c6ba5ce0ba (patch)
tree336303dea93cec53ff295deb57bcae2c7f9590fe
parent77646dd34de104f6bf92367fcffdf38994a33a78 (diff)
multi-pattern support added
-rw-r--r--misc/freeswitch/scripts/common/perimeter.lua24
1 files changed, 16 insertions, 8 deletions
diff --git a/misc/freeswitch/scripts/common/perimeter.lua b/misc/freeswitch/scripts/common/perimeter.lua
index d3b601c..8b06f1d 100644
--- a/misc/freeswitch/scripts/common/perimeter.lua
+++ b/misc/freeswitch/scripts/common/perimeter.lua
@@ -56,8 +56,14 @@ function Perimeter.setup(self, event)
self.checks.register = config.checks_register or {};
self.checks.call = config.checks_call or {};
- self.bad_headers.register = config.bad_headers_register;
- self.bad_headers.call = config.bad_headers_call;
+
+ for header, patterns in pairs(config.bad_headers_register) do
+ self.bad_headers.register[header] = common.str.strip_to_a(patterns, ',');
+ end
+
+ for header, patterns in pairs(config.bad_headers_call) do
+ self.bad_headers.call[header] = common.str.strip_to_a(patterns, ',');
+ end
self.log:info('[perimeter] PERIMETER - setup perimeter defense');
end
@@ -205,12 +211,14 @@ end
function Perimeter.check_bad_headers(self, event)
local points = nil;
- for name, pattern in pairs(self.bad_headers[event.action]) do
- pattern = common.array.expand_variables(pattern, event);
- local success, result = pcall(string.find, event[name], pattern);
- if success and result then
- self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern);
- points = (points or 0) + 1;
+ for name, patterns in pairs(self.bad_headers[event.action]) do
+ for index, pattern in ipairs(patterns) do
+ pattern = common.array.expand_variables(pattern, event);
+ local success, result = pcall(string.find, event[name], pattern);
+ if success and result then
+ self.log:debug('[', event.key, '/', event.sequence, '] PERIMETER_BAD_HEADERS - ', name, '=', event[name], ' ~= ', pattern);
+ points = (points or 0) + 1;
+ end
end
end