modules/admin-full: Added support for interface aliases
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / dhcp.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.model.uci")
15 require("luci.sys")
16 require("luci.util")
17
18 m = Map("dhcp", "DHCP")
19
20 s = m:section(TypedSection, "dhcp", "")
21 s.addremove = true
22 s.anonymous = true
23
24 iface = s:option(ListValue, "interface", translate("interface"))
25 luci.model.uci.foreach("network", "interface",
26 function (section)
27 if section[".name"] ~= "loopback" then
28 iface.default = iface.default or section[".name"]
29 iface:value(section[".name"])
30 s:depends("interface", section[".name"])
31 end
32 end)
33
34 luci.model.uci.foreach("network", "alias",
35 function (section)
36 iface:value(section[".name"])
37 s:depends("interface", section[".name"])
38 end)
39
40 s:option(Value, "start", translate("start")).rmempty = true
41
42 s:option(Value, "limit", translate("limit")).rmempty = true
43
44 s:option(Value, "leasetime").rmempty = true
45
46 s:option(Flag, "dynamicdhcp").rmempty = true
47
48 s:option(Value, "name", translate("name")).optional = true
49
50 s:option(Flag, "ignore").optional = true
51
52 s:option(Value, "netmask", translate("netmask")).optional = true
53
54 s:option(Flag, "force").optional = true
55
56 for i, line in pairs(luci.util.execl("dnsmasq --help dhcp")) do
57 k, v = line:match("([^ ]+) +([^ ]+)")
58 s:option(Value, "dhcp"..k, v).optional = true
59 end
60
61 m2 = Map("luci_ethers", translate("luci_ethers"))
62
63 s = m2:section(TypedSection, "static_lease", "")
64 s.addremove = true
65 s.anonymous = true
66 s.template = "cbi/tblsection"
67
68 mac = s:option(Value, "macaddr", translate("macaddress"))
69 ip = s:option(Value, "ipaddr", translate("ipaddress"))
70 for i, dataset in ipairs(luci.sys.net.arptable()) do
71 ip:value(dataset["IP address"])
72 mac:value(dataset["HW address"],
73 dataset["HW address"] .. " (" .. dataset["IP address"] .. ")")
74 end
75
76
77 return m, m2