Comparison

mod_firewall/definitions.lib.lua @ 4016:b872f111b7af

mod_firewall: Add option to ignore missing list files
author Matthew Wild <mwild1@gmail.com>
date Mon, 11 May 2020 17:18:30 +0100
parent 3240:c30f2cfe9f15
child 4017:015452258952
comparison
equal deleted inserted replaced
4015:001c756ead7d 4016:b872f111b7af
8 local timer = require "util.timer"; 8 local timer = require "util.timer";
9 local set = require"util.set"; 9 local set = require"util.set";
10 local new_throttle = require "util.throttle".create; 10 local new_throttle = require "util.throttle".create;
11 local hashes = require "util.hashes"; 11 local hashes = require "util.hashes";
12 local jid = require "util.jid"; 12 local jid = require "util.jid";
13 local lfs = require "lfs";
13 14
14 local multirate_cache_size = module:get_option_number("firewall_multirate_cache_limit", 1000); 15 local multirate_cache_size = module:get_option_number("firewall_multirate_cache_limit", 1000);
15 16
16 function definition_handlers.ZONE(zone_name, zone_members) 17 function definition_handlers.ZONE(zone_name, zone_members)
17 local zone_member_list = {}; 18 local zone_member_list = {};
148 file = { 149 file = {
149 init = function (self, file_spec, opts) 150 init = function (self, file_spec, opts)
150 local items = {}; 151 local items = {};
151 local n = 0; 152 local n = 0;
152 local filename = file_spec:gsub("^file:", ""); 153 local filename = file_spec:gsub("^file:", "");
154 if opts.missing == "ignore" and not lfs.attributes(filename, "mode") then
155 module:log("debug", "Ignoring missing list file: %s", filename);
156 return;
157 end
153 local file, err = io.open(filename); 158 local file, err = io.open(filename);
154 if not file then 159 if not file then
155 module:log("warn", "Failed to open list from %s: %s", filename, err); 160 module:log("warn", "Failed to open list from %s: %s", filename, err);
156 return; 161 return;
157 else 162 else