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

Revision 5743, 1.7 KB (checked in by jow, 3 years ago)

luci-0.9: drop luci_ethers, static lease mgmnt. is now covered by /etc/config/dhcp

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2008 Steven Barth <steven@midlink.org>
5Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
6
7Licensed under the Apache License, Version 2.0 (the "License");
8you may not use this file except in compliance with the License.
9You may obtain a copy of the License at
10
11    http://www.apache.org/licenses/LICENSE-2.0
12
13$Id$
14]]--
15
16local uci = require "luci.model.uci".cursor()
17local sys = require "luci.sys"
18local wa  = require "luci.tools.webadmin"
19local fs  = require "nixio.fs"
20
21m2 = Map("dhcp", translate("dhcp_leases"))
22
23local leasefn, leasefp, leases
24uci:foreach("dhcp", "dnsmasq",
25 function(section)
26    leasefn = section.leasefile
27 end
28) 
29local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn)
30if leasefp then
31    leases = {}
32    for lease in leasefp do
33        table.insert(leases, luci.util.split(lease, " "))
34    end
35end
36
37if 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
48end
49
50s = m2:section(TypedSection, "host", translate("luci_ethers"))
51s.addremove = true
52s.anonymous = true
53s.template = "cbi/tblsection"
54
55name = s:option(Value, "name", translate("hostname"))
56mac = s:option(Value, "mac", translate("macaddress"))
57ip = s:option(Value, "ip", translate("ipaddress"))
58sys.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    )
64end)
65
66   
67return m2
Note: See TracBrowser for help on using the browser.