comparison mod_firewall/actions.lib.lua @ 3483:78049e8b5a6b

mod_firewall: Improve debug logging for chain results
author Matthew Wild <mwild1@gmail.com>
date Mon, 11 Mar 2019 11:54:16 +0000
parents 68842409f4e7
children df6227e288e5
comparison
equal deleted inserted replaced
3482:0fd7802b435e 3483:78049e8b5a6b
1 local interpolation = require "util.interpolation";
2 local template = interpolation.new("%b$$", function (s) return ("%q"):format(s) end);
3
1 --luacheck: globals meta idsafe 4 --luacheck: globals meta idsafe
2 local action_handlers = {}; 5 local action_handlers = {};
3 6
4 7
5 -- Takes an XML string and returns a code string that builds that stanza 8 -- Takes an XML string and returns a code string that builds that stanza
191 function action_handlers.JUMP_EVENT(name) 194 function action_handlers.JUMP_EVENT(name)
192 return ("do return fire_event(%q, event); end"):format(name); 195 return ("do return fire_event(%q, event); end"):format(name);
193 end 196 end
194 197
195 function action_handlers.JUMP_CHAIN(name) 198 function action_handlers.JUMP_CHAIN(name)
196 return ([[do 199 return template([[do
197 local ret = fire_event(%q, event); 200 local ret = fire_event($chain_event$, event);
198 log('debug', 'chain \"%%s\" returned %%s', %q, tostring(ret));
199 if ret ~= nil then 201 if ret ~= nil then
200 if ret == false then 202 if ret == false then
201 log("debug", "Chain accepted stanza"); 203 log("debug", "Chain %q accepted stanza (ret %s)", $chain_name$, tostring(ret));
202 return pass_return; 204 return pass_return;
203 end 205 end
204 log("debug", "Chain rejected stanza"); 206 log("debug", "Chain %q rejected stanza (ret %s)", $chain_name$, tostring(ret));
205 return ret; 207 return ret;
206 end 208 end
207 log("debug", "Chain did not accept or reject stanza"); 209 log("debug", "Chain %q did not accept or reject stanza (ret %s)", $chain_name$, tostring(ret));
208 end]]):format("firewall/chains/"..name, name); 210 end]], { chain_event = "firewall/chains/"..name, chain_name = name });
209 end 211 end
210 212
211 function action_handlers.MARK_ORIGIN(name) 213 function action_handlers.MARK_ORIGIN(name)
212 return [[session.firewall_marked_]]..idsafe(name)..[[ = current_timestamp;]], { "timestamp" }; 214 return [[session.firewall_marked_]]..idsafe(name)..[[ = current_timestamp;]], { "timestamp" };
213 end 215 end