5 function _config.read(file)
7 local file = file or "/opt/squid-auth-helper/config.json"
8 local f = assert(io.open(file))
9 local cfg = json.decode(f:read("*all"))
11 _config.pmap = cfg["portmap"] or {}
13 _config.ident_timeout = 2
14 _config.ident_default = nil
17 _config.ident_timeout = cfg["ident"]["timeout"] or _config.ident_timeout
18 _config.ident_default = cfg["ident"]["default"] or _config.ident_default
25 if cfg["hosts"]["ip"] then
26 for k, v in pairs(cfg["hosts"]["ip"]) do
27 local k, n = string.gsub(k, "%.", "%%.")
28 local k, n = string.gsub(k,"%*",".*")
29 _config.ipmap["^"..k.."$"] = v
32 if cfg["hosts"]["mac"] then
33 for k, v in pairs(cfg["hosts"]["mac"]) do
34 local k, n = string.gsub(k,"%*",".*")
35 _config.macmap["^"..k.."$"] = v
42 if cfg["arp-ttl"] then
43 _config.arp_ttl = tonumber(cfg["arp-ttl"])
48 function _config.map_port(port)
49 return _config.pmap[tostring(port)] or port
52 function _config.map_ip(ip)
53 for k,v in pairs(_config.ipmap) do
54 if string.match(ip,k) then
61 function _config.map_mac(mac)
62 for k,v in pairs(_config.macmap) do
63 if string.match(mac,k) then