applications/luci-splash: Use a seperate config file for leases, #590

This commit is contained in:
Manuel Munz 2013-08-11 16:42:53 +00:00
parent 64607feec4
commit bbc5b2ef69
3 changed files with 13 additions and 12 deletions

View file

@ -30,7 +30,7 @@ uci:foreach("dhcp", "dnsmasq",
end) end)
uci:foreach("luci_splash", "lease", uci:foreach("luci_splash_leases", "lease",
function(s) function(s)
if s.start and s.mac then if s.start and s.mac then
clients[s.mac:lower()] = { clients[s.mac:lower()] = {

View file

@ -0,0 +1 @@
# This file should always stay empty and is just needed to be able to use this config in /var/state!

View file

@ -149,7 +149,7 @@ function get_known_macs(list)
local leased_macs = { } local leased_macs = { }
if not list or list == "lease" then if not list or list == "lease" then
uci:foreach("luci_splash", "lease", uci:foreach("luci_splash_leases", "lease",
function(s) leased_macs[s.mac:lower()] = true end) function(s) leased_macs[s.mac:lower()] = true end)
end end
@ -231,12 +231,12 @@ function add_lease(mac, arp, no_uci)
-- Add lease if there is an ip addr -- Add lease if there is an ip addr
if ipaddr then if ipaddr then
if not no_uci then if not no_uci then
uci:section("luci_splash", "lease", convert_mac_to_secname(mac), { uci:section("luci_splash_leases", "lease", convert_mac_to_secname(mac), {
mac = mac, mac = mac,
ipaddr = ipaddr, ipaddr = ipaddr,
start = os.time() start = os.time()
}) })
uci:save("luci_splash") uci:save("luci_splash_leases")
end end
add_lease_rule(mac, ipaddr) add_lease_rule(mac, ipaddr)
else else
@ -249,7 +249,7 @@ end
function remove_lease(mac) function remove_lease(mac)
mac = mac:lower() mac = mac:lower()
uci:delete_all("luci_splash", "lease", uci:delete_all("luci_splash_leases", "lease",
function(s) function(s)
if s.mac:lower() == mac then if s.mac:lower() == mac then
remove_lease_rule(mac, s.ipaddr) remove_lease_rule(mac, s.ipaddr)
@ -258,7 +258,7 @@ function remove_lease(mac)
return false return false
end) end)
uci:save("luci_splash") uci:save("luci_splash_leases")
end end
@ -363,14 +363,14 @@ function sync()
local time = os.time() local time = os.time()
-- Current leases in state files -- Current leases in state files
local leases = uci:get_all("luci_splash") local leases = uci:get_all("luci_splash_leases")
-- Convert leasetime to seconds -- 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 -- Clean state file
uci:load("luci_splash") uci:load("luci_splash_leases")
uci:revert("luci_splash") uci:revert("luci_splash_leases")
-- For all leases -- For all leases
for k, v in pairs(leases) do for k, v in pairs(leases) do
@ -380,7 +380,7 @@ function sync()
remove_lease_rule(v.mac, v.ipaddr) remove_lease_rule(v.mac, v.ipaddr)
else else
-- Rewrite state -- Rewrite state
uci:section("luci_splash", "lease", convert_mac_to_secname(v.mac), { uci:section("luci_splash_leases", "lease", convert_mac_to_secname(v.mac), {
mac = v.mac, mac = v.mac,
ipaddr = v.ipaddr, ipaddr = v.ipaddr,
start = v.start start = v.start
@ -389,7 +389,7 @@ function sync()
end end
end end
uci:save("luci_splash") uci:save("luci_splash_leases")
-- Get current IPs and MAC addresses -- Get current IPs and MAC addresses
local macs = get_known_macs() local macs = get_known_macs()
@ -441,7 +441,7 @@ function list()
end end
-- Print listings -- Print listings
local leases = uci:get_all("luci_splash") local leases = uci:get_all("luci_splash_leases")
print(string.format( print(string.format(
"%-17s %-15s %-9s %-4s %-7s %20s", "%-17s %-15s %-9s %-4s %-7s %20s",