require("luci.model.uci")
-- Init state session
-luci.model.uci.load_state("luci_splash")
-local uci = luci.model.uci
+local uci = luci.model.uci.cursor_state()
function main(argv)
-- Add a lease to state and invoke add_rule
function add_lease(mac)
- uci.section("luci_splash", "lease", nil, {
+ uci:section("luci_splash", "lease", nil, {
mac = mac,
start = os.time()
})
add_rule(mac)
- uci.save_state("luci_splash")
+ uci:save("luci_splash")
end
mac = mac:lower()
local del = {}
- uci.foreach("luci_splash", "lease",
+ uci:foreach("luci_splash", "lease",
function (section)
if section.mac:lower() == mac then
table.insert(del, section[".name"])
for i,j in ipairs(del) do
remove_rule(j)
- uci.delete("luci_splash", j)
+ uci:delete("luci_splash", j)
end
- uci.save_state("luci_splash")
+ uci:save("luci_splash")
end
mac = mac:lower()
local stat = false
- uci.foreach("luci_splash", "lease",
+ uci:foreach("luci_splash", "lease",
function (section)
if section.mac:lower() == mac then
stat = true
function iswhitelisted(mac)
mac = mac:lower()
- uci.foreach("luci_splash", "whitelist",
+ uci:foreach("luci_splash", "whitelist",
function (section)
if section.mac:lower() == mac then
stat = true
local time = os.time()
-- Current leases in state files
- local leases = uci.get_all("luci_splash")
+ local leases = uci:get_all("luci_splash")
-- Convert leasetime to seconds
- local leasetime = tonumber(uci.get("luci_splash", "general", "leasetime")) * 3600
+ local leasetime = tonumber(uci:get("luci_splash", "general", "leasetime")) * 3600
-- Clean state file
- uci.load_state("luci_splash")
- uci.revert("luci_splash")
+ uci:load("luci_splash")
+ uci:revert("luci_splash")
-- For all leases
remove_rule(v.mac)
else
-- Rewrite state
- uci.section("luci_splash", "lease", nil, {
+ uci:section("luci_splash", "lease", nil, {
mac = v.mac,
start = v.start
})
end
end
- uci.save_state("luci_splash")
+ uci:save("luci_splash")
end
main(arg)
\ No newline at end of file