1 package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path
2 package.cpath = "/usr/lib/lua/?.so;" .. package.cpath
6 require("ffluci.model.uci")
9 uci = ffluci.model.uci.Session("/var/state")
12 -- Add a lease to state and invoke add_rule
13 function add_lease(mac)
14 local key = uci:add("luci_splash", "lease")
15 uci:set("luci_splash", key, "mac", mac)
16 uci:set("luci_splash", key, "start", os.time())
21 -- Remove a lease from state and invoke remove_rule
22 function remove_lease(mac)
25 for k, v in pairs(uci:show("luci_splash").luci_splash) do
26 if v.mac:lower() == mac then
28 uci:del("luci_splash", k)
34 -- Add an iptables rule
35 function add_rule(mac)
36 return os.execute("iptables -t nat -I luci_splash_leases -m mac --mac-source '"..mac.."' -j RETURN")
40 -- Remove an iptables rule
41 function remove_rule(mac)
42 return os.execute("iptables -t nat -D luci_splash_leases -m mac --mac-source '"..mac.."' -j RETURN")
46 -- Get the MAC-Address of current user
50 for i, l in ipairs(ffluci.sys.net.arptable()) do
51 if l["IP address"] == ip then
60 -- Check whether a MAC-Address is listed in the lease state list
61 function haslease(mac)
64 for k, v in pairs(uci:show("luci_splash").luci_splash) do
65 if v[".type"] == "lease" and v.mac and v.mac:lower() == mac then
74 -- Check whether a MAC-Address is whitelisted
75 function iswhitelisted(mac)
78 for k, v in pairs(uci:show("luci_splash").luci_splash) do
79 if v[".type"] == "whitelist" and v.mac and v.mac:lower() == mac then
88 -- Returns a list of MAC-Addresses for which a rule is existing
90 local cmd = "iptables -t nat -L luci_splash_leases | grep RETURN |"
91 cmd = cmd .. "egrep -io [0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+"
92 return ffluci.util.split(ffluci.sys.exec(cmd))