UCI API changes
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / dhcpleases.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 require("luci.sys")
15 require("luci.tools.webadmin")
16 m2 = Map("luci_ethers", translate("dhcp_leases"))
17
18 local leasefn, leasefp, leases
19 luci.model.uci.cursor():foreach("dhcp", "dnsmasq",
20 function(section)
21 leasefn = section.leasefile
22 end
23 )
24 local leasefp = leasefn and luci.fs.access(leasefn) and io.lines(leasefn)
25 if leasefp then
26 leases = {}
27 for lease in leasefp do
28 table.insert(leases, luci.util.split(lease, " "))
29 end
30 end
31
32 if leases then
33 v = m2:section(Table, leases, translate("dhcp_leases_active"))
34 ip = v:option(DummyValue, 3, translate("ipaddress"))
35
36 mac = v:option(DummyValue, 2, translate("macaddress"))
37
38 ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
39 function ltime.cfgvalue(self, ...)
40 local value = DummyValue.cfgvalue(self, ...)
41 return luci.tools.webadmin.date_format(
42 os.difftime(tonumber(value), os.time())
43 )
44 end
45 end
46
47 s = m2:section(TypedSection, "static_lease", translate("luci_ethers"))
48 s.addremove = true
49 s.anonymous = true
50 s.template = "cbi/tblsection"
51
52 mac = s:option(Value, "macaddr", translate("macaddress"))
53 ip = s:option(Value, "ipaddr", translate("ipaddress"))
54 for i, dataset in ipairs(luci.sys.net.arptable()) do
55 ip:value(dataset["IP address"])
56 mac:value(dataset["HW address"],
57 dataset["HW address"] .. " (" .. dataset["IP address"] .. ")")
58 end
59
60
61 return m2