comparison mod_firewall/mod_firewall.lua @ 1343:7dbde05b48a9

all the things: Remove trailing whitespace
author Florian Zeitz <florob@babelmonkeys.de>
date Tue, 11 Mar 2014 18:44:01 +0100
parents b21236b6b8d8
children 2356114ff505
comparison
equal deleted inserted replaced
1342:0ae065453dc9 1343:7dbde05b48a9
136 return rule; 136 return rule;
137 end 137 end
138 138
139 local function compile_firewall_rules(filename) 139 local function compile_firewall_rules(filename)
140 local line_no = 0; 140 local line_no = 0;
141 141
142 local function errmsg(err) 142 local function errmsg(err)
143 return "Error compiling "..filename.." on line "..line_no..": "..err; 143 return "Error compiling "..filename.." on line "..line_no..": "..err;
144 end 144 end
145 145
146 local ruleset = { 146 local ruleset = {
147 deliver = {}; 147 deliver = {};
148 }; 148 };
149 149
150 local chain = "deliver"; -- Default chain 150 local chain = "deliver"; -- Default chain
151 local rule; 151 local rule;
152 152
153 local file, err = io.open(filename); 153 local file, err = io.open(filename);
154 if not file then return nil, err; end 154 if not file then return nil, err; end
155 155
156 local state; -- nil -> "rules" -> "actions" -> nil -> ... 156 local state; -- nil -> "rules" -> "actions" -> nil -> ...
157 157
158 local line_hold; 158 local line_hold;
159 for line in file:lines() do 159 for line in file:lines() do
160 line = line:match("^%s*(.-)%s*$"); 160 line = line:match("^%s*(.-)%s*$");
161 if line_hold and line:sub(-1,-1) ~= "\\" then 161 if line_hold and line:sub(-1,-1) ~= "\\" then
162 line = line_hold..line; 162 line = line_hold..line;
163 line_hold = nil; 163 line_hold = nil;
164 elseif line:sub(-1,-1) == "\\" then 164 elseif line:sub(-1,-1) == "\\" then
165 line_hold = (line_hold or "")..line:sub(1,-2); 165 line_hold = (line_hold or "")..line:sub(1,-2);
166 end 166 end
167 line_no = line_no + 1; 167 line_no = line_no + 1;
168 168
169 if line_hold or line:match("^[#;]") then 169 if line_hold or line:match("^[#;]") then
170 -- No action; comment or partial line 170 -- No action; comment or partial line
171 elseif line == "" then 171 elseif line == "" then
172 if state == "rules" then 172 if state == "rules" then
173 return nil, ("Expected an action on line %d for preceding criteria") 173 return nil, ("Expected an action on line %d for preceding criteria")
266 for _, dep in ipairs(condition_deps or {}) do 266 for _, dep in ipairs(condition_deps or {}) do
267 table.insert(rule.deps, dep); 267 table.insert(rule.deps, dep);
268 end 268 end
269 end 269 end
270 end 270 end
271 271
272 -- Compile ruleset and return complete code 272 -- Compile ruleset and return complete code
273 273
274 local chain_handlers = {}; 274 local chain_handlers = {};
275 275
276 -- Loop through the chains in the parsed ruleset (e.g. incoming, outgoing) 276 -- Loop through the chains in the parsed ruleset (e.g. incoming, outgoing)
277 for chain_name, rules in pairs(ruleset) do 277 for chain_name, rules in pairs(ruleset) do
278 local code = { included_deps = {}, global_header = {} }; 278 local code = { included_deps = {}, global_header = {} };
336 ..table.concat(code, "") 336 ..table.concat(code, "")
337 .."\n\tend;\nend"; 337 .."\n\tend;\nend";
338 338
339 chain_handlers[chain_name] = code_string; 339 chain_handlers[chain_name] = code_string;
340 end 340 end
341 341
342 return chain_handlers; 342 return chain_handlers;
343 end 343 end
344 344
345 local function compile_handler(code_string, filename) 345 local function compile_handler(code_string, filename)
346 -- Prepare event handler function 346 -- Prepare event handler function
360 active_definitions = {}; 360 active_definitions = {};
361 local firewall_scripts = module:get_option_set("firewall_scripts", {}); 361 local firewall_scripts = module:get_option_set("firewall_scripts", {});
362 for script in firewall_scripts do 362 for script in firewall_scripts do
363 script = resolve_relative_path(prosody.paths.config, script); 363 script = resolve_relative_path(prosody.paths.config, script);
364 local chain_functions, err = compile_firewall_rules(script) 364 local chain_functions, err = compile_firewall_rules(script)
365 365
366 if not chain_functions then 366 if not chain_functions then
367 module:log("error", "Error compiling %s: %s", script, err or "unknown error"); 367 module:log("error", "Error compiling %s: %s", script, err or "unknown error");
368 else 368 else
369 for chain, handler_code in pairs(chain_functions) do 369 for chain, handler_code in pairs(chain_functions) do
370 local handler, err = compile_handler(handler_code, "mod_firewall::"..chain); 370 local handler, err = compile_handler(handler_code, "mod_firewall::"..chain);