applications/luci-splash: Use a seperate config file for leases, #590
authorManuel Munz <freifunk@somakoma.de>
Sun, 11 Aug 2013 16:42:53 +0000 (16:42 +0000)
committerManuel Munz <freifunk@somakoma.de>
Sun, 11 Aug 2013 16:42:53 +0000 (16:42 +0000)
applications/luci-splash/luasrc/view/admin_status/splash.htm
applications/luci-splash/root/etc/config/luci_splash_leases [new file with mode: 0644]
applications/luci-splash/root/usr/sbin/luci-splash

index 56cbe01..61b32ba 100644 (file)
@@ -30,7 +30,7 @@ uci:foreach("dhcp", "dnsmasq",
        end)
 
 
        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()] = {
        function(s)
                if s.start and s.mac then
                        clients[s.mac:lower()] = {
diff --git a/applications/luci-splash/root/etc/config/luci_splash_leases b/applications/luci-splash/root/etc/config/luci_splash_leases
new file mode 100644 (file)
index 0000000..6afdd90
--- /dev/null
@@ -0,0 +1 @@
+# This file should always stay empty and is just needed to be able to use this config in /var/state!
index 34b2e9c..e4fa6e7 100755 (executable)
@@ -149,7 +149,7 @@ function get_known_macs(list)
        local leased_macs = { }
 
        if not list or list == "lease" then
        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
 
                        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
        -- 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()
                        })
                                mac    = mac,
                                ipaddr = ipaddr,
                                start  = os.time()
                        })
-                       uci:save("luci_splash")
+                       uci:save("luci_splash_leases")
                end
                add_lease_rule(mac, ipaddr)
        else
                end
                add_lease_rule(mac, ipaddr)
        else
@@ -249,7 +249,7 @@ end
 function remove_lease(mac)
        mac = mac:lower()
 
 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)
                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)
                
                        return false
                end)
                
-       uci:save("luci_splash")
+       uci:save("luci_splash_leases")
 end
 
 
 end
 
 
@@ -363,14 +363,14 @@ function sync()
        local time = os.time()
 
        -- Current leases in state files
        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
        
        -- 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
        
        -- 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
                                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
                                        mac    = v.mac,
                                        ipaddr = v.ipaddr,
                                        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
        local macs = get_known_macs()
 
        -- Get current IPs and MAC addresses
        local macs = get_known_macs()
@@ -441,7 +441,7 @@ function list()
        end
 
        -- Print listings
        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",
 
        print(string.format(
                "%-17s  %-15s  %-9s  %-4s  %-7s  %20s",