root/luci/branches/luci-0.9/modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua @ 5118

Revision 5118, 1.6 KB (checked in by jow, 4 years ago)

luci-0.9: merge r5027 - r5112

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