luci-0.9: merge r5750
[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 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 local uci = require "luci.model.uci".cursor()
17 local sys = require "luci.sys"
18 local wa = require "luci.tools.webadmin"
19 local fs = require "nixio.fs"
20
21 m2 = Map("dhcp", translate("dhcp_leases"))
22
23 local leasefn, leasefp, leases
24 uci:foreach("dhcp", "dnsmasq",
25 function(section)
26 leasefn = section.leasefile
27 end
28 )
29 local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn)
30 if leasefp then
31 leases = {}
32 for lease in leasefp do
33 table.insert(leases, luci.util.split(lease, " "))
34 end
35 end
36
37 if leases then
38 v = m2:section(Table, leases, translate("dhcp_leases_active"))
39 ip = v:option(DummyValue, 3, translate("ipaddress"))
40
41 mac = v:option(DummyValue, 2, translate("macaddress"))
42
43 ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
44 function ltime.cfgvalue(self, ...)
45 local value = DummyValue.cfgvalue(self, ...)
46 return wa.date_format(os.difftime(tonumber(value), os.time()))
47 end
48 end
49
50 s = m2:section(TypedSection, "host", translate("luci_ethers"))
51 s.addremove = true
52 s.anonymous = true
53 s.template = "cbi/tblsection"
54
55 name = s:option(Value, "name", translate("hostname"))
56 mac = s:option(Value, "mac", translate("macaddress"))
57 ip = s:option(Value, "ip", translate("ipaddress"))
58 sys.net.arptable(function(entry)
59 ip:value(entry["IP address"])
60 mac:value(
61 entry["HW address"],
62 entry["HW address"] .. " (" .. entry["IP address"] .. ")"
63 )
64 end)
65
66
67 return m2