Several escaping fixes
[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.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         v.anonymous = true
35         v.rowcolors = true
36         
37         ip = v:option(DummyValue, 3, translate("ipaddress"))
38         
39         mac  = v:option(DummyValue, 2, translate("macaddress"))
40         
41         ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
42         function ltime.cfgvalue(self, ...)
43                 local value = DummyValue.cfgvalue(self, ...)
44                 return luci.tools.webadmin.date_format(
45                  os.difftime(tonumber(value), os.time())
46                 )
47         end
48 end
49
50 s = m2:section(TypedSection, "static_lease", translate("luci_ethers"))
51 s.addremove = true
52 s.anonymous = true
53 s.template = "cbi/tblsection"
54
55 mac = s:option(Value, "macaddr", translate("macaddress"))
56 ip = s:option(Value, "ipaddr", translate("ipaddress"))
57 for i, dataset in ipairs(luci.sys.net.arptable()) do
58         ip:value(dataset["IP address"])
59         mac:value(dataset["HW address"],
60          dataset["HW address"] .. " (" .. dataset["IP address"] .. ")")
61 end
62
63         
64 return m2