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 function _config.map_port(port)
43 return _config.pmap[tostring(port)] or port
46 function _config.map_ip(ip)
47 for k,v in pairs(_config.ipmap) do
48 if string.match(ip,k) then
55 function _config.map_mac(mac)
56 for k,v in pairs(_config.macmap) do
57 if string.match(mac,k) then