2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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
11 http://www.apache.org/licenses/LICENSE-2.0
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"
21 m = Map("dhcp", "DHCP")
23 s = m:section(TypedSection, "dhcp", "DHCP-Server")
28 s:depends("interface", "lan")
30 enable = s:option(ListValue, "ignore", translate("enable"), "")
31 enable:value(0, translate("enable"))
32 enable:value(1, translate("disable"))
34 start = s:option(Value, "start", translate("m_n_d_firstaddress"))
36 start:depends("ignore", "0")
39 limit = s:option(Value, "limit", translate("m_n_d_numleases"), "")
40 limit:depends("ignore", "0")
42 function limit.cfgvalue(self, section)
43 local value = Value.cfgvalue(self, section)
46 return tonumber(value) + 1
50 function limit.write(self, section, value)
51 value = tonumber(value) - 1
52 return Value.write(self, section, value)
57 time = s:option(Value, "leasetime")
58 time:depends("ignore", "0")
62 local leasefn, leasefp, leases
63 uci:foreach("dhcp", "dnsmasq",
65 leasefn = section.leasefile
68 local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn)
71 for lease in leasefp do
72 table.insert(leases, luci.util.split(lease, " "))
77 v = m:section(Table, leases, translate("dhcp_leases_active"))
78 name = v:option(DummyValue, 4, translate("hostname"))
79 function name.cfgvalue(self, ...)
80 local value = DummyValue.cfgvalue(self, ...)
81 return (value == "*") and "?" or value
83 ip = v:option(DummyValue, 3, translate("ipaddress"))
84 mac = v:option(DummyValue, 2, translate("macaddress"))
85 ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
86 function ltime.cfgvalue(self, ...)
87 local value = DummyValue.cfgvalue(self, ...)
88 return wa.date_format(os.difftime(tonumber(value), os.time()))
92 s2 = m:section(TypedSection, "host", translate("luci_ethers"))
95 s2.template = "cbi/tblsection"
97 name = s2:option(Value, "name", translate("hostname", "Hostname"))
98 mac = s2:option(Value, "mac", translate("macaddress"))
99 ip = s2:option(Value, "ip", translate("ipaddress"))
100 sys.net.arptable(function(entry)
101 ip:value(entry["IP address"])
104 entry["HW address"] .. " (" .. entry["IP address"] .. ")"