applications/luci-splash: Use a seperate config file for leases, #590
This commit is contained in:
parent
64607feec4
commit
bbc5b2ef69
3 changed files with 13 additions and 12 deletions
|
@ -30,7 +30,7 @@ uci:foreach("dhcp", "dnsmasq",
|
|||
end)
|
||||
|
||||
|
||||
uci:foreach("luci_splash", "lease",
|
||||
uci:foreach("luci_splash_leases", "lease",
|
||||
function(s)
|
||||
if s.start and s.mac then
|
||||
clients[s.mac:lower()] = {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
# This file should always stay empty and is just needed to be able to use this config in /var/state!
|
|
@ -149,7 +149,7 @@ function get_known_macs(list)
|
|||
local leased_macs = { }
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -231,12 +231,12 @@ function add_lease(mac, arp, no_uci)
|
|||
-- Add lease if there is an ip addr
|
||||
if ipaddr 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,
|
||||
ipaddr = ipaddr,
|
||||
start = os.time()
|
||||
})
|
||||
uci:save("luci_splash")
|
||||
uci:save("luci_splash_leases")
|
||||
end
|
||||
add_lease_rule(mac, ipaddr)
|
||||
else
|
||||
|
@ -249,7 +249,7 @@ end
|
|||
function remove_lease(mac)
|
||||
mac = mac:lower()
|
||||
|
||||
uci:delete_all("luci_splash", "lease",
|
||||
uci:delete_all("luci_splash_leases", "lease",
|
||||
function(s)
|
||||
if s.mac:lower() == mac then
|
||||
remove_lease_rule(mac, s.ipaddr)
|
||||
|
@ -258,7 +258,7 @@ function remove_lease(mac)
|
|||
return false
|
||||
end)
|
||||
|
||||
uci:save("luci_splash")
|
||||
uci:save("luci_splash_leases")
|
||||
end
|
||||
|
||||
|
||||
|
@ -363,14 +363,14 @@ function sync()
|
|||
local time = os.time()
|
||||
|
||||
-- Current leases in state files
|
||||
local leases = uci:get_all("luci_splash")
|
||||
local leases = uci:get_all("luci_splash_leases")
|
||||
|
||||
-- Convert leasetime to seconds
|
||||
local leasetime = tonumber(uci:get("luci_splash", "general", "leasetime")) * 3600
|
||||
|
||||
-- Clean state file
|
||||
uci:load("luci_splash")
|
||||
uci:revert("luci_splash")
|
||||
uci:load("luci_splash_leases")
|
||||
uci:revert("luci_splash_leases")
|
||||
|
||||
-- For all leases
|
||||
for k, v in pairs(leases) do
|
||||
|
@ -380,7 +380,7 @@ function sync()
|
|||
remove_lease_rule(v.mac, v.ipaddr)
|
||||
else
|
||||
-- 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,
|
||||
ipaddr = v.ipaddr,
|
||||
start = v.start
|
||||
|
@ -389,7 +389,7 @@ function sync()
|
|||
end
|
||||
end
|
||||
|
||||
uci:save("luci_splash")
|
||||
uci:save("luci_splash_leases")
|
||||
|
||||
-- Get current IPs and MAC addresses
|
||||
local macs = get_known_macs()
|
||||
|
@ -441,7 +441,7 @@ function list()
|
|||
end
|
||||
|
||||
-- Print listings
|
||||
local leases = uci:get_all("luci_splash")
|
||||
local leases = uci:get_all("luci_splash_leases")
|
||||
|
||||
print(string.format(
|
||||
"%-17s %-15s %-9s %-4s %-7s %20s",
|
||||
|
|
Loading…
Reference in a new issue